JAVA easy solution


  • 0
    R
     public List<String> fizzBuzz(int n) {
         
        	List<String> ls=new ArrayList<String>();   
            	
    	for(int i=1;i<=n;i++)
    	{
    		if(i%15==0)
    			ls.add("FizzBuzz");
    		else if(i%5==0)
    		ls.add("Buzz");
    		else if(i%3==0)
    		ls.add("Fizz");
    		else{
    			
    		ls.add(Integer.toString(i));
    			
    		}
    		
    	}
            
            return ls;
            
        }```

Log in to reply
 

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