Skip to content

Commit fecffa7

Browse files
author
zj972
committed
add 36. golang & update readme.md
1 parent 6ec5592 commit fecffa7

File tree

29 files changed

+312
-30
lines changed

29 files changed

+312
-30
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
|033|Search in Rotated Sorted Array|[Golang](https://github.com/zj972/leetcode/tree/master/code/033.%20Search%20in%20Rotated%20Sorted%20Array)|Medium|
4040
|034|Find First and Last Position of Element in Sorted Array|[Golang](https://github.com/zj972/leetcode/tree/master/code/034.%20Find%20First%20and%20Last%20Position%20of%20Element%20in%20Sorted%20Array)|Medium|
4141
|035|Search Insert Position|[Golang](https://github.com/zj972/leetcode/tree/master/code/035.%20Search%20Insert%20Position)|Easy|
42-
|036|Valid Sudoku|[JavaScript](https://github.com/zj972/leetcode/tree/master/code/036.%20Valid%20Sudoku)|Easy|
42+
|036|Valid Sudoku|[JavaScript & Golang](https://github.com/zj972/leetcode/tree/master/code/036.%20Valid%20Sudoku)|Easy|
4343
|038|Count and Say|[JavaScript](https://github.com/zj972/leetcode/tree/master/code/038.%20Count%20and%20Say)|Easy|
4444
|058|Length of Last Word|[JavaScript](https://github.com/zj972/leetcode/tree/master/code/058.%20Length%20of%20Last%20Word)|Easy|
4545
|062|Unique Paths|[JavaScript](https://github.com/zj972/leetcode/tree/master/code/062.%20Unique%20Paths)|Medium|

code/002. Add Two Numbers/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ You may assume the two numbers do not contain any leading zero, except the numbe
77
##### Example:
88

99
Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
10+
1011
Output: 7 -> 0 -> 8
12+
1113
Explanation: 342 + 465 = 807.

code/003. Longest Substring Without Repeating Characters/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,25 @@ Given a string, find the length of the longest substring without repeating chara
55
##### Example 1:
66

77
Input: "abcabcbb"
8+
89
Output: 3
10+
911
Explanation: The answer is "abc", with the length of 3.
1012

1113
##### Example 2:
1214

1315
Input: "bbbbb"
16+
1417
Output: 1
18+
1519
Explanation: The answer is "b", with the length of 1.
1620

1721
##### Example 3:
1822

1923
Input: "pwwkew"
24+
2025
Output: 3
26+
2127
Explanation: The answer is "wke", with the length of 3.
22-
Note that the answer must be a substring, "pwke" is a subsequence and not a substring.
28+
29+
Note that the answer must be a substring, "pwke" is a subsequence and not a substring.

code/004. Median of Two Sorted Arrays/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ You may assume nums1 and nums2 cannot be both empty.
99
##### Example 1:
1010

1111
nums1 = [1, 3]
12+
1213
nums2 = [2]
1314

1415
The median is 2.0
1516

1617
##### Example 2:
1718

1819
nums1 = [1, 2]
20+
1921
nums2 = [3, 4]
2022

2123
The median is (2 + 3)/2 = 2.5

code/005. Longest Palindromic Substring/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ Given a string s, find the longest palindromic substring in s. You may assume th
55
##### Example 1:
66

77
Input: "babad"
8+
89
Output: "bab"
10+
911
Note: "aba" is also a valid answer.
1012

1113
##### Example 2:
1214

1315
Input: "cbbd"
16+
1417
Output: "bb"

code/006. ZigZag Conversion/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ string convert(string s, int numRows);
1717
##### Example 1:
1818

1919
Input: s = "PAYPALISHIRING", numRows = 3
20+
2021
Output: "PAHNAPLSIIGYIR"
2122

2223
##### Example 2:
2324

2425
Input: s = "PAYPALISHIRING", numRows = 4
26+
2527
Output: "PINALSIGYAHRPI"
28+
2629
Explanation:
2730

2831
```text

code/007. Reverse Integer/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ Given a 32-bit signed integer, reverse digits of an integer.
55
##### Example 1:
66

77
Input: 123
8+
89
Output: 321
910

1011
##### Example 2:
1112

1213
Input: -123
14+
1315
Output: -321
1416

1517
##### Example 3:
1618

1719
Input: 120
20+
1821
Output: 21
1922

2023
##### Note:

code/008. String to Integer (atoi)/README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,48 @@ If no valid conversion could be performed, a zero value is returned.
1313
##### Note:
1414

1515
Only the space character ' ' is considered as whitespace character.
16+
1617
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−2<sup>31</sup>, 2<sup>31</sup> − 1]. If the numerical value is out of the range of representable values, INT_MAX (2<sup>31</sup> − 1) or INT_MIN (−2<sup>31</sup>) is returned.
1718

1819
##### Example 1:
1920

2021
Input: "42"
22+
2123
Output: 42
2224

2325
##### Example 2:
2426

2527
Input: " -42"
28+
2629
Output: -42
30+
2731
Explanation: The first non-whitespace character is '-', which is the minus sign.
2832
Then take as many numerical digits as possible, which gets 42.
2933

3034
##### Example 3:
3135

3236
Input: "4193 with words"
37+
3338
Output: 4193
39+
3440
Explanation: Conversion stops at digit '3' as the next character is not a numerical digit.
3541

3642
##### Example 4:
3743

3844
Input: "words and 987"
45+
3946
Output: 0
40-
Explanation: The first non-whitespace character is 'w', which is not a numerical
41-
digit or a +/- sign. Therefore no valid conversion could be performed.
47+
48+
Explanation: The first non-whitespace character is 'w', which is not a numerical
49+
50+
digit or a +/- sign. Therefore no valid conversion could be performed.
4251

4352
##### Example 5:
4453

4554
Input: "-91283472332"
55+
4656
Output: -2147483648
57+
4758
Explanation: The number "-91283472332" is out of the range of a 32-bit signed integer.
48-
Thefore INT_MIN (−2<sup>31</sup>) is returned.
59+
60+
Thefore INT_MIN (−2<sup>31</sup>) is returned.

code/009. Palindrome Number/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@ Determine whether an integer is a palindrome. An integer is a palindrome when it
55
##### Example 1:
66

77
Input: 121
8+
89
Output: true
910

1011
##### Example 2:
1112

1213
Input: -121
14+
1315
Output: false
16+
1417
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
1518

1619
##### Example 3:
1720

1821
Input: 10
22+
1923
Output: false
20-
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
21-
Follow up:
2224

23-
Coud you solve it without converting the integer to a string?
25+
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.

code/010. Regular Expression Matching/README.md

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,58 @@ The matching should cover the entire input string (not partial).
99
##### Note:
1010

1111
s could be empty and contains only lowercase letters a-z.
12+
1213
p could be empty and contains only lowercase letters a-z, and characters like . or *.
1314

1415
##### Example 1:
1516

1617
Input:
17-
s = "aa"
18-
p = "a"
18+
19+
s = "aa"
20+
p = "a"
21+
1922
Output: false
23+
2024
Explanation: "a" does not match the entire string "aa".
2125

2226
##### Example 2:
2327

2428
Input:
25-
s = "aa"
26-
p = "a*"
29+
30+
s = "aa"
31+
p = "a*"
32+
2733
Output: true
34+
2835
Explanation: '*' means zero or more of the precedeng element, 'a'. Therefore, by repeating 'a' once, it becomes "aa".
2936

3037
##### Example 3:
3138

3239
Input:
33-
s = "ab"
34-
p = ".*"
40+
41+
s = "ab"
42+
p = ".*"
43+
3544
Output: true
45+
3646
Explanation: ".*" means "zero or more (*) of any character (.)".
37-
Example 4:
47+
48+
##### Example 4:
3849

3950
Input:
40-
s = "aab"
41-
p = "c*a*b"
51+
52+
s = "aab"
53+
p = "c*a*b"
54+
4255
Output: true
56+
4357
Explanation: c can be repeated 0 times, a can be repeated 1 time. Therefore it matches "aab".
4458

4559
##### Example 5:
4660

4761
Input:
48-
s = "mississippi"
49-
p = "mis*is*p*."
62+
63+
s = "mississippi"
64+
p = "mis*is*p*."
65+
5066
Output: false

code/011. Container With Most Water/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this c
1313
##### Example:
1414

1515
Input: [1,8,6,2,5,4,8,3,7]
16+
1617
Output: 49

code/012. Integer to Roman/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,33 @@ Given an integer, convert it to a roman numeral. Input is guaranteed to be withi
2828
##### Example 1:
2929

3030
Input: 3
31+
3132
Output: "III"
3233

3334
##### Example 2:
3435

3536
Input: 4
37+
3638
Output: "IV"
3739

3840
##### Example 3:
3941

4042
Input: 9
43+
4144
Output: "IX"
4245

4346
##### Example 4:
4447

4548
Input: 58
49+
4650
Output: "LVIII"
51+
4752
Explanation: C = 100, L = 50, XXX = 30 and III = 3.
4853

4954
##### Example 5:
5055

5156
Input: 1994
57+
5258
Output: "MCMXCIV"
59+
5360
Explanation: M = 1000, CM = 900, XC = 90 and IV = 4.

code/013. Roman to Integer/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,33 @@ Given a roman numeral, convert it to an integer. Input is guaranteed to be withi
2929
##### Example 1:
3030

3131
Input: "III"
32+
3233
Output: 3
3334

3435
##### Example 2:
3536

3637
Input: "IV"
38+
3739
Output: 4
3840

3941
##### Example 3:
4042

4143
Input: "IX"
44+
4245
Output: 9
4346

4447
##### Example 4:
4548

4649
Input: "LVIII"
50+
4751
Output: 58
52+
4853
Explanation: L = 50, V= 5, III = 3.
4954

5055
##### Example 5:
5156

5257
Input: "MCMXCIV"
58+
5359
Output: 1994
60+
5461
Explanation: M = 1000, CM = 900, XC = 90 and IV = 4.

code/014. Longest Common Prefix/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ If there is no common prefix, return an empty string "".
77
##### Example 1:
88

99
Input: ["flower","flow","flight"]
10+
1011
Output: "fl"
1112

1213
##### Example 2:
1314

1415
Input: ["dog","racecar","car"]
16+
1517
Output: ""
18+
1619
Explanation: There is no common prefix among the input strings.
1720

1821
##### Note:

code/015. 3Sum/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ The solution set must not contain duplicate triplets.
1111
Given array nums = [-1, 0, 1, 2, -1, -4],
1212

1313
A solution set is:
14+
15+
```text
1416
[
1517
[-1, 0, 1],
1618
[-1, -1, 2]
17-
]
19+
]
20+
```

code/018. 4Sum/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ The solution set must not contain duplicate quadruplets.
1111
Given array nums = [1, 0, -1, 0, -2, 2], and target = 0.
1212

1313
A solution set is:
14+
15+
```text
1416
[
1517
[-1, 0, 0, 1],
1618
[-2, -1, 1, 2],
1719
[-2, 0, 0, 2]
18-
]
20+
]
21+
```

0 commit comments

Comments
 (0)