Simple Java Solution -Easy to understand


  • 0
    G

    ...

        List <String> ret = new ArrayList<String>();
        StringBuffer sb = new StringBuffer();
        
        String str = String.valueOf(n);
        
        String numArray[] = str.split("");
        
        for(int i=0;i<=n;i++) {
        	if(i==0) continue;
        	if(i%3==0 &&i%5!=0 ) {
        		ret.add("Fizz");
        	}
        	
        	else if(i%5==0 && i%3!=0 ) {
        		ret.add("Buzz");
        	}
    
        	else if(i%5==0 && i%3==0) {
        		ret.add("FizzBuzz");
        	}
        	
        	else {        		
        		ret.add(String.valueOf(i));
        	}        	
        }
        
        return ret;
    

    ...


Log in to reply
 

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