본문 바로가기

Algorithm/Leetcode

(21)
[Top Interview 150 - Array / String] 80. Remove Duplicates from Sorted Array II [Q] [Medium]Given an integer array nums sorted in non-decreasing order, remove some duplicates in-place such that each unique element appears at most twice.The relative order of the elements should be kept the same.Since it is impossible to change the length of the array in some languages, you must instead have the result be placed in the first part of the array nums. More formally, if there are..
[Top Interview 150 - Array / String] 26. Remove Duplicates from Sorted Array [Q] [Easy]Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. Then return the number of unique elements in nums.Consider the number of unique elements of nums to be k, to get accepted, you need to do the following things:Change the array nums such th..
[Problem List - Array / String] 21. Merge Two Sorted Lists [Q] [Easy]You are given the heads of two sorted linked lists list1 and list2.Merge the two lists into one sorted list.The list should be made by splicing together the nodes of the first two lists.Return the head of the merged linked list.  list 2개 합쳐서 sort 하면 될 것으로 생각했는데, "linked" 가 복병이었음list1 과 list2 가 모두 none 인 경우, 하나만 none 인 경우는 따로 처리해줌list1 과 list2 크기 비교하여 처리 해주는건 재귀적으로 처리함 # Answer# Definit..
[Top Interview 150 - Array / String] 88. Merge Sorted Array [Q] [Easy]You are given two integer arrays nums1 and nums2,sorted in non-decreasing order,and two integers m and n, representing the number of elements in nums1 and nums2 respectively.Merge nums1 and nums2 into a single array sorted in non-decreasing order.The final sorted array should not be returned by the function,but instead be stored inside the array nums1.To accommodate this, nums1 has a l..
[Top Interview 150 - Array / String] 27. Remove Element [Q] [Easy]Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The order of the elements may be changed. Then return the number of elements in nums which are not equal to val.Consider the number of elements in nums which are not equal to val be k, to get accepted, you need to do the following things:Change the array nums such that the first k elements o..