Coding Test
-
[Leet Code] 27.Remove Element - EasyCS기초/Algorithm, Data Structures 2023. 8. 3. 00:15
문제 Description Input: nums => list[int], val => int Remove all elements same with "val" in the given array "nums" and change the array to starts with the elements which are not same with "val". The array must be changed in place. Return the number of elements same with "val". The judge will test below two points: 1. The returned value is correct - name this value as "k" 2. Each element from 0 to..
-
[Leet Code] Two Pointers (투포인터): 19.Remove Nth Node From End of List - MediumCS기초/Coding Test 2023. 1. 5. 02:43
문제 / 코드 Description Remove the nth node from the end of the list and return its head. How to solve Since the given linked list can only be traversed from the first to the last node, we need to find a way to calculate where nth node from the end is from the start. However, the length of a linked list is not fixed, how can we find it? Let the length of the given linked list be l. Then the position..
-
[Leet Code] Two Pointers (투포인터): 876.Middle of the Linked List - EasyCS기초/Algorithm, Data Structures 2023. 1. 2. 02:04
문제 / 코드 드디어 linked list가 나왔다. 링크드리스트 자료구조 포스팅이랑 같이 올리려고 했는데 시간이 너무 늦어 다음 코드리뷰 포스팅이랑 같이 올려야겠다 (어차피 앞으로 링크드리스트 주구장창 나올 예정이기 때문에..) Description Return middle node of the linked list. If there are two middle nodes, return the second middle node. How to solve Simple way Iterate the linked list from the first node to get the full length. Iterate the linked list from the first node again, change the cu..
-
[Leet Code] Two Pointers (투포인터): 189. Rotate Array - Medium (What "modify in-place" means on Leetcode?)CS기초/Coding Test 2022. 12. 20. 01:36
문제 / 코드 사실 이 문제도 미디움치고는 정말 빨리 풀었다. 나중에 나오는 링크드 리스트 미디움에 비하면 정말.. 이건 이지다. 릿코드에서 이 문제를 투포인터로 분류해놨는데 나는 왜 이 문제가 투 포인터인지 한참을 생각했다 (심지어 투 포인터로 푸는 방법이 따로 있는지 계속 생각함). 원리를 이해하니 두 점을 찍고 푼다는 점에서 투 포인터가 맞는데 기존의 투 포인터 푸는 방식과 다르다는 이유로 투 포인터라고 생각을 안했다니, 역시 고정관념에서 벗어나는 것이 참 힘들다. Leetcode said it's a Two pointers problem, I was confused how it can be done with two pointers with O(1) extra space (well, it wasn'..
-
[Leet Code] Two Pointers (투포인터): 167. Two Sum 2 - Input Array Is Sorted - MediumCS기초/Coding Test 2022. 12. 19. 21:37
* Two Pointers 알고리즘 설명 문제 / 코드 개인적으로 medium 중 제일 쉬웠던 문제. Two pointers에서 항상 중앙값을 가지고 풀던 것을 끝 값을 활용하는 것으로 아이디어만 바꾸면 수월하게 풀 수 있는 문제이다. Description Find two numbers such that they add up to a specific target number and return a list of those integers' index in the input array. Condition - The input array is 1-indexed - The array is already sorted in non-decreasing order - There is only one solution ..
-
[Leet Code] Two Pointers (투포인터): 283. Move Zeroes - EasyCS기초/Coding Test 2022. 11. 14. 01:19
* Two Pointers 알고리즘 설명 문제 / 코드 개인적으로 label은 easy인데 swap하는 방법을 생각을 못해 medium보다 오래 걸렸던 문제. 아직도 a, b = b, a로 구현하는 코드가 익숙하지 않다. 그리고 문제 푸는 시간을 정확하게 기록하는 습관을 들여야하는데 계속 까먹는다.. Description move all zeros in the array to the end of array. Other integers keep it's order, just move foward to keep the length of the original input array. Requirements - Do in-place w/o making a copy of the array. How to solve..