Skip to content

Commit f2922e1

Browse files
authored
Added tasks 6-9, 494-1143
1 parent dbd9261 commit f2922e1

File tree

36 files changed

+1006
-0
lines changed

36 files changed

+1006
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ implementation 'com.github.javadev:leetcode-in-scala:1.0'
152152

153153
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
154154
|-|-|-|-|-|-
155+
| 1143 |[Longest Common Subsequence](src/main/scala/g1101_1200/s1143_longest_common_subsequence/Solution.scala)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n\*m)_Space_O(n\*m) | 507 | 100.00
155156

156157
#### Day 18 Dynamic Programming
157158

@@ -458,6 +459,7 @@ implementation 'com.github.javadev:leetcode-in-scala:1.0'
458459

459460
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
460461
|-|-|-|-|-|-
462+
| 1143 |[Longest Common Subsequence](src/main/scala/g1101_1200/s1143_longest_common_subsequence/Solution.scala)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n\*m)_Space_O(n\*m) | 507 | 100.00
461463
| 0072 |[Edit Distance](src/main/scala/g0001_0100/s0072_edit_distance/Solution.scala)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 487 | 100.00
462464

463465
#### Day 20
@@ -566,6 +568,7 @@ implementation 'com.github.javadev:leetcode-in-scala:1.0'
566568

567569
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
568570
|-|-|-|-|-|-
571+
| 0739 |[Daily Temperatures](src/main/scala/g0701_0800/s0739_daily_temperatures/Solution.scala)| Medium | Top_100_Liked_Questions, Array, Stack, Monotonic_Stack, Big_O_Time_O(n)_Space_O(n) | 931 | 97.30
569572

570573
#### Day 7
571574

@@ -897,6 +900,7 @@ implementation 'com.github.javadev:leetcode-in-scala:1.0'
897900

898901
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
899902
|-|-|-|-|-|-
903+
| 0543 |[Diameter of Binary Tree](src/main/scala/g0501_0600/s0543_diameter_of_binary_tree/Solution.scala)| Easy | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 479 | 90.48
900904
| 0437 |[Path Sum III](src/main/scala/g0401_0500/s0437_path_sum_iii/Solution.scala)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 498 | 90.91
901905

902906
#### Day 8 Binary Search
@@ -986,6 +990,8 @@ implementation 'com.github.javadev:leetcode-in-scala:1.0'
986990
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
987991
|-|-|-|-|-|-
988992
| 0136 |[Single Number](src/main/scala/g0101_0200/s0136_single_number/Solution.scala)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Big_O_Time_O(N)_Space_O(1) | 530 | 78.57
993+
| 0007 |[Reverse Integer](src/main/scala/g0001_0100/s0007_reverse_integer/Solution.scala)| Medium | Top_Interview_Questions, Math | 405 | 90.16
994+
| 0009 |[Palindrome Number](src/main/scala/g0001_0100/s0009_palindrome_number/Solution.scala)| Easy | Math | 453 | 99.49
989995

990996
#### Udemy Strings
991997

@@ -1068,6 +1074,7 @@ implementation 'com.github.javadev:leetcode-in-scala:1.0'
10681074
|-|-|-|-|-|-
10691075
| 0094 |[Binary Tree Inorder Traversal](src/main/scala/g0001_0100/s0094_binary_tree_inorder_traversal/Solution.scala)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Big_O_Time_O(n)_Space_O(n) | 456 | 68.42
10701076
| 0102 |[Binary Tree Level Order Traversal](src/main/scala/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.scala)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 522 | 83.33
1077+
| 0543 |[Diameter of Binary Tree](src/main/scala/g0501_0600/s0543_diameter_of_binary_tree/Solution.scala)| Easy | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 479 | 90.48
10711078
| 0226 |[Invert Binary Tree](src/main/scala/g0201_0300/s0226_invert_binary_tree/Solution.scala)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 421 | 97.33
10721079
| 0104 |[Maximum Depth of Binary Tree](src/main/scala/g0101_0200/s0104_maximum_depth_of_binary_tree/Solution.scala)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(H) | 472 | 90.83
10731080
| 0124 |[Binary Tree Maximum Path Sum](src/main/scala/g0101_0200/s0124_binary_tree_maximum_path_sum/Solution.scala)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 523 | 89.47
@@ -1096,6 +1103,7 @@ implementation 'com.github.javadev:leetcode-in-scala:1.0'
10961103
| 0070 |[Climbing Stairs](src/main/scala/g0001_0100/s0070_climbing_stairs/Solution.scala)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 369 | 98.32
10971104
| 0064 |[Minimum Path Sum](src/main/scala/g0001_0100/s0064_minimum_path_sum/Solution.scala)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 521 | 92.86
10981105
| 0300 |[Longest Increasing Subsequence](src/main/scala/g0201_0300/s0300_longest_increasing_subsequence/Solution.scala)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 522 | 88.89
1106+
| 1143 |[Longest Common Subsequence](src/main/scala/g1101_1200/s1143_longest_common_subsequence/Solution.scala)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n\*m)_Space_O(n\*m) | 507 | 100.00
10991107
| 0072 |[Edit Distance](src/main/scala/g0001_0100/s0072_edit_distance/Solution.scala)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 487 | 100.00
11001108
| 0010 |[Regular Expression Matching](src/main/scala/g0001_0100/s0010_regular_expression_matching/Solution.scala)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Recursion, Big_O_Time_O(m\*n)_Space_O(m\*n) | 459 | 75.00
11011109

