// Complete the fizzBuzz function below.
static void fizzBuzz(int n) {
for (int i = 1; i <= n; ++i) {
if(i % 3 == 0 || i % 5 == 0) {
print(i);
} else {
System.out.println(i);
}
}
}
// Complete the fizzBuzz function below.
static void print(int n) {
if (n % 3 == 0 && n % 5 == 0) {
System.out.println("FizzBuzz");
return;
}
if (n % 3 == 0) {
System.out.println("Fizz");
return;
}
if (n % 5 == 0) {
System.out.println("Buzz");
}
}
/*
* Complete the function below.
*/
/*
For your reference:
LinkedListNode {
int val;
LinkedListNode *next;
};
*/
static LinkedListNode removeNodes(LinkedListNode list, int x) {
LinkedListNode head;
//find first viable number
for(head = list; null != head && head.val > x; head = head.next);
//find next viable number
for (LinkedListNode current = head; null != current && null != current.next; ) {
if (current.next.val > x) {
current.next = current.next.next;
} else {
current = current.next;
}
}
return head;
}
// Complete the maximumSum function below.
static long maximumSum(List<Integer> arr) {
if (arr.isEmpty()) {
return 0;
}
long acc = 0, max = Integer.MIN_VALUE;
for(int i=0; i < arr.size(); i++) {
acc = Math.max(acc, 0); // ignore any negative accumulated sum
acc += arr.get(i);
max = Math.max(max, acc);
}
return max;
}