Skip to content

Commit 2eeb02d

Browse files
authored
Improved tasks 815, 823, 828
1 parent 9b79c85 commit 2eeb02d

File tree

3 files changed

+6
-11
lines changed
  • src/main/kotlin/g0801_0900

3 files changed

+6
-11
lines changed

src/main/kotlin/g0801_0900/s0815_bus_routes/Solution.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package g0801_0900.s0815_bus_routes
33
// #Hard #Array #Hash_Table #Breadth_First_Search #Level_2_Day_11_Graph/BFS/DFS
44
// #2023_03_22_Time_429_ms_(100.00%)_Space_55.8_MB_(100.00%)
55

6-
import java.util.Arrays
76
import java.util.LinkedList
87
import java.util.Queue
98
import kotlin.collections.ArrayList
@@ -53,14 +52,14 @@ class Solution {
5352
val len = routes.size
5453
val graph: Array<ArrayList<Int>?> = arrayOfNulls(len)
5554
for (i in 0 until len) {
56-
Arrays.sort(routes[i])
55+
routes[i].sort()
5756
graph[i] = ArrayList()
58-
var id = Arrays.binarySearch(routes[i], source)
57+
var id = routes[i].binarySearch(source)
5958
if (id >= 0) {
6059
queue.offer(i)
6160
taken[i] = true
6261
}
63-
id = Arrays.binarySearch(routes[i], target)
62+
id = routes[i].binarySearch(target)
6463
if (id >= 0) {
6564
targetRoutes.add(i)
6665
}

src/main/kotlin/g0801_0900/s0823_binary_trees_with_factors/Solution.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ package g0801_0900.s0823_binary_trees_with_factors
33
// #Medium #Array #Hash_Table #Dynamic_Programming
44
// #2023_03_25_Time_298_ms_(100.00%)_Space_45.1_MB_(100.00%)dsecx
55

6-
import java.util.Arrays
7-
86
class Solution {
97
private val dp: MutableMap<Int, Long> = HashMap()
108
private val nums: MutableMap<Int, Int> = HashMap()
119
fun numFactoredBinaryTrees(arr: IntArray): Int {
12-
Arrays.sort(arr)
10+
arr.sort()
1311
for (i in arr.indices) {
1412
nums[arr[i]] = i
1513
}

src/main/kotlin/g0801_0900/s0828_count_unique_characters_of_all_substrings_of_a_given_string/Solution.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@ package g0801_0900.s0828_count_unique_characters_of_all_substrings_of_a_given_st
33
// #Hard #String #Hash_Table #Dynamic_Programming
44
// #2023_03_25_Time_216_ms_(100.00%)_Space_37.1_MB_(50.00%)
55

6-
import java.util.Arrays
7-
86
class Solution {
97
fun uniqueLetterString(s: String): Int {
108
// Store last index of a character.
119
val lastCharIdx = IntArray(26)
1210
// Store last to last index of a character.
1311
// Eg. For ABA - lastCharIdx = 2, prevLastCharIdx = 0.
1412
val prevLastCharIdx = IntArray(26)
15-
Arrays.fill(lastCharIdx, -1)
16-
Arrays.fill(prevLastCharIdx, -1)
13+
lastCharIdx.fill(-1)
14+
prevLastCharIdx.fill(-1)
1715
val len = s.length
1816
val dp = IntArray(len)
1917
var account = 1

0 commit comments

Comments
 (0)