Skip to content

Commit ef2eda1

Browse files
authored
Updated readmes
1 parent fbc98ee commit ef2eda1

File tree

49 files changed

+316
-91
lines changed

Some content is hidden

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

49 files changed

+316
-91
lines changed

src/main/python/g0001_0100/s0001_two_sum/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ You can return the answer in any order.
4040

4141
**Follow-up:** Can you come up with an algorithm that is less than <code>O(n<sup>2</sup>)</code> time complexity?
4242

43-
44-
4543
## Solution
4644

4745
```python

src/main/python/g0001_0100/s0002_add_two_numbers/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ You may assume the two numbers do not contain any leading zero, except the numbe
3737
* `0 <= Node.val <= 9`
3838
* It is guaranteed that the list represents a number that does not have leading zeros.
3939

40-
41-
4240
## Solution
4341

4442
```python

src/main/python/g0001_0100/s0003_longest_substring_without_repeating_characters/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ Given a string `s`, find the length of the **longest substring** without repeati
4242
* <code>0 <= s.length <= 5 * 10<sup>4</sup></code>
4343
* `s` consists of English letters, digits, symbols and spaces.
4444

45-
46-
4745
## Solution
4846

4947
```python

src/main/python/g0001_0100/s0004_median_of_two_sorted_arrays/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ The overall run time complexity should be `O(log (m+n))`.
5252
* `1 <= m + n <= 2000`
5353
* <code>-10<sup>6</sup> <= nums1[i], nums2[i] <= 10<sup>6</sup></code>
5454

55-
56-
5755
## Solution
5856

5957
```python

src/main/python/g0001_0100/s0005_longest_palindromic_substring/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ Given a string `s`, return _the longest palindromic substring_ in `s`.
3636
* `1 <= s.length <= 1000`
3737
* `s` consist of only digits and English letters.
3838

39-
40-
4139
## Solution
4240

4341
```python

src/main/python/g0001_0100/s0006_zigzag_conversion/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ string convert(string s, int numRows);
4141
* `s` consists of English letters (lower-case and upper-case), `','` and `'.'`.
4242
* `1 <= numRows <= 1000`
4343

44-
45-
4644
## Solution
4745

4846
```python

src/main/python/g0001_0100/s0007_reverse_integer/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ Given a signed 32-bit integer `x`, return `x` _with its digits reversed_. If rev
3737

3838
* <code>-2<sup>31</sup> <= x <= 2<sup>31</sup> - 1</code>
3939

40-
41-
4240
## Solution
4341

4442
```python

src/main/python/g0001_0100/s0008_string_to_integer_atoi/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ Since -91283472332 is less than the lower bound of the range [-2<sup>31</sup>, 2
115115
* `0 <= s.length <= 200`
116116
* `s` consists of English letters (lower-case and upper-case), digits (`0-9`), `' '`, `'+'`, `'-'`, and `'.'`.
117117

118-
119-
120118
## Solution
121119

122120
```python

src/main/python/g0001_0100/s0009_palindrome_number/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ An integer is a **palindrome** when it reads the same backward as forward. For e
4343

4444
**Follow up:** Could you solve it without converting the integer to a string?
4545

46-
47-
4846
## Solution
4947

5048
```python

src/main/python/g0001_0100/s0010_regular_expression_matching/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ The matching should cover the **entire** input string (not partial).
5858
* `p` contains only lowercase English letters, `'.'`, and `'*'`.
5959
* It is guaranteed for each appearance of the character `'*'`, there will be a previous valid character to match.
6060

61-
62-
6361
## Solution
6462

6563
```python

src/main/python/g0001_0100/s0011_container_with_most_water/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ Given `n` non-negative integers <code>a<sub>1</sub>, a<sub>2</sub>, ..., a<sub>n
4343
* <code>2 <= n <= 10<sup>5</sup></code>
4444
* <code>0 <= height[i] <= 10<sup>4</sup></code>
4545

46-
47-
4846
## Solution
4947

5048
```python

src/main/python/g0001_0100/s0015_3sum/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ Notice that the solution set must not contain duplicate triplets.
3232
* `0 <= nums.length <= 3000`
3333
* <code>-10<sup>5</sup> <= nums[i] <= 10<sup>5</sup></code>
3434

35-
36-
3735
## Solution
3836

3937
```python

src/main/python/g0001_0100/s0017_letter_combinations_of_a_phone_number/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ A mapping of digit to letters (just like on the telephone buttons) is given belo
3434
* `0 <= digits.length <= 4`
3535
* `digits[i]` is a digit in the range `['2', '9']`.
3636

37-
38-
3937
## Solution
4038

4139
```python

src/main/python/g0001_0100/s0019_remove_nth_node_from_end_of_list/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ Given the `head` of a linked list, remove the `nth` node from the end of the lis
3636

3737
**Follow up:** Could you do this in one pass?
3838

39-
40-
4139
## Solution
4240

4341
```python

