분류 전체보기

개요 문자열(String)은 하나 또는 여러 개의 문자(글자, 숫자, 기호)가 일렬로 나열된 것입니다. 텍스트는 일상 생활에서 사용하는 일반적인 데이터 형식으로 이를 표현하는 문자열 자료형은 파이썬(Python)을 포함한 여러 프로그래밍 언어에서 매우 중요한 구성요소입니다. 이번 글에서는 파이썬에서 문자열을 생성하고 출력하는 방법, 문자열을 병합(연결)하고 복제하는 방법, 변수에 문자열을 저장하는 방법을 설명합니다. 문자열 생성 및 출력 파이썬에서 문자열은 문자(글자, 숫자, 기호)를 나열한 후, 작은따옴표 '또는 큰 따옴표 "로 묶어서 만듭니다. 'This is a string in single quotes.' "This is a string in double quotes." 작은 따옴표 또는 큰 따옴..
문제 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..
쓴웃음
'분류 전체보기' 카테고리의 글 목록 (16 Page)