數字對兒 去重(18今日頭條春招筆試題)

思路一:建立數組,二重循環枚舉遍歷,將差值爲k的數組對象存入set的pair中去重,最後輸出set的size。---時間複雜度爲O(n^2) 思路二: 用哈希表和計數器。 ---時間複雜度爲O(n) 下面爲思路二的解:ios #include<iostream> #include<unordered_set> using namespace std; int main() { int n,k,d
相關文章
相關標籤/搜索