짱이 될거야
백준 25501: 재귀의 귀재 Python 본문
https://www.acmicpc.net/problem/25501
def isPalindrome(s):
return recursion(s, 0, len(s)-1)
def recursion(s, l, r): # s: 문자열, l: 시작, r: 끝
global count
count += 1
if l >= r:
return 1
elif s[l] != s[r]:
return 0
else:
return recursion(s, l+1, r-1)
T = int(input()) # 테스트케이스의 수
for _ in range(T):
count = 0 # recursion 함수의 호출 횟수
print(isPalindrome(input()), end=' ')
print(count)
'알고리즘' 카테고리의 다른 글
백준 7569: 토마토 Python (BFS) (0) | 2022.11.28 |
---|---|
백준 3009: 네 번째 점 Python (0) | 2022.11.25 |
백준 2566: 최댓값 Python (0) | 2022.11.24 |
백준 2738: 행렬 덧셈 (0) | 2022.11.24 |
백준 10807: 개수 세기 Python (0) | 2022.11.23 |
Comments