3 lines accepted Java O(n) space DP solution


  • -3
    B
    public int calculateMinimumHP(int[][] d) {
        int[] h = new int[d[0].length];
        for (int i = d.length - 1; i >= 0; i--) for (int j = d[0].length - 1; j >= 0; j--) h[j] = Math.max(1, Math.min(i == d.length - 1 ? Integer.MAX_VALUE : h[j], j == h.length - 1 ? (i == d.length - 1 ? 1 : Integer.MAX_VALUE) : h[j + 1]) - d[i][j]);
        return h[0];
    }

  • 1
    H

    I'm not sure why people fancy bare minimum line solutions so much. In an interview situation, your interviewer would probably be very discontent about your code.


  • 1
    J

    Not cool to call this 3 liner.


Log in to reply
 

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