You are viewing a single comment's thread. Return to all comments →
public static String fairRations(List B) { int count = 0; for (int i = 0; i < B.size() - 1 ; i++) { if(B.get(i) % 2 != 0){ B.set(i, B.get(i) + 1 ); B.set(i + 1, B.get(i + 1) + 1); count += 2; } } if (B.get(B.size() - 1) % 2 != 0) { return "NO"; } return String.valueOf(count); }
Seems like cookies are disabled on this browser, please enable them to open this website
Fair Rations
You are viewing a single comment's thread. Return to all comments →
JAVA
public static String fairRations(List B) { int count = 0; for (int i = 0; i < B.size() - 1 ; i++) { if(B.get(i) % 2 != 0){ B.set(i, B.get(i) + 1 ); B.set(i + 1, B.get(i + 1) + 1); count += 2; } } if (B.get(B.size() - 1) % 2 != 0) { return "NO"; } return String.valueOf(count); }