Problem Solving/LeetCode
-
[LeetCode] Rotate Array: 배열 회전 마스터하기 (Kotlin 풀이 및 최적화 전략)Problem Solving/LeetCode 2026. 1. 16. 23:18
오늘은 기술 면접 단골 문제인 LeetCode의 189. Rotate Array 문제를 함께 살펴보겠습니다. 배열을 다루는 기본적인 감각은 물론, 공간 복잡도 최적화 능력을 어필하기 아주 좋은 문제입니다.📌 문제 개요주어진 정수 배열 nums를 오른쪽으로 k단계만큼 회전시키는 문제입니다.Input: nums = [1,2,3,4,5,6,7], k = 3Output: [5,6,7,1,2,3,4]핵심 조건: k는 음수가 아닐 수 있으며, 배열의 길이보다 클 수 있습니다. 또한, 가능하다면 O(1) 공간 복잡도(In-place)로 해결하는 것이 권장됩니다.💡 첫 번째 접근: 임시 배열 활용하기 (Space O(n))코드 구현 (Kotlin)class Solution { fun rotate(nums: I..
-
[LeetCode] 27. Remove ElementProblem Solving/LeetCode 2025. 3. 2. 14:22
class Solution(object): def removeElement(self, nums, val): result = [] k = 0 for i in nums: if val != i: k+=1 result+=[i] nums[:] = result[:] return khttps://leetcode.com/problems/remove-element/?envType=study-plan-v2&envId=top-interview-150 주어진 배열 nums에서 val 이라는 값을 전부 제거한 뒤, val이 아닌 원소의 개수를 반환하는 문제새로운 배열을 만들..
-
[LeetCode] 88. Merge Sorted ArrayProblem Solving/LeetCode 2025. 2. 23. 16:08
오랜만에 리트코드를 풀어봤다https://leetcode.com/problems/merge-sorted-array/?envType=study-plan-v2&envId=top-interview-150오름차순으로 정렬된 두 개의 배열을 합치는 것포인터 두 개를 사용했고, 마지막 인덱스 처리하기 번거로워서 각각의 배열 양 끝에 max number 값을 넣어주었다import sysclass Solution(object): def merge(self, nums1, m, nums2, n): i = 0 j = 0 result = [] nums1+=[sys.maxsize] nums2+=[sys.maxsize] while i오랜만에 푸니까 ..
-
[LeetCode] 2. Add Two Numbers(Java)Problem Solving/LeetCode 2021. 9. 4. 02:17
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 링크드리스트를 쓰길래 아주아주아주아주 오랜만에 자바로 문제를 풀어봤다 ^^ 이왕 하는김에 vscode에 java 개발 환경 구축도 하고 .. 재밋다ㅠ 백준 프로그래머스는 코테 연습용으로 푸는 마음가짐이라면 릿코드는 취미의 영역이 될 것 같다 백준에서의 큰 수 더하기 문제와 같은 문제 !! 최대 100자..
-
[LeetCode] 7. Reverse Integer(Python)Problem Solving/LeetCode 2021. 8. 27. 22:02
https://leetcode.com/problems/reverse-integer/ Reverse Integer - 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 소스콘 팀원님의 추천으로 릿코드를 시작하게 되엇다 👏👏 릿허브 크롬 익스텐션을 설치하니까 Accepted와 동시에 깃허브 레포에도 올라가서 잔디심기에 좋을 것 같고 문제에서 틀렸다면 어떤 테스트케이스에서 틀렸는지도 알려주고, 솔루션도 보여주고 내부 IDE도 바로 코딩하기 좋아서 (아직 2문제밖에 안 풀..