上一页 1 ··· 8 9 10 11 12 13 14 15 16 下一页
摘要: 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; *... 阅读全文
posted @ 2014-01-28 16:15 Razer.Lu 阅读(101) 评论(0) 推荐(0) 编辑
摘要: [解题思路]创建一个新的interval集合,然后每次从旧的里面取一个interval出来,然后插入到新的集合中。没什么好说的,遍历已有vector,如果当前interval小于newinterval,插入当前;如果当前interval大于newInterval,则插入newInterval及当前;如果两者重叠,merge以后插入新的interval。实现中之所以重新new了一个vector来存放结果的原因,是不愿意破坏传入参数。在原有的vector上面直接修改的话,唯一的区别就是,一旦发现当前interval大于newInterval,就应该return了。/** * Definition 阅读全文
posted @ 2014-01-28 14:44 Razer.Lu 阅读(207) 评论(0) 推荐(0) 编辑
摘要: 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 阅读全文
posted @ 2014-01-28 14:29 Razer.Lu 阅读(721) 评论(0) 推荐(1) 编辑
摘要: 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 ... 阅读全文
posted @ 2014-01-28 13:58 Razer.Lu 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 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 阅读全文
posted @ 2014-01-28 13:41 Razer.Lu 阅读(291) 评论(0) 推荐(0) 编辑
摘要: 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'.& 阅读全文
posted @ 2014-01-28 12:46 Razer.Lu 阅读(246) 评论(0) 推荐(0) 编辑
摘要: 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的开头或者 阅读全文
posted @ 2014-01-28 03:28 Razer.Lu 阅读(313) 评论(0) 推荐(0) 编辑
摘要: package validNumber;public class Solution { public boolean isNumber(String s) { if (s == null) return false; char[] sArr = s.trim().toCharArray(); if (sArr.length == 0) return false; // if string 长度为1 且不是数字 if (sArr.length == 1 && !Characte... 阅读全文
posted @ 2014-01-27 12:44 Razer.Lu 阅读(239) 评论(0) 推荐(0) 编辑
摘要: Given a number represented as an array of digits, plus one to the number.public class Solution { public int[] plusOne(int[] digits) { int carry = 0; int length = digits.length; digits[length-1] = digits[length -1] + 1; for(int i = length -1 ; i>=0; i--){ ... 阅读全文
posted @ 2014-01-26 16:51 Razer.Lu 阅读(191) 评论(0) 推荐(0) 编辑
摘要: Given two words (startandend), and a dictionary, find the length of shortest transformation sequence fromstarttoend, such that:Only one letter can be ... 阅读全文
posted @ 2014-01-26 16:50 Razer.Lu 阅读(217) 评论(0) 推荐(0) 编辑
上一页 1 ··· 8 9 10 11 12 13 14 15 16 下一页