<filename>0055.Jump Game/solution.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
*****************************************
Author:         zhlinh
Email:          <EMAIL>
Version:        0.0.1
Created Time:   2016-02-22
Last_modify:    2016-02-22
******************************************
'''

'''
Given an array of non-negative integers,
you are initially positioned at the first index of the array.

Each element in the array represents your maximum jump length at that position.

Determine if you are able to reach the last index.

For example:
A = [2,3,1,1,4], return true.

A = [3,2,1,0,4], return false.
'''

class Solution(object):
    def canJump(self, nums):
        """
        :type nums: List[int]
        :rtype: bool
        """
        i, reach = 0, 0
        while i < len(nums) and i <= reach:
            reach = max(reach, i + nums[i])
            i += 1
        return i == len(nums)

<filename>0055.Jump Game/solution.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
*****************************************
Author:         zhlinh
Email:          <EMAIL>
Version:        0.0.1
Created Time:   2016-02-22
Last_modify:    2016-02-22
******************************************
'''

'''
Given an array of non-negative integers,
you are initially positioned at the first index of the array.

Each element in the array represents your maximum jump length at that position.

Determine if you are able to reach the last index.

For example:
A = [2,3,1,1,4], return true.

A = [3,2,1,0,4], return false.
'''

class Solution(object):
    def canJump(self, nums):
        """
        :type nums: List[int]
        :rtype: bool
        """
        i, reach = 0, 0
        while i < len(nums) and i <= reach:
            reach = max(reach, i + nums[i])
            i += 1
        return i == len(nums)

#!/usr/bin/env python # -*- coding: utf-8 -*- ***************************************** Author:         zhlinh Email:          <EMAIL> Version:        0.0.1 Created Time:   2016-02-22 Last_modify:    2016-02-22 ****************************************** Given an array of non-negative integers, you are initially positioned at the first index of the array.  Each element in the array represents your maximum jump length at that position.  Determine if you are able to reach the last index.  For example: A = [2,3,1,1,4], return true.  A = [3,2,1,0,4], return false. :type nums: List[int]         :rtype: bool