@@ -1241,6 +1249,7 @@ implementation 'com.github.javadev:leetcode-in-scala:1.0'
12411249
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
12421250
|-|-|-|-|-|-
12431251
| 0238 |[Product of Array Except Self](src/main/scala/g0201_0300/s0238_product_of_array_except_self/Solution.scala)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Prefix_Sum, Big_O_Time_O(n^2)_Space_O(n) | 634 | 79.44
1252+
| 0560 |[Subarray Sum Equals K](src/main/scala/g0501_0600/s0560_subarray_sum_equals_k/Solution.scala)| Medium | Top_100_Liked_Questions, Array, Hash_Table, Prefix_Sum, Big_O_Time_O(n)_Space_O(n) | 627 | 92.31
12441253

12451254
#### Day 6 String
12461255

@@ -1251,6 +1260,7 @@ implementation 'com.github.javadev:leetcode-in-scala:1.0'
12511260

12521261
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
12531262
|-|-|-|-|-|-
1263+
| 0763 |[Partition Labels](src/main/scala/g0701_0800/s0763_partition_labels/Solution.scala)| Medium | Top_100_Liked_Questions, String, Hash_Table, Greedy, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 442 | 100.00
12541264

12551265
#### Day 8 String
12561266

@@ -1422,6 +1432,13 @@ implementation 'com.github.javadev:leetcode-in-scala:1.0'
14221432

