leetcode[Fizz Buzz]//待整理多种解法

解法一:

public class Solution {
	private boolean isFizz(int x){
		return (x % 3) == 0;
	}
	
	private boolean isBuzz(int x){
		return (x % 5) == 0;
	}
	
	private boolean isFizzBuzz(int x){
		return (x % 3) == 0 && (x % 5) == 0;
	}
    public List fizzBuzz(int n) {
    	List list = new ArrayList<>();
        for(int i = 1; i <= n; i++){
        	if(isFizzBuzz(i)){
        		list.add("FizzBuzz");
        	}
        	else if(isFizz(i)){
        		list.add("Fizz");
        	}
        	else if(isBuzz(i)){
        		list.add("Buzz");
        	}
        	else{
        		list.add(i + "");
        	}
        }
        
        return list;
    }
}


你可能感兴趣的:(LeetCode)