File tree Expand file tree Collapse file tree 3 files changed +6
-11
lines changed
src/main/kotlin/g0801_0900
s0823_binary_trees_with_factors
s0828_count_unique_characters_of_all_substrings_of_a_given_string Expand file tree Collapse file tree 3 files changed +6
-11
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ package g0801_0900.s0815_bus_routes
3
3
// #Hard #Array #Hash_Table #Breadth_First_Search #Level_2_Day_11_Graph/BFS/DFS
4
4
// #2023_03_22_Time_429_ms_(100.00%)_Space_55.8_MB_(100.00%)
5
5
6
- import java.util.Arrays
7
6
import java.util.LinkedList
8
7
import java.util.Queue
9
8
import kotlin.collections.ArrayList
@@ -53,14 +52,14 @@ class Solution {
53
52
val len = routes.size
54
53
val graph: Array <ArrayList <Int >? > = arrayOfNulls(len)
55
54
for (i in 0 until len) {
56
- Arrays .sort( routes[i])
55
+ routes[i].sort( )
57
56
graph[i] = ArrayList ()
58
- var id = Arrays .binarySearch( routes[i], source)
57
+ var id = routes[i].binarySearch( source)
59
58
if (id >= 0 ) {
60
59
queue.offer(i)
61
60
taken[i] = true
62
61
}
63
- id = Arrays .binarySearch( routes[i], target)
62
+ id = routes[i].binarySearch( target)
64
63
if (id >= 0 ) {
65
64
targetRoutes.add(i)
66
65
}
Original file line number Diff line number Diff line change @@ -3,13 +3,11 @@ package g0801_0900.s0823_binary_trees_with_factors
3
3
// #Medium #Array #Hash_Table #Dynamic_Programming
4
4
// #2023_03_25_Time_298_ms_(100.00%)_Space_45.1_MB_(100.00%)dsecx
5
5
6
- import java.util.Arrays
7
-
8
6
class Solution {
9
7
private val dp: MutableMap <Int , Long > = HashMap ()
10
8
private val nums: MutableMap <Int , Int > = HashMap ()
11
9
fun numFactoredBinaryTrees (arr : IntArray ): Int {
12
- Arrays .sort(arr )
10
+ arr .sort()
13
11
for (i in arr.indices) {
14
12
nums[arr[i]] = i
15
13
}
Original file line number Diff line number Diff line change @@ -3,17 +3,15 @@ package g0801_0900.s0828_count_unique_characters_of_all_substrings_of_a_given_st
3
3
// #Hard #String #Hash_Table #Dynamic_Programming
4
4
// #2023_03_25_Time_216_ms_(100.00%)_Space_37.1_MB_(50.00%)
5
5
6
- import java.util.Arrays
7
-
8
6
class Solution {
9
7
fun uniqueLetterString (s : String ): Int {
10
8
// Store last index of a character.
11
9
val lastCharIdx = IntArray (26 )
12
10
// Store last to last index of a character.
13
11
// Eg. For ABA - lastCharIdx = 2, prevLastCharIdx = 0.
14
12
val prevLastCharIdx = IntArray (26 )
15
- Arrays .fill(lastCharIdx, - 1 )
16
- Arrays .fill(prevLastCharIdx, - 1 )
13
+ lastCharIdx .fill(- 1 )
14
+ prevLastCharIdx .fill(- 1 )
17
15
val len = s.length
18
16
val dp = IntArray (len)
19
17
var account = 1
You can’t perform that action at this time.
0 commit comments