sagar.cdafle
BAN USERExternal Sorting
External sorting is a term for a class of sorting algorithms that can handle massive amounts of data. External sorting is required when the data being sorted do not fit into the main memory of a computing device (usually RAM) and instead they must reside in the slower external memory (usually a hard drive). External sorting typically uses a hybrid sort-merge strategy. In the sorting phase, chunks of data small enough to fit in main memory are read, sorted, and written out to a temporary file. In the merge phase, the sorted sub-files are combined into a single larger file.
public int maxProfit(int[] nums) {
int n = nums.length;
int even = 0;
int odd = 0;
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
even = Math.max(odd, even + nums[i]);
} else {
odd = Math.max(even, odd + nums[i]);
}
}
return Math.max(even, odd);
}
Can someone post solution(s) in Java?
- sagar.cdafle May 28, 2017
PErefect
- sagar.cdafle August 18, 2017