๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿš“ Self Study/๐Ÿ”“ LeetCode

LeetCode (Two Sum) C++

by UKHYUN22 2022. 1. 7.
728x90

 

class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        vector<int> answer;
        
        for(int i = 0 ; i < nums.size() - 1 ; 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;
    }
};

 

'๐Ÿš“ Self Study > ๐Ÿ”“ LeetCode' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

LeetCode (Add two numbers) C++  (0) 2022.01.07
LeetCode (Employee Importance) C++  (0) 2022.01.06
LeetCode (Sum of Left Leaves) C++  (0) 2022.01.06