Skip to content

Instantly share code, notes, and snippets.

@kimji1
Last active August 6, 2020 10:38
Show Gist options
  • Select an option

  • Save kimji1/354752b2104ccf068a24964c15ecee66 to your computer and use it in GitHub Desktop.

Select an option

Save kimji1/354752b2104ccf068a24964c15ecee66 to your computer and use it in GitHub Desktop.
fun main() {
println(maxSubArray(intArrayOf(-2,1,-3,4,-1,2,1,-5,4)))
}
fun maxSubArray(nums: IntArray): Int {
var currentMax = nums[0]
var max = nums[0]
for (i in 1 until nums.size) {
currentMax = Math.max(nums[i], nums[i]+currentMax)
max = Math.max(currentMax, max)
}
return max
}
@kimji1

kimji1 commented Aug 6, 2020

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment