Issue with my code ?


  • -2
    R
            int answer = 0;
            for(int i = 0; i < triangle.size(); i++){
                List<Integer> arr = new ArrayList<>();
                arr = triangle.get(i);
    //Sort the array
                arr.sort((o1, o2) -> o1.compareTo(o2));
                answer += arr.get(0);
            }
    
            return answer;
    

    following test case is failing
    Input:
    [[-1],[2,3],[1,-1,-3]]
    Output:
    -2
    Expected:
    -1

    lowest value is -1, 2, -3, thn how it is expected to be -1


  • 0

    Two things you can do better next time:

    • format your code properly using ```
    • present your programming language which will be easier for others to help you out

  • 0

    @rahil3 After formatting your code myself, I am stunned...what are you trying to ask? Post your complete code next time!!!


Log in to reply
 

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