본문 바로가기

Algorithm/Code Fights (Code Signal)

Aracade Intro #18 PalindromeRearranging, Codefights, CodeSignal, 코드파이트, 코드시그널, c++ java c# scalar

Aracade Intro #18 PalindromeRearranging, Codefights, CodeSignal, 코드파이트, 코드시그널, c++ java c# scalar



Given a string, find out if its characters can be rearranged to form a palindrome.


주어진 문자열이, 회문(중간을 기준으로 대칭)자가 될수 있는지 확인한다.


e.g. abcba / 다시합창합시다 / bbbbcddcbbbb / 말해말


Input -> "aabb"

Output -> palindromeRearranging(inputString) = true



We can rearrange "aabb" to make "abba", which is a palindrome.



//Process

//1. Input inputString

//2. Iterate from begin to the end

// 2.1. Check the char of that index is in the tempVector

//  2.1.1. If so -> erase that char

//  2.1.2. If not -> add that char

//3. Check if tempVector is 1 or less

// 3.1. If so -> It's true

// 3.2. If not -> It's false

//4. Return result


//처리과정

//1. inputString을 입력받는다.

//2. 시작부터 끝까지 반복한다.

// 2.1. 해당 인덱스번째의 char 가 tempVector에 있는지 확인한다.

//  2.1.1. 있으면 -> char 지운다.

//  2.1.2. 없으면 -> char 넣는다.

//3. tempVector 의 길이가 1 이하인지 확인해서

// 3.1. 이하면 true

// 3.2. 초과면 false

//4. 결과 반환한다.




Code.. let me see code!!!!!!!!!


코드.. 코드를 보자!!!!!!!!




bool palindromeRearranging(std::string inputString) {


    bool answer = false;

    std::vector<char*> tempArray;

    int length = inputString.size();

    int i = 0;

    int j;

    bool isExist;

    while (i < length) {

        j = 0;

        isExist = false;

        while (j < tempArray.size() && isExist == false) {

            if ((inputString.at(i)) == *(tempArray[j])) {

                isExist = true;

            }

            j++;

        }

        if (isExist == true) {

            tempArray.erase(tempArray.begin() + j - 1);

        }

        else {

            char* tempChar = &(inputString.at(i));

            tempArray.push_back(tempChar);

        }

        i++;

    }

    if (tempArray.size() < 2) {

        answer = true;

    }

    return answer;

}




2018/10/24 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #18 PalindromeRearranging, Codefights, CodeSignal, 코드파이트, 코드시그널, c++ java c# scalar

2018/10/24 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #17 ArrayChange, Codefights, CodeSignal, 코드파이트, 코드시그널, c++ java c# scalar

2018/10/21 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #16 AreSimilar?, Codefights, CodeSignal, 코드파이트, 코드시그널, c++ java c# scalar

2018/10/21 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #15 AddBorder, Codefights, CodeSignal, 코드파이트, 코드시그널, c++ java c# scalar

2018/10/20 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #14 AlternatingSums, Codefights, CodeSignal

2018/10/19 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #13 ReverseParentheses, Codefights, CodeSignal

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