본문 바로가기
IT/알고리즘

41] Leetcode 1. Two Sum

by 깻잎쌈 2020. 8. 18.
반응형

https://leetcode.com/problems/two-sum/

 

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>ans;
        
        for(int i = 0;i<nums.size();i++)
            for(int j = i+1; j<nums.size(); j++)
                if(nums[i]+nums[j] == target){
                    ans.push_back(i);
                    ans.push_back(j);
                }
        
        return ans;
                    
                    
    }
};
반응형

댓글