Last active
April 18, 2020 13:59
-
-
Save anohk/3883e08b2f4cc8224c5c8a37e25bf6ad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
from collections import defaultdict | |
def check_palindrome_permutation(input_string): | |
"""입력받은 문자열이 palindrome의 순열을 갖는지 확인한다.""" | |
char_count = defaultdict(int) | |
for char in input_string: | |
char_count[char] += 1 | |
odd_occurred = False | |
for char, count in char_count.items(): | |
if count % 2 == 1: | |
if odd_occurred: | |
return False | |
else: | |
odd_occurred = True | |
return True | |
def check_palindrome(input_string): | |
"""입력받은 문자열이 palindrome 인지 확인한다.""" | |
for i in range(len(input_string) // 2): | |
if input_string[i] != input_string[-1 - i]: | |
return False | |
return True | |
class TestCheckPalindromePermutation(unittest.TestCase): | |
def test_check_check_palindrome_permutation(self): | |
self.assertTrue(check_palindrome_permutation('treret')) | |
self.assertTrue(check_palindrome_permutation('akayk')) | |
self.assertFalse(check_palindrome_permutation('levels')) | |
class TestCheckPalindrome(unittest.TestCase): | |
def test_check_palindrome(self): | |
self.assertTrue(check_palindrome('terret')) | |
self.assertTrue(check_palindrome('kayak')) | |
self.assertFalse(check_palindrome('levels')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment