
def solution(s):
dp = [0]*len(s)
string = ""
for i in range(len(s)):
string += s[i]
for j in range(len(string)):
target = string[j:]
#print(string[j::-1])
if target == target[::-1]:
dp[j] = max(dp[j], len(target))
#print(dp)
return max(dp)
string[j::-1] 이런식으로 쓰면 이상해져서 따로 변수에다 할당하고 target[::-1] 이렇게 비교했다def solution(n, edge):
answer = 0
graph = [[] for _ in range(n+1)]
shortest = [10**15]*(n+1)
for i,j in edge:
graph[i].append(j)
graph[j].append(i)
shortest[0] = 0
shortest[1] = 0
queue = []
heappush(queue, [0,1])
while queue:
accum_dist, node = heappop(queue)
for next_node in graph[node]:
if accum_dist + 1 >= shortest[next_node]:
continue
shortest[next_node] = accum_dist + 1
heappush(queue, [accum_dist+1, next_node])
#print(shortest)
#shortest.sort()
return shortest.count(max(shortest))
여기서 accum_dist + 1 >= shortest[next_node]: 이 부분 등호 안넣어주면 일부 테스트케이스에서 queue가 비질 않아서 무한루프 돌게되는 현상 확인!