Skip to content

Commit 0052acc

Browse files
committed
Added tags.
1 parent 321374b commit 0052acc

File tree

18 files changed

+63
-27
lines changed

18 files changed

+63
-27
lines changed

src/main/kotlin/g0001_0100/s0001_two_sum/Solution.kt

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package g0001_0100.s0001_two_sum
22

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+
36
import java.util.Arrays
47

58
class Solution {

src/main/kotlin/g0001_0100/s0002_add_two_numbers/Solution.kt

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package g0001_0100.s0002_add_two_numbers
22

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+
37
import com_github_leetcode.ListNode
48

59
/*
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
package g0001_0100.s0003_longest_substring_without_repeating_characters
22

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+
36
class Solution {
47
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
814
}
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++
1720
} 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+
}
2526
}
2627
}
27-
return maxLen
28+
return longest
2829
}
2930
}

src/main/kotlin/g0001_0100/s0004_median_of_two_sorted_arrays/Solution.kt

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package g0001_0100.s0004_median_of_two_sorted_arrays
22

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+
36
import kotlin.collections.ArrayList
47

58
class Solution {

src/main/kotlin/g0001_0100/s0005_longest_palindromic_substring/Solution.kt

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package g0001_0100.s0005_longest_palindromic_substring
22

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+
37
class Solution {
48
fun longestPalindrome(s: String): String {
59
val newStr = CharArray(s.length * 2 + 1)

src/main/kotlin/g0001_0100/s0006_zigzag_conversion/Solution.kt

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package g0001_0100.s0006_zigzag_conversion
22

3+
// #Medium #String #2022_03_22_Time_351_ms_(78.99%)_Space_40_MB_(84.02%)
4+
35
class Solution {
46
fun convert(s: String, numRows: Int): String {
57
val sLen = s.length

src/main/kotlin/g0001_0100/s0007_reverse_integer/Solution.kt

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package g0001_0100.s0007_reverse_integer
22

3+
// #Medium #Top_Interview_Questions #Math #2022_03_22_Time_230_ms_(57.36%)_Space_34.3_MB_(61.43%)
4+
35
class Solution {
46
fun reverse(x: Int): Int {
57
var rev: Long = 0

src/main/kotlin/g0001_0100/s0008_string_to_integer_atoi/Solution.kt

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package g0001_0100.s0008_string_to_integer_atoi
22

3+
// #Medium #Top_Interview_Questions #String #2022_03_22_Time_152_ms_(99.64%)_Space_35.2_MB_(97.83%)
4+
35
class Solution {
46
fun myAtoi(str: String?): Int {
57
if (str == null || str.isEmpty()) {

src/main/kotlin/g0001_0100/s0009_palindrome_number/Solution.kt

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package g0001_0100.s0009_palindrome_number
22

3+
// #Easy #Math #2022_03_22_Time_208_ms_(94.88%)_Space_35.9_MB_(90.14%)
4+
35
class Solution {
46
fun isPalindrome(x: Int): Boolean {
57
if (x < 0) return false

src/main/kotlin/g0001_0100/s0010_regular_expression_matching/Solution.kt

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package g0001_0100.s0010_regular_expression_matching
22

3+
// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #String #Dynamic_Programming #Recursion
4+
35
class Solution {
46
private lateinit var cache: Array<Array<Boolean?>>
57

src/main/kotlin/g0001_0100/s0011_container_with_most_water/Solution.kt

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package g0001_0100.s0011_container_with_most_water
22

3+
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Greedy #Two_Pointers
4+
// #2022_02_17_Time_3_ms_(91.89%)_Space_81.7_MB_(5.91%)
5+
36
class Solution {
47
fun maxArea(height: IntArray): Int {
58
var max = 0

src/main/kotlin/g0001_0100/s0012_integer_to_roman/Solution.kt

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package g0001_0100.s0012_integer_to_roman
22

3+
// #Medium #String #Hash_Table #Math #2022_02_17_Time_7_ms_(70.99%)_Space_44.8_MB_(31.56%)
4+
35
class Solution {
46
fun intToRoman(num: Int): String? {
57
var localNum = num

src/main/kotlin/g0001_0100/s0013_roman_to_integer/Solution.kt

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package g0001_0100.s0013_roman_to_integer
22

3+
// #Easy #Top_Interview_Questions #String #Hash_Table #Math
4+
// #2022_02_17_Time_5_ms_(82.08%)_Space_45_MB_(29.21%)
5+
36
class Solution {
47
fun romanToInt(s: String): Int {
58
var x = 0

src/main/kotlin/g0001_0100/s0015_3sum/Solution.kt

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package g0001_0100.s0015_3sum
22

3+
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Sorting #Two_Pointers
4+
// #2022_02_17_Time_29_ms_(68.11%)_Space_59.7_MB_(23.79%)
5+
36
import java.util.Arrays
47
import kotlin.collections.ArrayList
58

src/main/kotlin/g0001_0100/s0020_valid_parentheses/Solution.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package g0001_0100.s0020_valid_parentheses
22

3-
import java.util.Stack
4-
53
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #String #Stack
64
// #2022_02_17_Time_3_ms_(53.65%)_Space_42.1_MB_(17.58%)
75

6+
import java.util.Stack
7+
88
class Solution {
99
fun isValid(s: String): Boolean {
1010
val stack = Stack<Char>()

src/main/kotlin/g0001_0100/s0021_merge_two_sorted_lists/Solution.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package g0001_0100.s0021_merge_two_sorted_lists
22

3-
import com_github_leetcode.ListNode
4-
53
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Linked_List #Recursion
64
// #2022_02_17_Time_1_ms_(61.88%)_Space_42.8_MB_(22.76%)
75

6+
import com_github_leetcode.ListNode
7+
88
class Solution {
99
fun mergeTwoLists(l1: ListNode?, l2: ListNode?): ListNode? {
1010
var l1 = l1

src/main/kotlin/g0001_0100/s0023_merge_k_sorted_lists/Solution.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package g0001_0100.s0023_merge_k_sorted_lists
22

3-
import com_github_leetcode.ListNode
4-
53
// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Heap_Priority_Queue #Linked_List
64
// #Divide_and_Conquer #Merge_Sort #2022_02_18_Time_1_ms_(100.00%)_Space_43.9_MB_(75.94%)
75

6+
import com_github_leetcode.ListNode
7+
88
class Solution {
99
fun mergeKLists(lists: Array<ListNode>): ListNode? {
1010
return if (lists.size == 0) {

src/main/kotlin/g0001_0100/s0024_swap_nodes_in_pairs/Solution.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package g0001_0100.s0024_swap_nodes_in_pairs
22

3-
import com_github_leetcode.ListNode
4-
53
// #Medium #Linked_List #Recursion #2022_02_18_Time_0_ms_(100.00%)_Space_41.9_MB_(22.86%)
64

5+
import com_github_leetcode.ListNode
6+
77
class Solution {
88
fun swapPairs(head: ListNode?): ListNode? {
99
if (head == null) {

0 commit comments

Comments
 (0)