본문 바로가기

Algorithm

(51)
[Top Interview 150 - Array / String] 189. Rotate Array [Q] [Medium]Given an integer array nums, rotate the array to the right by k steps, where k is non-negative.Constraints:1  일단 rotate 문제니까, deque.rotate(k) 쓰면 된다고 생각했다.그래서 작성했는데 먹히지 않음.이번엔 아래와 같이 작성했는데 또 안됨! 왜!조건들 때문이었다.. 그래서 if 문 추가하고 k가 n 보다 클 수 있어서 k%=n 추가하고 제출# Wrong Answerclass Solution: def rotate(self, nums: List[int], k: int) -> None: """ Do not return anything, modify num..
[Top Interview 150 - Array / String] 169. Majority Element [Q] [Easy]Given an array nums of size n, return the majority element.The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array. 일단 in-place 문제가 아니면 좀 더 편하게 풀 수 있는 것 같다.라고 생각했는데 제출하니까 틀렸다고 한다.아무리봐도 틀린 부분이 없는 것 같아 colab 에서 돌려봤더니 맞게 답이 나오는데 어디서 연산이 잘못 되었을까..n 이 $len(nums)$ 라고 했는데 내가 다른 변수로 써서 그런가 해서 m 으로 바꿔보기도 하고, f..
[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..
[MySQL] [SUM, MAX, MIN] / 최댓값 구하기 [문제 설명]ANIMAL_INS 테이블은 동물 보호소에 들어온 동물의 정보를 담은 테이블입니다.ANIMAL_INS 테이블 구조는 다음과 같으며,ANIMAL_ID, ANIMAL_TYPE, DATETIME, INTAKE_CONDITION, NAME, SEX_UPON_INTAKE는각각 동물의 아이디, 생물 종, 보호 시작일, 보호 시작 시 상태, 이름, 성별 및 중성화 여부를 나타냅니다.가장 최근에 들어온 동물은 언제 들어왔는지 조회하는 SQL 문을 작성해주세요.   [A] 내가쓴답">내가쓴답-- 1안 (MAX 이용 X)SELECT DATETIME AS 시간FROM ANIMAL_INSORDER BY DATETIME DESCLIMIT 1-- 2안 (MAX 이용 ..