Tap here to switch tabs
Problem
Submissions

Problem: Replace Elements in an Array

Try to solve the Replace Elements in an Array problem.

Statement

You are given an integer array nums consisting of distinct positive integers, and a 2extD2 ext{D} integer array operations where operations[i] = [oldValue, newValue].

You need to apply all operations in sequence. For each operation operations[i], replace the element in nums that has the value operations[i][0] with the value operations[i][1].

Return the array nums after performing all operations.

Constraints:

  • n ==== nums.length

  • m ==== operations.length

  • 1≤1 \leq n, m ≤105\leq 10^5

  • All the values of nums are distinct.

  • operations[i].length ==2== 2

  • 1≤1 \leq nums[i], operations[i][0], operations[i][1] ≤106\leq 10^6

  • operations[i][0] will exist in nums when applying the iextthi^{ ext{th}} operation.

  • operations[i][1] will not exist in nums when applying the iextthi^{ ext{th}} operation.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Replace Elements in an Array

Try to solve the Replace Elements in an Array problem.

Statement

You are given an integer array nums consisting of distinct positive integers, and a 2extD2 ext{D} integer array operations where operations[i] = [oldValue, newValue].

You need to apply all operations in sequence. For each operation operations[i], replace the element in nums that has the value operations[i][0] with the value operations[i][1].

Return the array nums after performing all operations.

Constraints:

  • n ==== nums.length

  • m ==== operations.length

  • 1≤1 \leq n, m ≤105\leq 10^5

  • All the values of nums are distinct.

  • operations[i].length ==2== 2

  • 1≤1 \leq nums[i], operations[i][0], operations[i][1] ≤106\leq 10^6

  • operations[i][0] will exist in nums when applying the iextthi^{ ext{th}} operation.

  • operations[i][1] will not exist in nums when applying the iextthi^{ ext{th}} operation.