int max = nums[ 0 ] ;
int pre = 0 ;
for ( int i = 1 ; i < nums. length; i++ )
{
if ( nums[ i] + pre >= nums[ i] )
{
pre = nums[ i] + pre;
}
else if ( nums[ i] + pre < nums[ i] )
{
pre = nums[ i] ;
}
max = Math. max ( max, pre) ;
}
return max;
class Solution {
public String multiply ( String num1, String num2)
{
if ( num1. equals ( "0" ) || num2. equals ( "0" ) )
{
return "0" ;
}
StringBuffer[ ] sb = new StringBuffer [ num2. length ( ) ] ;
for ( int j = 0 ; j < num2. length ( ) ; j++ )
{
sb[ j] = new StringBuffer ( ) ;
}
int j = num2. length ( ) - 1 ;
int k = 0 ;
while ( j >= 0 )
{
int i = num1. length ( ) - 1 ;
int n2 = num2. charAt ( j) - '0' ;
int check = 0 ;
while ( i >= 0 )
{
int n1 = num1. charAt ( i) - '0' ;
int temp = n1 * n2 + check;
check = temp / 10 ;
sb[ k] = sb[ k] . append ( temp % 10 ) ;
-- i;
}
if ( check > 0 )
{
sb[ k] = sb[ k] . append ( check) ;
}
sb[ k] = sb[ k] . reverse ( ) ;
for ( int q = 0 ; q < k; q++ )
{
sb[ k] = sb[ k] . append ( "0" ) ;
}
++ k;
-- j;
}
StringBuffer sum = new StringBuffer ( "0" ) ;
for ( int p = 0 ; p < sb. length; p++ )
{
sum = addStrings ( sum, sb[ p] ) ;
}
return sum. toString ( ) ;
}
public static StringBuffer addStrings ( StringBuffer num1, StringBuffer num2)
{
StringBuffer sb = new StringBuffer ( ) ;
int i = num1. length ( ) - 1 , j = num2. length ( ) - 1 ;
int check = 0 ;
while ( i >= 0 || j >= 0 )
{
int n1 = i >= 0 ? num1. charAt ( i) - '0' : 0 ;
int n2 = j >= 0 ? num2. charAt ( j) - '0' : 0 ;
int temp = n1 + n2 + check;
check = temp / 10 ;
sb = sb. append ( temp % 10 ) ;
-- i;
-- j;
}
if ( check == 1 )
{
sb = sb. append ( '1' ) ;
}
return sb. reverse ( ) ;
}
}
class Solution {
public List< List< Integer> > permute ( int [ ] nums) {
List< List< Integer> > res = new ArrayList < List< Integer> > ( ) ;
List< Integer> output = new ArrayList < Integer> ( ) ;
for ( int num : nums) {
output. add ( num) ;
}
int n = nums. length;
backtrack ( n, output, res, 0 ) ;
return res;
}
public void backtrack ( int n, List< Integer> output, List< List< Integer> > res, int first) {
if ( first == n) {
res. add ( new ArrayList < Integer> ( output) ) ;
}
for ( int i = first; i < n; i++ ) {
Collections. swap ( output, first, i) ;
backtrack ( n, output, res, first + 1 ) ;
Collections. swap ( output, first, i) ;
}
}
}