binary (6) 썸네일형 리스트형 [이분탐색] 릿코드 153 Medium 'Find Minimum in Rotated Sorted Array' (Python) https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/ Find Minimum in Rotated 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 1. 배열의 최소 요소를 반환하라고 했으므로 min 함수 사용 class Solution: def findMin(self, nums: List[int]) -> int: return min(nums) [이분탐색] 릿코드 Medium 74 'Search a 2D Matrix' (Python) https://leetcode.com/problems/search-a-2d-matrix/ Search a 2D Matrix - 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 1. 각 행에 target 값이 있으면 true class Solution: def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: for i in matrix: if target in i: return True retur.. [비트연산] 릿코드 Easy 191 'Number of 1 Bits' (Python) https://leetcode.com/problems/number-of-1-bits/ Number of 1 Bits - 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 정수로 들어온 값을 2진수로 바꿔주고 1의 개수를 센다 class Solution: def hammingWeight(self, n: int) -> int: return str(bin(n)).count('1') [이분탐색] 릿코드 Easy 704 'Binary Search' (Python) https://leetcode.com/problems/binary-search/ Binary Search - 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 이분탐색으로 리스트의 인덱스 찾기 class Solution: def search(self, nums: List[int], target: int) -> int: def binary_search(array,target,start,end): if start>end: return None mid = (start+e.. [재귀함수] 백준 10829번 '이진수 변환' (Python) https://www.acmicpc.net/problem/10829 10829번: 이진수 변환 첫째 줄에 자연수 N이 주어진다. (1 ≤ N ≤ 100,000,000,000,000) www.acmicpc.net 10진수를 2진수로 바꿔주는 bin() 메서드 사용 bin() 메서드는 앞에 0b가 붙으므로 replace() 메서드로 제거 ''' 53 ''' n = int(input()) k = bin(n) print(k.replace("0b","")) 재귀 함수로도 풀어보기 10진수에서 2진수로 바꿀 때 지수 말고 몫, 나머지 활용하기 [이분탐색] 난이도2, 이취코 201p '떡볶이 떡 만들기' (Python) 오늘 동빈이는 여행 가신 부모님을 대신해서 떡집 일을 하기로 했다. 오늘은 떡볶이 떡을 만드는 날이다. 동빈이네 떡볶이 떡은 재밌게도 떡볶이 떡의 길이가 일정하지 않다. 대신에 한 봉지 안에 들어가는 떡의 총 길이는 절단기로 잘라서 맞춰준다. 절단기의 높이(H)를 지정하면 줄지어진 떡을 한 번에 절단한다. 높이가 H보다 긴 떡은 H 위의 부분이 잘릴 것이고, 낮은 떡은 잘리지 않는다. 예를 들어 높이가 19, 14, 10, 17cm인 떡이 나란히 있고 절단기 높이를 15cm로 지정하면 자른 뒤 떡의 높이는 15, 14, 10, 15cm가 될 것이다. 잘린 떡의 길이는 차례대로 4, 0, 0, 2cm이다. 손님은 6cm만큼의 길이를 가져간다. 손님이 왔을 때 요청한 총 길이가 M일 때 적어도 M만큼의 떡을.. 이전 1 다음