반응형
○
PrefixSum - Medium (난이도 이상함. Easy 임)
LeetCode 2640. Find the Score of All Prefixes of an Array
let solution = Solution()
print(solution.findPrefixScore([2,3,7,5,10])) //[2,4,8,16,32,64]
class Solution {
func findPrefixScore(_ nums: [Int]) -> [Int] {
var maxNum = nums[0]
var conver = 0
var result = [Int]()
for i in nums {
maxNum = max(maxNum, i)
conver += i + maxNum
result.append(conver)
}
return result
}
}
728x90
반응형
'Algorithm > LeetCode' 카테고리의 다른 글
[Swift 알고리즘] LeetCode 1884. Egg Drop With 2 Eggs and N Floors (0) | 2023.07.23 |
---|---|
[Swift 알고리즘] LeetCode 2078. Two Furthest Houses With Different Colors (0) | 2023.05.13 |
[Swift 알고리즘] LeetCode 922. Sort Array By Parity II (1) | 2023.05.10 |
[Swift 알고리즘] LeetCode 1387. Sort Integers by The Power Value (0) | 2023.05.06 |
[Swift 알고리즘] LeetCode 496. Next Greater Element I (0) | 2023.04.30 |