• + 0 comments

    Solution in Swift only storing the last two items in the array to calculate the new value

    func isFibo(n: Int) -> String {
        var nums = [0,1]
        while nums[1] < n {
            nums.swapAt(0, 1)
            nums[1] = nums.reduce(0, +)
        }
        
        return nums[1] == n ? "IsFibo" : "IsNotFibo"
    }