max_no_square
and max_square
to 0, and global_max
to negative infinity.num
in nums
.
a. Update max_no_square
to the maximum of num
and num + max_no_square
(Kadane's algorithm).
b. Update max_square
to the maximum of num * num
, num * num + max_no_square
, and num + max_square
.
c. Update global_max
to the maximum of global_max
and max_square
.global_max
as the result.