摘要:
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value./** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; *... 阅读全文
摘要:
[解题思路]创建一个新的interval集合,然后每次从旧的里面取一个interval出来,然后插入到新的集合中。没什么好说的,遍历已有vector,如果当前interval小于newinterval,插入当前;如果当前interval大于newInterval,则插入newInterval及当前;如果两者重叠,merge以后插入新的interval。实现中之所以重新new了一个vector来存放结果的原因,是不愿意破坏传入参数。在原有的vector上面直接修改的话,唯一的区别就是,一旦发现当前interval大于newInterval,就应该return了。/** * Definition 阅读全文
摘要:
Implement regular expression matching with support for'.'and'*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input string (not partial).The function prototype should be:bool isMatch(const char 阅读全文
摘要:
public class Solution { public int romanToInt(String s) { int result = 0; if(s == null || s.length() == 0){ return result; } for(int i = 0; i 0 && cToI(s.charAt(i)) > cToI(s.charAt(i-1))){ // IV(4) result = 1 + 5 - 1*2 = 4 ... 阅读全文
摘要:
Solution andPrecautions:Very similar to the classical merger sort for two sorted arrays, since the k linked list are already sorted, we just find the smallest number among the heads list[i][0] (i=0,…k-1), of course, if some list already reached to the end, that is list[i][0] is NULL, we just ignore 阅读全文
摘要:
Then-queens puzzle is the problem of placingnqueens on ann×nchessboard such that no two queens attack each other.Given an integern, return all distinct solutions to then-queens puzzle.Each solution contains a distinct board configuration of then-queens' placement, where'Q'and'.& 阅读全文
摘要:
Givens1,s2,s3, find whethers3is formed by the interleaving ofs1ands2.For example,Given:s1="aabcc",s2="dbbca",Whens3="aadbbcbcac", return true.Whens3="aadbbbaccc", return false.[解题思路]分析题目给定3个字符串(s1,s2,s3),看s3是否是有s1和s2通过交织可以得到。可以这么来看这个问题,每次从s3开头拿出来一个字符,如果s1的开头或者 阅读全文