src/main/python/g0001_0100/s0020_valid_parentheses/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ An input string is valid if:
4747
* <code>1 <= s.length <= 10<sup>4</sup></code>
4848
* `s` consists of parentheses only `'()[]{}'`.
4949

50-
51-
5250
## Solution
5351

5452
```python

src/main/python/g0001_0100/s0021_merge_two_sorted_lists/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ Merge two sorted linked lists and return it as a **sorted** list. The list shoul
3333
* `-100 <= Node.val <= 100`
3434
* Both `l1` and `l2` are sorted in **non-decreasing** order.
3535

36-
37-
3836
## Solution
3937

4038
```python

src/main/python/g0001_0100/s0022_generate_parentheses/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ Given `n` pairs of parentheses, write a function to _generate all combinations o
2323

2424
* `1 <= n <= 8`
2525

26-
27-
2826
## Solution
2927

3028
```python

src/main/python/g0001_0100/s0023_merge_k_sorted_lists/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ _Merge all the linked-lists into one sorted linked-list and return it._
3838
* `lists[i]` is sorted in **ascending order**.
3939
* The sum of `lists[i].length` won't exceed `10^4`.
4040

41-
42-
4341
## Solution
4442

4543
```python

src/main/python/g0001_0100/s0024_swap_nodes_in_pairs/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ Given a linked list, swap every two adjacent nodes and return its head. You must
3232
* The number of nodes in the list is in the range `[0, 100]`.
3333
* `0 <= Node.val <= 100`
3434

35-
36-
3735
## Solution
3836

3937
```python

src/main/python/g0001_0100/s0025_reverse_nodes_in_k_group/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ You may not alter the values in the list's nodes, only nodes themselves may be c
4848

4949
**Follow-up:** Can you solve the problem in O(1) extra memory space?
5050

51-
52-
5351
## Solution
5452

5553
```python