14231433
| # | Title | Difficulty | Tag | Time, ms | Time, %
14241434
|------|----------------|-------------|-------------|----------|---------
1435+
| 1143 |[Longest Common Subsequence](src/main/scala/g1101_1200/s1143_longest_common_subsequence/Solution.scala)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, Algorithm_II_Day_17_Dynamic_Programming, Dynamic_Programming_I_Day_19, Udemy_Dynamic_Programming, Big_O_Time_O(n\*m)_Space_O(n\*m) | 507 | 100.00
1436+
| 0763 |[Partition Labels](src/main/scala/g0701_0800/s0763_partition_labels/Solution.scala)| Medium | Top_100_Liked_Questions, String, Hash_Table, Greedy, Two_Pointers, Data_Structure_II_Day_7_String, Big_O_Time_O(n)_Space_O(1) | 442 | 100.00
1437+
| 0739 |[Daily Temperatures](src/main/scala/g0701_0800/s0739_daily_temperatures/Solution.scala)| Medium | Top_100_Liked_Questions, Array, Stack, Monotonic_Stack, Programming_Skills_II_Day_6, Big_O_Time_O(n)_Space_O(n) | 931 | 97.30
1438+
| 0647 |[Palindromic Substrings](src/main/scala/g0601_0700/s0647_palindromic_substrings/Solution.scala)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n) | 423 | 100.00
1439+
| 0560 |[Subarray Sum Equals K](src/main/scala/g0501_0600/s0560_subarray_sum_equals_k/Solution.scala)| Medium | Top_100_Liked_Questions, Array, Hash_Table, Prefix_Sum, Data_Structure_II_Day_5_Array, Big_O_Time_O(n)_Space_O(n) | 627 | 92.31
1440+
| 0543 |[Diameter of Binary Tree](src/main/scala/g0501_0600/s0543_diameter_of_binary_tree/Solution.scala)| Easy | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Level_2_Day_7_Tree, Udemy_Tree_Stack_Queue, Big_O_Time_O(n)_Space_O(n) | 479 | 90.48
1441+
| 0494 |[Target Sum](src/main/scala/g0401_0500/s0494_target_sum/Solution.scala)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Backtracking, Big_O_Time_O(n\*(sum+s))_Space_O(n\*(sum+s)) | 494 | 100.00
14251442
| 0438 |[Find All Anagrams in a String](src/main/scala/g0401_0500/s0438_find_all_anagrams_in_a_string/Solution.scala)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Algorithm_II_Day_5_Sliding_Window, Programming_Skills_II_Day_12, Level_1_Day_12_Sliding_Window/Two_Pointer, Big_O_Time_O(n+m)_Space_O(1) | 576 | 100.00
14261443
| 0437 |[Path Sum III](src/main/scala/g0401_0500/s0437_path_sum_iii/Solution.scala)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Level_2_Day_7_Tree, Big_O_Time_O(n)_Space_O(n) | 498 | 90.91
14271444
| 0416 |[Partition Equal Subset Sum](src/main/scala/g0401_0500/s0416_partition_equal_subset_sum/Solution.scala)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Level_2_Day_13_Dynamic_Programming, Big_O_Time_O(n\*sums)_Space_O(n\*sums) | 577 | 100.00
@@ -1510,6 +1527,10 @@ implementation 'com.github.javadev:leetcode-in-scala:1.0'
15101527
| 0015 |[3Sum](src/main/scala/g0001_0100/s0015_3sum/Solution.scala)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Data_Structure_II_Day_1_Array, Algorithm_II_Day_3_Two_Pointers, Udemy_Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 721 | 95.24
15111528
| 0011 |[Container With Most Water](src/main/scala/g0001_0100/s0011_container_with_most_water/Solution.scala)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Greedy, Two_Pointers, Algorithm_II_Day_4_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 683 | 99.13
15121529
| 0010 |[Regular Expression Matching](src/main/scala/g0001_0100/s0010_regular_expression_matching/Solution.scala)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Recursion, Udemy_Dynamic_Programming, Big_O_Time_O(m\*n)_Space_O(m\*n) | 459 | 75.00
1530+
| 0009 |[Palindrome Number](src/main/scala/g0001_0100/s0009_palindrome_number/Solution.scala)| Easy | Math, Udemy_Integers | 453 | 99.49
1531+
| 0008 |[String to Integer (atoi)](src/main/scala/g0001_0100/s0008_string_to_integer_atoi/Solution.scala)| Medium | Top_Interview_Questions, String | 441 | 100.00
1532+
| 0007 |[Reverse Integer](src/main/scala/g0001_0100/s0007_reverse_integer/Solution.scala)| Medium | Top_Interview_Questions, Math, Udemy_Integers | 405 | 90.16
1533+
| 0006 |[Zigzag Conversion](src/main/scala/g0001_0100/s0006_zigzag_conversion/Solution.scala)| Medium | String | 542 | 85.71
15131534
| 0005 |[Longest Palindromic Substring](src/main/scala/g0001_0100/s0005_longest_palindromic_substring/Solution.scala)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Data_Structure_II_Day_9_String, Algorithm_II_Day_14_Dynamic_Programming, Dynamic_Programming_I_Day_17, Udemy_Strings, Big_O_Time_O(n)_Space_O(n) | 502 | 87.65
15141535
| 0004 |[Median of Two Sorted Arrays](src/main/scala/g0001_0100/s0004_median_of_two_sorted_arrays/Solution.scala)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Divide_and_Conquer, Big_O_Time_O(log(min(N,M)))_Space_O(1) | 644 | 80.82
15151536
| 0003 |[Longest Substring Without Repeating Characters](src/main/scala/g0001_0100/s0003_longest_substring_without_repeating_characters/Solution.scala)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Algorithm_I_Day_6_Sliding_Window, Level_2_Day_14_Sliding_Window/Two_Pointer, Udemy_Strings, Big_O_Time_O(n)_Space_O(1) | 482 | 96.91
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package g0001_0100.s0006_zigzag_conversion
2+
3+
import scala.collection.mutable
4+
5+
// #Medium #String #2023_11_09_Time_542_ms_(85.71%)_Space_55.7_MB_(90.48%)
6+
7+
object Solution {
8+
def convert(s: String, numRows: Int): String = {
9+
if (numRows == 1) return s
10+
val map = new mutable.HashMap[Int, String]()
11+
var string = ""
12+
var counter = 0
13+
var counterBool = true
14+
for (i <- s) {
15+
val currentValue = map.getOrElse(counter, "")
16+
map(counter) = currentValue + i.toString
17+
counterBool = if (counter == numRows - 1) false else if (counter == 0) true else counterBool
18+
counter = if (counterBool) counter + 1 else counter - 1
19+
}
20+
map.foreach {
21+
case (_, value) => string += value
22+
}
23+
string
24+
}
25+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
6\. Zigzag Conversion
2+
3+
Medium
4+
5+
The string `"PAYPALISHIRING"` 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)
6+
7+
P A H N A P L S I I G Y I R
8+
9+
And then read line by line: `"PAHNAPLSIIGYIR"`
10+
11+
Write the code that will take a string and make this conversion given a number of rows:
12+
13+
string convert(string s, int numRows);
14+
15+
**Example 1:**
16+
17+
**Input:** s = "PAYPALISHIRING", numRows = 3
18+
19+
**Output:** "PAHNAPLSIIGYIR"
20+
21+
**Example 2:**
22+
23+
**Input:** s = "PAYPALISHIRING", numRows = 4
24+
25+
**Output:** "PINALSIGYAHRPI"
26+
27+
**Explanation:** P I N A L S I G Y A H R P I
28+
29+
**Example 3:**
30+
31+
**Input:** s = "A", numRows = 1
32+
33+
**Output:** "A"
34+
35+
**Constraints:**
36+
37+
* `1 <= s.length <= 1000`
38+
* `s` consists of English letters (lower-case and upper-case), `','` and `'.'`.
39+
* `1 <= numRows <= 1000`
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package g0001_0100.s0007_reverse_integer
2+
3+
// #Medium #Top_Interview_Questions #Math #Udemy_Integers
4+
// #2023_11_09_Time_405_ms_(90.16%)_Space_52.3_MB_(31.15%)
5+
6+
object Solution {
7+
def reverse(x: Int): Int = {
8+
var rev: Long = 0
9+
var remaining = x
10+
while (remaining != 0) {
11+
rev = (rev * 10) + (remaining % 10)
12+
remaining /= 10
13+
}
14+
if (rev > Integer.MAX_VALUE || rev < Integer.MIN_VALUE) {
15+
return 0
16+
}
17+
rev.toInt
18+
}
19+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
7\. Reverse Integer
2+
3+
Medium
4+
5+
Given a signed 32-bit integer `x`, return `x` _with its digits reversed_. If reversing `x` 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 `0`.
6+
7+
**Assume the environment does not allow you to store 64-bit integers (signed or unsigned).**
8+
9+
**Example 1:**
10+
11+
**Input:** x = 123
12+
13+
**Output:** 321
14+
15+
**Example 2:**
16+
17+
**Input:** x = -123
18+
19+
**Output:** -321
20+
21+
**Example 3:**
22+
23+
**Input:** x = 120
24+
25+
**Output:** 21
26+
27+
**Example 4:**
28+
29+
**Input:** x = 0
30+
31+
**Output:** 0
32+
33+
**Constraints:**
34+
35+
* <code>-2<sup>31</sup> <= x <= 2<sup>31</sup> - 1</code>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package g0001_0100.s0008_string_to_integer_atoi
2+
3+
// #Medium #Top_Interview_Questions #String #2023_11_09_Time_441_ms_(100.00%)_Space_54.7_MB_(67.86%)
4+
5+
object Solution {
6+
@SuppressWarnings(Array("scala:S3776"))
7+
def myAtoi(str: String): Int = {
8+
if (str == null || str.isEmpty) {
9+
return 0
10+
}
11+
12+
var i = 0
13+
var negativeSign = false
14+
val input = str.toCharArray
15+
16+
while (i < input.length && input(i) == ' ') {
17+
i += 1
18+
}
19+
20+
if (i == input.length) {
21+
return 0
22+
} else if (input(i) == '+') {
23+
i += 1
24+
} else if (input(i) == '-') {
25+
i += 1
26+
negativeSign = true
27+
}
28+
29+
var num = 0
30+
while (i < input.length && input(i) <= '9' && input(i) >= '0') {
31+
// current char
32+
val temp = input(i) - '0'
33+
val tempValue = if (negativeSign) -temp else temp
34+
35+
// avoid invalid numbers like 038
36+
if (num == 0 && tempValue == 0) {
37+
i += 1
38+
} else if (num == Integer.MIN_VALUE / 10 && tempValue <= -8 || num < Integer.MIN_VALUE / 10) {
39+
return Integer.MIN_VALUE
40+
} else if (num == Integer.MAX_VALUE / 10 && tempValue >= 7 || num > Integer.MAX_VALUE / 10) {
41+
return Integer.MAX_VALUE
42+
} else {
43+
num = num * 10 + tempValue
44+
i += 1
45+
}
46+
}
47+
48+
num
49+
}
50+
}

0 commit comments

Comments
 (0)