Skip to content

Commit c35da55

Browse files
committed
Added tags
1 parent 9b0027d commit c35da55

File tree

4 files changed

+13
-18
lines changed
  • src/main/kotlin/g3101_3200

4 files changed

+13
-18
lines changed

src/main/kotlin/g3101_3200/s3184_count_pairs_that_form_a_complete_day_i/Solution.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package g3101_3200.s3184_count_pairs_that_form_a_complete_day_i
22

3-
// #Easy #Array #Hash_Table #Counting #2024_06_21_Time_1_ms_(98.20%)_Space_42_MB_(83.72%)
3+
// #Easy #Array #Hash_Table #Counting #2024_06_22_Time_171_ms_(68.42%)_Space_35.1_MB_(91.58%)
44

55
class Solution {
66
fun countCompleteDayPairs(hours: IntArray): Int {

src/main/kotlin/g3101_3200/s3185_count_pairs_that_form_a_complete_day_ii/Solution.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package g3101_3200.s3185_count_pairs_that_form_a_complete_day_ii
22

3-
// #Medium #Array #Hash_Table #Counting #2024_06_21_Time_3_ms_(97.60%)_Space_97.1_MB_(14.69%)
3+
// #Medium #Array #Hash_Table #Counting #2024_06_22_Time_578_ms_(78.33%)_Space_115_MB_(66.67%)
44

55
class Solution {
66
fun countCompleteDayPairs(hours: IntArray): Long {

src/main/kotlin/g3101_3200/s3186_maximum_total_damage_with_spell_casting/Solution.kt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ class Solution {
2424
}
2525
val dp = LongArray(maxPower + 6)
2626
dp[1] = counts[1].toLong()
27-
dp[2] = max((counts[2] * 2L).toDouble(), dp[1].toDouble()).toLong()
27+
dp[2] = max((counts[2] * 2L), dp[1])
2828
for (i in 3..maxPower) {
29-
dp[i] = max((counts[i] * i + dp[i - 3]).toDouble(), max(dp[i - 1].toDouble(), dp[i - 2].toDouble()))
30-
.toLong()
29+
dp[i] = max((counts[i] * i + dp[i - 3]), max(dp[i - 1], dp[i - 2]))
3130
}
3231
return dp[maxPower]
3332
}
@@ -45,15 +44,12 @@ class Solution {
4544
count++
4645
} else {
4746
val curVal = max(
48-
(curPower.toLong() * count + prevs[3]).toDouble(),
49-
max(prevs[1].toDouble(), prevs[2].toDouble())
47+
(curPower * count + prevs[3]),
48+
max(prevs[1], prevs[2])
5049
)
51-
.toLong()
52-
val diff = min((p - curPower).toDouble(), (prevs.size - 1).toDouble()).toInt()
50+
val diff = min((p - curPower), (prevs.size - 1))
5351
val nextCurVal =
54-
if ((diff == 1)) 0 else max(prevs[3].toDouble(), max(curVal.toDouble(), prevs[2].toDouble()))
55-
.toLong()
56-
// Shift the values in prevs[].
52+
if ((diff == 1)) 0 else max(prevs[3], max(curVal, prevs[2]))
5753
var k = prevs.size - 1
5854
if (diff < prevs.size - 1) {
5955
while (k > diff) {

src/main/kotlin/g3101_3200/s3187_peaks_in_array/Solution.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package g3101_3200.s3187_peaks_in_array
22

3-
// #2024_06_21_Time_18_ms_(100.00%)_Space_137.7_MB_(31.34%)
3+
// #Hard #Array #Segment_Tree #Binary_Indexed_Tree
4+
// #2024_06_22_Time_1339_ms_(80.00%)_Space_135.1_MB_(70.00%)
45

56
import kotlin.math.max
67

@@ -10,12 +11,11 @@ class Solution {
1011
val peaks = BooleanArray(nums.size)
1112
val binaryIndexedTree = IntArray(Integer.highestOneBit(peaks.size) * 2 + 1)
1213
for (i in 1 until peaks.size - 1) {
13-
if (nums[i] > max(nums[i - 1].toDouble(), nums[i + 1].toDouble())) {
14+
if (nums[i] > max(nums[i - 1], nums[i + 1])) {
1415
peaks[i] = true
1516
update(binaryIndexedTree, i + 1, 1)
1617
}
1718
}
18-
1919
val result: MutableList<Int> = ArrayList()
2020
for (query in queries) {
2121
if (query[0] == 1) {
@@ -30,7 +30,7 @@ class Solution {
3030
val affected = index + i
3131
if (affected >= 1 && affected <= nums.size - 2) {
3232
val peak =
33-
nums[affected] > max(nums[affected - 1].toDouble(), nums[affected + 1].toDouble())
33+
nums[affected] > max(nums[affected - 1], nums[affected + 1])
3434
if (peak != peaks[affected]) {
3535
if (peak) {
3636
update(binaryIndexedTree, affected + 1, 1)
@@ -47,8 +47,7 @@ class Solution {
4747
}
4848

4949
private fun computeRangeSum(binaryIndexedTree: IntArray, beginIndex: Int, endIndex: Int): Int {
50-
return if ((beginIndex <= endIndex)
51-
) (query(binaryIndexedTree, endIndex) - query(binaryIndexedTree, beginIndex - 1))
50+
return if (beginIndex <= endIndex) query(binaryIndexedTree, endIndex) - query(binaryIndexedTree, beginIndex - 1)
5251
else 0
5352
}
5453

0 commit comments

Comments
 (0)