Skip to content

Commit bcc8e30

Browse files
committed
update at 2018-04-13
1 parent ef8bb89 commit bcc8e30

File tree

14 files changed

+189
-59
lines changed

14 files changed

+189
-59
lines changed

007-reverse-integer/reverse-integer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,27 @@
55
#
66
# Example 1:
77
#
8-
# Input: 123
9-
# Output: 321
108
#
9+
# Input: 123
10+
# Output: 321
1111
#
1212
#
1313
# Example 2:
1414
#
15+
#
1516
# Input: -123
1617
# Output: -321
1718
#
1819
#
19-
#
2020
# Example 3:
2121
#
22+
#
2223
# Input: 120
2324
# Output: 21
2425
#
2526
#
26-
#
2727
# Note:
28-
# Assume we are dealing with an environment which could only hold integers within the 32-bit signed integer range. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.
28+
# Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231,  231 − 1]. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.
2929
#
3030

3131

009-palindrome-number/palindrome-number.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
11
# -*- coding:utf-8 -*-
22

33

4-
# Determine whether an integer is a palindrome. Do this without extra space.
4+
# Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.
55
#
6-
# click to show spoilers.
6+
# Example 1:
77
#
8-
# Some hints:
98
#
10-
# Could negative integers be palindromes? (ie, -1)
9+
# Input: 121
10+
# Output: true
1111
#
12-
# If you are thinking of converting the integer to string, note the restriction of using extra space.
1312
#
14-
# You could also try reversing an integer. However, if you have solved the problem "Reverse Integer", you know that the reversed integer might overflow. How would you handle such case?
13+
# Example 2:
1514
#
16-
# There is a more generic way of solving this problem.
1715
#
16+
# Input: -121
17+
# Output: false
18+
# Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
19+
#
20+
#
21+
# Example 3:
22+
#
23+
#
24+
# Input: 10
25+
# Output: false
26+
# Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
27+
#
28+
#
29+
# Follow up:
30+
#
31+
# Coud you solve it without converting the integer to a string?
1832
#
1933

2034

010-regular-expression-matching/regular-expression-matching.py

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,70 @@
11
# -*- coding:utf-8 -*-
22

33

4-
# Implement regular expression matching with support for '.' and '*'.
4+
# Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'.
55
#
66
#
7-
# '.' Matches any single character.
8-
# '*' Matches zero or more of the preceding element.
7+
# '.' Matches any single character.
8+
# '*' Matches zero or more of the preceding element.
9+
#
910
#
1011
# The matching should cover the entire input string (not partial).
1112
#
12-
# The function prototype should be:
13-
# bool isMatch(const char *s, const char *p)
14-
#
15-
# Some examples:
16-
# isMatch("aa","a") → false
17-
# isMatch("aa","aa") → true
18-
# isMatch("aaa","aa") → false
19-
# isMatch("aa", "a*") → true
20-
# isMatch("aa", ".*") → true
21-
# isMatch("ab", ".*") → true
22-
# isMatch("aab", "c*a*b") → true
13+
# Note:
14+
#
15+
#
16+
# s could be empty and contains only lowercase letters a-z.
17+
# p could be empty and contains only lowercase letters a-z, and characters like . or *.
18+
#
19+
#
20+
# Example 1:
21+
#
22+
#
23+
# Input:
24+
# s = "aa"
25+
# p = "a"
26+
# Output: false
27+
# Explanation: "a" does not match the entire string "aa".
28+
#
29+
#
30+
# Example 2:
31+
#
32+
#
33+
# Input:
34+
# s = "aa"
35+
# p = "a*"
36+
# Output: true
37+
# Explanation: '*' means zero or more of the precedeng element, 'a'. Therefore, by repeating 'a' once, it becomes "aa".
38+
#
39+
#
40+
# Example 3:
41+
#
42+
#
43+
# Input:
44+
# s = "ab"
45+
# p = ".*"
46+
# Output: true
47+
# Explanation: ".*" means "zero or more (*) of any character (.)".
48+
#
49+
#
50+
# Example 4:
51+
#
52+
#
53+
# Input:
54+
# s = "aab"
55+
# p = "c*a*b"
56+
# Output: true
57+
# Explanation: c can be repeated 0 times, a can be repeated 1 time. Therefore it matches "aab".
58+
#
59+
#
60+
# Example 5:
61+
#
62+
#
63+
# Input:
64+
# s = "mississippi"
65+
# p = "mis*is*p*."
66+
# Output: false
67+
#
2368
#
2469

2570

015-3sum/3sum.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
// 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.
1+
// Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.
22
//
3-
// Note: The solution set must not contain duplicate triplets.
3+
// Note:
44
//
5+
// The solution set must not contain duplicate triplets.
56
//
6-
// For example, given array S = [-1, 0, 1, 2, -1, -4],
7+
// Example:
8+
//
9+
//
10+
// Given array nums = [-1, 0, 1, 2, -1, -4],
711
//
812
// A solution set is:
913
// [
1014
// [-1, 0, 1],
1115
// [-1, -1, 2]
1216
// ]
1317
//
18+
//
1419

