2016年11月30日 星期三

[LeetCode] 18. 4Sum

轉自LeetCode

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: The solution set must not contain duplicate quadruplets.
For example, given array S = [1, 0, -1, 0, -2, 2], and target = 0.

A solution set is:
[
  [-1,  0, 0, 1],
  [-2, -1, 1, 2],
  [-2,  0, 0, 2]
]
<Solution>

[LeetCode] 17. Letter Combinations of a Phone Number

轉自LeetCode

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", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
<Solution>

[LeetCode] 16. 3Sum Closest

轉自LeetCode

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 -4}, and target = 1.

    The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).
<Solution>

[LeetCode] 15. 3Sum

轉自LeetCode

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: The solution set must not contain duplicate triplets.
For example, given array S = [-1, 0, 1, 2, -1, -4],

A solution set is:
[
  [-1, 0, 1],
  [-1, -1, 2]
]
<Solution>

[LeetCode] 14. Longest Common Prefix

轉自LeetCode

Write a function to find the longest common prefix string amongst an array of strings.

<Solution>

[LeetCode] 13. Roman to Integer

轉自LeetCode

Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.
<Solution>

[LeetCode] 12. Integer to Roman

轉自LeetCode

Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
<Solution>