摘要: http://oj.leetcode.com/problems/swap-nodes-in-pairs/Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. You may not modify the values in the list 阅读全文
posted @ 2013-10-28 22:34 移山测试工作室黑灯老师 阅读(885) 评论(0) 推荐(0) 编辑
摘要: http://oj.leetcode.com/problems/merge-k-sorted-lists/Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.思路:不停的做两两合并就可以了。 1 class Solution { 2 public: 3 ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) { 4 ListNode *head = NULL, *tail = NU... 阅读全文
posted @ 2013-10-28 21:40 移山测试工作室黑灯老师 阅读(892) 评论(0) 推荐(0) 编辑
摘要: http://oj.leetcode.com/problems/generate-parentheses/Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()()"思路 阅读全文
posted @ 2013-10-28 18:17 移山测试工作室黑灯老师 阅读(1045) 评论(0) 推荐(0) 编辑
摘要: http://oj.leetcode.com/problems/valid-parentheses/Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" 阅读全文
posted @ 2013-10-28 17:44 移山测试工作室黑灯老师 阅读(365) 评论(0) 推荐(0) 编辑
摘要: http://oj.leetcode.com/problems/remove-nth-node-from-end-of-list/Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked list becomes 1->2->3- 阅读全文
posted @ 2013-10-28 17:24 移山测试工作室黑灯老师 阅读(236) 评论(0) 推荐(0) 编辑
摘要: http://oj.leetcode.com/problems/letter-combinations-of-a-phone-number/Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit string "23"Output: ["ad&quo 阅读全文
posted @ 2013-10-28 16:45 移山测试工作室黑灯老师 阅读(527) 评论(0) 推荐(0) 编辑
摘要: http://oj.leetcode.com/problems/4sum/Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:Elements in a quadruplet (a,b,c,d) must be in non-descending order. (ie, a ≤ b ≤ c 阅读全文
posted @ 2013-10-28 16:23 移山测试工作室黑灯老师 阅读(454) 评论(0) 推荐(0) 编辑
摘要: http://oj.leetcode.com/problems/3sum-closest/Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution. For example, given array S = {-1 2 1 ... 阅读全文
posted @ 2013-10-28 16:07 移山测试工作室黑灯老师 阅读(941) 评论(0) 推荐(0) 编辑
摘要: http://oj.leetcode.com/problems/3sum/Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c) must be in non-descending order. (ie, a ≤ b ≤ c)The solution set must not 阅读全文
posted @ 2013-10-28 15:28 移山测试工作室黑灯老师 阅读(499) 评论(0) 推荐(0) 编辑
摘要: http://oj.leetcode.com/problems/longest-common-prefix/Write a function to find the longest common prefix string amongst an array of strings.思路:没什么技巧,第一行第一个字符拿出来和其它所有行的第一个字符比,然后第二个,第三个。如果碰到不相等或某行结束就中断。 1 class Solution { 2 public: 3 string longestCommonPrefix(vector &strs) { 4 if (0 == st... 阅读全文
posted @ 2013-10-28 15:12 移山测试工作室黑灯老师 阅读(334) 评论(0) 推荐(0) 编辑
摘要: http://oj.leetcode.com/problems/roman-to-integer/Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.思路:根据个十百千位分别作为一个状态机处理就可以了。 1 class Solution { 2 public: 3 int romanToInt(string s) { 4 int val = 0, mul = 0; 5 char one, five... 阅读全文
posted @ 2013-10-28 14:12 移山测试工作室黑灯老师 阅读(453) 评论(0) 推荐(0) 编辑
摘要: http://oj.leetcode.com/problems/integer-to-roman/Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.思路:先google一下罗马数字表示法。然后查表搞定。 1 static char* roman_table[4][9] = {{"I", "II", "III", "IV", "V", & 阅读全文
posted @ 2013-10-28 13:47 移山测试工作室黑灯老师 阅读(294) 评论(0) 推荐(0) 编辑
摘要: http://oj.leetcode.com/problems/container-with-most-water/Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a 阅读全文
posted @ 2013-10-28 13:14 移山测试工作室黑灯老师 阅读(341) 评论(0) 推荐(0) 编辑
摘要: http://oj.leetcode.com/problems/regular-expression-matching/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 par 阅读全文
posted @ 2013-10-28 12:20 移山测试工作室黑灯老师 阅读(995) 评论(0) 推荐(0) 编辑
count website visits
Buy Computers