1. Description
Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums.
constraints :
- n == nums.length
- 1 <= n <= \(10^{5}\)
- 1 <= nums[i] <= n
2. Algorithms
- Start
- Store the length of input nums into variable name "n".
- Declare set data structure named all_nums. This variable will store all integers range in 1 to n.
- Make set from input nums.
- Calculate difference between all_nums and nums, and return the difference in list.
- End
3. Codes
class Solution:
def findDisappearedNumbers(self, nums: List[int]) -> List[int]:
n = len(nums)
all_nums = set(range(1, n+1))
nums = set(nums)
return all_nums - nums
4. Conclusion
'LeetCode > Easy' 카테고리의 다른 글
459 Repeated Substring Pattern (0) | 2022.08.30 |
---|---|
455 Assign Cookies (0) | 2022.08.30 |
441 Arranging Coins (0) | 2022.08.30 |
434 Number of Segments in a String (0) | 2022.08.30 |
415 Add Strings (0) | 2022.08.30 |