Loading...

[Python] BOJ 6603 - 로또(Lotto)

https://www.acmicpc.net/problem/6603 6603번: 로또 입력은 여러 개의 테스트 케이스로 이루어져 있다. 각 테스트 케이스는 한 줄로 이루어져 있다. 첫 번째 수는 k (6 < k < 13)이고, 다음 k개 수는 집합 S에 포함되는 수이다. S의 원소는 오름차순으로 www.acmicpc.net # 백트래킹 문제이다. # k와 숫자들 num을 입력받은 뒤, BT함수로 백트래킹을 실행한다. # BT함수에서 len이 6이면, 숫자6개를 모두 뽑았으므로 answer에 nums.copy()를 append해주고 함수를 종료한다. # 이미 뽑은 숫자를 또 뽑을 수 없으므로, prev변수를 통해 현재 뽑은 숫자의 다음 인덱스부터 nums에 append되도록 했다. import sys inp..

[Python] Leetcode - Combination Sum

https://leetcode.com/problems/combination-sum/ Combination Sum - 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 # 요즘 연습하고 있는 백트래킹 문제이다. candidates의 수들 중 합이 target인 배열을 return하는 문제이다. # 6번째 줄에서 comb를 바로 append하면 안되고, comb.copy()를 append해줘야 answer에 값이 제대로 들어간다. class Solution: def c..

[Python] LeetCode - Letter Combinations of a Phone Number

https://leetcode.com/problems/letter-combinations-of-a-phone-number/ Letter Combinations of a Phone Number - 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 # 외국 문제풀이 사이트인 LeetCode문제이다. 영어문제를 해석하면서 풀어야해서 영어실력 증진에도 도움이 되는 것 같다. # '백트래킹' 기초를 연습하기 위해 푼 문제이다. # class와 letterCombination..