File tree Expand file tree Collapse file tree 18 files changed +63
-27
lines changed
src/main/kotlin/g0001_0100
s0003_longest_substring_without_repeating_characters
s0004_median_of_two_sorted_arrays
s0005_longest_palindromic_substring
s0008_string_to_integer_atoi
s0010_regular_expression_matching
s0011_container_with_most_water
s0021_merge_two_sorted_lists
s0023_merge_k_sorted_lists
s0024_swap_nodes_in_pairs Expand file tree Collapse file tree 18 files changed +63
-27
lines changed Original file line number Diff line number Diff line change 1
1
package g0001_0100.s0001_two_sum
2
2
3
+ // #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table
4
+ // #Data_Structure_I_Day_2_Array #2022_03_22_Time_292_ms_(80.69%)_Space_41.6_MB_(60.71%)
5
+
3
6
import java.util.Arrays
4
7
5
8
class Solution {
Original file line number Diff line number Diff line change 1
1
package g0001_0100.s0002_add_two_numbers
2
2
3
+ // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Math #Linked_List #Recursion
4
+ // #Data_Structure_II_Day_10_Linked_List #Programming_Skills_II_Day_15
5
+ // #2022_03_22_Time_212_ms_(93.71%)_Space_43.1_MB_(81.36%)
6
+
3
7
import com_github_leetcode.ListNode
4
8
5
9
/*
Original file line number Diff line number Diff line change 1
1
package g0001_0100.s0003_longest_substring_without_repeating_characters
2
2
3
+ // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table #Sliding_Window
4
+ // #Algorithm_I_Day_6_Sliding_Window #2022_03_22_Time_212_ms_(91.24%)_Space_37_MB_(87.08%)
5
+
3
6
class Solution {
4
7
fun lengthOfLongestSubstring (s : String ): Int {
5
- val lastIndices = IntArray (256 )
6
- for (i in 0 .. 255 ) {
7
- lastIndices[i] = - 1
8
+ var i = 0
9
+ var j = 0
10
+ var longest = 0
11
+ // 1. if string empty, return 0
12
+ if (s.isEmpty()) {
13
+ return 0
8
14
}
9
- var maxLen = 0
10
- var curLen = 0
11
- var start = 0
12
- for (i in s.indices) {
13
- val cur = s[i]
14
- if (lastIndices[cur.code] < start) {
15
- lastIndices[cur.code] = i
16
- curLen++
15
+ while (j < s.length) {
16
+ // 2. if the char at index j already seen, update the longest if needs
17
+ if (i != j && s.substring(i, j).indexOf(s[j]) > - 1 ) {
18
+ longest = Math .max(j - i, longest)
19
+ i++
17
20
} else {
18
- val lastIndex = lastIndices[cur.code]
19
- start = lastIndex + 1
20
- curLen = i - start + 1
21
- lastIndices[cur.code] = i
22
- }
23
- if (curLen > maxLen) {
24
- maxLen = curLen
21
+ // 3. j out of bound already, update longest
22
+ if (++ j == s.length) {
23
+ longest = Math .max(s.length - i, longest)
24
+ break
25
+ }
25
26
}
26
27
}
27
- return maxLen
28
+ return longest
28
29
}
29
30
}
Original file line number Diff line number Diff line change 1
1
package g0001_0100.s0004_median_of_two_sorted_arrays
2
2
3
+ // #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Array #Binary_Search #Divide_and_Conquer
4
+ // #2022_03_22_Time_276_ms_(91.12%)_Space_47_MB_(85.71%)
5
+
3
6
import kotlin.collections.ArrayList
4
7
5
8
class Solution {
Original file line number Diff line number Diff line change 1
1
package g0001_0100.s0005_longest_palindromic_substring
2
2
3
+ // #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Dynamic_Programming
4
+ // #Data_Structure_II_Day_9_String #Algorithm_II_Day_14_Dynamic_Programming
5
+ // #Dynamic_Programming_I_Day_17 #2022_03_22_Time_359_ms_(69.08%)_Space_38.5_MB_(61.84%)
6
+
3
7
class Solution {
4
8
fun longestPalindrome (s : String ): String {
5
9
val newStr = CharArray (s.length * 2 + 1 )
Original file line number Diff line number Diff line change 1
1
package g0001_0100.s0006_zigzag_conversion
2
2
3
+ // #Medium #String #2022_03_22_Time_351_ms_(78.99%)_Space_40_MB_(84.02%)
4
+
3
5
class Solution {
4
6
fun convert (s : String , numRows : Int ): String {
5
7
val sLen = s.length
Original file line number Diff line number Diff line change 1
1
package g0001_0100.s0007_reverse_integer
2
2
3
+ // #Medium #Top_Interview_Questions #Math #2022_03_22_Time_230_ms_(57.36%)_Space_34.3_MB_(61.43%)
4
+
3
5
class Solution {
4
6
fun reverse (x : Int ): Int {
5
7
var rev: Long = 0
Original file line number Diff line number Diff line change 1
1
package g0001_0100.s0008_string_to_integer_atoi
2
2
3
+ // #Medium #Top_Interview_Questions #String #2022_03_22_Time_152_ms_(99.64%)_Space_35.2_MB_(97.83%)
4
+
3
5
class Solution {
4
6
fun myAtoi (str : String? ): Int {
5
7
if (str == null || str.isEmpty()) {
Original file line number Diff line number Diff line change 1
1
package g0001_0100.s0009_palindrome_number
2
2
3
+ // #Easy #Math #2022_03_22_Time_208_ms_(94.88%)_Space_35.9_MB_(90.14%)
4
+
3
5
class Solution {
4
6
fun isPalindrome (x : Int ): Boolean {
5
7
if (x < 0 ) return false
Original file line number Diff line number Diff line change 1
1
package g0001_0100.s0010_regular_expression_matching
2
2
3
+ // #Hard #Top_100_Liked_Questions #Top_Interview_Questions #String #Dynamic_Programming #Recursion
4
+
3
5
class Solution {
4
6
private lateinit var cache: Array <Array <Boolean ?>>
5
7
You can’t perform that action at this time.
0 commit comments