Skip to content

Commit 256aff9

Browse files
authored
Improved tasks 815, 819, 831, 843, 855, 857
1 parent 988fd54 commit 256aff9

File tree

6 files changed

+11
-24
lines changed

6 files changed

+11
-24
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ package g0801_0900.s0815_bus_routes
55

66
import java.util.LinkedList
77
import java.util.Queue
8-
import kotlin.collections.ArrayList
9-
import kotlin.collections.HashSet
10-
import kotlin.collections.MutableSet
118

129
class Solution {
1310
fun numBusesToDestination(routes: Array<IntArray>, source: Int, target: Int): Int {

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ package g0801_0900.s0819_most_common_word
22

33
// #Easy #String #Hash_Table #Counting #2023_03_24_Time_211_ms_(83.33%)_Space_36.9_MB_(88.89%)
44

5-
import java.util.Locale
6-
75
@Suppress("NAME_SHADOWING")
86
class Solution {
97
fun mostCommonWord(paragraph: String, banned: Array<String>): String {
108
var paragraph = paragraph
11-
paragraph = paragraph.replace("\\p{Punct}".toRegex(), " ").lowercase(Locale.getDefault())
9+
paragraph = paragraph.replace("\\p{Punct}".toRegex(), " ").lowercase()
1210
val a = paragraph.split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
1311
for (i in banned.indices) {
14-
banned[i] = banned[i].lowercase(Locale.getDefault())
12+
banned[i] = banned[i].lowercase()
1513
}
1614
val map: MutableMap<String, Int> = HashMap()
1715
for (s in a) {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ package g0801_0900.s0831_masking_personal_information
22

33
// #Medium #String #2023_03_25_Time_149_ms_(100.00%)_Space_35.3_MB_(100.00%)
44

5-
import java.util.Locale
6-
75
class Solution {
86
fun maskPII(s: String): String {
97
val masked = StringBuilder()
108
return if (Character.isAlphabetic(s[0].code)) {
119
val locationOfAtSymbol = s.indexOf("@") - 1
1210
masked.append(s[0]).append("*****").append(s.substring(locationOfAtSymbol))
13-
masked.toString().lowercase(Locale.getDefault())
11+
masked.toString().lowercase()
1412
} else {
1513
val allDigits = StringBuilder()
1614
var pointer = -1

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package g0801_0900.s0843_guess_the_word
33
// #Hard #Array #String #Math #Game_Theory #Interactive
44
// #2023_03_29_Time_75_ms_(100.00%)_Space_31.5_MB_(100.00%)
55

6-
import java.util.Collections
7-
86
/*
97
* // This is the Master's API interface.
108
* // You should not implement it, or speculate about its implementation
@@ -20,8 +18,8 @@ class Solution {
2018
private var next = 0
2119

2220
fun findSecretWord(wordlist: Array<String>, master: Master) {
23-
val list = listOf(*wordlist)
24-
Collections.shuffle(list)
21+
val list = wordlist.copyOf()
22+
list.shuffle()
2523
val test = BooleanArray(wordlist.size)
2624
while (true) {
2725
val num = master.guess(list[next])
@@ -32,7 +30,7 @@ class Solution {
3230
}
3331
}
3432

35-
private fun updateList(list: List<String?>, test: BooleanArray, num: Int) {
33+
private fun updateList(list: Array<String>, test: BooleanArray, num: Int) {
3634
val index = next
3735
for (i in index + 1 until test.size) {
3836
if (test[i]) {
@@ -47,10 +45,10 @@ class Solution {
4745
}
4846
}
4947

50-
private fun getSame(word1: String?, word2: String?): Int {
48+
private fun getSame(word1: String, word2: String): Int {
5149
var ret = 0
5250
for (i in 0..5) {
53-
if (word1!![i] == word2!![i]) {
51+
if (word1[i] == word2[i]) {
5452
ret++
5553
}
5654
}

src/main/kotlin/g0801_0900/s0855_exam_room/ExamRoom.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package g0801_0900.s0855_exam_room
22

33
// #Medium #Design #Ordered_Set #2023_03_31_Time_644_ms_(83.33%)_Space_40.4_MB_(100.00%)
44

5-
import java.util.Objects
6-
75
class ExamRoom() {
86
private class Node(var `val`: Int, map: MutableMap<Int?, Node>) {
97
var pre: Node? = null
@@ -67,7 +65,7 @@ class ExamRoom() {
6765
}
6866
return if (right > max) {
6967
Node(n - 1, map).insert(tail.pre)
70-
} else Node(maxAt, map).insert(Objects.requireNonNull(maxAtLeft))
68+
} else Node(maxAt, map).insert(maxAtLeft)
7169
}
7270

7371
fun leave(p: Int) {

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ class Solution {
1313
workers[i] = Worker(wage[i], quality[i])
1414
}
1515
workers.sortBy { it!!.ratio() }
16-
val maxHeap = PriorityQueue { a: Int?, b: Int? ->
17-
Integer.compare(
18-
b!!, a!!
19-
)
16+
val maxHeap = PriorityQueue { a: Int, b: Int ->
17+
b.compareTo(a)
2018
}
2119
var sumQuality = 0
2220
var result = Double.MAX_VALUE

0 commit comments

Comments
 (0)