You are viewing a single comment's thread. Return to all comments →
static String canModify(int[] a) { /* * Write your code here. */ int [] temp = a.clone(); for(int i = 1; i<a.length; i++){ if(a[i]<a[i-1]){ temp[i-1]=a[i]; a[i] = a[i-1]; break; } } int x = 0; int y = 0; for(int i = 0; i<a.length-1; i++){ if(a[i]>a[i+1]) x++; if(temp[i]>temp[i+1]) y++; } return x==0 || y==0 ? "YES":"NO"; }
Seems like cookies are disabled on this browser, please enable them to open this website
Impressing the Boss
You are viewing a single comment's thread. Return to all comments →