摘要:[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...
阅读全文
摘要:[Problem]Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.[Analysis]这题一上来,就会想到之前做过的Merge Two Sorted Lis...
阅读全文
摘要:[Problem]Givennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, givenn= 3, a solution set i...
阅读全文
摘要:[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....
阅读全文
摘要:[Problem]Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets must close in the...
阅读全文
摘要:[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. ...
阅读全文
摘要:[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...
阅读全文
摘要:[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...
阅读全文
摘要:[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...
阅读全文
摘要:[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...
阅读全文
摘要:[Problem]Write a function to find the longest common prefix string amongst an array of strings.[Analysis]思路非常简单,循环验证每一个字符串就可以通过OJ,代码也没有优化。[Solution]pu...
阅读全文
摘要:[Problem]Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.[Analysis]建立一个字符到数字的map之后只需要抓住两个条件:...
阅读全文
摘要:[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,这题我采用了...
阅读全文
摘要:[Problem]Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endp...
阅读全文
摘要:[Problem]Implement regular expression matching with support for'.'and'*'.'.' Matches any single character.'*' Matches zero or more of the preceding el...
阅读全文
摘要:[Problem]Determine whether an integer is a palindrome. Do this without extra space.[Analysis]这题不能转换为String来做因为要求constant space。只要依次比较头尾两个数字就可以了。[Solut...
阅读全文
摘要:[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...
阅读全文
摘要:[Problem]Reverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321[Analysis]这题不难,关键是要注意overflow的处理,因为reverse后的数字有可能超出Int...
阅读全文
摘要:[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...
阅读全文
摘要:[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...
阅读全文