forked from Garvit244/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1064.py
37 lines (30 loc) · 794 Bytes
/
1064.py
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
27
28
29
30
31
32
33
34
35
36
37
'''
Given an array A of distinct integers sorted in ascending order, return the smallest index i that satisfies A[i] == i. Return -1 if no such i exists.
Example 1:
Input: [-10,-5,0,3,7]
Output: 3
Explanation:
For the given array, A[0] = -10, A[1] = -5, A[2] = 0, A[3] = 3, thus the output is 3.
Example 2:
Input: [0,2,5,8,17]
Output: 0
Explanation:
A[0] = 0, thus the output is 0.
Example 3:
Input: [-10,-5,3,4,7,9]
Output: -1
Explanation:
There is no such i that A[i] = i, thus the output is -1.
'''
class Solution(object):
def fixedPoint(self, A):
"""
:type A: List[int]
:rtype: int
"""
if not A:
return -1
for index, num in enumerate(A):
if num == index:
return index
return -1