面试题 08.03. 魔术索引 发表于 2020-07-31 更新于 2020-09-13 分类于 leetcode 阅读次数: 1. 顺序遍历逐个判断,时间O(n),空间O(1)。 123456789101112131415class Solution {public: int findMagicIndex(vector<int>& nums) { int n = nums.size(); int ans = -1; for (int i = 0; i < n; i++) { if (i == nums[i]) { ans = i; break; } } return ans; }};