最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

Leetcode 2295. Replace Elements in an Array

2023-03-24 11:23 作者:您是打尖兒還是住店呢  | 我要投稿

You are given a?0-indexed?array?nums?that consists of?n?distinct?positive integers. Apply?m?operations to this array, where in the?ith?operation you replace the number?operations[i][0]?with?operations[i][1].

It is guaranteed that in the?ith?operation:

  • operations[i][0]?exists?in?nums.

  • operations[i][1]?does?not?exist in?nums.

Return?the array obtained after applying all the operations.

?

Example 1:

Input: nums = [1,2,4,6], operations = [[1,3],[4,7],[6,1]]

Output: [3,2,7,1]

Explanation: We perform the following operations on nums:?

- Replace the number 1 with 3. nums becomes [3,2,4,6].?

- Replace the number 4 with 7. nums becomes [3,2,7,6].?

- Replace the number 6 with 1. nums becomes [3,2,7,1].?

We return the final array [3,2,7,1].

Example 2:

Input: nums = [1,2], operations = [[1,3],[2,1],[3,2]]

Output: [2,1]

Explanation: We perform the following operations to nums:

- Replace the number 1 with 3. nums becomes [3,2].

- Replace the number 2 with 1. nums becomes [3,1].

- Replace the number 3 with 2. nums becomes [2,1].

We return the array [2,1].

?

Constraints:

  • n == nums.length

  • m == operations.length

  • 1 <= n, m <= 105

  • All the values of?nums?are?distinct.

  • operations[i].length == 2

  • 1 <= nums[i], operations[i][0], operations[i][1] <= 106

  • operations[i][0]?will exist in?nums?when applying the?ith?operation.

  • operations[i][1]?will not exist in?nums?when applying the?ith?operation.

以為用map會(huì)稍微快一點(diǎn),結(jié)果。。。

Runtime:?68 ms, faster than?19.71%?of?Java?online submissions for?Replace Elements in an Array.

Memory Usage:?92.9 MB, less than?71.14%?of?Java?online submissions for?Replace Elements in an Array.


Leetcode 2295. Replace Elements in an Array的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國家法律
乌鲁木齐市| 怀安县| 石台县| 凤凰县| 平和县| 广昌县| 民县| 福安市| 宜昌市| 健康| 怀柔区| 东方市| 蕉岭县| 天等县| 镶黄旗| 南和县| 丰镇市| 喀喇| 乃东县| 子长县| 顺昌县| 西吉县| 普格县| 和顺县| 雷州市| 南漳县| 宁都县| 沾化县| 南靖县| 高雄县| 肇东市| 武义县| 光山县| 彭阳县| 屏山县| 铁岭县| 普定县| 南阳市| 兴和县| 眉山市| 新乡市|