close
題目: Given two arrays of integers nums and index. Your task is to create target array under the following rules: Initially target array is empty. From left to right read nums[i] and index[i], insert at index index[i] the value nums[i] in target array. Repeat the previous step until there are no elements to read in nums and index. Return the target array. It is guaranteed that the insertion operations will be valid. 解題: 將nums,index兩個list使用zip打包然後循序插入即可。 Python Code:
class Solution: def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]: ans=[] for a,b in zip(nums,index): ans.insert(b,a) return ans
文章標籤
全站熱搜
留言列表