3 ms Simple Java Solution


  • 0
    K

    '''
    public static List<String> print(int n) {

    	List<String> list = new ArrayList<>();
    
    	for (int i = 1; i <= n; i++) {
    
    		boolean isFizz = (i % 3 == 0) ? true : false;
    
    		boolean isBuzz = (i % 5 == 0) ? true : false;
    
    		if (isFizz && isBuzz) {
    			list.add("FizzBuzz");
    			continue;
    
    		}
    
    		if (isFizz) {
    			list.add("Fizz");
    			continue;
    		}
    
    		if (isBuzz) {
    			list.add("Buzz");
    			continue;
    		}
    
    		list.add(String.valueOf(i));
    
    	}
    
    	return list;
    
    }
    

    '''


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.