发布时间:2013-12-23 11:21:22
DP。二维数组isIntr[i][j]表示s3前i+j个字符是否是s1前i个字符与s2前j个字符的interleaving。那么有如下关系式isIntr[i][j]=((isIntr[i-1][j]&&s1[i-1]==s3[i+j-1])||(isIntr[i][j-1]&&s2[j-1]==s3[i+j-1]));最后isIntr[s1.length()][s2.length()]即为结果。点击(此处)折叠或打开class S.........【阅读全文】
发布时间:2013-12-22 18:03:49
中序遍历的话BST应该递增,那么在中序遍历过程中检查是否有节点违反这一规则即可。点击(此处)折叠或打开/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; *.........【阅读全文】
发布时间:2013-12-19 17:26:52
点击(此处)折叠或打开/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), r.........【阅读全文】
发布时间:2013-12-13 10:45:05
递归检查每个节点其左右子树最大深度差不超过1即可。点击(此处)折叠或打开/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right;.........【阅读全文】
发布时间:2013-12-10 10:54:05
点击(此处)折叠或打开/** * Definition for binary tree with next pointer. * struct TreeLinkNode { * int val; * TreeLinkNode *left, *right, *next; * TreeLinkNode(int x) : val(x), left.........【阅读全文】