본문 바로가기

python20

[Python-Leetcode] 9. Palindrome Number (difficulty : Easy - ☆) 문제 설명 Given an integer x, return true if x is palindrome integer. An integer is a palindrome when it reads the same backward as forward. For example, 121 is a palindrome while 123 is not. Example 1: Input: x = 121 Output: true Explanation: 121 reads as 121 from left to right and from right to left. Example 2: Input: x = -121 Output: false Explanation: From left to right, it reads -121. From righ.. 2022. 4. 27.
[Python-Leetcode] 4. Median of Two Sorted Arrays (difficulty : Hard - ☆☆☆) 문제 설명 Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Example 1: Input: nums1 = [1,3], nums2 = [2] Output: 2.00000 Explanation: merged array = [1,2,3] and median is 2. Example 2: Input: nums1 = [1,2], nums2 = [3,4] Output: 2.50000 Explanation: merged array = [1,2,3,4] and med.. 2022. 4. 27.
[Python-Leetcode] 739. dailyTemperatures (difficulty : Medium - ☆☆) 문제 설명 Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature. If there is no future day for which this is possible, keep answer[i] == 0 instead. Example 1: Input: temperatures = [73,74,75,71,69,72,76,73] Output: [1,1,4,2,1,1,0,0] Example 2: Input: te.. 2021. 8. 11.
Python - Sorted (정렬, key 2개) 오름차순 / 내림차순 파이썬, Sorted 정렬 (Key 2개) dic1 = {'A':[(0, 1), (5, 1), (5, 3), (9, 2), (6, 2), (6, 1)]} dic1 {'A': [(0, 1), (5, 1), (5, 3), (9, 2), (6, 2), (6, 1)]} dic1['A']를 sorting할 때, 앞의 숫자는 증가하는 방향(오름차순) / 뒤의 숫자는 내림차순하도록 하려면 sorted(dic1['A'], key=lambda x:(x[0], -x[1])) [(0, 1), (5, 3), (5, 1), (6, 2), (6, 1), (9, 2)] sorted에서, key는 어떤 것을 기준으로 sort를 할 것인지를 정하는 것입니다. x[0]은 앞의 숫자를 기준으로 오름차순이며, -x[1]은 뒤의 숫자를 기준.. 2021. 8. 9.
[Programmers] 해시 - 위장 ❓ 위장 https://programmers.co.kr/learn/courses/30/lessons/42578 코딩테스트 연습 - 위장 programmers.co.kr 🅿 문제 설명 스파이들은 매일 다른 옷을 조합하여 입어 자신을 위장합니다. 예를 들어 스파이가 가진 옷이 아래와 같고 오늘 스파이가 동그란 안경, 긴 코트, 파란색 티셔츠를 입었다면 다음날은 청바지를 추가로 입거나 동그란 안경 대신 검정 선글라스를 착용하거나 해야 합니다. 종류이름 얼굴 동그란 안경, 검정 선글라스 상의 파란색 티셔츠 하의 청바지 겉옷 긴 코트 스파이가 가진 의상들이 담긴 2차원 배열 clothes가 주어질 때 서로 다른 옷의 조합의 수를 return 하도록 solution 함수를 작성해주세요. 제한사항 clothes의 각.. 2021. 8. 8.
[Programmers] 해시 - 전화번호 목록 ❓ 전화번호 목록 https://programmers.co.kr/learn/courses/30/lessons/42577 코딩테스트 연습 - 전화번호 목록 전화번호부에 적힌 전화번호 중, 한 번호가 다른 번호의 접두어인 경우가 있는지 확인하려 합니다. 전화번호가 다음과 같을 경우, 구조대 전화번호는 영석이의 전화번호의 접두사입니다. 구조 programmers.co.kr 🅿 문제 설명 전화번호부에 적힌 전화번호 중, 한 번호가 다른 번호의 접두어인 경우가 있는지 확인하려 합니다. 전화번호가 다음과 같을 경우, 구조대 전화번호는 영석이의 전화번호의 접두사입니다. 전화번호부에 적힌 전화번호 중, 한 번호가 다른 번호의 접두어인 경우가 있는지 확인하려 합니다. 전화번호가 다음과 같을 경우, 구조대 전화번호는 영석.. 2021. 8. 8.