Monthly Archives: May 2017

  1. Boundary of Binary Tree

    Leave a comment

    May 26, 2017 by oneOokay

    Given a binary tree, return the values of its boundary in anti-clockwise direction starting from root. Boundary includes left boundary, …
    Continue reading

  2. Binary Tree Longest Consecutive Sequence II

    Leave a comment

    May 26, 2017 by oneOokay

    Given a binary tree, you need to find the length of Longest Consecutive Path in Binary Tree. Especially, this path …
    Continue reading

  3. Shortest Unsorted Continuous Subarray

    Leave a comment

    May 25, 2017 by oneOokay

    Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending …
    Continue reading

  4. Edit Distance

    Leave a comment

    May 25, 2017 by oneOokay

    Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation …
    Continue reading

  5. 二维矩阵int[][] tips

    Leave a comment

    May 24, 2017 by oneOokay

    一个二维矩阵int[][] : m X n 在不另建class的情况下: Queue<int[]> queue = new LinkedList<int[]>();  queue里面直接放一个Int[2]代表一个点 queue.offer(new int[]{x, y}); queue.offer(start); //if start 是一个int[2] boolean[][] …
    Continue reading

  6. Generate Parentheses

    Leave a comment

    May 14, 2017 by oneOokay

    Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = …
    Continue reading

  7. Spiral Matrix

    Leave a comment

    May 14, 2017 by oneOokay

    不写下来我会忘…如何像削苹果皮一样一圈一圈地把一个matrix给剥出一层皮… 需要四个值: rowStart, rowEnd, colStart, colEnd.这四个值在traversal的时候用来限定范围. 一个while loop剥一层: while loop里面的start和end是要取等的,这样才能够取到最中间的奇数元素. while loop里面四个for-loop分别: 从左到右剥完第一行(所以这里其实剥掉了左右一列的第一个元素) 从上到下剥完除第一行最后一个元素以外的最后一列(这里也剥掉了最后一行到最后一个元素) 从右到左剥完最后一行(这里剥掉了第一列的最后一个元素) 从下到上剥完第一列剩余的元素(第一列的第一个元素在第一个for-loop里面剥完了,第一列的最后一个元素在上一个for-loop里面剥完了) public List spiralOrder(int[][] matrix) …
    Continue reading