Some Question About Two Sum In C++


  • -1
    C

    class Solution

    {

    public:

    int[] twoSum(int[] nums, int target)
    
    {
    
        for (int i = 0; i < nums.length; i++)
    
        {
    
            for (int j = i + 1; j < nums.length; j++)
    
            {
    
                if (nums[j] == target - nums[i])
    
                {
    
                    return new int[] { i, j };
    
                }
    
            }
    
        }
    
        throw new IllegalArgumentException("No two sum solution");
    
    }
    

    };

    I copied the answer, but it still doesn't work...


  • 0
    D

    It's written by Java, but not c++.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.