problem
找出陣列中是否一個重複的數字,如果有任何數字出現至少兩次則返回true,每個數字都不同則返回false
Solution
sorting
可以先sort 是否有前後兩元素相同
1  | class Solution {  | 
hash table
set or map
1  | class Solution {  | 
analysis
- sorting
- time complexity 
O(nlogn) - space complexity 
O(1) 
 - time complexity 
 - hash table
- time complexity 
O(n)assuming set find operation cost const time - space complexity 
O(n) 
 - time complexity