Skip to content

Commit 6c3399d

Browse files
committed
08-27
1 parent f9c619a commit 6c3399d

File tree

637 files changed

+24166
-21
lines changed

Some content is hidden

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

637 files changed

+24166
-21
lines changed

__pycache__/copy.cpython-312.pyc

1.71 KB
Binary file not shown.

copy.py

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,46 @@
1212
print("!folder " + folder)
1313
# Open file
1414
newfolder = "./problems/" + folder
15-
print("!newfolder " + newfolder)
16-
for name in os.listdir(newfolder):
17-
# print("name " + name)
18-
filename = os.path.join(folder, "README.md")
19-
# print("filename " + filename)
20-
if os.path.exists(filename) is True:
21-
with open(filename) as f:
22-
#print(f"Content of '{name}'")
23-
# Read content of file
24-
#print(f.read())
25-
newfilename = destination + folder + '.html'
26-
shutil.copyfile(filename, newfilename)
27-
#print("True")
28-
count = count + 1
29-
30-
else:
31-
15+
#print("!newfolder " + newfolder)
16+
#for name in os.listdir(newfolder):
17+
#print("name " + name)
18+
filename = os.path.join(newfolder, "README.md")
19+
print("filename " + filename)
20+
if os.path.exists(filename) is True:
21+
with open(filename) as f:
22+
#print(f"Content of '{name}'")
23+
# Read content of file
24+
#print(f.read())
3225
newfilename = destination + folder + '.html'
33-
with open(newfilename, 'w') as fp:
34-
pass
35-
list.append(newfilename)
26+
shutil.copyfile(filename, newfilename)
27+
#print("True")
28+
count = count + 1
29+
30+
else:
31+
32+
newfilename = destination + folder + '.html'
33+
with open(newfilename, 'w') as fp:
34+
pass
35+
list.append(newfilename)
3636

37-
print("count ", count)
37+
print("Count: ", count)
38+
39+
40+
'''
41+
#convert html to pdf
42+
from pyhtml2pdf import converter
43+
44+
for folder in os.listdir(directory):
45+
print("!folder " + folder)
46+
# Open file
47+
newfolder = "./problems/" + folder
48+
#print("!newfolder " + newfolder)
49+
#for name in os.listdir(newfolder):
50+
#print("name " + name)
51+
filename = os.path.join(newfolder, "README.md")
52+
print("filename " + filename)
53+
newfilename = destination + folder + '.html'
54+
newfilenamePdf = destination + folder + '.pdf'
55+
path = os.path.abspath(newfilename)
56+
converter.convert(f'file:///{path}', f'file:///{newfilenamePdf}')
57+
'''

final/0001-two-sum.html

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<h2><a href="https://leetcode.com/problems/two-sum/">1. Two Sum</a></h2><h3>Easy</h3><hr><div><p>Given an array of integers <code>nums</code>&nbsp;and an integer <code>target</code>, return <em>indices of the two numbers such that they add up to <code>target</code></em>.</p>
2+
3+
<p>You may assume that each input would have <strong><em>exactly</em> one solution</strong>, and you may not use the <em>same</em> element twice.</p>
4+
5+
<p>You can return the answer in any order.</p>
6+
7+
<p>&nbsp;</p>
8+
<p><strong class="example">Example 1:</strong></p>
9+
10+
<pre><strong>Input:</strong> nums = [2,7,11,15], target = 9
11+
<strong>Output:</strong> [0,1]
12+
<strong>Explanation:</strong> Because nums[0] + nums[1] == 9, we return [0, 1].
13+
</pre>
14+
15+
<p><strong class="example">Example 2:</strong></p>
16+
17+
<pre><strong>Input:</strong> nums = [3,2,4], target = 6
18+
<strong>Output:</strong> [1,2]
19+
</pre>
20+
21+
<p><strong class="example">Example 3:</strong></p>
22+
23+
<pre><strong>Input:</strong> nums = [3,3], target = 6
24+
<strong>Output:</strong> [0,1]
25+
</pre>
26+
27+
<p>&nbsp;</p>
28+
<p><strong>Constraints:</strong></p>
29+
30+
<ul>
31+
<li><code>2 &lt;= nums.length &lt;= 10<sup>4</sup></code></li>
32+
<li><code>-10<sup>9</sup> &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
33+
<li><code>-10<sup>9</sup> &lt;= target &lt;= 10<sup>9</sup></code></li>
34+
<li><strong>Only one valid answer exists.</strong></li>
35+
</ul>
36+
37+
<p>&nbsp;</p>
38+
<strong>Follow-up:&nbsp;</strong>Can you come up with an algorithm that is less than&nbsp;<code>O(n<sup>2</sup>)&nbsp;</code>time complexity?</div>

final/0002-add-two-numbers.html

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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<h2><a href="https://leetcode.com/problems/median-of-two-sorted-arrays/">4. Median of Two Sorted Arrays</a></h2><h3>Hard</h3><hr><div><p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
2+
3+
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
4+
5+
<p>&nbsp;</p>
6+
<p><strong class="example">Example 1:</strong></p>
7+
8+
<pre><strong>Input:</strong> nums1 = [1,3], nums2 = [2]
9+
<strong>Output:</strong> 2.00000
10+
<strong>Explanation:</strong> merged array = [1,2,3] and median is 2.
11+
</pre>
12+
13+
<p><strong class="example">Example 2:</strong></p>
14+
15+
<pre><strong>Input:</strong> nums1 = [1,2], nums2 = [3,4]
16+
<strong>Output:</strong> 2.50000
17+
<strong>Explanation:</strong> merged array = [1,2,3,4] and median is (2 + 3) / 2 = 2.5.
18+
</pre>
19+
20+
<p>&nbsp;</p>
21+
<p><strong>Constraints:</strong></p>
22+
23+
<ul>
24+
<li><code>nums1.length == m</code></li>
25+
<li><code>nums2.length == n</code></li>
26+
<li><code>0 &lt;= m &lt;= 1000</code></li>
27+
<li><code>0 &lt;= n &lt;= 1000</code></li>
28+
<li><code>1 &lt;= m + n &lt;= 2000</code></li>
29+
<li><code>-10<sup>6</sup> &lt;= nums1[i], nums2[i] &lt;= 10<sup>6</sup></code></li>
30+
</ul>
31+
</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>

final/0006-zigzag-conversion.html

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>

final/0007-reverse-integer.html

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>

0 commit comments

Comments
 (0)