1ms java O(k) space beats 90%


  • 1
    C
    public class Solution {
        public List<Integer> getRow(int rowIndex) {
            int n = rowIndex;
            int[] tmp = new int[2*n+3];
            tmp[n+1] = 1;
            int left = n+1, right = n+1;
            while (n-- > 0) {
                --left;
                ++right;
                for (int i = left; i <= right; i += 2) {
                    tmp[i] = tmp[i-1] + tmp[i+1];
                }
            }
            List<Integer> ret = new ArrayList<>();
            for (int i = left; i <= right; i += 2) {
                ret.add(tmp[i]);
            }
            return ret;
        }
    }

  • 0
    C

    Why does this solution only take 1ms? It seems to be more complex than the solution at https://leetcode.com/discuss/43757/another-accepted-java-solution


  • 0
    C

    I suppose the solution you mentioned should also take 1ms or less, no?


Log in to reply
 

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