본문 바로가기
반응형

#알고리즘 [Algorithm]/Problem40

[LeetCode] 3Sum Closest 📄 [LeetCode] 3Sum Closest Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution. class Solution { func threeSumClosest(_ nums: [Int], _ target: Int) -> Int { var result: (Int, Int) = (Int.max, Int.zero) let sortedNums: Array =.. 2021. 3. 23.
[LeetCode] 3Sum 📄 [LeetCode] 3Sum Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Notice that the solution set must not contain duplicate triplets. func threeSum(_ nums: [Int]) -> [[Int]] { let testcase = nums.sorted() var result: [Int: Array] = [:] // Notice that the solution set must not contain d.. 2021. 3. 23.
[LeetCode] Valid Parentheses 📄 Vaild parentheses for Swift Source Code class Solution { func isValid(_ s: String) -> Bool { let confirm: [Character: Character] = ["(": ")", "{": "}", "[": "]"] var result: [Character] = [] for letter in s { if confirm.keys.contains(letter) { result.append(letter) continue } if let lastValue = result.last, let pair = confirm[lastValue], letter == pair { result.removeLast() continue } result.a.. 2021. 3. 21.
[프로그래머스 - 구현] 자동완성 (for kakao) 카테고리 게시글 작성 날짜 게시글 최근 수정 날짜 작성자 Algorithm 2019-08-27 20:38 2022.02.26. 19:51 Dev.Yang 포털 다음에서 검색어 자동완성 기능을 넣고 싶은 라이언은 한 번 입력된 문자열을 학습해서 다음 입력 때 활용하고 싶어 졌다. 예를 들어, go 가 한 번 입력되었다면, 다음 사용자는 g 만 입력해도 go를 추천해주므로 o를 입력할 필요가 없어진다! 단, 학습에 사용된 단어들 중 앞부분이 같은 경우에는 어쩔 수 없이 다른 문자가 나올 때까지 입력을 해야 한다. 효과가 얼마나 좋을지 알고 싶은 라이언은 학습된 단어들을 찾을 때 몇 글자를 입력해야 하는지 궁금해졌다. 예를 들어, 학습된 단어들이 아래와 같을 때 go gone guild go를 찾을 때 go를.. 2019. 8. 27.
반응형