摘要:        
先序遍历的一个变化。记录下上次的节点就行了。public class Solution { public void flatten(TreeNode root) { Stack stack = new Stack(); TreeNode n = root; TreeNode last = null; while (n != null || !stack.empty()) { if (n != null) { if (last != null) { ...    阅读全文
posted @ 2013-08-19 13:48
阿牧遥
阅读(190)
评论(0)
推荐(0)
        
            
        
        
摘要:        
动态规划。不过一开始老是把循环中的i写成n。有的时候会忘记i是循环中的边界。public class Solution { public int numTrees(int n) { if (n ==0) return 0; int sum[] = new int[n+1]; sum[1] = 1; for (int i = 2; i <= n; i++) { int total = 0; for (int j = 1; j <=i; j++) { if (j ...    阅读全文
posted @ 2013-08-19 00:24
阿牧遥
阅读(206)
评论(0)
推荐(0)
        
            
        
        
摘要:        
简单题。不过又出现了一次初始状态设置的错误,当numRows==0时所作的设置,numRows==1时也需要。但一开始放到if block里面去了。public class Solution { public ArrayList> generate(int numRows) { ArrayList> ans = new ArrayList>(); if (numRows == 0) return ans; ArrayList tmp = new ArrayList(); tmp.add(1); ans.add(tmp)...    阅读全文
posted @ 2013-08-19 00:00
阿牧遥
阅读(218)
评论(0)
推荐(0)
        
 
                     
                    
                 
                    
                
 
         浙公网安备 33010602011771号
浙公网安备 33010602011771号