Skip to content

Commit 1abcc90

Browse files
committed
feat: Add solution for LeetCode problem 53
1 parent 8284d27 commit 1abcc90

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

maximum-subarray/WhiteHyun.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// 53. Maximum Subarray
3+
// https://leetcode.com/problems/maximum-subarray/description/
4+
// Dale-Study
5+
//
6+
// Created by WhiteHyun on 2024/07/20.
7+
//
8+
9+
class Solution {
10+
func maxSubArray(_ numbers: [Int]) -> Int {
11+
var tracking = numbers[0]
12+
var answer = numbers[0]
13+
for value in numbers.dropFirst() {
14+
tracking = max(tracking + value, value)
15+
if tracking > answer {
16+
answer = tracking
17+
}
18+
}
19+
20+
return answer
21+
}
22+
}

0 commit comments

Comments
 (0)