publicclassTest{publicstaticvoidmain(String[] args){}}classSolution{publicintmaxProfit(int[] prices){int res =0;int index =0;int n = prices.length -1;while(index < n){while(index < n && prices[index +1]<= prices[index]){
index++;}int min = prices[index];while(index < n && prices[index +1]>= prices[index]){
index++;}
res += prices[index]- min;}return res;}}classSolution1{publicintmaxProfit(int[] prices){int res =0;int n = prices.length -1;for(int i =0; i < n; i++){
res +=Math.max(0, prices[i +1]- prices[i]);}return res;}}