본문 바로가기

반응형

코딩 테스트/LeetCode(swift)

(28)
[LeetCode] 153. Find Minimum in Rotated Sorted Array 문제 leetcode.com/problems/find-minimum-in-rotated-sorted-array/ Find Minimum in Rotated Sorted Array - 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 코드 (22년 2월 15일 구현) class Solution { func findMin(_ nums: [Int]) -> Int { var leftIndex = 0 var rightIndex = nums.count - 1 if nums[l..
[LeetCode] 152. Maximum Product Subarray 문제 leetcode.com/problems/maximum-product-subarray/ Maximum Product Subarray - 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 코드 class Solution { func maxProduct(_ nums: [Int]) -> Int { var minValue = nums[0] var maxValue = nums[0] var result = nums[0] for i in 1..
[LeetCode] 53. Maximum Subarray 문제 leetcode.com/problems/maximum-subarray/ Maximum Subarray - 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 잠깐 우리가 같이 풀었던 로직을 활용해야 하는 로직입니다. 저는 2가지 방식으로 풀었습니다. 코드 (22년 2월 15일 풀이) class Solution { func maxSubArray(_ nums: [Int]) -> Int { var maxSum = nums[0] var sumValue = nums[0]..
[LeetCode] 238. Product of Array Except Self 문제 leetcode.com/problems/product-of-array-except-self/ Product of Array Except Self - 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 잠깐 array에서 자기 자신을 제외한 곱의 값을 넘겨 주는 문제. 코드 class Solution { func productExceptSelf(_ nums: [Int]) -> [Int] { var answer: [Int] = Array(repeating: 0, c..
[LeetCode] 217. Contains Duplicate 문제 leetcode.com/problems/contains-duplicate/ Contains Duplicate - 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 잠깐 단순 이중 for문으로 구현하면 안될것 같은 느낌 받으셨죠? 그럼 특정 작업 후 이중 for문으로 구현하거나 단일 for문으로 구현해야 할거 같은데요 코드 class Solution { func containsDuplicate(_ nums: [Int]) -> Bool { var numSet = ..
[LeetCode] 121. Best Time to Buy and Sell Stock 문제 leetcode.com/problems/best-time-to-buy-and-sell-stock/ Best Time to Buy and Sell Stock - 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 잠깐 "1. Two Sum" 문제 처럼 이중 for문으로 구현할 경우 시간 초과가 발생합니다. 단순 이중 for문 보다 더 효율적으로 구현하라는 말이죠. 그럼 이중 for문의 종료 시점 혹은 단일 for문, DP에 대해서 생각해볼 필요가 있겠네요. 코드 ..
[LeetCode] 1. Two Sum 문제 leetcode.com/problems/two-sum/ 잠깐 문제를 간단히 설명하자면 다음과 같습니다. int 어레이 중 2개의 엘리먼트를 선택하여 그 합이 target인 엘리먼트들을 찾아라. (같은 엘리먼트 사용 불가) 자세한건 구글 번역을 사용해보세요. (크롬 확장 프로그램으로 구글 번역 추천) 해당 문제는 단순 이중 for문으로 구현이 가능합니다. 하지만 더 효율적인 코드를 짜는게 관건이겠죠? 코드 class Solution { func twoSum(_ nums: [Int], _ target: Int) -> [Int] { for firstIndex in 0..
[LeetCode] 추천 75문제와 알고리즘 공부 방법 주소 www.teamblind.com/post/New-Year-Gift---Curated-List-of-Top-75-LeetCode-Questions-to-Save-Your-Time-OaM1orEU New Year Gift - Curated List of Top 75 LeetCode Questions to Save Your Time New Year Gift to every fellow time-constrained engineer out there looking for a job, here's a list of the best LeetCode questions that teach you core concepts and techniques for each category/type of problems! ..

반응형