LeetCode91 LeetCode. Remove Nth Node From End of List [Linked List] Problem: Given a linked list, remove the n-th node from the end of list and return its head. Example: Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked list becomes 1->2->3->5. Note: Given n will always be valid. -Summary- 1. First, create two dummy variables pointing to the head and copied dummy. 2. Calculate the head length 3. Once we face the.. 2020. 6. 3. LeetCode. Delete Node in a Linked List [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. 6. 3. LeetCode. Count and Say [String] Problem: The count-and-say sequence is the sequence of integers with the first five terms as following: 1. 1 2. 11 3. 21 4. 1211 5. 111221 1 is read off as "one 1" or 11. 11 is read off as "two 1s" or 21. 21 is read off as "one 2, then one 1" or 1211. Given an integer n where 1 ≤ n ≤ 30, generate the nth term of the count-and-say sequence. You can do so recursively, in other words from the previ.. 2020. 6. 3. LeetCode. Longest Common Prefix [String] Problem: Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "". Example 1: Input: ["flower","flow","flight"] Output: "FL" Example 2: Input: ["dog","racecar","car"] Output: "" Explanation: There is no common prefix among the input strings. Note: All given inputs are in lowercase letters a-z. -Summary- 1. If s.. 2020. 6. 2. LeetCode. Implement strStr() [String] Problem: Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Example 1: Input: haystack = "hello", needle = "ll" Output: 2 Example 2: Input: haystack = "aaaaa", needle = "bba" Output: -1 -Summary- 1. Check if needle str is in haystack str if not, return False. 2. using index() method to find the first occurrence of the need.. 2020. 6. 2. LeetCode. String to Integer (atoi) [String] Problem: Implement atoi which converts a string to an integer. The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value. The string can contain additional charac.. 2020. 6. 2. 이전 1 ··· 9 10 11 12 13 14 15 16 다음