본문 바로가기

LeetCode91

LeetCode. Valid Palindrome [String] Problem: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. Note: For the purpose of this problem, we define empty string as valid palindrome. Example 1: Input: "A man, a plan, a canal: Panama" Output: true Example 2: Input: "race a car" Output: false -Summary- 1. Modified the given s string to remove all white spaces and special charact.. 2020. 6. 1.
LeetCode 21. Merge Two Sorted Lists Problem: Merge two sorted linked lists and return it as a new sorted list. The new list should be made by splicing together the nodes of the first two lists. Example: Input: 1->2->4, 1->3->4 Output: 1->1->2->3->4->4 -Summary- 1. Create a dummy and curr variables to track and merge the two lists. 2. Compare l1 and l2 value. 'curr' will connect to the less value. Update l1 or l2 depends on the res.. 2020. 6. 1.
LeetCode 206. Reverse Linked List Problem: Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL -Summary- 1. Keep track of current / prev (copy the original list in the curr and prev) 2. Update and move the head (original) 3. Return prev 정답을 보니 recursive 하게 푸는 방법도 있었다. leetcode.com/problems/reverse-linked-list/discuss/609282/Python-Recursion-Highly-Commented-(greater99) 모든 문제에 대한 저작권은 Lee.. 2020. 6. 1.
LeetCode 876. Middle of the Linked List Problem: Given a non-empty, singly linked list with head node head, return a middle node of linked list. If there are two middle nodes, return the second middle node. Example 1: Input: [1,2,3,4,5] Output: Node 3 from this list (Serialization: [3,4,5]) The returned node has value 3. (The judge's serialization of this node is [3,4,5]). Note that we returned a ListNode object ans, such that: ans.va.. 2020. 5. 31.
LeetCode 1290. Convert Binary Number in a Linked List to Integer Problem: Given head which is a reference node to a singly-linked list. The value of each node in the linked list is either 0 or 1. The linked list holds the binary representation of a number. Return the decimal value of the number in the linked list. Example 1: Input: head = [1,0,1] Output: 5 Explanation: (101) in base 2 = (5) in base 10 Example 2: Input: head = [0] Output: 0 Example 3: Input: h.. 2020. 5. 31.
LeetCode 242. Delete Node in a Linked List Problem: Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Given linked list -- head = [4,5,1,9], which looks like following: Example 1: Input: head = [4,5,1,9], node = 5 Output: [4,1,9] Explanation: You are given the second node with value 5, the linked list should become 4 -> 1 -> 9 after calling your function. Example 2: Input: head =.. 2020. 5. 31.