문제 Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. Example: Input: 1->2->4, 1->3->4 Output: 1->1->2->3->4->4 풀이 Divide & Conquer 전략에 따라 작은 문제를 해결하고, 이를 조합하여 큰 문제를 해결한다. class Solution: def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode: if l1 is None : return l2 if l2 is None : return l1 if..
분류 전체보기
문제 Given a sorted linked list, delete all duplicates such that each element appear only once. Example 1: Input: 1->1->2 Output: 1->2Example 2: Input: 1->1->2->3->3 Output: 1->2->3풀이 정렬된 단일연결리스트를 순회하며 중복(동일값) 여부를 확인하여 제거한다. class Solution: def deleteDuplicates(self, head: ListNode) -> ListNode: cur = head while cur : if cur.next and cur.val == cur.next.val : cur.next = cur.next.next else : cur = ..
문제 You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Note: Given n will be a positive integer. Example 1: Input: 2 Output: 2 Explanation: There are two ways to climb to the top. 1. 1 step + 1 step 2. 2 stepsExample 2: Input: 3 Output: 3 Explanation: There are three ways to climb to..
문제 Implement int sqrt(int x). Compute and return the square root of x, where x is guaranteed to be a non-negative integer. Since the return type is an integer, the decimal digits are truncated and only the integer part of the result is returned. Example 1: Input: 4 Output: 2Example 2: Input: 8 Output: 2 Explanation: The square root of 8 is 2.82842..., and since the decimal part is truncated, 2 i..
문제 Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word (last word means the last appearing word if we loop from left to right) in the string. If the last word does not exist, return 0. Note: A word is defined as a maximal substring consisting of non-space characters only. Example: Input: "Hello World" Output: 5풀이 class So..
문제 Given a sorted array 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 may assume no duplicates in the array. Example 1: Input: [1,3,5,6], 5 Output: 2Example 2: Input: [1,3,5,6], 2 Output: 1Example 3: Input: [1,3,5,6], 7 Output: 4Example 4: Input: [1,3,5,6], 0 Output: 0풀이 class Solution: def searchInsert(s..
일러두기 유튜브(YouTube)에서 영상을 다운로드하는 것은 유튜브의 정책을 위반하는 것입니다. 오로지 자신이 올린 데이터(영상)만 사용 중지전 사본을 백업할 목적으로 다운로드할 수 있습니다. 개요 python에서 youtube_dl 모듈을 이용해 유튜브 영상의 오디오(mp3) 추출(다운로드)하는 방법입니다. 필요한 프로그램 ※ 아래의 작업은 Ubuntu18.04(WSL)에서 수행하였습니다. python3와 package manager(pip3) $ sudo apt install python3 pip3 youtube_dl 모듈 $ pip3 install youtube_dl ffmpeg ffmpeg는 youtube_dl로 다운로드한 영상(.mp4)을 오디오(.mp3)로 변환할 수 있는 도구 입니다. $ s..
문제 Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Example 1: Input: haystack = "hello", needle = "ll" Output: 2Example 2: Input: haystack = "aaaaa", needle = "bba" Output: -1Clarification: What should we return when needle is an empty string? This is a great question to ask during an interview. For the purpose of this ..