[백준] #25501 재귀의 귀재 python
2022. 12. 28. 00:07
https://www.acmicpc.net/problem/25501
25501번: 재귀의 귀재
각 테스트케이스마다, isPalindrome 함수의 반환값과 recursion 함수의 호출 횟수를 한 줄에 공백으로 구분하여 출력한다.
www.acmicpc.net
📕 설명 📕
주어진 힌트에 대하여 문자를 앞부터, 그리고 뒤부터 비교해 가며 풀이하였다.
🧑🏻💻 나의 풀이 🧑🏻💻
N = int(input())
def recursion(s, left, right, cnt):
cnt += 1
if left >= right:
return 1, cnt
elif s[left] != s[right]:
return 0, cnt
else:
return recursion(s, left+1, right-1, cnt)
def isPalindrome(s):
cnt = 0
return recursion(s, 0, len(s)-1, cnt)
for i in range(N):
print(*isPalindrome(input()))
'Programming > Algorithm' 카테고리의 다른 글
[백준] #2447 별 찍기 python (0) | 2022.12.28 |
---|---|
[백준] #24060 알고리즘 수업 - 병합 정렬 1 python (0) | 2022.12.28 |
[백준] #10872 팩토리얼 python (0) | 2022.12.28 |
[백준] #10870 피보나치 수 5 python (0) | 2022.12.28 |
[백준] #18870 좌표 압축 python (0) | 2022.12.27 |