1520

1621
/**

015-3sum/3sum.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
# -*- coding:utf-8 -*-
22

33

4-
# 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.
4+
# Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.
55
#
6-
# Note: The solution set must not contain duplicate triplets.
6+
# Note:
77
#
8+
# The solution set must not contain duplicate triplets.
89
#
9-
# For example, given array S = [-1, 0, 1, 2, -1, -4],
10+
# Example:
11+
#
12+
#
13+
# Given array nums = [-1, 0, 1, 2, -1, -4],
1014
#
1115
# A solution set is:
1216
# [
1317
# [-1, 0, 1],
1418
# [-1, -1, 2]
1519
# ]
1620
#
21+
#
1722

1823

1924
class Solution(object):

016-3sum-closest/3sum-closest.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# -*- coding:utf-8 -*-
22

33

4-
# 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.
4+
# Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution.
55
#
6+
# Example:
67
#
7-
# For example, given array S = {-1 2 1 -4}, and target = 1.
88
#
9-
# The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).
9+
# Given array nums = [-1, 2, 1, -4], and target = 1.
10+
#
11+
# The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).
1012
#
1113
#
1214

017-letter-combinations-of-a-phone-number/letter-combinations-of-a-phone-number.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
# -*- coding:utf-8 -*-
22

33

4-
# Given a digit string, return all possible letter combinations that the number could represent.
4+
# Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.
55
#
6-
# A mapping of digit to letters (just like on the telephone buttons) is given below.
6+
# A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.
77
#
88
#
99
#
10+
# Example:
1011
#
11-
# Input:Digit string "23"
12+
#
13+
# Input: "23"
1214
# Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
1315
#
1416
#
1517
# Note:
18+
#
1619
# Although the above answer is in lexicographical order, your answer could be in any order you want.
1720
#
1821

018-4sum/4sum.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
# -*- coding:utf-8 -*-
22

33

4-
# 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.
4+
# Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.
55
#
6-
# Note: The solution set must not contain duplicate quadruplets.
6+
# Note:
77
#
8+
# The solution set must not contain duplicate quadruplets.
89
#
10+
# Example:
911
#
10-
# For example, given array S = [1, 0, -1, 0, -2, 2], and target = 0.
12+
#
13+
# Given array nums = [1, 0, -1, 0, -2, 2], and target = 0.
1114
#
1215
# A solution set is:
1316
# [
@@ -16,6 +19,7 @@
1619
# [-2, 0, 0, 2]
1720
# ]
1821
#
22+
#
1923

2024

2125
class Solution(object):

019-remove-nth-node-from-end-of-list/remove-nth-node-from-end-of-list.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
# -*- coding:utf-8 -*-
22

33

4-
# Given a linked list, remove the nth node from the end of list and return its head.
4+
# Given a linked list, remove the n-th node from the end of list and return its head.
55
#
6-
# For example,
6+
# Example:
77
#
88
#
9-
# Given linked list: 1->2->3->4->5, and n = 2.
9+
# Given linked list: 1->2->3->4->5, and n = 2.
1010
#
11-
# After removing the second node from the end, the linked list becomes 1->2->3->5.
11+
# After removing the second node from the end, the linked list becomes 1->2->3->5.
1212
#
1313
#
1414
# Note:
15+
#
1516
# Given n will always be valid.
16-
# Try to do this in one pass.
17+
#
18+
# Follow up:
19+
#
20+
# Could you do this in one pass?
1721
#
1822

1923

020-valid-parentheses/valid-parentheses.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,44 @@
11
# -*- coding:utf-8 -*-
22

33

4-
# Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
4+
# Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
55
#
6-
# The brackets must close in the correct order, "()" and "()[]{}" are all valid but "(]" and "([)]" are not.
6+
# An input string is valid if:
7+
#
8+
#
9+
# Open brackets must be closed by the same type of brackets.
10+
# Open brackets must be closed in the correct order.
11+
# It is an empty string.
12+
#
13+
#
14+
# Example 1:
15+
#
16+
# Input: "()"
17+
# Output: true
18+
#
19+
#
20+
# Example 2:
21+
#
22+
# Input: "()[]{}"
23+
# Output: true
24+
#
25+
#
26+
# Example 3:
27+
#
28+
# Input: "(]"
29+
# Output: false
30+
#
31+
#
32+
# Example 4:
33+
#
34+
# Input: "([)]"
35+
# Output: false
36+
#
37+
#
38+
# Example 5:
39+
#
40+
# Input: "{[]}"
41+
# Output: true
742
#
843

944

0 commit comments

Comments
 (0)