Dashboard Temp Share Shortlinks Frames API

HTMLify

LeetCode - Fizz Buzz - PHP
Views: 7 | Author: abh
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
// @leet start
class Solution {

    /**
     * @param Integer $n
     * @return String[]
     */
    function fizzBuzz($n) {
        $ans = array();
        for ($i = 1; $i <= $n; $i++) {
            if (($i % 3 == 0) && ($i % 5 == 0)) {
                array_push($ans, "FizzBuzz");
            } else if ($i % 3 == 0) {
                array_push($ans, "Fizz");
            } else if ($i % 5 == 0) {
                array_push($ans, "Buzz");
            } else {
                array_push($ans, (string)$i);
            }
        }
        return $ans;
    }
}
// @leet end
?>