본문 바로가기

Computer Science/CODINGTEST_PRACTICE

[Leetcode/medium] 12. Integer to Roman 미디움 문제 쉽게 풀어서 지금 약간 기분 좋음 https://leetcode.com/problems/integer-to-roman/ integer를 roman으로 변환하는 문제인데 greedy로 해결함...근데 어제 푼 미디움 문제도 greedy였는데... 알고보면 의외로 그리디 문제가 많은듯? 900, 400, 90, 40, 9, 4 등 특수한 케이스에만 roman 숫자가 다르게 적용되기 때문에 500, 100 등으로 나누기 전에 먼저 해당 숫자로 나눠보고 quotient(몫)이 1보다 크면 사용하는 방식으로 해결! 이제 웬만하게 array나 map 등을 greedy로 풀어내는 건 잘 푸는듯 불연듯 학부생 떄나 열심히 하지 이제와서 이걸 왜 풀고 있나 싶기도 한데 오히려 지금이 더 재밌다..... 이.. 더보기
[Leetcode/medium] 11. Container With Most Water 아마존 인터뷰 시리즈 중에 있어서 풀어봄 https://leetcode.com/problems/container-with-most-water/description/ easy 문제인줄 알았는데 나중에 보니 medium문제네... (그렇다고 쉽게 푼것도 아님) 막상 풀려고 보면 brute force로 푸는게 바로 생각남... 실제로 그렇게 푸는 문제는 거의 없으니 아닐게 분명하고.. 힌트를 살짝 봤다 1번힌트: n^2은 아님 (.......그건 나도 알아....) 어쩔 수 없이 2번 힌트 2번힌트: 포인터 2개를 사용해서 값이 작은 쪽을 이동해라 아 듣는순간 해결방법이 바로 떠오름 좌우에서 그리디하게 현재 바가 더 짧은 것을 중앙쪽으로 이동시키면서 최대 면적을 탐색하면 되는구나... 최대 면적 탐색에서 순.. 더보기
35. Search Insert Position https://leetcode.com/problems/search-insert-position/description/ Search Insert Position - LeetCode Search Insert Position - Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You must write an algorithm with O(log n) runtime com leetcode.com sorted array에 주어진 하나의 숫자를 정확한 .. 더보기
[LeetCode] 27. Remove Element https://leetcode.com/problems/remove-element/ Remove Element - LeetCode Remove Element - Given an integer array nums and an integer val, remove all occurrences of val in nums in-place [https://en.wikipedia.org/wiki/In-place_algorithm]. The relative order of the elements may be changed. Since it is impossible to change the leng leetcode.com array에서 특정 값을 삭제하는데 in-place 방식(extra datastructre를 사용하지.. 더보기
[LeeCode] 53. Maximum Subarray 목표없이 풀다보니 의지가 약해지는 것 같아 'data structure'로 묶인 문제를 풀기로 결정. https://leetcode.com/study-plan/data-structure/?progress=x0f8sqb1 Data Structure - Study Plan - LeetCode In computer science, a data structure is a way to store and organize data. During the computer programming process, identifying and using the appropriate data structure is an important task as it can improve the overall efficiency of th.. 더보기
[LeetCode] 217. Contains Duplicate 목표없이 풀다보니 의지가 약해지는 것 같아 'data structure'로 묶인 문제를 풀기로 결정. https://leetcode.com/study-plan/data-structure/?progress=x0f8sqb1 Data Structure - Study Plan - LeetCode In computer science, a data structure is a way to store and organize data. During the computer programming process, identifying and using the appropriate data structure is an important task as it can improve the overall efficiency of th.. 더보기
[LeetCode] 26. Remove Duplicates from Sorted Array 기록 https://leetcode.com/problems/remove-duplicates-from-sorted-array/description/ Remove Duplicates from 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 오름차순으로 정렬된 중복되는 숫자가 존재하는 array에서 중복 숫자를 제거하는 문제 제거 하는 문제는 일반적으로 뒤에서부터 루프를 돌아야 index 관리가 편하다. class Solution: def remo.. 더보기
[LeetCode] 21. Merge Two Sorted Lists 기록 https://leetcode.com/problems/merge-two-sorted-lists/description/ Merge Two Sorted Lists - 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 두개의 linked list를 sorting하면서 합치는 문제 일단 적나라한 실력 테스트를 위해 그냥 풀었다. # Definition for singly-linked list. class ListNode: def __init__(self, val=0, ne.. 더보기