파비의 매일매일 공부기록

2023.12.15 Today's Challenge 본문

Problem Solving/LeetCode

2023.12.15 Today's Challenge

fabichoi 2023. 12. 15. 23:45

https://leetcode.com/problems/destination-city/

 

Destination City - LeetCode

Can you solve this real interview question? Destination City - You are given the array paths, where paths[i] = [cityAi, cityBi] means there exists a direct path going from cityAi to cityBi. Return the destination city, that is, the city without any path ou

leetcode.com

조건이 너무 타이트해서... 별로 도움이 안되는 문제

class Solution:
    def destCity(self, paths: List[List[str]]) -> str:
        s = set()
        for i in range(len(paths)):
            s.add(paths[i][0])
        for i in range(len(paths)):
            c = paths[i][1]
            if c not in s:
                return c
        return ""
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

2023.12.17 Today's Challenge  (0) 2023.12.17
2023.12.16 Today's Challenge  (1) 2023.12.16
2023.12.14 Today's Challenge  (0) 2023.12.14
2023.12.13 Today's Challenge  (0) 2023.12.13
2023.12.12 Today's Challenge  (0) 2023.12.12
Comments