Skip to content

Commit ca1159e

Browse files
authored
Added tasks 3354-3357
1 parent 97a9abd commit ca1159e

File tree

387 files changed

+1484
-661
lines changed

Some content is hidden

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

387 files changed

+1484
-661
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,6 +1816,10 @@
18161816

18171817
| # | Title | Difficulty | Tag | Time, ms | Time, %
18181818
|------|----------------|-------------|-------------|----------|--------
1819+
| 3357 |[Minimize the Maximum Adjacent Element Difference](src/main/kotlin/g3301_3400/s3357_minimize_the_maximum_adjacent_element_difference)| Hard | Array, Greedy, Binary_Search | 13 | 100.00
1820+
| 3356 |[Zero Array Transformation II](src/main/kotlin/g3301_3400/s3356_zero_array_transformation_ii)| Medium | Array, Binary_Search, Prefix_Sum | 5 | 100.00
1821+
| 3355 |[Zero Array Transformation I](src/main/kotlin/g3301_3400/s3355_zero_array_transformation_i)| Medium | Array, Prefix_Sum | 6 | 36.84
1822+
| 3354 |[Make Array Elements Equal to Zero](src/main/kotlin/g3301_3400/s3354_make_array_elements_equal_to_zero)| Easy | Array, Simulation, Prefix_Sum | 153 | 96.67
18191823
| 3352 |[Count K-Reducible Numbers Less Than N](src/main/kotlin/g3301_3400/s3352_count_k_reducible_numbers_less_than_n)| Hard | String, Dynamic_Programming, Math, Combinatorics | 170 | 100.00
18201824
| 3351 |[Sum of Good Subsequences](src/main/kotlin/g3301_3400/s3351_sum_of_good_subsequences)| Hard | Array, Hash_Table, Dynamic_Programming | 16 | 100.00
18211825
| 3350 |[Adjacent Increasing Subarrays Detection II](src/main/kotlin/g3301_3400/s3350_adjacent_increasing_subarrays_detection_ii)| Medium | Array, Binary_Search | 947 | 48.57

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

