Skip to content

Latest commit

 

History

History
22 lines (22 loc) · 596 Bytes

File metadata and controls

22 lines (22 loc) · 596 Bytes

寻找重复数

思路

  • 遍历,当前的和后面的下标值相比
class Solution {
public:
    int findDuplicate(vector<int>& nums) {
        if(nums.size()<1) return 0;
        int tmp;
        for(int i = 0; i < nums.size() - 1; i++){
            tmp = nums[i];
            for(int j = i+1; j < nums.size(); j++){
                if(nums[j] == tmp) {
                    return tmp;
                }  
            }
        }
        return 0;
    }
};