-
[Leetcode] 19. Remove Nth Node From End of List (In Python)[Python] 파이썬/Leetcode_Medium 2021. 1. 14. 20:18
간략한 코드들은 github.com/Eastar-DS/Python 의 Leetcode 폴더에도 있습니다
Eastar-DS/Python
Contribute to Eastar-DS/Python development by creating an account on GitHub.
github.com
끝에서 n번째 노드를 없애는 문제.
Medium난이도의 문제치고는 쉽게풀었던거같고 결과도 빠르고 좋았다.
node1을 이용해서는 주어진 리스트노드의 length를 구했고(while문을 이용해서) delnum(예시에서는 val=3인 노드를 가리킬 숫자)을 설정했다. delnum이 4를 가리키지않고 3을 가리키게 설정한 이유는 3의 노드에서 next를 5로 설정할것이기때문이다. 4까지 갈 이유가 없음.
node2에서 idx=0부터 delnum까지 넘기고 지울 노드를 넘겨서 next로 설정해주면 게임끝!
문제의 출처는 leetcode.com/problems/4sum/입니다.
모르시는게 있으시다면 언제든지 댓글로 질문을 남겨주세요. 저에게 큰 공부가 됩니다. 감사합니다.
'[Python] 파이썬 > Leetcode_Medium' 카테고리의 다른 글
[Leetcode] 198. House Robber(In Python) (0) 2021.12.02 [Leetcode] 24. Swap Nodes in Pairs (In Python) (0) 2021.01.17 [Leetcode] 18. 4Sum (In Python) (0) 2021.01.13 [Leetcode] 17. Letter Combinations of a Phone Number (In Python) (0) 2021.01.12 [Leetcode] 16. 3Sum Closest (In Python) (0) 2021.01.12