package org.example;
/**
* https://leetcode.com/problems/maximum-subarray/
*/
public class Main {
public static void main(String[] args) {
}
/**
* Kadane algo, all sums end up at some index, we compare that sum with new starting array
*
* @param nums
* @return
*/
public int maxSubArray(int[] nums) {
int res = nums[0];
int max = nums[0];
for (int i = 1; i < nums.length; i++) {
// Find the maximum sum ending at index i by either extending
// the maximum sum subarray ending at index i - 1 or by
// starting a new subarray from index i
max = Math.max(max + nums[i], nums[i]);
res = Math.max(res, max);
}
return res;
}
}
-
MY PROJECTS
-
Recent Posts
- Reading.CleanArchitecture.BusinessRules
- Reading.CleanArchitecture.PolicyAndLevel
- Reading.CleanArchitecture.Boundaries
- Reading.CleanArchitecture.Independence
- Reading.CleanArchitecture.ArchitectureDefinition
- Algo.Java.CheckPrimeNumber
- Algo.Java.DetectPatternInArray
- Algo.Java.Regex.Tips
- Algo.Java.925. Long Pressed Name.TwoPointers
- Algo.Java.MaxRepeatingSubString
- Algo.Java.DayOfTheYear
- Algo.Java.Number of Days Between Two Dates
- Algo.Java.GCDandLCM
- Algo.Java.ConvertBinaryToInt.Theory
- Algo.Java.prefixesDivBy5
- Algo.Java.ShiftArray.ClosestTargetInCircularArray
- Algo.Java.ShiftArray
- Algo.Java.PowerOfTreeSet
- Algo.Java.ShiftArrayToTheRight2
- Java.Algo.RotateMatrix.90.Clockwise
Categories
- Aptana
- Azure
- C#
- DataSnap
- DBExpress
- Delphi
- Delphi и сети
- Delphi. Язык программирования
- ExtJS
- FastReport
- FireDAC
- FireMonkey
- GIT
- ICS
- IDE
- IIS
- Indy
- InnoSetup
- javascript
- jQuery
- JSON
- LiveBindings
- MSHTML
- MySQL
- PHP
- REST
- Ribbons
- SMS
- SQL инструкции
- SVN
- TRichView
- UniGui
- WebBroker
- WinAPI
- Windows
- Алгоритмы
- Без рубрики
- Деревья
- Ищу ответ
- Компонентостроение
- Мои компоненты
- Начальный уровень
- Обработка исключений
- Парсинг
- Потоки(Threads)
- Регулярные выражения
- Тестирование приложений