The most concise Java solution possible


  • 2
    C

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


  • 0
    K

    @CookBoom You forgot to use the three ticks to properly insert code

    void ItLooks()
    {
        like.this()
    }
    

    Your blocks aren't indented at all.


Log in to reply
 

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