전체 글
-
[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" ..
-
[LeetCode] 283. Move Zeroes / Swift프로그래밍/코딩테스트 2021. 6. 26. 20:29
[문제 보기] 더보기 Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements. Note that you must do this in-place without making a copy of the array. Example 1: Input: nums = [0,1,0,3,12] Output: [1,3,12,0,0] Example 2: Input: nums = [0] Output: [0] Constraints: 1
-
[LeetCode] 234. Palindrome Linked List / Swift프로그래밍/코딩테스트 2021. 6. 26. 02:08
[문제 보기] 더보기 Given the head of a singly linked list, return true if it is a palindrome. Example 1: Input: head = [1,2,2,1] Output: true Example 2: Input: head = [1,2] Output: false Constraints: The number of nodes in the list is in the range [1, 10^5]. 0
-
[LeetCode] 226. Invert Binary Tree / Swift프로그래밍/코딩테스트 2021. 6. 26. 00:13
[문제 보기] 더보기 Given the root of a binary tree, invert the tree, and return its root. Example 1: Input: root = [4,2,7,1,3,6,9] Output: [4,7,2,9,6,3,1] Example 2: Input: root = [2,1,3] Output: [2,3,1] Example 3: Input: root = [] Output: [] Constraints: The number of nodes in the tree is in the range [0, 100]. -100
-
[LeetCode] 206. Reverse Linked List / Swift프로그래밍/코딩테스트 2021. 6. 25. 23:50
[문제 보기] 더보기 Given the head of a singly linked list, reverse the list, and return the reversed list. Example 1: Input: head = [1,2,3,4,5] Output: [5,4,3,2,1] Example 2: Input: head = [1,2] Output: [2,1] Example 3: Input: head = [] Output: [] Constraints: The number of nodes in the list is the range [0, 5000]. -5000 ListNode? { var stack = [ListNode]() var cur = head while cur != nil { stack.appen..
-
[LeetCode] 141. Linked List Cycle / Swift프로그래밍/코딩테스트 2021. 6. 25. 19:09
[문제 보기] 더보기 141. Linked List Cycle Given head, the head of a linked list, determine if the linked list has a cycle in it. There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail's next pointer is connected to. Note that pos is not passed as a paramet..
-
[LeetCode] 136. Single Number / Swift프로그래밍/코딩테스트 2021. 6. 24. 16:08
[문제 보기] 더보기 Given a non-empty array of integers nums, every element appears twice except for one. Find that single one. You must implement a solution with a linear runtime complexity and use only constant extra space. Example 1: Input: nums = [2,2,1] Output: 1 Example 2: Input: nums = [4,1,2,1,2] Output: 4 Example 3: Input: nums = [1] Output: 1 Constraints: 1
-
[LeetCode] 94. Binary Tree Inorder Traversal / Swift프로그래밍/코딩테스트 2021. 6. 24. 00:49
[문제 보기] 더보기 Given the root of a binary tree, return the inorder traversal of its nodes' values. Example 1: Input: root = [1,null,2,3] Output: [1,3,2] Example 2: Input: root = [] Output: [] Example 3: Input: root = [1] Output: [1] Example 4: Input: root = [1,2] Output: [2,1] Example 5: Input: root = [1,null,2] Output: [1,2] Constraints: The number of nodes in the tree is in the range [0, 100]. -1..
-
[2020 카카오 인턴십] 보석 쇼핑 / Swift프로그래밍/코딩테스트 2021. 6. 22. 17:07
[문제 보기] 더보기 [본 문제는 정확성과 효율성 테스트 각각 점수가 있는 문제입니다.] 개발자 출신으로 세계 최고의 갑부가 된 어피치는 스트레스를 받을 때면 이를 풀기 위해 오프라인 매장에 쇼핑을 하러 가곤 합니다. 어피치는 쇼핑을 할 때면 매장 진열대의 특정 범위의 물건들을 모두 싹쓸이 구매하는 습관이 있습니다. 어느 날 스트레스를 풀기 위해 보석 매장에 쇼핑을 하러 간 어피치는 이전처럼 진열대의 특정 범위의 보석을 모두 구매하되 특별히 아래 목적을 달성하고 싶었습니다. 진열된 모든 종류의 보석을 적어도 1개 이상 포함하는 가장 짧은 구간을 찾아서 구매 예를 들어 아래 진열대는 4종류의 보석(RUBY, DIA, EMERALD, SAPPHIRE) 8개가 진열된 예시입니다. 진열대 번호: 1, 2, 3,..
-
[Contest 246] 1904. The Number of ... / Swift프로그래밍/코딩테스트 2021. 6. 21. 01:04
1904. The Number of Full Rounds You Have Played / Swift [문제 보기] 더보기 1904. The Number of Full Rounds You Have Played User Accepted:3829 User Tried:4637 Total Accepted:3987 Total Submissions:10719 Difficulty:Medium A new online video game has been released, and in this video game, there are 15-minute rounds scheduled every quarter-hour period. This means that at HH:00, HH:15, HH:30 and HH:45, a ne..
-
[Contest 246] 1903. Largest Odd Number in String / Swift프로그래밍/코딩테스트 2021. 6. 21. 00:54
[문제 보기] 더보기 You are given a string num, representing a large integer. Return the largest-valued odd integer (as a string) that is a non-empty substring of num, or an empty string "" if no odd integer exists. A substring is a contiguous sequence of characters within a string. Example 1: Input: num = "52" Output: "5" Explanation: The only non-empty substrings are "5", "2", and "52". "5" is the onl..