(1) Two Sum - LeetCode (Return Indices)

PHOTO EMBED

Thu Aug 12 2021 08:48:54 GMT+0000 (UTC)

Saved by @MorningStar #c++

class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        vector<int> I;
        
        int y;
        for (int x=0; x<nums.size(); x++)
        {
            y=0;
            for (int z=x+1; z<nums.size(); z++)
            {
                y=nums[x]+nums[z];
            if(y==target)
            {
                I.push_back(x);
                I.push_back(z);
                break;
            }
            }
               
            
                
        }
        
        return I;
    }
};
content_copyCOPY

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