본문 바로가기
공부용/연습장

[리트코드]20일차

by alpakaka 2025. 2. 28.

60문제 가량 풀었다.

 

86. Partition List

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public ListNode partition(ListNode head, int x) {
        ListNode slist = new ListNode();
        ListNode blist = new ListNode();
        ListNode small = slist;
        ListNode big = blist;

        while (head != null){
            if (head.val < x){
                small.next = head;
                small = small.next;
            }else{
                big.next = head;
                big = big.next;
            }

            head = head.next;
        }

        small.next = blist.next;
        big.next = null;

        return slist.next;
        
    }
}

문제 이해가 어려웠다...

 

 

 

'공부용 > 연습장' 카테고리의 다른 글

[leetcode] 3-1 회차  (0) 2025.04.15
[리트코드]2-2일차  (0) 2025.03.25
리트코드 19일차  (0) 2025.02.27
리트코드 18일차  (0) 2025.02.25
[리트코드] 18일차  (0) 2025.02.24