基于排列构建数组
2025-4-20
| 2025-4-20
Words 319Read Time 1 min
type
status
date
slug
summary
tags
category
icon
password

题目:

给你一个 从 0 开始的排列 nums下标也从 0 开始)。请你构建一个 同样长度 的数组 ans ,其中,对于每个 i0 <= i < nums.length),都满足 ans[i] = nums[nums[i]] 。返回构建好的数组 ans
从 0 开始的排列 nums 是一个由 0nums.length - 10nums.length - 1 也包含在内)的不同整数组成的数组。
来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
示例 1:
示例 2:
提示:
  • 1 <= nums.length <= 1000
  • 0 <= nums[i] < nums.length
  • nums 中的元素 互不相同

思路:

  • 遍历赋值

代码:

结果:

notion image
image-20220130231658303
基于注解配置bean-AutoWired垃圾回收器
Loading...