Skip to content

Commit 3a904f2

Browse files
committed
08-27
1 parent 77f6bd0 commit 3a904f2

File tree

212 files changed

+7353
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

212 files changed

+7353
-1
lines changed
File renamed without changes.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<h2><a href="https://leetcode.com/problems/add-two-numbers/">2. Add Two Numbers</a></h2><h3>Medium</h3><hr><div><p>You are given two <strong>non-empty</strong> linked lists representing two non-negative integers. The digits are stored in <strong>reverse order</strong>, and each of their nodes contains a single digit. Add the two numbers and return the sum&nbsp;as a linked list.</p>
2+
3+
<p>You may assume the two numbers do not contain any leading zero, except the number 0 itself.</p>
4+
5+
<p>&nbsp;</p>
6+
<p><strong class="example">Example 1:</strong></p>
7+
<img alt="" src="https://assets.leetcode.com/uploads/2020/10/02/addtwonumber1.jpg" style="width: 483px; height: 342px;">
8+
<pre><strong>Input:</strong> l1 = [2,4,3], l2 = [5,6,4]
9+
<strong>Output:</strong> [7,0,8]
10+
<strong>Explanation:</strong> 342 + 465 = 807.
11+
</pre>
12+
13+
<p><strong class="example">Example 2:</strong></p>
14+
15+
<pre><strong>Input:</strong> l1 = [0], l2 = [0]
16+
<strong>Output:</strong> [0]
17+
</pre>
18+
19+
<p><strong class="example">Example 3:</strong></p>
20+
21+
<pre><strong>Input:</strong> l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]
22+
<strong>Output:</strong> [8,9,9,9,0,0,0,1]
23+
</pre>
24+
25+
<p>&nbsp;</p>
26+
<p><strong>Constraints:</strong></p>
27+
28+
<ul>
29+
<li>The number of nodes in each linked list is in the range <code>[1, 100]</code>.</li>
30+
<li><code>0 &lt;= Node.val &lt;= 9</code></li>
31+
<li>It is guaranteed that the list represents a number that does not have leading zeros.</li>
32+
</ul>
33+
</div>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<h2><a href="https://leetcode.com/problems/longest-substring-without-repeating-characters/">3. Longest Substring Without Repeating Characters</a></h2><h3>Medium</h3><hr><div><p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
2+
3+
<p>&nbsp;</p>
4+
<p><strong class="example">Example 1:</strong></p>
5+
6+
<pre><strong>Input:</strong> s = "abcabcbb"
7+
<strong>Output:</strong> 3
8+
<strong>Explanation:</strong> The answer is "abc", with the length of 3.
9+
</pre>
10+
11+
<p><strong class="example">Example 2:</strong></p>
12+
13+
<pre><strong>Input:</strong> s = "bbbbb"
14+
<strong>Output:</strong> 1
15+
<strong>Explanation:</strong> The answer is "b", with the length of 1.
16+
</pre>
17+
18+
<p><strong class="example">Example 3:</strong></p>
19+
20+
<pre><strong>Input:</strong> s = "pwwkew"
21+
<strong>Output:</strong> 3
22+
<strong>Explanation:</strong> The answer is "wke", with the length of 3.
23+
Notice that the answer must be a substring, "pwke" is a subsequence and not a substring.
24+
</pre>
25+
26+
<p>&nbsp;</p>
27+
<p><strong>Constraints:</strong></p>
28+
29+
<ul>
30+
<li><code>0 &lt;= s.length &lt;= 5 * 10<sup>4</sup></code></li>
31+
<li><code>s</code> consists of English letters, digits, symbols and spaces.</li>
32+
</ul>
33+
</div>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<h2><a href="https://leetcode.com/problems/longest-palindromic-substring/">5. Longest Palindromic Substring</a></h2><h3>Medium</h3><hr><div><p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>
2+
3+
<p>&nbsp;</p>
4+
<p><strong class="example">Example 1:</strong></p>
5+
6+
<pre><strong>Input:</strong> s = "babad"
7+
<strong>Output:</strong> "bab"
8+
<strong>Explanation:</strong> "aba" is also a valid answer.
9+
</pre>
10+
11+
<p><strong class="example">Example 2:</strong></p>
12+
13+
<pre><strong>Input:</strong> s = "cbbd"
14+
<strong>Output:</strong> "bb"
15+
</pre>
16+
17+
<p>&nbsp;</p>
18+
<p><strong>Constraints:</strong></p>
19+
20+
<ul>
21+
<li><code>1 &lt;= s.length &lt;= 1000</code></li>
22+
<li><code>s</code> consist of only digits and English letters.</li>
23+
</ul>
24+
</div>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<h2><a href="https://leetcode.com/problems/zigzag-conversion/">6. Zigzag Conversion</a></h2><h3>Medium</h3><hr><div><p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
2+
3+
<pre>P A H N
4+
A P L S I I G
5+
Y I R
6+
</pre>
7+
8+
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"</code></p>
9+
10+
<p>Write the code that will take a string and make this conversion given a number of rows:</p>
11+
12+
<pre>string convert(string s, int numRows);
13+
</pre>
14+
15+
<p>&nbsp;</p>
16+
<p><strong class="example">Example 1:</strong></p>
17+
18+
<pre><strong>Input:</strong> s = "PAYPALISHIRING", numRows = 3
19+
<strong>Output:</strong> "PAHNAPLSIIGYIR"
20+
</pre>
21+
22+
<p><strong class="example">Example 2:</strong></p>
23+
24+
<pre><strong>Input:</strong> s = "PAYPALISHIRING", numRows = 4
25+
<strong>Output:</strong> "PINALSIGYAHRPI"
26+
<strong>Explanation:</strong>
27+
P I N
28+
A L S I G
29+
Y A H R
30+
P I
31+
</pre>
32+
33+
<p><strong class="example">Example 3:</strong></p>
34+
35+
<pre><strong>Input:</strong> s = "A", numRows = 1
36+
<strong>Output:</strong> "A"
37+
</pre>
38+
39+
<p>&nbsp;</p>
40+
<p><strong>Constraints:</strong></p>
41+
42+
<ul>
43+
<li><code>1 &lt;= s.length &lt;= 1000</code></li>
44+
<li><code>s</code> consists of English letters (lower-case and upper-case), <code>','</code> and <code>'.'</code>.</li>
45+
<li><code>1 &lt;= numRows &lt;= 1000</code></li>
46+
</ul>
47+
</div>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<h2><a href="https://leetcode.com/problems/reverse-integer/">7. Reverse Integer</a></h2><h3>Medium</h3><hr><div><p>Given a signed 32-bit integer <code>x</code>, return <code>x</code><em> with its digits reversed</em>. If reversing <code>x</code> causes the value to go outside the signed 32-bit integer range <code>[-2<sup>31</sup>, 2<sup>31</sup> - 1]</code>, then return <code>0</code>.</p>
2+
3+
<p><strong>Assume the environment does not allow you to store 64-bit integers (signed or unsigned).</strong></p>
4+
5+
<p>&nbsp;</p>
6+
<p><strong class="example">Example 1:</strong></p>
7+
8+
<pre><strong>Input:</strong> x = 123
9+
<strong>Output:</strong> 321
10+
</pre>
11+
12+
<p><strong class="example">Example 2:</strong></p>
13+
14+
<pre><strong>Input:</strong> x = -123
15+
<strong>Output:</strong> -321
16+
</pre>
17+
18+
<p><strong class="example">Example 3:</strong></p>
19+
20+
<pre><strong>Input:</strong> x = 120
21+
<strong>Output:</strong> 21
22+
</pre>
23+
24+
<p>&nbsp;</p>
25+
<p><strong>Constraints:</strong></p>
26+
27+
<ul>
28+
<li><code>-2<sup>31</sup> &lt;= x &lt;= 2<sup>31</sup> - 1</code></li>
29+
</ul>
30+
</div>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<h2><a href="https://leetcode.com/problems/string-to-integer-atoi/">8. String to Integer (atoi)</a></h2><h3>Medium</h3><hr><div><p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer (similar to C/C++'s <code>atoi</code> function).</p>
2+
3+
<p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p>
4+
5+
<ol>
6+
<li>Read in and ignore any leading whitespace.</li>
7+
<li>Check if the next character (if not already at the end of the string) is <code>'-'</code> or <code>'+'</code>. Read this character in if it is either. This determines if the final result is negative or positive respectively. Assume the result is positive if neither is present.</li>
8+
<li>Read in next the characters until the next non-digit character or the end of the input is reached. The rest of the string is ignored.</li>
9+
<li>Convert these digits into an integer (i.e. <code>"123" -&gt; 123</code>, <code>"0032" -&gt; 32</code>). If no digits were read, then the integer is <code>0</code>. Change the sign as necessary (from step 2).</li>
10+
<li>If the integer is out of the 32-bit signed integer range <code>[-2<sup>31</sup>, 2<sup>31</sup> - 1]</code>, then clamp the integer so that it remains in the range. Specifically, integers less than <code>-2<sup>31</sup></code> should be clamped to <code>-2<sup>31</sup></code>, and integers greater than <code>2<sup>31</sup> - 1</code> should be clamped to <code>2<sup>31</sup> - 1</code>.</li>
11+
<li>Return the integer as the final result.</li>
12+
</ol>
13+
14+
<p><strong>Note:</strong></p>
15+
16+
<ul>
17+
<li>Only the space character <code>' '</code> is considered a whitespace character.</li>
18+
<li><strong>Do not ignore</strong> any characters other than the leading whitespace or the rest of the string after the digits.</li>
19+
</ul>
20+
21+
<p>&nbsp;</p>
22+
<p><strong class="example">Example 1:</strong></p>
23+
24+
<pre><strong>Input:</strong> s = "42"
25+
<strong>Output:</strong> 42
26+
<strong>Explanation:</strong> The underlined characters are what is read in, the caret is the current reader position.
27+
Step 1: "42" (no characters read because there is no leading whitespace)
28+
^
29+
Step 2: "42" (no characters read because there is neither a '-' nor '+')
30+
^
31+
Step 3: "<u>42</u>" ("42" is read in)
32+
^
33+
The parsed integer is 42.
34+
Since 42 is in the range [-2<sup>31</sup>, 2<sup>31</sup> - 1], the final result is 42.
35+
</pre>
36+
37+
<p><strong class="example">Example 2:</strong></p>
38+
39+
<pre><strong>Input:</strong> s = " -42"
40+
<strong>Output:</strong> -42
41+
<strong>Explanation:</strong>
42+
Step 1: "<u> </u>-42" (leading whitespace is read and ignored)
43+
^
44+
Step 2: " <u>-</u>42" ('-' is read, so the result should be negative)
45+
^
46+
Step 3: " -<u>42</u>" ("42" is read in)
47+
^
48+
The parsed integer is -42.
49+
Since -42 is in the range [-2<sup>31</sup>, 2<sup>31</sup> - 1], the final result is -42.
50+
</pre>
51+
52+
<p><strong class="example">Example 3:</strong></p>
53+
54+
<pre><strong>Input:</strong> s = "4193 with words"
55+
<strong>Output:</strong> 4193
56+
<strong>Explanation:</strong>
57+
Step 1: "4193 with words" (no characters read because there is no leading whitespace)
58+
^
59+
Step 2: "4193 with words" (no characters read because there is neither a '-' nor '+')
60+
^
61+
Step 3: "<u>4193</u> with words" ("4193" is read in; reading stops because the next character is a non-digit)
62+
^
63+
The parsed integer is 4193.
64+
Since 4193 is in the range [-2<sup>31</sup>, 2<sup>31</sup> - 1], the final result is 4193.
65+
</pre>
66+
67+
<p>&nbsp;</p>
68+
<p><strong>Constraints:</strong></p>
69+
70+
<ul>
71+
<li><code>0 &lt;= s.length &lt;= 200</code></li>
72+
<li><code>s</code> consists of English letters (lower-case and upper-case), digits (<code>0-9</code>), <code>' '</code>, <code>'+'</code>, <code>'-'</code>, and <code>'.'</code>.</li>
73+
</ul>
74+
</div>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<h2><a href="https://leetcode.com/problems/container-with-most-water/">11. Container With Most Water</a></h2><h3>Medium</h3><hr><div><p>You are given an integer array <code>height</code> of length <code>n</code>. There are <code>n</code> vertical lines drawn such that the two endpoints of the <code>i<sup>th</sup></code> line are <code>(i, 0)</code> and <code>(i, height[i])</code>.</p>
2+
3+
<p>Find two lines that together with the x-axis form a container, such that the container contains the most water.</p>
4+
5+
<p>Return <em>the maximum amount of water a container can store</em>.</p>
6+
7+
<p><strong>Notice</strong> that you may not slant the container.</p>
8+
9+
<p>&nbsp;</p>
10+
<p><strong class="example">Example 1:</strong></p>
11+
<img alt="" src="https://s3-lc-upload.s3.amazonaws.com/uploads/2018/07/17/question_11.jpg" style="width: 600px; height: 287px;">
12+
<pre><strong>Input:</strong> height = [1,8,6,2,5,4,8,3,7]
13+
<strong>Output:</strong> 49
14+
<strong>Explanation:</strong> The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.
15+
</pre>
16+
17+
<p><strong class="example">Example 2:</strong></p>
18+
19+
<pre><strong>Input:</strong> height = [1,1]
20+
<strong>Output:</strong> 1
21+
</pre>
22+
23+
<p>&nbsp;</p>
24+
<p><strong>Constraints:</strong></p>
25+
26+
<ul>
27+
<li><code>n == height.length</code></li>
28+
<li><code>2 &lt;= n &lt;= 10<sup>5</sup></code></li>
29+
<li><code>0 &lt;= height[i] &lt;= 10<sup>4</sup></code></li>
30+
</ul>
31+
</div>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<h2><a href="https://leetcode.com/problems/integer-to-roman/">12. Integer to Roman</a></h2><h3>Medium</h3><hr><div><p>Roman numerals are represented by seven different symbols:&nbsp;<code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
2+
3+
<pre><strong>Symbol</strong> <strong>Value</strong>
4+
I 1
5+
V 5
6+
X 10
7+
L 50
8+
C 100
9+
D 500
10+
M 1000</pre>
11+
12+
<p>For example,&nbsp;<code>2</code> is written as <code>II</code>&nbsp;in Roman numeral, just two one's added together. <code>12</code> is written as&nbsp;<code>XII</code>, which is simply <code>X + II</code>. The number <code>27</code> is written as <code>XXVII</code>, which is <code>XX + V + II</code>.</p>
13+
14+
<p>Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not <code>IIII</code>. Instead, the number four is written as <code>IV</code>. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as <code>IX</code>. There are six instances where subtraction is used:</p>
15+
16+
<ul>
17+
<li><code>I</code> can be placed before <code>V</code> (5) and <code>X</code> (10) to make 4 and 9.&nbsp;</li>
18+
<li><code>X</code> can be placed before <code>L</code> (50) and <code>C</code> (100) to make 40 and 90.&nbsp;</li>
19+
<li><code>C</code> can be placed before <code>D</code> (500) and <code>M</code> (1000) to make 400 and 900.</li>
20+
</ul>
21+
22+
<p>Given an integer, convert it to a roman numeral.</p>
23+
24+
<p>&nbsp;</p>
25+
<p><strong class="example">Example 1:</strong></p>
26+
27+
<pre><strong>Input:</strong> num = 3
28+
<strong>Output:</strong> "III"
29+
<strong>Explanation:</strong> 3 is represented as 3 ones.
30+
</pre>
31+
32+
<p><strong class="example">Example 2:</strong></p>
33+
34+
<pre><strong>Input:</strong> num = 58
35+
<strong>Output:</strong> "LVIII"
36+
<strong>Explanation:</strong> L = 50, V = 5, III = 3.
37+
</pre>
38+
39+
<p><strong class="example">Example 3:</strong></p>
40+
41+
<pre><strong>Input:</strong> num = 1994
42+
<strong>Output:</strong> "MCMXCIV"
43+
<strong>Explanation:</strong> M = 1000, CM = 900, XC = 90 and IV = 4.
44+
</pre>
45+
46+
<p>&nbsp;</p>
47+
<p><strong>Constraints:</strong></p>
48+
49+
<ul>
50+
<li><code>1 &lt;= num &lt;= 3999</code></li>
51+
</ul>
52+
</div>

amazon_6months/0015-3sum.html

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<h2><a href="https://leetcode.com/problems/3sum/">15. 3Sum</a></h2><h3>Medium</h3><hr><div><p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
2+
3+
<p>Notice that the solution set must not contain duplicate triplets.</p>
4+
5+
<p>&nbsp;</p>
6+
<p><strong class="example">Example 1:</strong></p>
7+
8+
<pre><strong>Input:</strong> nums = [-1,0,1,2,-1,-4]
9+
<strong>Output:</strong> [[-1,-1,2],[-1,0,1]]
10+
<strong>Explanation:</strong>
11+
nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0.
12+
nums[1] + nums[2] + nums[4] = 0 + 1 + (-1) = 0.
13+
nums[0] + nums[3] + nums[4] = (-1) + 2 + (-1) = 0.
14+
The distinct triplets are [-1,0,1] and [-1,-1,2].
15+
Notice that the order of the output and the order of the triplets does not matter.
16+
</pre>
17+
18+
<p><strong class="example">Example 2:</strong></p>
19+
20+
<pre><strong>Input:</strong> nums = [0,1,1]
21+
<strong>Output:</strong> []
22+
<strong>Explanation:</strong> The only possible triplet does not sum up to 0.
23+
</pre>
24+
25+
<p><strong class="example">Example 3:</strong></p>
26+
27+
<pre><strong>Input:</strong> nums = [0,0,0]
28+
<strong>Output:</strong> [[0,0,0]]
29+
<strong>Explanation:</strong> The only possible triplet sums up to 0.
30+
</pre>
31+
32+
<p>&nbsp;</p>
33+
<p><strong>Constraints:</strong></p>
34+
35+
<ul>
36+
<li><code>3 &lt;= nums.length &lt;= 3000</code></li>
37+
<li><code>-10<sup>5</sup> &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
38+
</ul>
39+
</div>

0 commit comments

Comments
 (0)