Description:
Basically, we will look into the array, and then find out if there are same numbers. If there is a duplication in array, then we return "True", or not then "False".
Solution1(not Answer):
Time Complexity for this algorithms O(N^2). In contrast, space complexity is O(1). When you submit this method, you can see the time complexity exceed for some case! That's definitely doesn't work.
Solution2(not Answer):
This solution doesn't work for some case, and get wrong answer.
Solution3:
The third solution is using set() in python. We actually made a set, and put the nums in it if it doesn't exist in seen. If there is a num already in seen and find out there are one duplicated number in nums, then return True.
Space complexity: O(N)
Time complexity: O(N)
Addition:
I used the list instead of set(), but it exceeded the time limit. I learned that it is much faster to find some value in set or dict in this case!
'LeetCode ๐๏ธ > Array' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
152. Maximum Product Subarray (0) | 2023.05.28 |
---|---|
53. Maximum Subarray (0) | 2023.05.27 |
238. Product of Array Except Self (0) | 2023.01.29 |
121. Best Time to Buy and Sell Stock (0) | 2023.01.28 |
1. Two Sum (0) | 2023.01.24 |