본문 바로가기

전체 글148

[Swift] LeetCode - 200. Number of Islands 문제: https://leetcode.com/problems/number-of-islands/ Number of Islands - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com DFS로 풀었습니다. import Foundation class Solution { func numIslands(_ grid: [[Character]]) -> Int { var result = 0 var visited = Array(repeating: Array(repeating: fal.. 2022. 2. 16.
[Swift] LeetCode - 3. Longest Substring Without Repeating Characters 문제: https://leetcode.com/problems/longest-substring-without-repeating-characters/ Longest Substring Without Repeating Characters - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com used 딕셔너리로 start ~ index 사이에 중복이 있는지 없는지 검사했습니다 import Foundation class Solution { func lengthOfLongest.. 2022. 2. 16.
[Swift] LeetCode - 641. Design Circular Deque 문제: https://leetcode.com/problems/design-circular-deque/ Design Circular Deque - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com rear는 한 칸 뒤를 가리킵니다. class MyCircularDeque { var front: Int = 0 var rear: Int = 0 var queue: [Int?] let capacity: Int init(_ k: Int) { self.queue = Array(.. 2022. 2. 16.
[Swift] LeetCode - 20. Valid Parentheses 문제: https://leetcode.com/problems/valid-parentheses/ Valid Parentheses - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com import Foundation class Solution { func isValid(_ s: String) -> Bool { var stack = [Character]() for char in s { if char == "(" || char == "{" || char == "[" { s.. 2022. 2. 15.
[Swift] LeetCode - 2. Add Two Numbers 문제: https://leetcode.com/problems/add-two-numbers/ Add Two Numbers - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 연결리스트 문제는 CustomStringConvertible을 익스텐션으로 해서 프린트해가며 풀고 있습니다. ㅎㅎ import Foundation public class ListNode { public var val: Int public var next: ListNode? public init(.. 2022. 2. 15.
[Swift] LeetCode - 49. Group Anagrams 문제: https://leetcode.com/problems/group-anagrams/ Group Anagrams - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com import Foundation class Solution { func groupAnagrams(_ strs: [String]) -> [[String]] { var dict = [String: [String]]() for str in strs { let key = String(str.sorted().. 2022. 2. 14.