Skip to content

Commit 4505ccc

Browse files
committed
https://leetcode.cn/problems/maximum-number-of-weeks-for-which-you-can-work
1 parent d9c8b2b commit 4505ccc

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,4 +2612,6 @@ https://leetcode.cn/problems/equal-row-and-column-pairs
26122612

26132613
https://leetcode.cn/problems/count-vowel-strings-in-ranges
26142614

2615+
https://leetcode.cn/problems/maximum-number-of-weeks-for-which-you-can-work
2616+
26152617
</details>

leetcode-test.iml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<sourceFolder url="file://$MODULE_DIR$/count-vowel-strings-in-ranges" isTestSource="false" packagePrefix="com.github.masx200.leetcode_test.count_vowel_strings_in_ranges" />
66
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" packagePrefix="com.github.masx200.leetcode_test" />
77
<sourceFolder url="file://$MODULE_DIR$/zigzag-iterator" isTestSource="false" packagePrefix="com.github.masx200.leetcode_test.zigzag_iterator" />
8+
<sourceFolder url="file://$MODULE_DIR$/maximum-number-of-weeks-for-which-you-can-work" isTestSource="false" packagePrefix="com.github.masx200.leetcode_test.maximum_number_of_weeks_for_which_you_can_work" />
89
<excludeFolder url="file://$MODULE_DIR$/target" />
910
</content>
1011
</component>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.github.masx200.leetcode_test.maximum_number_of_weeks_for_which_you_can_work
2+
3+
class Solution {
4+
fun numberOfWeeks(milestones: IntArray): Long {
5+
var sum: Long = 0
6+
var max: Long = 0
7+
milestones.forEach {
8+
sum += it.toLong()
9+
max = Math.max(max, it.toLong())
10+
}
11+
return if (max * 2 > sum) (sum - max) * 2 + 1 else sum
12+
13+
14+
}
15+
}

0 commit comments

Comments
 (0)