CodeSignal/Arcade
CodeSignal [25/60] Array Replace
벤진[Benzene]
2020. 5. 16. 08:53
문제: Given an array of integers, replace all the occurrences of elemToReplace with substitutionElem.
Example: For inputArray = [1, 2, 1], elemToReplace = 1, and substitutionElem = 3, the output should be
arrayReplace(inputArray, elemToReplace, substitutionElem) = [3, 2, 3].
요약정리
1. Input Array 의 모든 element 들에 대하여 loop을 돈다.
2. Loop을 돌며, 만약 element 가 elemToReplace 와 값이 같으면, substitutionElem으로 교체해준다.
3. Loop을 마치고 바뀐 Input Array 값을 리턴.
모든 문제에 대한 저작권은 CodeSignal 회사에 있습니다. [Copyright © 2020 BrainFights Inc. All rights reserved]