Home Archives About Tags Works
8月 31 2017
Online Judge►Codewars

[Codewars] 5 kyu - Maximum subarray sum

題意

求最大子序列。

程式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
var maxSequence = function(arr){
var max = 0 ;
var sum = 0 ;
for ( var i = 0 ; i < arr.length ; i ++ ){
sum += arr[i] ;
if ( sum > max ){
max = sum ;
}
if ( sum < 0 ){
sum = 0 ;
}
}
return max ;
}
Share Comments
  • 5 kyu
  • Codewars
Newer
[Codewars] 4 kyu - Human readable duration format
Older
[Codewars] 4 kyu - Sum Strings as Numbers

Categories

  • Content Management System1
    • Joomla1
  • Learning Note1
    • Machine Learning1
  • Mobile Application9
    • Android6
    • Cordova3
  • Online Judge47
    • Codewars3
    • Google Code Jam1
    • LeetCode31
    • Pwnable.kr1
    • UVa11
  • Other3
  • Programming Language19
    • C/C++4
    • Java5
    • JavaScript9
    • Python1
  • Security1
  • Server1
    • CentOS1
  • Tool3
    • Compiler1
    • Parser1
      • Bison1
    • Scanner1
      • Flex1
  • Web44
    • Front-End19
    • Hexo3
    • Markdown1
    • Node.js2
    • Other4
    • Overall9
    • PHP3
    • Phoenix1
    • Redux1
    • jQuery1

Recents

  • [LeetCode] 670 - Maximum Swap
  • [LeetCode] 654 - Maximum Binary Tree
  • [LeetCode] 647 - Palindromic Substrings
  • [LeetCode] 560 - Subarray Sum Equals K
  • [LeetCode] 515 - Find Largest Value in Each Tree Row
  • [LeetCode] 513 - Find Bottom Left Tree Value
  • [LeetCode] 508 - Most Frequent Subtree Sum
  • [LeetCode] 451 - Sort Characters By Frequency
  • [LeetCode] 442 - Find All Duplicates in an Array
  • [LeetCode] 287 - Find the Duplicate Number

Links

  • Online Avalon
  • MapleStory Defense
  • Building House
Powered by Hexo and Theme by landscape © Chi-Wei Liu
Home Archives About Tags Works