Skip to content

Commit d7e8641

Browse files
committed
Updated java and kotlin tasks
1 parent f9ef4ce commit d7e8641

File tree

95 files changed

+775
-592
lines changed

Some content is hidden

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

95 files changed

+775
-592
lines changed

README.md

+156-152
Large diffs are not rendered by default.

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ You can return the answer in any order.
1717

1818
**Output:** [0,1]
1919

20-
**Explanation:** Because nums[0] + nums[1] == 9, we return [0, 1].
20+
**Output:** Because nums[0] + nums[1] == 9, we return [0, 1].
2121

2222
**Example 2:**
2323

@@ -38,7 +38,7 @@ You can return the answer in any order.
3838
* <code>-10<sup>9</sup> <= target <= 10<sup>9</sup></code>
3939
* **Only one valid answer exists.**
4040

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

4343
## Solution
4444

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,14 @@ class Solution {
5353
var lpsCenter = 0
5454
var lpsRadius = 0
5555
for (i in newStr.indices) {
56-
dp[i] = if (friendCenter + friendRadius > i) Math.min(
57-
dp[friendCenter * 2 - i],
58-
friendCenter + friendRadius - i
59-
) else 1
56+
dp[i] = if (friendCenter + friendRadius > i) {
57+
Math.min(
58+
dp[friendCenter * 2 - i],
59+
friendCenter + friendRadius - i,
60+
)
61+
} else {
62+
1
63+
}
6064
while (i + dp[i] < newStr.size && i - dp[i] >= 0 && newStr[i + dp[i]] == newStr[i - dp[i]]) {
6165
dp[i]++
6266
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class Solution {
8989
i,
9090
j - 2,
9191
s,
92-
p
92+
p,
9393
)
9494
}
9595
} else {

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ A mapping of digit to letters (just like on the telephone buttons) is given belo
1515

1616
**Input:** digits = "23"
1717

18-
**Output:** ["ad","ae","af","bd","be","bf","cd","ce","cf"]
18+
**Output:** ["ad","ae","af","bd","be","bf","cd","ce","cf"]
1919

2020
**Example 2:**
2121

2222
**Input:** digits = ""
2323

24-
**Output:** []
24+
**Output:** []
2525

2626
**Example 3:**
2727

2828
**Input:** digits = "2"
2929

30-
**Output:** ["a","b","c"]
30+
**Output:** ["a","b","c"]
3131

3232
**Constraints:**
3333

@@ -52,7 +52,7 @@ class Solution {
5252
nums: String,
5353
letters: Array<String>,
5454
curr: StringBuilder,
55-
ans: MutableList<String>
55+
ans: MutableList<String>,
5656
) {
5757
if (curr.length == nums.length) {
5858
ans.add(curr.toString())

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ Given the `head` of a linked list, remove the `nth` node from the end of the lis
1313

1414
**Input:** head = [1,2,3,4,5], n = 2
1515

16-
**Output:** [1,2,3,5]
16+
**Output:** [1,2,3,5]
1717

1818
**Example 2:**
1919

2020
**Input:** head = [1], n = 1
2121

22-
**Output:** []
22+
**Output:** []
2323

2424
**Example 3:**
2525

2626
**Input:** head = [1,2], n = 1
2727

28-
**Output:** [1]
28+
**Output:** [1]
2929

3030
**Constraints:**
3131

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,31 @@ An input string is valid if:
1616

1717
**Input:** s = "()"
1818

19-
**Output:** true
19+
**Output:** true
2020

2121
**Example 2:**
2222

2323
**Input:** s = "()[]{}"
2424

25-
**Output:** true
25+
**Output:** true
2626

2727
**Example 3:**
2828

2929
**Input:** s = "(]"
3030

31-
**Output:** false
31+
**Output:** false
3232

3333
**Example 4:**
3434

3535
**Input:** s = "([)]"
3636

37-
**Output:** false
37+
**Output:** false
3838

3939
**Example 5:**
4040

4141
**Input:** s = "{[]}"
4242

43-
**Output:** true
43+
**Output:** true
4444

4545
**Constraints:**
4646

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ Merge two sorted linked lists and return it as a **sorted** list. The list shoul
1313

1414
**Input:** l1 = [1,2,4], l2 = [1,3,4]
1515

16-
**Output:** [1,1,2,3,4,4]
16+
**Output:** [1,1,2,3,4,4]
1717

1818
**Example 2:**
1919

2020
**Input:** l1 = [], l2 = []
2121

22-
**Output:** []
22+
**Output:** []
2323

2424
**Example 3:**
2525

2626
**Input:** l1 = [], l2 = [0]
2727

28-
**Output:** [0]
28+
**Output:** [0]
2929

3030
**Constraints:**
3131

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ Given `n` pairs of parentheses, write a function to _generate all combinations o
1111

1212
**Input:** n = 3
1313

14-
**Output:** ["((()))","(()())","(())()","()(())","()()()"]
14+
**Output:** ["((()))","(()())","(())()","()(())","()()()"]
1515

1616
**Example 2:**
1717

1818
**Input:** n = 1
1919

20-
**Output:** ["()"]
20+
**Output:** ["()"]
2121

2222
**Constraints:**
2323

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ _Merge all the linked-lists into one sorted linked-list and return it._
1515

1616
**Output:** [1,1,2,3,4,4,5,6]
1717

18-
**Explanation:** The linked-lists are: [ 1->4->5, 1->3->4, 2->6 ] merging them into one sorted list: 1->1->2->3->4->4->5->6
18+
**Explanation:** The linked-lists are: [ 1->4->5, 1->3->4, 2->6 ] merging them into one sorted list: 1->1->2->3->4->4->5->6
1919

2020
**Example 2:**
2121

2222
**Input:** lists = []
2323

24-
**Output:** []
24+
**Output:** []
2525

2626
**Example 3:**
2727

2828
**Input:** lists = \[\[]]
2929

30-
**Output:** []
30+
**Output:** []
3131

3232
**Constraints:**
3333

@@ -56,7 +56,9 @@ class Solution {
5656
fun mergeKLists(lists: Array<ListNode>): ListNode? {
5757
return if (lists.isEmpty()) {
5858
null
59-
} else mergeKLists(lists, 0, lists.size)
59+
} else {
60+
mergeKLists(lists, 0, lists.size)
61+
}
6062
}
6163

6264
private fun mergeKLists(lists: Array<ListNode>, leftIndex: Int, rightIndex: Int): ListNode? {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ Given a linked list, swap every two adjacent nodes and return its head. You must
1313

1414
**Input:** head = [1,2,3,4]
1515

16-
**Output:** [2,1,4,3]
16+
**Output:** [2,1,4,3]
1717

1818
**Example 2:**
1919

2020
**Input:** head = []
2121

22-
**Output:** []
22+
**Output:** []
2323

2424
**Example 3:**
2525

2626
**Input:** head = [1]
2727

28-
**Output:** [1]
28+
**Output:** [1]
2929

3030
**Constraints:**
3131

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,27 @@ You may not alter the values in the list's nodes, only nodes themselves may be c
1717

1818
**Input:** head = [1,2,3,4,5], k = 2
1919

20-
**Output:** [2,1,4,3,5]
20+
**Output:** [2,1,4,3,5]
2121

2222
**Example 2:**
2323

2424
![](https://assets.leetcode.com/uploads/2020/10/03/reverse_ex2.jpg)
2525

2626
**Input:** head = [1,2,3,4,5], k = 3
2727

28-
**Output:** [3,2,1,4,5]
28+
**Output:** [3,2,1,4,5]
2929

3030
**Example 3:**
3131

3232
**Input:** head = [1,2,3,4,5], k = 1
3333

34-
**Output:** [1,2,3,4,5]
34+
**Output:** [1,2,3,4,5]
3535

3636
**Example 4:**
3737

3838
**Input:** head = [1], k = 1
3939

40-
**Output:** [1]
40+
**Output:** [1]
4141

4242
**Constraints:**
4343

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

+13-11
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,37 @@
55

66
Medium
77

8-
Implement **next permutation**, which rearranges numbers into the lexicographically next greater permutation of numbers.
8+
A **permutation** of an array of integers is an arrangement of its members into a sequence or linear order.
99

10-
If such an arrangement is not possible, it must rearrange it as the lowest possible order (i.e., sorted in ascending order).
10+
* For example, for `arr = [1,2,3]`, the following are all the permutations of `arr`: `[1,2,3], [1,3,2], [2, 1, 3], [2, 3, 1], [3,1,2], [3,2,1]`.
11+
12+
The **next permutation** of an array of integers is the next lexicographically greater permutation of its integer. More formally, if all the permutations of the array are sorted in one container according to their lexicographical order, then the **next permutation** of that array is the permutation that follows it in the sorted container. If such arrangement is not possible, the array must be rearranged as the lowest possible order (i.e., sorted in ascending order).
13+
14+
* For example, the next permutation of `arr = [1,2,3]` is `[1,3,2]`.
15+
* Similarly, the next permutation of `arr = [2,3,1]` is `[3,1,2]`.
16+
* While the next permutation of `arr = [3,2,1]` is `[1,2,3]` because `[3,2,1]` does not have a lexicographical larger rearrangement.
17+
18+
Given an array of integers `nums`, _find the next permutation of_ `nums`.
1119

1220
The replacement must be **[in place](http://en.wikipedia.org/wiki/In-place_algorithm)** and use only constant extra memory.
1321

1422
**Example 1:**
1523

1624
**Input:** nums = [1,2,3]
1725

18-
**Output:** [1,3,2]
26+
**Output:** [1,3,2]
1927

2028
**Example 2:**
2129

2230
**Input:** nums = [3,2,1]
2331

24-
**Output:** [1,2,3]
32+
**Output:** [1,2,3]
2533

2634
**Example 3:**
2735

2836
**Input:** nums = [1,1,5]
2937

30-
**Output:** [1,5,1]
31-
32-
**Example 4:**
33-
34-
**Input:** nums = [1]
35-
36-
**Output:** [1]
38+
**Output:** [1,5,1]
3739

3840
**Constraints:**
3941

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ Given a string containing just the characters `'('` and `')'`, find the length o
1313

1414
**Output:** 2
1515

16-
**Explanation:** The longest valid parentheses substring is "()".
16+
**Explanation:** The longest valid parentheses substring is "()".
1717

1818
**Example 2:**
1919

2020
**Input:** s = ")()())"
2121

2222
**Output:** 4
2323

24-
**Explanation:** The longest valid parentheses substring is "()()".
24+
**Explanation:** The longest valid parentheses substring is "()()".
2525

2626
**Example 3:**
2727

2828
**Input:** s = ""
2929

30-
**Output:** 0
30+
**Output:** 0
3131

3232
**Constraints:**
3333

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ You must write an algorithm with `O(log n)` runtime complexity.
1717

1818
**Input:** nums = [4,5,6,7,0,1,2], target = 0
1919

20-
**Output:** 4
20+
**Output:** 4
2121

2222
**Example 2:**
2323

2424
**Input:** nums = [4,5,6,7,0,1,2], target = 3
2525

26-
**Output:** -1
26+
**Output:** -1
2727

2828
**Example 3:**
2929

3030
**Input:** nums = [1], target = 0
3131

32-
**Output:** -1
32+
**Output:** -1
3333

3434
**Constraints:**
3535

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ You must write an algorithm with `O(log n)` runtime complexity.
1515

1616
**Input:** nums = [5,7,7,8,8,10], target = 8
1717

18-
**Output:** [3,4]
18+
**Output:** [3,4]
1919

2020
**Example 2:**
2121

2222
**Input:** nums = [5,7,7,8,8,10], target = 6
2323

24-
**Output:** [-1,-1]
24+
**Output:** [-1,-1]
2525

2626
**Example 3:**
2727

2828
**Input:** nums = [], target = 0
2929

30-
**Output:** [-1,-1]
30+
**Output:** [-1,-1]
3131

3232
**Constraints:**
3333

0 commit comments

Comments
 (0)