프로그래밍/코딩테스트
-
[LeetCode] 19. Remove Nth Node From End of List / Swift프로그래밍/코딩테스트 2021. 7. 6. 20:26
[문제 보기] 더보기 Given the head of a linked list, remove the nth node from the end of the list and return its head. Example 1: Input: head = [1,2,3,4,5], n = 2 Output: [1,2,3,5] Example 2: Input: head = [1], n = 1 Output: [] Example 3: Input: head = [1,2], n = 1 Output: [1] Constraints: The number of nodes in the list is sz. 1
-
[LeetCode] 17. Letter Combinations of a Phone Number / Swift프로그래밍/코딩테스트 2021. 7. 6. 15:24
[문제 보기] 더보기 Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order. A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters. Example 1: Input: digits = "23" Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"] Example 2: Input:..
-
[LeetCode] 15. 3Sum / Swift프로그래밍/코딩테스트 2021. 7. 2. 01:54
[문제 보기] 더보기 Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0. Notice that the solution set must not contain duplicate triplets. Example 1: Input: nums = [-1,0,1,2,-1,-4] Output: [[-1,-1,2],[-1,0,1]] Example 2: Input: nums = [] Output: [] Example 3: Input: nums = [0] Output: [] Constraints: ..
-
[LeetCode] 11. Container With Most Water / Swift프로그래밍/코딩테스트 2021. 7. 1. 21:29
[문제 보기] 더보기 Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of the line i is at (i, ai) and (i, 0). Find two lines, which, together with the x-axis forms a container, such that the container contains the most water. Notice that you may not slant the container. Example 1: Input: height = [1..
-
[LeetCode] 5. Longest Palindromic Substring / Swift프로그래밍/코딩테스트 2021. 7. 1. 15:29
[문제 보기] 더보기 Given a string s, return the longest palindromic substring in s. Example 1: Input: s = "babad" Output: "bab" Note: "aba" is also a valid answer. Example 2: Input: s = "cbbd" Output: "bb" Example 3: Input: s = "a" Output: "a" Example 4: Input: s = "ac" Output: "a" Constraints: 1
-
[LeetCode] 3. Longest Substring Without Repeating Characters / Swift프로그래밍/코딩테스트 2021. 6. 30. 19:29
[문제 보기] 더보기 Given a string s, find the length of the longest substring without repeating characters. Example 1: Input: s = "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. Example 2: Input: s = "bbbbb" Output: 1 Explanation: The answer is "b", with the length of 1. Example 3: Input: s = "pwwkew" Output: 3 Explanation: The answer is "wke", with the length of 3. Notice ..
-
[LeetCode] 2. Add Two Numbers / Swift프로그래밍/코딩테스트 2021. 6. 29. 19:34
[문제 보기] 더보기 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 contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 itself. Example 1: Input: l1 = [2,4,3], l2 = [5,6,4] Output: [7,0,8] Explan..
-
[LeetCode] 543. Diameter of Binary Tree / Swift프로그래밍/코딩테스트 2021. 6. 29. 16:28
[문제 보기] 더보기 Given the root of a binary tree, return the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may not pass through the root. The length of a path between two nodes is represented by the number of edges between them. Example 1: Input: root = [1,2,3,4,5] Output: 3 Explanation: 3is the le..
-
[LeetCode] 1047. Remove All Adjacent Duplicates In String / Swift프로그래밍/코딩테스트 2021. 6. 29. 15:47
[문제 보기] 더보기 You are given a string s consisting of lowercase English letters. A duplicate removal consists of choosing two adjacent and equal letters and removing them. We repeatedly make duplicate removals on s until we no longer can. Return the final string after all such duplicate removals have been made. It can be proven that the answer is unique. Example 1: Input: s = "abbaca" Output: "ca" ..