LeetCode

1365. How Many Numbers Are Smaller Than the Current Number

LeetCode の挑戦ログ Problem https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number/ 数字の配列が与えられる それぞれの値より少ない値がいくつ含まれているか数える その数を同じ index の配列にして返す Solution class …

1207. Unique Number of Occurrences

LeetCode の挑戦ログ Problem https://leetcode.com/problems/unique-number-of-occurrences/ 整数の配列を渡される 値の登場回数がユニークで構成される場合は true を返す Solution class Solution { public boolean uniqueOccurrences(int[] arr) { Map<Integer, Long> m</integer,>…

977. Squares of a Sorted Array

LeetCode の挑戦ログ Problem https://leetcode.com/problems/squares-of-a-sorted-array/ 整数の昇順でソートされた配列が渡される 各要素を自乗して、それを昇順でソートした配列にする Solution class Solution { public int[] sortedSquares(int[] A) { …

617. Merge Two Binary Trees

LeetCode の挑戦ログ Problem https://leetcode.com/problems/merge-two-binary-trees/ 2つのバイナリツリーを同階層でマージしたツリーを作る Solution /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; …

657. Robot Return to Origin

LeetCode の挑戦ログ Problem https://leetcode.com/problems/robot-return-to-origin/ 座標位置を上下左右に動かす指示が文字列で与えられる R (right), L (left), U (up), and D (down) 元の位置 (0, 0) に戻っていたら true , 戻っていなければ false を…

728. Self Dividing Numbers

LeetCode の挑戦ログ Problem https://leetcode.com/problems/self-dividing-numbers/ 整数の範囲が渡される 範囲の中から、自身の桁ごとの数字で割り切れる値を抽出する 0 を含む値は除外する Solution class Solution { public List<Integer> selfDividingNumbers(i</integer>…

627. Swap Salary

LeetCode の挑戦ログ Problem https://leetcode.com/problems/swap-salary/ salary テーブルの性別を入れ替える f の行は m に m の行は f に Solution UPDATE salary SET sex = ( CASE WHEN sex = 'f' THEN 'm' ELSE 'f' END ); Impressions CASE 文便利

961. N-Repeated Element in Size 2N Array

LeetCode の挑戦ログ Problem https://leetcode.com/problems/n-repeated-element-in-size-2n-array/ 2N サイズの配列が与えられる N+1 種類の整数が含まれている 一つの要素が N 回繰り返されている N 回繰り返されてる数を特定する Solution class Solutio…

905. Sort Array By Parity

LeetCode の挑戦ログ Problem https://leetcode.com/problems/sort-array-by-parity/ 正の整数からなる配列を渡される 偶数 -> 奇数の順にソートする 偶数 -> 奇数であれば他の順序は問わない Solution class Solution { public int[] sortArrayByParity(int…

832. Flipping an Image

LeetCode の挑戦ログ Problem https://leetcode.com/problems/flipping-an-image/ バイナリマトリックス(二次元配列)が渡される 各行をひっくり返した後、反転させる Solution class Solution { public int[][] flipAndInvertImage(int[][] A) { return Ar…

1299. Replace Elements with Greatest Element on Right Side

LeetCode の挑戦ログ Problem https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side/ 配列の右側で最大の値に置き換えた配列を作成する 配列の最後に -1 をつける Solution class Solution { public int[] replaceElements(…