Algorithm/백준
[백준 Python] 25501번 재귀의 귀재 문제풀이
얼음새꽃
2023. 7. 11. 17:40
반응형
문제
https://www.acmicpc.net/problem/25501
풀이
깊게 고민안하고 내가 좋아하는 딕셔너리에 값을 넣어서 반환했다.
def recursion(s, i, r, count):
if i >= r:
return {"result": 1, "count": count}
elif s[i] != s[r]:
return {"result": 0, "count": count}
else:
count += 1
return recursion(s, i + 1, r - 1, count)
def is_palindrome(s):
return recursion(s, 0, len(s) - 1, 1)
if __name__ == '__main__':
input_count = int(input())
input_string_list = []
for index in range(input_count):
input_string = input()
input_string_list.append(input_string)
for input_string in input_string_list:
result = is_palindrome(input_string)
print(f"{result['result']} {result['count']}")
반응형