src/main/python/g0001_0100/s0031_next_permutation/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ The replacement must be **[in place](http://en.wikipedia.org/wiki/In-place_algor
4040
* `1 <= nums.length <= 100`
4141
* `0 <= nums[i] <= 100`
4242

43-
44-
4543
## Solution
4644

4745
```python

src/main/python/g0001_0100/s0032_longest_valid_parentheses/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ Given a string containing just the characters `'('` and `')'`, find the length o
3434
* <code>0 <= s.length <= 3 * 10<sup>4</sup></code>
3535
* `s[i]` is `'('`, or `')'`.
3636

37-
38-
3937
## Solution
4038

4139
```python

src/main/python/g0001_0100/s0033_search_in_rotated_sorted_array/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ You must write an algorithm with `O(log n)` runtime complexity.
3939
* `nums` is an ascending array that is possibly rotated.
4040
* <code>-10<sup>4</sup> <= target <= 10<sup>4</sup></code>
4141

42-
43-
4442
## Solution
4543

4644
```python

src/main/python/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/readme.md

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,73 @@ You must write an algorithm with `O(log n)` runtime complexity.
3636
* `nums` is a non-decreasing array.
3737
* <code>-10<sup>9</sup> <= target <= 10<sup>9</sup></code>
3838

39-
To solve this problem efficiently with a runtime complexity of O(log n), we can use binary search to find the starting and ending positions of the target value in the sorted array.
39+
To solve this problem efficiently with a runtime complexity of O(log n), we can use binary search to find the starting and ending positions of the target value in the sorted array. Here are the steps:
40+
41+
### Approach:
42+
43+
1. **Binary Search for Starting Position:**
44+
- Use binary search to find the starting position of the target value.
45+
- When the target value is found, continue searching towards the left to find the leftmost occurrence.
46+
- Update the left boundary to narrow down the search space.
47+
48+
2. **Binary Search for Ending Position:**
49+
- Use binary search to find the ending position of the target value.
50+
- When the target value is found, continue searching towards the right to find the rightmost occurrence.
51+
- Update the right boundary to narrow down the search space.
52+
53+
3. **Handle Missing Target:**
54+
- If the target value is not found, return [-1, -1].
55+
56+
### Python Code:
57+
58+
```python
59+
class Solution:
60+
def searchRange(self, nums, target):
61+
def search_boundary(nums, target, is_left):
62+
left, right = 0, len(nums) - 1
63+
boundary = -1
64+
65+
while left <= right:
66+
mid = (left + right) // 2
67+
68+
if nums[mid] == target:
69+
boundary = mid
70+
if is_left:
71+
right = mid - 1
72+
else:
73+
left = mid + 1
74+
elif nums[mid] < target:
75+
left = mid + 1
76+
else:
77+
right = mid - 1
78+
79+
return boundary
80+
81+
left_boundary = search_boundary(nums, target, is_left=True)
82+
right_boundary = search_boundary(nums, target, is_left=False)
83+
84+
return [left_boundary, right_boundary]
85+
86+
# Example Usage:
87+
solution = Solution()
88+
89+
# Example 1:
90+
nums1 = [5, 7, 7, 8, 8, 10]
91+
target1 = 8
92+
print(solution.searchRange(nums1, target1)) # Output: [3, 4]
93+
94+
# Example 2:
95+
nums2 = [5, 7, 7, 8, 8, 10]
96+
target2 = 6
97+
print(solution.searchRange(nums2, target2)) # Output: [-1, -1]
98+
99+
# Example 3:
100+
nums3 = []
101+
target3 = 0
102+
print(solution.searchRange(nums3, target3)) # Output: [-1, -1]
103+
```
104+
105+
This code defines a `Solution` class with a `searchRange` method to find the starting and ending positions of the target value in the given array. The example usage demonstrates how to create an instance of the `Solution` class and call the `searchRange` method with different inputs.
40106

41107
## Solution
42108

src/main/python/g0001_0100/s0035_search_insert_position/readme.md

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,65 @@ You must write an algorithm with `O(log n)` runtime complexity.
4646
* `nums` contains **distinct** values sorted in **ascending** order.
4747
* <code>-10<sup>4</sup> <= target <= 10<sup>4</sup></code>
4848

49-
To solve this problem efficiently with a runtime complexity of O(log n), we can use binary search to find the insertion position of the target value in the sorted array.
49+
To solve this problem efficiently with a runtime complexity of O(log n), we can use binary search to find the insertion position of the target value in the sorted array. Here are the steps:
50+
51+
### Approach:
52+
53+
1. **Binary Search:**
54+
- Implement binary search to find the insertion position of the target value.
55+
- If the target value is found, return its index.
56+
- If the target value is not found, binary search will determine the index where the target would be inserted to maintain the sorted order.
57+
58+
### Python Code:
59+
60+
```python
61+
class Solution:
62+
def searchInsert(self, nums, target):
63+
left, right = 0, len(nums) - 1
64+
65+
while left <= right:
66+
mid = (left + right) // 2
67+
68+
if nums[mid] == target:
69+
return mid
70+
elif nums[mid] < target:
71+
left = mid + 1
72+
else:
73+
right = mid - 1
74+
75+
# If the target is not found, return the insertion position (left).
76+
return left
77+
78+
# Example Usage:
79+
solution = Solution()
80+
81+
# Example 1:
82+
nums1 = [1, 3, 5, 6]
83+
target1 = 5
84+
print(solution.searchInsert(nums1, target1)) # Output: 2
85+
86+
# Example 2:
87+
nums2 = [1, 3, 5, 6]
88+
target2 = 2
89+
print(solution.searchInsert(nums2, target2)) # Output: 1
90+
91+
# Example 3:
92+
nums3 = [1, 3, 5, 6]
93+
target3 = 7
94+
print(solution.searchInsert(nums3, target3)) # Output: 4
95+
96+
# Example 4:
97+
nums4 = [1, 3, 5, 6]
98+
target4 = 0
99+
print(solution.searchInsert(nums4, target4)) # Output: 0
100+
101+
# Example 5:
102+
nums5 = [1]
103+
target5 = 0
104+
print(solution.searchInsert(nums5, target5)) # Output: 0
105+
```
106+
107+
This code defines a `Solution` class with a `searchInsert` method to find the insertion position of the target value in the given sorted array. The example usage demonstrates how to create an instance of the `Solution` class and call the `searchInsert` method with different inputs.
50108

51109
## Solution
52110

src/main/python/g0001_0100/s0039_combination_sum/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ It is **guaranteed** that the number of unique combinations that sum up to `targ
5454
* All elements of `candidates` are **distinct**.
5555
* `1 <= target <= 500`
5656

57-
58-
5957
## Solution
6058

6159
```python

src/main/python/g0001_0100/s0041_first_missing_positive/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ You must implement an algorithm that runs in `O(n)` time and uses constant extra
3232
* <code>1 <= nums.length <= 5 * 10<sup>5</sup></code>
3333
* <code>-2<sup>31</sup> <= nums[i] <= 2<sup>31</sup> - 1</code>
3434

35-
36-
3735
## Solution
3836

3937
```python

src/main/python/g0001_0100/s0042_trapping_rain_water/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ Given `n` non-negative integers representing an elevation map where the width of
2929
* <code>1 <= n <= 2 * 10<sup>4</sup></code>
3030
* <code>0 <= height[i] <= 10<sup>5</sup></code>
3131

32-
33-
3432
## Solution
3533

3634
```python

src/main/python/g0001_0100/s0045_jump_game_ii/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ You can assume that you can always reach the last index.
3232
* <code>1 <= nums.length <= 10<sup>4</sup></code>
3333
* `0 <= nums[i] <= 1000`
3434

35-
36-
3735
## Solution
3836

3937
```python

src/main/python/g0001_0100/s0046_permutations/readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ Given an array `nums` of distinct integers, return _all the possible permutation
3131
* `-10 <= nums[i] <= 10`
3232
* All the integers of `nums` are **unique**.
3333

34-
35-
3634
## Solution
3735

3836
```python

0 commit comments

Comments
 (0)