[LeetCode#234] Palindrome Linked List

2024. 7. 24. 12:01·Algorithm/문제풀이

❒ Description


제목 Palindrome Linked List
링크 https://leetcode.com/problems/palindrome-linked-list/description/
자료구조 선형자료 구조 (연결 리스트)
푼 날짜 7/24

 

 

 

 

❒ Solution


1. Deque 자료구조를 사용한 풀이

public static boolean solve(ListNode head) {
    Deque<Integer> deque = new LinkedList<>();
    ListNode node = head;
    while (node != null) {
        deque.add(node.val);
        node = node.next;
    }
    while (!deque.isEmpty() && deque.size() > 1) {
        if (deque.pollFirst() != deque.pollLast()) {
            return false;
        }
    }
    return true;
}

 

팰린드롬 여부를 판단하기 위해서는 앞뒤로 모두 추출할 수 있는 자료구조가 필요한데,

Deque(데크)가 이에 가장 적합하다.

 

 

2. 러너를 사용한 풀이 

이해가 안되서 다음번 풀이 때 재도전 

'Algorithm > 문제풀이' 카테고리의 다른 글

[LeetCode#206] Reverse Linked List  (0) 2024.07.28
[LeetCode#21] Merge Two Sorted Lists  (0) 2024.07.24
[LeetCode#121] Best Time to Buy and Sell Stock  (0) 2024.07.24
[LeetCode#238] Product of Array Except Self  (0) 2024.07.23
[LeetCode#15] 3Sum  (0) 2024.07.23
'Algorithm/문제풀이' 카테고리의 다른 글
  • [LeetCode#206] Reverse Linked List
  • [LeetCode#21] Merge Two Sorted Lists
  • [LeetCode#121] Best Time to Buy and Sell Stock
  • [LeetCode#238] Product of Array Except Self
gilbert9172
gilbert9172
gilbert9172 님의 블로그 입니다.
  • gilbert9172
    バックエンド
    gilbert9172
  • 전체
    오늘
    어제
    • All Categories (207)
      • 우테코 7기 (21)
        • 1주차 (8)
        • 2주차 (5)
        • 3주차 (6)
      • Langauge (6)
        • Java (3)
        • Kotlin (3)
      • Back-End (13)
        • SpringBoot (1)
        • Trouble Shooting (0)
        • Setup & Configuration (1)
        • SQL (3)
        • Redis (8)
      • Architecture (6)
        • Multi Module (1)
        • DDD (5)
      • CS (30)
        • Data Structure (6)
        • Operating System (0)
        • Network (12)
        • Database (10)
        • Design Pattern (2)
      • Algorithm (78)
        • 내용 정리 (18)
        • 문제풀이 (60)
      • DevOps (6)
        • AWS (5)
        • Git (1)
      • Front-End (1)
        • Trouble Shooting (1)
      • Project (6)
        • 페이스콕 (6)
      • Book (39)
        • 친절한 SQL 튜닝 (9)
        • 데이터 중심 애플리케이션 설계 (14)
        • 이벤트 기반 마이크로서비스 구축 (6)
        • Spring Batch docs (10)
        • Quartz docs (0)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    sliding-window
    binarysearch
    greedy
    부분단조성
    Two-Pointer
    오블완
    Back-Tracking
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.2
gilbert9172
[LeetCode#234] Palindrome Linked List
상단으로

티스토리툴바