Lines changed: 8 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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/s0023_merge_k_sorted_lists/readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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/s0030_substring_with_concatenation_of_all_words/readme.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ class Solution {
8686
// move a word's length each time
8787
var j = i
8888
while (j + window <= s.length) {
89-
9089
// get the subStr
9190
val subStr = s.substring(j, j + window)
9291
val map: MutableMap<String, Int> = HashMap()

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Solution {
4848
target: Int,
4949
start: Int,
5050
sums: MutableList<List<Int>>,
51-
sum: LinkedList<Int>
51+
sum: LinkedList<Int>,
5252
) {
5353
if (target == 0) {
5454
// make a deep copy of the current combination
@@ -57,7 +57,6 @@ class Solution {
5757
}
5858
var i = start
5959
while (i < candidates.size && target >= candidates[i]) {
60-
6160
// If candidate[i] equals candidate[i-1], then solutions for i is subset of
6261
// solution of i-1
6362
if (i == start || i > start && candidates[i] != candidates[i - 1]) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Solution {
4848
nums: IntArray,
4949
finalResult: MutableList<List<Int>>,
5050
currResult: MutableList<Int>,
51-
used: BooleanArray
51+
used: BooleanArray,
5252
) {
5353
if (currResult.size == nums.size) {
5454
finalResult.add(ArrayList(currResult))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Solution {
4343
intArrayOf(i, j),
4444
intArrayOf(j, n - 1 - i),
4545
intArrayOf(n - 1 - i, n - 1 - j),
46-
intArrayOf(n - 1 - j, i)
46+
intArrayOf(n - 1 - j, i),
4747
)
4848
var t = matrix[pos[0][0]][pos[0][1]]
4949
for (k in 1 until pos.size) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Solution {
4444
ch.sort()
4545
val temp = String(ch)
4646
hm.computeIfAbsent(
47-
temp
47+
temp,
4848
) { _: String? -> ArrayList() }
4949
hm.getValue(temp).add(s)
5050
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ class Solution {
5757
}
5858
return if (n < 0) {
5959
1.0 / res
60-
} else res
60+
} else {
61+
res
62+
}
6163
}
6264
}
6365
```

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Solution {
4747
row: BooleanArray,
4848
col: BooleanArray,
4949
diagonal: BooleanArray,
50-
antiDiagonal: BooleanArray
50+
antiDiagonal: BooleanArray,
5151
): Int {
5252
if (r == n) {
5353
return 1

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Solution {
5353
word: String,
5454
index: Int,
5555
x: Int,
56-
y: Int
56+
y: Int,
5757
): Boolean {
5858
if (index == word.length) {
5959
return true
@@ -82,7 +82,7 @@ class Solution {
8282
fun exist(board: Array<CharArray>, word: String): Boolean {
8383
val visited = Array(board.size) {
8484
BooleanArray(
85-
board[0].size
85+
board[0].size,
8686
)
8787
}
8888
for (i in board.indices) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class Solution {
7070
maxOfThreeNums(
7171
largestArea(a, start, minInd),
7272
a[minInd] * (limit - start),
73-
largestArea(a, minInd + 1, limit)
73+
largestArea(a, minInd + 1, limit),
7474
)
7575
}
7676
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Solution {
5252
'.' +
5353
octets[2] +
5454
'.' +
55-
octets[3]
55+
octets[3],
5656
)
5757
} else if (count < 4 && pos < 12) {
5858
var octet = 0

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Solution {
6767
i1: Int,
6868
i2: Int,
6969
i3: Int,
70-
cache: Array<Array<Boolean?>>
70+
cache: Array<Array<Boolean?>>,
7171
): Boolean {
7272
if (cache[i1][i2] != null) {
7373
return cache[i1][i2]!!

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ class Solution {
6464
}
6565
return if (root.`val` <= left || root.`val` >= right) {
6666
false
67-
} else solve(root.left, left, root.`val`.toLong()) && solve(root.right, root.`val`.toLong(), right)
67+
} else {
68+
solve(root.left, left, root.`val`.toLong()) && solve(root.right, root.`val`.toLong(), right)
69+
}
6870
}
6971
}
7072
```

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ class Solution {
5858
return if (n != null && m != null) {
5959
if (n.`val` != m.`val`) {
6060
false
61-
} else trav(n.left, m.left) && trav(n.right, m.right)
61+
} else {
62+
trav(n.left, m.left) && trav(n.right, m.right)
63+
}
6264
} else {
6365
n == null && m == null
6466
}

src/main/kotlin/g0101_0200/s0101_symmetric_tree/readme.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ class Solution {
4949
fun isSymmetric(root: TreeNode?): Boolean {
5050
return if (root == null) {
5151
true
52-
} else helper(root.left, root.right)
52+
} else {
53+
helper(root.left, root.right)
54+
}
5355
}
5456

5557
private fun helper(leftNode: TreeNode?, rightNode: TreeNode?): Boolean {
@@ -58,7 +60,9 @@ class Solution {
5860
}
5961
return if (leftNode.`val` != rightNode.`val`) {
6062
false
61-
} else helper(leftNode.left, rightNode.right) && helper(leftNode.right, rightNode.left)
63+
} else {
64+
helper(leftNode.left, rightNode.right) && helper(leftNode.right, rightNode.left)
65+
}
6266
}
6367
}
6468
```

src/main/kotlin/g0101_0200/s0112_path_sum/readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ class Solution {
7171
}
7272
return if (targetSum == root.`val` && root.left == null && root.right == null) {
7373
true
74-
} else hasPathSum(root.left, targetSum - root.`val`) || hasPathSum(root.right, targetSum - root.`val`)
74+
} else {
75+
hasPathSum(root.left, targetSum - root.`val`) || hasPathSum(root.right, targetSum - root.`val`)
76+
}
7577
}
7678
}
7779
```

src/main/kotlin/g0101_0200/s0113_path_sum_ii/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class Solution {
7474
al: ArrayList<Int>,
7575
sum: Int,
7676
targetSum: Int,
77-
root: TreeNode?
77+
root: TreeNode?,
7878
) {
7979
var sum = sum
8080
if (root == null) {

src/main/kotlin/g0101_0200/s0120_triangle/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class Solution {
6868
triangle[row][col] +
6969
Math.min(
7070
dfs(triangle, dp, row + 1, col),
71-
dfs(triangle, dp, row + 1, col + 1)
71+
dfs(triangle, dp, row + 1, col + 1),
7272
)
7373
)
7474
dp[row][col] = sum

src/main/kotlin/g0101_0200/s0123_best_time_to_buy_and_sell_stock_iii/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Find the maximum profit you can achieve. You may complete **at most two transact
4646
class Solution {
4747
fun maxProfit(prices: IntArray): Int {
4848
val n = prices.size
49-
if (n <2) {
49+
if (n < 2) {
5050
return 0
5151
}
5252
val a = IntArray(n) { 0 }

src/main/kotlin/g0101_0200/s0126_word_ladder_ii/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class Solution {
7676
if (isLadder(word, next)) {
7777
// construct the reverse graph from endWord
7878
val reverseLadders = reverse.computeIfAbsent(
79-
next
79+
next,
8080
) { _: String? -> HashSet() }
8181
reverseLadders.add(word)
8282
if (endWord == next) {
@@ -115,7 +115,7 @@ class Solution {
115115
beginWord: String,
116116
graph: Map<String, MutableSet<String>>,
117117
ans: MutableList<List<String>>,
118-
path: MutableSet<String>
118+
path: MutableSet<String>,
119119
) {
120120
val next = graph[endWord] ?: return
121121
for (word in next) {

src/main/kotlin/g0101_0200/s0128_longest_consecutive_sequence/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class Solution {
5050
if (num == lastNum) {
5151
continue
5252
}
53-
length ++
53+
length++
5454
if (num - lastNum > 1) {
5555
length = 1
5656
}

src/main/kotlin/g0101_0200/s0134_gas_station/readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ class Solution {
8181
}
8282
return if (sumGas < sumCost) {
8383
-1
84-
} else result
84+
} else {
85+
result
86+
}
8587
}
8688
}
8789
```

src/main/kotlin/g0101_0200/s0140_word_break_ii/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class Solution {
5555
wordSet: Set<String>,
5656
index: Int,
5757
sb: StringBuilder,
58-
result: MutableList<String>
58+
result: MutableList<String>,
5959
) {
6060
if (index == s.length) {
6161
if (sb[sb.length - 1] == ' ') {

src/main/kotlin/g0101_0200/s0150_evaluate_reverse_polish_notation/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class Solution {
6262
"/" to { a, b -> a / b },
6363
"*" to { a, b -> a * b },
6464
"+" to { a, b -> a + b },
65-
"-" to { a, b -> a - b }
65+
"-" to { a, b -> a - b },
6666
)
6767
fun evalRPN(tokens: Array<String>): Int {
6868
val stack = ArrayDeque<String>()

src/main/kotlin/g0101_0200/s0154_find_minimum_in_rotated_sorted_array_ii/readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ class Solution {
4444
fun findMin(nums: IntArray): Int {
4545
return if (nums.isEmpty()) {
4646
0
47-
} else find(0, nums.size - 1, nums)
47+
} else {
48+
find(0, nums.size - 1, nums)
49+
}
4850
}
4951

5052
private fun find(left: Int, right: Int, nums: IntArray): Int {

src/main/kotlin/g0101_0200/s0155_min_stack/readme.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ class MinStack() {
4848
private val stack: ArrayDeque<Pair<Int, Int>> = ArrayDeque()
4949

5050
fun push(x: Int) {
51-
val min: Int = if (stack.isEmpty()) x
52-
else getMin()
51+
val min: Int = if (stack.isEmpty()) {
52+
x
53+
} else {
54+
getMin()
55+
}
5356
stack.addLast(x to minOf(min, x))
5457
}
5558

src/main/kotlin/g0201_0300/s0201_bitwise_and_of_numbers_range/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class Solution {
7070
-0x10,
7171
-0x8,
7272
-0x4,
73-
-0x2
73+
-0x2,
7474
)
7575
}
7676
}

src/main/kotlin/g0201_0300/s0210_course_schedule_ii/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class Solution {
7575
private fun buildGraph(
7676
numCourses: Int,
7777
prerequisites: Array<IntArray>,
78-
indegrees: IntArray
78+
indegrees: IntArray,
7979
): List<List<Int>> {
8080
val graph = List(numCourses) { mutableListOf<Int>() }
8181
for ((cur, prev) in prerequisites) {

src/main/kotlin/g0201_0300/s0222_count_complete_tree_nodes/readme.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,17 @@ class Solution {
7070
private fun leftHeight(root: TreeNode?): Int {
7171
return if (root == null) {
7272
0
73-
} else 1 + leftHeight(root.left)
73+
} else {
74+
1 + leftHeight(root.left)
75+
}
7476
}
7577

7678
private fun rightHeight(root: TreeNode?): Int {
7779
return if (root == null) {
7880
0
79-
} else 1 + rightHeight(root.right)
81+
} else {
82+
1 + rightHeight(root.right)
83+
}
8084
}
8185
}
8286
```

src/main/kotlin/g0201_0300/s0258_add_digits/readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ class Solution {
3737
}
3838
return if (num % 9 == 0) {
3939
9
40-
} else num % 9
40+
} else {
41+
num % 9
42+
}
4143
}
4244
}
4345
```

0 commit comments

Comments
 (0)