EngTW / English-for-Programmers

《程式英文》:用英文提昇程式可讀性
971 stars 45 forks source link

1389. Create Target Array in the Given Order #83

Closed twy30 closed 3 years ago

twy30 commented 3 years ago

https://leetcode.com/problems/create-target-array-in-the-given-order/

using System.Collections.Generic;

public class Solution
{
    public int[] CreateTargetArray(int[] nums, int[] index)
    {
        // 「輸入的數字」(複數)
        var inputNumbers = nums;

        // 「『插入』的索引值」(複數)
        var insertionIndexes = index;

        // 「輸出值」
        var output = new List<int>(inputNumbers.Length);

        for (int i = 0; i < insertionIndexes.Length; ++i)
        {
            output.Insert(insertionIndexes[i], inputNumbers[i]);
        }

        return output.ToArray();
    }
}

請參考「刷 LeetCode 練習命名」 https://github.com/EngTW/English-for-Programmers/issues/69 😊