leetcode 217 存在重复元素
一、问题描述
二、解题思路
使用哈希表对字符串中字符出现的次数进行记录,如果出现次数大于等于2则返回true。
三、代码实现
时间复杂度:T(n)=O(n)
空间复杂度:S(n)=O(n)
class Solution {
public:bool containsDuplicate(vector<int>& nums) {//哈希表unordered_map<int,int> hash;for(auto x:nums){hash[x]++;if(hash[x]==2) return true;}return false;}
};