Aracade Intro #25 arrayReplace. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar
Q.
Given an array of integers, replace all the occurrences of elemToReplace with substitutionElem.
주어진 정수배열에서, elemToReplace 에 해당하는 정수를, substitutionElem 정수로 전부 바꿔라.
Example
Input -> inputArray = [1, 2, 1], elemToReplace = 1, and substitutionElem = 3
Output -> arrayReplace(inputArray, elemToReplace, substitutionElem) = [3, 2, 3].
//Process
//1. Input integer array, replaceNum, replaceVal
//2. Iterate begin to the end
// 2.1. Check if value is same as replaceNum
// 2.1.1. If so -> Change to replaceVal
//3. Return array
//처리과정
//1. 정수배열, 바꿔야할 정수, 바꿀 정수 입력받는다.
//2. 시작부터 끝까지 반복한다.
// 2.1. 바꿔야할 정수값이랑 같으면
// 2.1.1. -> 바꿀 정수값으로 바꾼다.
//3. 배열을 반환한다.
코드.. 코드를 보자....
Code.. lemme see code.....
std::vector<int> arrayReplace(std::vector<int> inputArray, int replaceNumber, int replaceValue) {
for(int i = 0; i < inputArray.size(); ++i)
{
if (inputArray[i] == replaceNumber)
{
inputArray[i] = replaceValue;
}
}
return inputArray;
}
Something else...
2018/10/08 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #12 SortByHeight
2018/10/06 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #11 IsLucky
2018/10/03 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #10 CommonCharacterCount
2018/09/26 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #9 AllLongestStrings
2018/09/24 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #8 MatrixElementsSum
2018/09/23 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #7 AlmostIncreasingSequence
2018/09/22 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #6 MakeArrayConsecutive2
2018/09/21 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #5 ShapeArea
2018/09/19 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #4 AdjacentElementsProduct
2018/09/16 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #3 CheckPalindrome
2018/09/16 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #2 CenturyFromYear
2018/09/16 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #1 Add