Algorithm
-
[Leetcode] 1742. Maximum Number of Balls in a BoxAlgorithm/LeetCode 2021. 9. 23. 16:49
You are working in a ball factory where you have n balls numbered from lowLimit up to highLimit inclusive (i.e., n == highLimit - lowLimit + 1), and an infinite number of boxes numbered from 1 to infinity. Your job at this factory is to put each ball in the box with a number equal to the sum of digits of the ball's number. For example, the ball number 321 will be put in the box number 3 + 2 + 1 ..
-
[Leetcode] 1748. Sum of Unique ElementsAlgorithm/LeetCode 2021. 8. 22. 17:02
You are given an integer array nums. The unique elements of an array are the elements that appear exactly once in the array. Return the sum of all the unique elements of nums. Example 1: Input: nums = [1,2,3,2] Output: 4 Explanation: The unique elements are [1,3], and the sum is 4. Example 2: Input: nums = [1,1,1,1,1] Output: 0 Explanation: There are no unique elements, and the sum is 0. Example..
-
[Leetcode] 961. N-Repeated Element in Size 2N ArrayAlgorithm/LeetCode 2021. 8. 22. 16:35
You are given an integer array nums with the following properties: nums.length == 2 * n. nums contains n + 1 unique elements. Exactly one element of nums is repeated n times. Return the element that is repeated n times. Example 1: Input: nums = [1,2,3,3] Output: 3 Example 2: Input: nums = [2,1,2,5,3,2] Output: 2 Example 3: Input: nums = [5,1,5,2,5,3,5,4] Output: 5 Constraints: 2
-
[Python] List Comprehension to DictAlgorithm 2021. 8. 21. 11:41
list comprehenion 으로 dict 구조 만들기 #1 몸풀기 arr = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], ] squared_list = [[n ** 2 for n in row] for row in arr] print(squared_list) [[1, 4, 9], [16, 25, 36], [49, 64, 81], [100, 121, 144]] #2 본론 from string import ascii_lowercase as LOWERS dict_boy = {c: n for c, n in zip(LOWERS, range(1, 27))} print(dict_boy) {'a': 1, 'b': 2, 'c': 3, ..., 'x': 24, 'y': 25, ..