[Java] LeetCode 455 : Assign Cookies
LeetCode # 455 Example 1: Input: g = [1,2,3], s = [1,1] Output: 1 Explanation: You have 3 children and 2 cookies. The greed factors of 3 children are 1, 2, 3. And even though you have 2 cookies, since their size is both 1, you could only make the child whose greed factor is 1 content. You need to output 1. Example 2: Input: g = [1,2], s = [1,2,3] Output: 2 Explanation: You have 2 children and 3 ..
2021. 5. 14.
[Java] LeetCode 561 : Array Partition I
LeetCode # 561 Example 1: Input: nums = [1,4,3,2] Output: 4 Explanation: All possible pairings (ignoring the ordering of elements) are: 1. (1, 4), (2, 3) -> min(1, 4) + min(2, 3) = 1 + 2 = 3 2. (1, 3), (2, 4) -> min(1, 3) + min(2, 4) = 1 + 2 = 3 3. (1, 2), (3, 4) -> min(1, 2) + min(3, 4) = 1 + 3 = 4 So the maximum possible sum is 4. Example 2: Input: nums = [6,2,6,5,1,2] Output: 9 Explanation: T..
2021. 5. 14.
[Java] LeetCode 989 : Add to Array-Form of Integer
LeetCode # 989 Example 1: Input: num = [1,2,0,0], k = 34 Output: [1,2,3,4] Explanation: 1200 + 34 = 1234 Example 2: Input: num = [9,9,9,9,9,9,9,9,9,9], k = 1 Output: [1,0,0,0,0,0,0,0,0,0,0] Explanation: 9999999999 + 1 = 10000000000 Constraints: 1 = 0 || sum > 0) { if (i >= 0) sum += (num[i]); list.addFirst(sum % 10); sum /= 10; i--; } return list; } } Result #2 💡 ArrayList에서 LinkedList로 자료형 변경 L..
2021. 5. 13.