Java solution - accepted


  • 1
    N
    public class Solution {
        public int[] twoSum(int[] nums, int target) {
            int i;
            int j;
            int size = nums.length;
            int[] result = new int[2];
            
            for( i = 0; i < size; i++ )
            {
                for ( j = i+1; j < size; j++)
                {
                    if(nums[i] + nums[j] == target)
                    {
                        result[0] = i;
                        result[1] = j;
                        break;
                    }
                    
                }
                
            }
            return result;
            
        }
    }
    

  • 0
    T

    This solution worked on all the recent test cases, whereas the top Java submissions have not. Thank you!


Log in to reply
 

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