https://oj.leetcode.com/problems/palindrome-number/http://fisherlei.blogspot.com/2012/12/leetcode-palindrome-number.htmlpublicclassSolution{
publicbooleanisPalindrome(intx){
//Assume
//Negativenumberscannotbepalindrome
if(x<0)
returnfalse;
//Noextrasp..
分类:
其他好文 时间:
2015-01-02 16:14:01
阅读次数:
116
https://oj.leetcode.com/problems/container-with-most-water/http://fisherlei.blogspot.com/2013/01/leetcode-container-with-most-water.htmlpublicclassSolution{
publicintmaxArea(int[]height){
//SolutionB:
//returnmaxArea_BruteForce(height);
//SolutionA:
retur..
分类:
其他好文 时间:
2015-01-02 16:15:22
阅读次数:
158
https://oj.leetcode.com/problems/integer-to-roman/http://fisherlei.blogspot.com/2012/12/leetcode-integer-to-roman.htmlpublicclassSolution{
//
//把4,9定义为特殊的字符
//从大到小适配
publicStringintToRoman(intnum){
if(num<1||num>3999)
returnnull;//Inva..
分类:
其他好文 时间:
2015-01-02 16:14:07
阅读次数:
128
https://oj.leetcode.com/problems/roman-to-integer/http://fisherlei.blogspot.com/2012/12/leetcode-roman-to-integer.html//Symbol Value
//I 1
//V 5
//X 10
//L 50
//C 100
//D 500
//M 1,000
publicclassSolution{
publicintromanToInt(Strings){
Map<Character,In..
分类:
其他好文 时间:
2015-01-02 16:13:57
阅读次数:
163
https://oj.leetcode.com/problems/longest-common-prefix/http://fisherlei.blogspot.com/2012/12/leetcode-longest-common-prefix.htmlpublicclassSolution{
publicStringlongestCommonPrefix(String[]strs)
{
//Validations
if(strs==null||strs.length==0)
return"";
if(s..
分类:
其他好文 时间:
2015-01-02 16:13:25
阅读次数:
103
https://oj.leetcode.com/problems/3sum/publicclassSolution{
publicList<List<Integer>>threeSum(int[]num){
//SolutionA
//returnthreeSum_Sort(num);
//SolutionB
returnthreeSum_Map(num);
}
////////////////////
//SolutionA:Sort
//
//O(n^2)
privateLi..
分类:
其他好文 时间:
2015-01-02 16:11:46
阅读次数:
119
https://oj.leetcode.com/problems/3sum-closest/http://fisherlei.blogspot.com/2013/01/leetcode-3sum-closest-solution.htmlpublicclassSolution{
publicintthreeSumClosest(int[]num,inttarget){
//Inputvalidations
//...
Arrays.sort(num);
intlen=num.length;
intmin..
分类:
其他好文 时间:
2015-01-02 16:14:25
阅读次数:
116
https://oj.leetcode.com/problems/letter-combinations-of-a-phone-number/http://fisherlei.blogspot.com/2012/12/leetcode-letter-combinations-of-phone.htmlpublicclassSolution{
publicList<String>letterCombinations(Stringdigits){
if(digits==null)
returnnul..
分类:
其他好文 时间:
2015-01-02 16:13:14
阅读次数:
134
https://oj.leetcode.com/problems/remove-nth-node-from-end-of-list/http://fisherlei.blogspot.com/2012/12/leetcode-remove-nth-node-from-end-of.html/**
*Definitionforsingly-linkedlist.
*publicclassListNode{
*intval;
*ListNodenext;
*ListNode(intx){
*val=x;
*nex..
分类:
其他好文 时间:
2015-01-02 16:12:53
阅读次数:
132
https://oj.leetcode.com/problems/valid-parentheses/http://fisherlei.blogspot.com/2013/01/leetcode-valid-parentheses.htmlpublicclassSolution{
publicbooleanisValid(Strings)
{
if(s==null)
returntrue;
Stack<Character>stack=newStack<>();
for(charc:s..
分类:
其他好文 时间:
2015-01-02 16:12:14
阅读次数:
99
https://oj.leetcode.com/problems/generate-parentheses/http://fisherlei.blogspot.com/2012/12/leetcode-generate-parentheses.htmlpublicclassSolution{
publicList<String>generateParenthesis(intn){
//SolutionB:
//returngenerateParenthesis_BruteForce(n);
..
分类:
其他好文 时间:
2015-01-02 16:12:32
阅读次数:
137
https://oj.leetcode.com/problems/merge-k-sorted-lists/http://fisherlei.blogspot.com/2012/12/leetcode-merge-k-sorted-lists.html/**
*Definitionforsingly-linkedlist.
*publicclassListNode{
*intval;
*ListNodenext;
*ListNode(intx){
*val=x;
*next=null;
*}
*}
*/
pu..
分类:
其他好文 时间:
2015-01-02 16:11:43
阅读次数:
152
https://oj.leetcode.com/problems/swap-nodes-in-pairs/http://fisherlei.blogspot.com/2013/01/leetcode-swap-nodes-in-pairs.html/**
*Definitionforsingly-linkedlist.
*publicclassListNode{
*intval;
*ListNodenext;
*ListNode(intx){
*val=x;
*next=null;
*}
*}
*/
publ..
分类:
其他好文 时间:
2015-01-02 16:12:21
阅读次数:
151
https://oj.leetcode.com/problems/reverse-nodes-in-k-group/http://fisherlei.blogspot.com/2012/12/leetcode-reverse-nodes-in-k-group.html/**
*Definitionforsingly-linkedlist.
*publicclassListNode{
*intval;
*ListNodenext;
*ListNode(intx){
*val=x;
*next=null;
*}
..
分类:
其他好文 时间:
2015-01-02 16:12:00
阅读次数:
238
https://oj.leetcode.com/problems/remove-duplicates-from-sorted-array/http://fisherlei.blogspot.com/2012/12/leetcode-remove-duplicates-from-sorted.htmlpublicclassSolution{
publicintremoveDuplicates(int[]A){
if(A==null||A.length==0)
return0;//Invalidinput.
..
分类:
其他好文 时间:
2015-01-02 16:12:07
阅读次数:
118
https://oj.leetcode.com/problems/remove-element/http://fisherlei.blogspot.com/2012/12/leetcode-remove-element.htmlpublicclassSolution{
publicintremoveElement(int[]A,intelem){
//Theordercanbechanged.
//Use2pointers.
//Onetoiteratethearray,
//Onetocopythelas..
分类:
其他好文 时间:
2015-01-02 16:10:11
阅读次数:
129
https://oj.leetcode.com/problems/implement-strstr/http://fisherlei.blogspot.com/2012/12/leetcode-implement-strstr.htmlpublicclassSolution{
publicintstrStr(Stringhaystack,Stringneedle){
//遍历haystack,对每一个字符,匹配needle
if(haystack==null||needle==nu..
分类:
其他好文 时间:
2015-01-02 16:12:25
阅读次数:
149