package suanfa.array;
public class MaxProfit {
public static void main(String[] args) {
int[] nums = new int[]{2, 1};
int result = maxProfit(nums);
System.out.println(result);
}
/**
* 双指针 暴力解法
*
* @param arrs
* @return
*/
public static int maxProfit(int[] arrs) {
int maxProfit = 0;
if (arrs.length == 1) {
return 0;
}
for (int left = 0; left < arrs.length; left++) {
int right = left + 1;
while (right < arrs.length) {
int tmpProfit = arrs[right] - arrs[left];
maxProfit = Integer.max(tmpProfit, maxProfit);
right++;
}
}
return maxProfit;
}}

京公网安备 11010502036488号