| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
- Count Monobit Integers
- 3D PRINTING
- GitLab
- ProblemSolving
- leetcode
- 파이썬
- hackerrank
- 문제해결
- 2022
- Kubernetes
- 리트코드
- Qualification Round
- Code Jam 2022
- 코딩테스트
- swift
- 해커랭크
- 알고리즘
- Code Jam
- First Unique Character in a String
- K8S
- C++
- LEVEL 2
- MySQL
- Python
- Certbot/dns-route53
- 프로그래머스
- 하늘과 바람과 별과 시
- 하늘과 바람과 별과 詩
- Algorithm
- Today
- Total
목록전체 글 (89)
공대생의 비망록
주어진 문자열 s에서 첫 번째의 고유 문자 위치를 찾아 반환하는 문제.문자열을 1회차로 순회하며 dictionary 자료구조에 모든 문자의 빈도를 저장하도록 하고, 2회차로 순회할 때 dictionary에 빈도가 1이라면 그 위치를 반환하도록 하여 문제를 해결하였다. 문제 풀이 (시간복잡도는 O(n)이다.):class Solution: def firstUniqChar(self, s: str) -> int: seen = {} for i in range(len(s)): if s[i] not in seen: seen[s[i]] = 1 else: seen[s[i]] += 1 f..
주어진 두 문자열 s, t가 애너그램 (Anagram)인 지 판단하는 문제. 문제에서는 문자열 안에는 소문자만 포함된다고 하였으나 확장성을 고려하여 딕셔너리 (dictionary) 자료구조를 활용하여 푼 버전과 소문자 26개 (혹은 존재하는 소문자 수)만큼의 길이를 가지는 배열 (list)을 활용하여 푼 버전을 각각 구현해보았다: 딕셔너리 활용 버전:class Solution: def isAnagram(self, s: str, t: str) -> bool: if len(s) != len(t): return False dicts = {}; dictt = {} for ch in s: if ch not in dicts: ..
주어진 n에 대하여 0부터 n까지 "0" 혹은 "1"으로만 비트가 구성되어 있는 정수 (Monobit Integer)를 구하는 문제. 처음에는 모든 비트가 같아야 한다는 점에 착안, 0부터 n까지 모든 수를 비트 문자열로 만들어 XOR 비트 연산을 수행하여 문제를 해결하도록 구현하였으나 매우 비효율적이었고, 그 후로 초기 방법 (모든 수를 비트 문자열로 생성하여 XOR 연산):class Solution: def countMonobit(self, n: int) -> int: if n == 0: return 1 bitified = ["0"] for i in range(1, n + 1): m = i bit ..
set으로 만들어서 고유한 숫자만 남겨 sum을 2배로 하여 nums의 sum 값과 차감하여 숫자를 찾아내는 풀이:class Solution: def singleNumber(self, nums: List[int]) -> int: mySum = sum(set(nums)) * 2 diff = mySum - sum(nums) return diff XOR 비트 연산으로 배열을 순회하여 숫자를 찾아내는 풀이: (연달아 XOR 비트 연산으로 풀 수 있는 문제를 만나 습득하게 되었습니다.)class Solution: def singleNumber(self, nums: List[int]) -> int: res = 0 for num in nums:..
이 문제는 보자마자 Python에 익숙한 사람이라면 누구나 쉽게 풀 수 있는 문제라는 생각이 들었다. for-loop을 통해 0부터 n까지 하나씩 확인하는 방법: (시간복잡도 O(n)이나 비효율적인 편)class Solution: def missingNumber(self, nums: List[int]) -> int: for i in range(len(nums) + 1): if i not in nums: return i set을 사용하며 쉽고 빠르게 문제를 해결하는 방법:class Solution: def missingNumber(self, nums: List[int]) -> int: comp = set(range(len(n..
멍청한 풀이: 시간복잡도 O(n^2)class Solution: def moveZeroes(self, nums: List[int]) -> None: """ Do not return anything, modify nums in-place instead. """ i = len(nums) - 1; j = 0; zeros = 0; moved = 0 while i >= 0: if nums[i] != 0: zeros += 1 i -= 1 else: if zeros == 0: # if there's 0 at the end of th..
class Solution: def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None: """ Do not return anything, modify nums1 in-place instead. """ if n == 0: return if m == 0: # nums1 = nums2 # This will not meet the in-place requirement for i in range(n): # To meet the in-place requirement nums1[i] = ..
중첩 for-loop 활용 방법: class Solution: def containsDuplicate(self, nums: List[int]) -> bool: for i in range(len(nums)): for j in range(i + 1, len(nums)): if nums[i] == nums[j]: return True return False 집합 (Set) 자료구조 활용 방법: class Solution: def containsDuplicate(self, nums: List[int]) -> bool: exists = set() for num in nums..
