integer로 구성된 sticks라는 input array의 모든 요소를 이어 붙이는 문제다. 이 때 더할 때 마다 발생하는 합이 최소가 되도록 하는 문제다. sorting을 통해 풀이를 해야하나 잠시 생각했지만 Min heap을 사용하면 쉽게 구현이 가능하다. class Solution: def connectSticks(self, sticks: List[int]) -> int: mh = sticks ret = 0 heapify(mh) while len(mh) > 1: m1 = heappop(mh) m2 = heappop(mh) sum_ = m1 + m2 ret += sum_ heappush(mh, sum_) return ret
createPath 함수에 주어지는 input 중 하나인 path를 '/'로 split해 parent path와 비교해가며 함수를 완성하려 했지만, Test case에 번번히 걸려 다른 방법으로 풀었다. split을 통해 '/'로 path를 자르는건 동일하지만 split 된 list에서 마지막 요소만 제외하고 하나의 String으로 다시 구성해 parent에 대한 True/False를 확인하는 방식으로 풀었다. get 함수는 Hash map을 통해 수월하게 구현했다. class FileSystem: def __init__(self): self.p = {} def createPath(self, path: str, value: int) -> bool: if path in self.p: return False..
알파벳 26개로 구성된 keyboard String이 input으로 주어지고 0부터 25까지를 개개의 index로 간주하고, Hash map의 key로 keyboard의 각 character를 value로 넣은 후, 또 다른 input인 word의 character를 앞에서 하나씩 읽어들여 각각을 Hash map의 key로서 value를 찾는다. 그리고 차이(절대값)의 누적합을 반환했다. class Solution: def calculateTime(self, keyboard: str, word: str) -> int: dic = {} p = 0 ret = 0 for i, k in enumerate(keyboard): dic[k] = i for i, w in enumerate(word): ret += ab..
class Solution: def minSwaps(self, data: List[int]) -> int: ret = ones = 0 for i, d in enumerate(data): if d == 1: ones += 1 for i in range(ones): if data[i] == 0: ret += 1 cnt = ret for i in range(ones, len(data)): if data[i-ones] == 0: cnt -= 1 if data[i] == 0: cnt += 1 ret = min(ret, cnt) return ret 0과 1로 이뤄진 'data'라는 binary array가 input으로 주어질 때 모든 1이 연속하도록 그룹을 지을 때 최소로 swap하는 수를 반환하는 문제다. Tw..
tesseract image.png output.txt Tesseract 공식 GitHub에 따르면 아래와 같다. : Tesseract는 오픈 소스 OCR 엔진으로 Apache 2.0 License 하에 이용이 가능하다. Tesseract는 command line을 통해 바로 사용이 가능하며, API를 사용해 이미지로부터 텍스트 추출도 가능하다. 광범위한 연어를 지원하고. Tesseract는 빌트인 GUI는 없지만, 여러 3rdParty에서 이용이 가능하다. Tesseract에 대한 외부 툴이나 래퍼, 트레이닝 프로젝트는 AddOns에 나열돼있다. Tesseract는 Aparche 2.0 License 하에 당신의 프로젝트에서도 사용이 가능하다. 모든 기능을 갖춘 API가 있으며, 안드로이드와 아이폰을 ..
Input으로 주어진 s가 또 다른 input인 t의 subsequence(연속이 아니더라도 포함이 돼있다면)인지 True/False를 반환하면 된다. 순서를 지켜야하기 때문에 sorting이나 hash map을 사용하는 것이 아니라 index를 이용해 비교해 나가는 방식으로 풀었다. Given two strings s and t, return true if s is a subsequence of t, or false otherwise. A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing t..
AWS에서 설명하는 OCR은 아래와 같다. : OCR은 이미지 파일의 텍스트를 기계가 읽을 수 있는 텍스트 포맷으로 변환하는 과정을 말한다. 예를 들어, 당신이 어떤 양식이나 영수증을 스캔한다면, 당신의 컴퓨터는 이를 이미지 파일로 저장할 것이다. 당신은 텍스트 에디터로 이 이미지 파일을 수정, 검색 또는 단어 개수 세기 등을 할 수 없다. 하지만 당신이 ocr을 이용해 이 이미지 파일을 텍스트 문서로 변환해 텍스트 데이터로 저장한다면 수정이나 검색 등이 가능하다. : Optical Character Recognition (OCR) is the process that converts an image of text into a machine-readable text format. For example, i..
'169. Majority Element'에서 난이도가 조금 올라간 문제지만 큰 틀에선 똑같기에 솔루션 역시 흡사하다. Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. Example 1: Input: nums = [3,2,3] Output: [3] Example 2: Input: nums = [1] Output: [1] class Solution: def majorityElement(self, nums: List[int]) -> List[int]: dic = defaultdict(int) for i, n in enumerate(nums): dic[n] += 1 ret = [] for i, k i..
1150번과 매우 유사한 문제다. 다만 다른 점은 해당 문제에선 Majority Element가 반드시 있다는 가정하에 이를 반환하는 것이고, 1150은 input으로 주어진 숫자가 Majority Element가 맞는지 틀린지를 반환하는 것이다. Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array. Example 1: Input: nums = [3,2,3] Output: 3 Example 2: In..
n이라는 input이 주어졌고 이는 계단의 높이로 계단은 한 번에 한 개 혹은 두 개를 오를 수 있고, 가장 높은 계단에 오를 수 있는 경우의 수를 구하는 것이다. 아래 제공된 솔루션은 한 개와 두 개를 오를 때 필요한 개수를 조합해 각 개수에 따른 경우의 수(number of cases)를 구해 하나씩 더해 나가는 것이다. You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?. Example 1: Input: n = 2 Output: 2 Explanation: There..
- Total
- Today
- Yesterday
- 안드로이드
- ml
- The Economist
- leetcode
- DICTIONARY
- Hash Map
- min heap
- defaultdict
- Computer Graphics
- 투 포인터
- 파이썬
- 소켓 프로그래밍
- socket programming
- 리트코드
- 딕셔너리
- 이코노미스트 에스프레소
- The Economist Espresso
- Android
- 머신 러닝
- Python
- I2C
- 티스토리챌린지
- join
- vertex shader
- tf-idf
- 이코노미스트
- 오블완
- java
- C++
- machine learning
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |