문제풀이 (8) 썸네일형 리스트형 문제 11723 - 집합 - 파이썬 개선해나갔던 사항을 아래와 같다. # list, set 사용 구분 # 저장시 str, int 사용 구분 # input 대신 readline 사용 # pypy는 시간은 적지만 메모리를 많이 소모하여 python으로 변경 코드는 아래와 같다. import sys S = set() cnt = int(sys.stdin.readline().strip()) for _ in range(cnt): given = sys.stdin.readline().strip().split() if given[0] == 'all': S = set([i for i in range(1, 21)]) continue elif given[0] == 'empty': S = set() continue else: cmd, x = given[0], i.. 리트 코드 - 2D 행렬 검색 II 240번 https://leetcode.com/problems/search-a-2d-matrix-ii/ Search a 2D Matrix II - 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 ** 내 풀이 import bisect from typing import List class Solution: #1 180ms, 20.5MB def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: for i in.. 리트코드 - Two Sum II - Input aarray is sorted 167번 https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/ Two Sum II - Input Array Is Sorted - 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 ** 내 풀이 import bisect from typing import List class Solution: # 1 225ms, 15MB def twoSum(self, numbers: List[int], target: int) -> Li.. 리트코드 - Intersection of Two Arrays 349번 https://leetcode.com/problems/intersection-of-two-arrays/ Intersection of Two Arrays - 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 ** 각기 다른 풀이 import bisect from typing import List class Solution: # 1 80ms, 14MB # def intersection(self, nums1: List[int], nums2: List[int]) -> Li.. 리트 코드 - Search In Rotated Sorted Array 33번 https://leetcode.com/problems/search-in-rotated-sorted-array/ Search 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 ** 각기 다른 풀이 import heapq from typing import List class Solution: # 1 74ms, 14.2MB # def search(self, nums: List[int], target: int) -> int: .. 리트 코드 - Binary Search 704번 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 ** 각기 다른 풀이 from bisect import bisect from typing import List import math class Solution: # 1 414ms, 15.5MB # def search(self, nums: List[int], target: int) -> int: # if tar.. 백준 - 단어 정렬 1181번 https://www.acmicpc.net/problem/1181 1181번: 단어 정렬 첫째 줄에 단어의 개수 N이 주어진다. (1 ≤ N ≤ 20,000) 둘째 줄부터 N개의 줄에 걸쳐 알파벳 소문자로 이루어진 단어가 한 줄에 하나씩 주어진다. 주어지는 문자열의 길이는 50을 넘지 않는다. www.acmicpc.net ** 내 풀이 from sys import stdin cnt = int(stdin.readline()) hh = [] for _ in range(cnt): oneword = stdin.readline().rstrip() if oneword not in hh: hh.append(oneword) hh.sort(key=lambda x:(len(x), x)) for i in hh: print(.. 5022번 - 전화번호 목록 **문제 https://www.acmicpc.net/problem/5052 5052번: 전화번호 목록 첫째 줄에 테스트 케이스의 개수 t가 주어진다. (1 ≤ t ≤ 50) 각 테스트 케이스의 첫째 줄에는 전화번호의 수 n이 주어진다. (1 ≤ n ≤ 10000) 다음 n개의 줄에는 목록에 포함되어 있는 전화번호가 www.acmicpc.net **오류 코드 (Time Limit) from sys import stdin numTestCase = int(stdin.readline().strip()) tot = [] for _ in range(numTestCase): cntPhone = int(stdin.readline().strip()) phoneNum = [] for _ in range(cntPhone):.. 이전 1 다음