★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公衆號:山青詠芝(shanqingyongzhi)
➤博客園地址:山青詠芝(https://www.cnblogs.com/strengthen/ )
➤GitHub地址:https://github.com/strengthen/LeetCode
➤原文地址:http://www.javashuo.com/article/p-cwaymett-mb.html
➤若是連接不是山青詠芝的博客園地址,則多是爬取做者的文章。
➤原文已修改更新!強烈建議點擊原文地址閱讀!支持做者!支持原創!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★html
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.git
Example 1:github
Input: [-10,-5,0,3,7]
Output: 3 Explanation: For the given array, , thus the output is 3. A[0] = -10, A[1] = -5, A[2] = 0, A[3] = 3
Example 2:數組
Input: [0,2,5,8,17]
Output: 0 Explanation: , thus the output is 0. A[0] = 0
Example 3:微信
Input: [-10,-5,3,4,7,9]
Output: -1 Explanation: There is no such that , thus the output is -1. iA[i] = i
Note:app
1 <= A.length < 10^4
-10^9 <= A[i] <= 10^9
給定已經按升序排列、由不一樣整數組成的數組 A
,返回知足 A[i] == i
的最小索引 i
。若是不存在這樣的 i
,返回 -1
。 spa
示例 1:code
輸入:[-10,-5,0,3,7] 輸出:3 解釋: 對於給定的數組,,所以輸出爲 3 。 A[0] = -10,A[1] = -5,A[2] = 0,A[3] = 3
示例 2:orm
輸入:[0,2,5,8,17] 輸出:0 示例: ,所以輸出爲 0 。 A[0] = 0
示例 3:htm
輸入:[-10,-5,3,4,7,9] 輸出:-1 解釋: 不存在這樣的 i 知足 ,所以輸出爲 -1 。A[i] = i
提示:
1 <= A.length < 10^4
-10^9 <= A[i] <= 10^9
1 class Solution { 2 func fixedPoint(_ A: [Int]) -> Int { 3 for i in 0..<A.count 4 { 5 if A[i] == i 6 { 7 return i 8 } 9 } 10 return -1 11 } 12 }