This is the fastest solution for FizzBuzz program in leetcode(Question 412). I can't able to understand it line of execution and whats actually happening in program. Please help me out with explaining the line of execution of the program. Just tell me where the looping happens.
import java.util.AbstractList;
class Solution {
public List<String> fizzBuzz(int n) {
return new AbstractList<>() {
@Override
public String get(int i) {
i++;
if(i%15==0)
return "FizzBuzz";
if(i%3==0)
return "Fizz";
if(i%5==0)
return "Buzz";
return i+"";
}
@Override
public int size() {
return n;
}
};
}
}
Actually there is no looping.
They create a list which overrides methods. Method
sizereturns givennvalue. Methodgetreturns a string dependent on a givenivalue. So, it means that they don't store values in a list - they just calculate value ("FizzBuzz"/"Fizz"/"Buzz") on a given index