728x90

알고리즘/해결 43

LeetCode821. Shortest Distance to a Character

1. 문제(원본) Given a string S and a character C, return an array of integers representing the shortest distance from the character C in the string. Example 1: Input: S = "loveleetcode", C = 'e' Output: [3, 2, 1, 0, 1, 0, 0, 1, 2, 2, 1, 0] Note: S string length is in [1, 10000]. C is a single character, and guaranteed to be in string S. All letters in S and C are lowercase. 2. 문제 입력받은 문자열에서 찾고자 하는 입..

알고리즘/해결 2020.04.20

LeetCode226. Invert Binary Tree

1. 문제(원본) Invert a binary tree. Example: Input: 4 / \ 2 7 / \ / \ 1 3 6 9 Output: 4 / \ 7 2 / \ / \ 9 6 3 1 2. 문제 2진트리의 왼쪽 노드랑 오른쪽 노드를 바꾸어라 public class TreeNode { public var val: Int public var left: TreeNode? public var right: TreeNode? public init(_ val: Int) { self.val = val self.left = nil self.right = nil } } 3. 나의 답 class Solution { func invertTree(_ root: TreeNode?) -> TreeNode? { guard ..

알고리즘/해결 2020.04.14

LeetCode283. Move Zeroes

1. 문제(원본) Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. Example: Input: [0,1,0,3,12] Output: [1,3,12,0,0] Note: You must do this in-place without making a copy of the array. Minimize the total number of operations. 2. 문제 임의의 배열에서 인덱스 0을 뒤로 옮겨라 3. 나의 답 class Solution { func moveZeroes(_ nums: inout [Int]) { fo..

알고리즘/해결 2020.04.12

LeetCode557. Reverse Words in a String III

1. 문제(원본) Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order. Example 1: Input: "Let's take LeetCode contest" Output: "s'teL ekat edoCteeL tsetnoc" Note: In the string, each word is separated by single space and there will not be any extra space in the string. 2. 문제 입력된 문자열을 스페이스를 간격으로 역순하여 출력하라 3. 나..

알고리즘/해결 2020.03.31
728x90