본문 바로가기

LeetCode/Problems25

LeetCode 3. Longest Substring Without Repeating Characters [Sliding Window, Two-Pointers] Problems: Given a string, find the length of the longest substring without repeating characters. Example 1: Input: "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. Example 2: Input: "bbbbb" Output: 1 Explanation: The answer is "b", with the length of 1. Example 3: Input: "pwwkew" Output: 3 Explanation: The answer is "wke", with the length of 3. Note that the answer mu.. 2020. 6. 10.
LeetCode 2. Add Two Numbers [Linked List] Problem: You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 itself. Example: Input: (2 -> 4 -> 3) + (5 -> 6 -> 4) Output: 7 -> 0 -> 8 Explanation.. 2020. 6. 9.
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.