Java solution - accepted


  • 0
    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;
            
        }
    }
    

Log in to reply
 

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