Skip to content

Latest commit

 

History

History
21 lines (21 loc) · 532 Bytes

1. Two Sum.md

File metadata and controls

21 lines (21 loc) · 532 Bytes
//644ms
class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        sort( nums.begin() , nums.end());
        int length = nums.size();
        vector <int> ans;
        for ( int i = 0 ; i < length ; i++ ) {
            for ( int j = i + 1 ; j < length ; j++) {
                if ( nums[i] + nums[j] == target) {
                    ans.push_back( i );
                    ans.push_back( j );
                    break;
                }
            }
        }
        return ans;
    }
};