본문 바로가기

leetcode

[알고리즘] 그리디 - 배낭 문제 (Python) 문제 설명 배낭에 담을 수 있는 무게의 최댓값이 정해져있고, 각각의 짐의 가치($ 단위)와 무게(kg 단위)가 있는 짐들을 배낭에 넣을 때 가치의 합이 최대가 되도록, 즉 $(달러)의 가치가 최대가 되도록 짐을 고르는 방법을 찾기 입출력 예 Input: cargo = [ (4, 12), (2, 1), (10, 4), (1, 1), (2, 2), ] Output: 17.333333333333332 Code def fractional_knapsack(cargo): capacity = 15 pack = [] # 단가 계산 역순 정렬 for c in cargo: pack.append((c[0] / c[1], c[0], c[1])) pack.sort(reverse = True) # 단가 순 그리디 계산 total.. 더보기
[알고리즘] Leetcode #424 가장 긴 반복 문자 대체 (Python) ↓↓↓ 아래는 내 리트코드 계정 ↓↓↓ leetcode.com/Jiwon_Lee/ Jiwon Lee - LeetCode Profile 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 문제 설명 You are given a string s and an integer k. You can choose any character of the string and change it to any other uppercase English character. You can perform this.. 더보기
[알고리즘] Leetcode #76 부분 문자열이 포함된 최소 윈도우 (Python) ↓↓↓ 아래는 내 리트코드 계정 ↓↓↓ leetcode.com/Jiwon_Lee/ Jiwon Lee - LeetCode Profile 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 문제 설명 Given two strings s and t of lengths m and n respectively, return the minimum window in s which will contain all the characters in t. If there is no such window i.. 더보기
[알고리즘] Leetcode #239 최대 슬라이딩 윈도우 (Python) ↓↓↓ 아래는 내 리트코드 계정 ↓↓↓ leetcode.com/Jiwon_Lee/ Jiwon Lee - LeetCode Profile 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 문제 설명 You are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see t.. 더보기
[알고리즘] Leetcode #543 이진 트리의 직경 (Python) ↓↓↓ 아래는 내 리트코드 계정 ↓↓↓ leetcode.com/Jiwon_Lee/ Jiwon Lee - LeetCode Profile 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 문제 설명 Given the root of a binary tree, return its maximum depth. A binary tree's maximum depth is thGiven the root of a binary tree, return the length of the diameter o.. 더보기
[알고리즘] Leetcode #49 그룹 애너그램 (Python) ↓↓↓ 아래는 내 리트코드 계정 ↓↓↓ leetcode.com/Jiwon_Lee/ Jiwon Lee - LeetCode Profile 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 문제 설명 Given an array of strings strs, group the anagrams together. You can return the answer in any order. An Anagram is a word or phrase formed by rearranging the lett.. 더보기
[알고리즘] Leetcode #125 유효한 팰린드롬 (Python) ↓↓↓ 아래는 내 리트코드 계정 ↓↓↓ leetcode.com/Jiwon_Lee/ Jiwon Lee - LeetCode Profile 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 문제 설명 Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. Note: For the purpose of this problem, we define emp.. 더보기