Post

leetcode(리트코드)287-Find the Duplicate Number

leetcode 287 - Find the Duplicate Number 문제입니다.

1. 문제

https://leetcode.com/problems/find-the-duplicate-number/


2. Input , Output


3. 분류 및 난이도

Medium 난이도 문제입니다.
leetcode Top 100 Liked 문제입니다.


4. 문제 해석

  • 배열이 들어옵니다. 반복되는 요소가 있는데, 그 요소를 찾아 값을 리턴합니다.

5. code

c++

1
2
3
4
5
6
7
8
9
10
class Solution {
public:
    int findDuplicate(vector<int>& nums) {
        sort(nums.begin(),nums.end());
        for(size_t i = 0 ; i<nums.size();++i){
            if(nums[i]==nums[i+1]) return nums[i];
        }
    return 0;
    }
};

6. 결과 및 후기, 개선점

c++ 73%

This post is licensed under CC BY 4.0 by the author.