Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

P.230 Q17 풀이 질문드립니다. #141

Open
Taemin90 opened this issue Jan 21, 2022 · 0 comments
Open

P.230 Q17 풀이 질문드립니다. #141

Taemin90 opened this issue Jan 21, 2022 · 0 comments

Comments

@Taemin90
Copy link

Taemin90 commented Jan 21, 2022

제가 푼 부분은 아래와 같습니다.
즉 임시 변수(객체)인 temp를 사용하여 풀었습니다.
temp = cur.next
cur.next = cur.next.next
temp.next = cur

def algorithm(head):
    prev = ListNode(0, head)
    cur = head
    if head and head.next:
        head = head.next

    while cur and cur.next:
        prev.next = cur.next
        prev = cur
        temp = cur.next
        cur.next = cur.next.next
        temp.next = cur
        cur = cur.next
    return head

그런데 multiple assignment로 위에 두꺼운 부분을 아래와 같이 한 문장으로 줄이고자 하면 무한루프에 빠지게 됩니다.
cur.next, cur.next.next = cur.next.next, cur
제가 multiple assignment를 잘못 이해하고 있는건지.. 도저히 모르겠습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant