摘要:
class Solution { public void recoverTree(TreeNode root) { TreeNode cur=root,pre=null,node1=null,node2=null, p=null; while(cur!=null) { if(cur.left!=null) ... 阅读全文
摘要:
public class Solution { public boolean isValidBST(TreeNode root) { Stack stack=new Stack(); TreeNode cur=null; while(root!=null||!stack.isEmpty()) { ... 阅读全文
摘要:
class Solution { public boolean isInterleave(String s1, String s2, String s3) { if(s1.length()+s2.length()!=s3.length()) return false; boolean [][] dp=new boolean[s1.l... 阅读全文
摘要:
public class Solution { public int numTrees(int n) { int[] dp=new int[n+1]; dp[0]=1; dp[1]=1; for(int i=2;i<=n;i++) for(int j=1;j<=i;j++) ... 阅读全文
摘要:
class Solution { public List generateTrees(int n) { if(n==0) return new ArrayList(); return generateTrees(1, n); } private List generateTrees(int i, int j) { ... 阅读全文
摘要:
public class Solution { public List inorderTraversal(TreeNode root) { List res=new ArrayList(); Stack stack=new Stack(); while(root!=null||!stack.isEmpty()) { ... 阅读全文
摘要:
class Solution { public List restoreIpAddresses(String s) { List res=new ArrayList(); restoreIpAddresses("", 0, 0, s, res); return res; } private void restoreIpAdd... 阅读全文