-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMaximumSubarray.java
More file actions
43 lines (31 loc) · 925 Bytes
/
Copy pathMaximumSubarray.java
File metadata and controls
43 lines (31 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package Introduction.MaximumSubarray;
import org.junit.Test;
import static org.junit.Assert.*;
import java.util.*;
/**
* Maximum Subarray | Leetcode #0053 | Easy
* https://leetcode.com/problems/maximum-subarray/
*
* Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.
* A subarray is a contiguous part of an array.
*/
/**
* Solution Notes by _______
*
*/
public class MaximumSubarray {
public static int maxSubArray(int[] nums) {
// TODO: Your solution
return 0;
}
@Test
public static void main(String[] args) {
int[] nums1 = { -2, 1, -3, 4, -1, 2, 1, -5, 4 };
assertEquals(6, maxSubArray(nums1));
int[] nums2 = { 1 };
assertEquals(1, maxSubArray(nums2));
int[] nums3 = { 5, 4, -1, 7, 8 };
assertEquals(23, maxSubArray(nums3));
System.out.println("All tests passed!");
}
}