본문 바로가기
개발/Coding Test

[LeetCode 1] Two Sum

by Eunduck 2022. 6. 7.
728x90

안녕하십니까. Eun🦆입니다.

풀이법 입니다.

 

 

Two Sum - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        vector<int> answer;
        for(int i=0;i<nums.size();i++)
        {
            for(int j=i+1;j<nums.size();j++)
            {
                if(nums[i]+nums[j]==target)
                {
                    answer.push_back(i);
                    answer.push_back(j);
                    return answer;
                }
            }
        }
        return answer;
    }
};

 

네이버 블로그 리뉴얼입니다.

(https://blog.naver.com/unsuk1/222036043633)

728x90

댓글