Skip to content

Instantly share code, notes, and snippets.

@powext
Last active January 12, 2019 19:06
Show Gist options
  • Save powext/d3df989cdc0c263829c773a906b56dfc to your computer and use it in GitHub Desktop.
Save powext/d3df989cdc0c263829c773a906b56dfc to your computer and use it in GitHub Desktop.
exDue 1 Gennaio 2019
public static int exDue(int[] a){
int result = 0;
if(a!=null&&a.length!=0){
result = exDueRic(a, 0, a.length-1);
} else {
return 0;
}
System.out.println(result);
return result;
}
public static int exDueRic(int[] a, int l, int r){
int result = 0;
if(l>=r){
if(testUno(a[l])&&!testDue(a[l])){
result+=a[l];
} else if(!testUno(a[l])&&testDue(a[l])){
result+=a[l];
}
} else {
int m = (r-l)/2;
result += exDueRic(a, l, m);
result += exDueRic(a, m+1, r);
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment