随笔分类 -  LeetCode之路

1 2 下一页

LeetCode #24 Swap Nodes in Pairs (M)
摘要:[Problem]Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Y... 阅读全文

posted @ 2015-10-24 03:23 张惬意 阅读(119) 评论(0) 推荐(0)

LeetCode #23 Merge k Sorted Lists (H)
摘要:[Problem]Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.[Analysis]这题一上来,就会想到之前做过的Merge Two Sorted Lis... 阅读全文

posted @ 2015-10-23 05:14 张惬意 阅读(268) 评论(0) 推荐(0)

LeetCode #22 Generate Parentheses (M)
摘要:[Problem]Givennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, givenn= 3, a solution set i... 阅读全文

posted @ 2015-10-10 00:31 张惬意 阅读(157) 评论(0) 推荐(0)

LeetCode #21 Merge Two Sorted Lists (E)
摘要:[Problem]Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.... 阅读全文

posted @ 2015-10-09 23:56 张惬意 阅读(93) 评论(0) 推荐(0)

LeetCode #20 Valid Parentheses (E)
摘要:[Problem]Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets must close in the... 阅读全文

posted @ 2015-10-09 23:52 张惬意 阅读(140) 评论(0) 推荐(0)

LeetCode #19 Remove Nth Node From End of List (E)
摘要:[Problem]Given a linked list, remove thenthnode from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. ... 阅读全文

posted @ 2015-10-09 23:49 张惬意 阅读(93) 评论(0) 推荐(0)

LeetCode #18 4Sum (M)
摘要:[Problem]Given an arraySofnintegers, are there elementsa,b,c, anddinSsuch thata+b+c+d= target? Find all unique quadruplets in the array which gives th... 阅读全文

posted @ 2015-10-09 23:30 张惬意 阅读(124) 评论(0) 推荐(0)

LeetCode #17 Letter Combinations of a Phone Number (M)
摘要:[Problem]Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the... 阅读全文

posted @ 2015-10-09 23:16 张惬意 阅读(138) 评论(0) 推荐(0)

LeetCode #16 3Sum Closest (M)
摘要:[Problem]Given an arraySofnintegers, find three integers inSsuch that the sum is closest to a given number, target. Return the sum of the three intege... 阅读全文

posted @ 2015-10-09 22:58 张惬意 阅读(150) 评论(0) 推荐(0)

LeetCode #15 3Sum (M)
摘要:[Problem]Given an arraySofnintegers, are there elementsa,b,cinSsuch thata+b+c= 0? Find all unique triplets in the array which gives the sum of zero.No... 阅读全文

posted @ 2015-10-09 22:49 张惬意 阅读(167) 评论(0) 推荐(0)

LeetCode #14 Longest Common Prefix (E)
摘要:[Problem]Write a function to find the longest common prefix string amongst an array of strings.[Analysis]思路非常简单,循环验证每一个字符串就可以通过OJ,代码也没有优化。[Solution]pu... 阅读全文

posted @ 2015-10-09 22:33 张惬意 阅读(143) 评论(0) 推荐(0)

LeetCode #13 Roman to Integer (E)
摘要:[Problem]Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.[Analysis]建立一个字符到数字的map之后只需要抓住两个条件:... 阅读全文

posted @ 2015-10-09 22:28 张惬意 阅读(115) 评论(0) 推荐(0)

LeetCode #12 Integer to Roman (M)
摘要:[Problem]Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.[Analysis]由于题目提示输入的范围是1至3999,这题我采用了... 阅读全文

posted @ 2015-10-09 22:18 张惬意 阅读(102) 评论(0) 推荐(0)

LeetCode #11 Container With Most Water (M)
摘要:[Problem]Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endp... 阅读全文

posted @ 2015-10-09 22:12 张惬意 阅读(111) 评论(0) 推荐(0)

LeetCode #10 Regular Expression Matching (H)
摘要:[Problem]Implement regular expression matching with support for'.'and'*'.'.' Matches any single character.'*' Matches zero or more of the preceding el... 阅读全文

posted @ 2015-10-06 02:20 张惬意 阅读(107) 评论(0) 推荐(0)

LeetCode #9 Palindrome Number (E)
摘要:[Problem]Determine whether an integer is a palindrome. Do this without extra space.[Analysis]这题不能转换为String来做因为要求constant space。只要依次比较头尾两个数字就可以了。[Solut... 阅读全文

posted @ 2015-10-06 01:50 张惬意 阅读(98) 评论(0) 推荐(0)

Leetcode #8 String to Integer (atoi) (E)
摘要:[Problem]Implementatoito convert a string to an integer.Hint:Carefully consider all possible input cases. If you want a challenge, please do not see b... 阅读全文

posted @ 2015-10-06 01:43 张惬意 阅读(100) 评论(0) 推荐(0)

LeetCode #7 Reverse Integer (E)
摘要:[Problem]Reverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321[Analysis]这题不难,关键是要注意overflow的处理,因为reverse后的数字有可能超出Int... 阅读全文

posted @ 2015-10-02 00:06 张惬意 阅读(135) 评论(0) 推荐(0)

LeetCode #6 ZigZag Conversion (E)
摘要:[Problem]The string"PAYPALISHIRING"is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixe... 阅读全文

posted @ 2015-10-01 23:51 张惬意 阅读(134) 评论(0) 推荐(0)

LeetCode #5 Longest Palindromic Substring (M)
摘要:[Problem]Given a stringS, find the longest palindromic substring inS. You may assume that the maximum length ofSis 1000, and there exists one unique l... 阅读全文

posted @ 2015-10-01 23:03 张惬意 阅读(154) 评论(0) 推荐(0)

1 2 下一页