문제 문자가 주어지면 그 중에서 반복하지 않는 첫번째 문자열 찾는 문제 풀이 1 s = 'aaabcccdeef' from collections import defaultdict # 빈도수 구하기 z = defauldict() for i in s: if z[i]: z[i] +=1 else: z[i] = 1 # Loop defaultdict to find the first for k, v in z.items(): if v ==1: return k 풀이 2 x = 'aaaabbbcddeef' for i in x: if x.find(i) == x.rfind(i): return i str.find() : 가장 작은 인덱스 반환 str.rfind() : 가장 큰 인덱스 반환 built-in function 을 사용..
List only def is_palindrom(s: str) -> bool: strs = [] # Using deque for char in s: if char.isalnum(): strs.append(char.lower()) while len(strs) > 1: if strs.pop(0) != strs.pop(): return False return True Using deque from collections import deque def is_palindrom(s: str) -> bool: strs = deque([]) for char in s: if char.isalnum(): strs.append(char.lower()) while len(strs) > 1: if strs.popleft() !=..
Question Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix. Note that it is the kth smallest element in the sorted order, not the kth distinct element. Example matrix = [ [ 1, 5, 9], [10, 11, 13], [12, 13, 15] ], k = 8, return 13. 처음 생각한 간단한 방식은 matrix를 flatten 한 뒤 그 리스트의 k-1번째 인덱스를 리턴하면 될 듯하여 만든 코드입니다. class Soluti..
Reverse Linked list # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def reverseList(self, head: ListNode) -> ListNode: prev = None curr = head while curr: nex = curr.next curr.next = prev prev = curr curr = nex return prev Linked List Palindrome # Definition for singly-linked list. # class ListNode..
Question Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. Solution class Solution: def searchInsert(self, nums: List[int], target: int) -> int: return 1일1깡 방법 if target in nums: return nums.index(target) else: nums.append(target) nums.sort() return nums.index(target) Binary Search low = 0 hi..
Description Given two binary strings, return their sum (also a binary string). The input strings are both non-empty and contains only characters 1 or 0. Answer class Solution: def addBinary(self, a: str, b: str) -> str: i = int(a,2) j = int(b,2) # ans = i+j # return bin(ans)[2:] return format(i+j,'b') 진수 변환 >> bin(30) '0b1110' >> oct(30) '0o36' >> hex(30) '0x1e' Format 함수 # 접두어 제외하기 >> format(0b..
Problem no.93 Restore IP Address Question: Given a string containing only digits, restore it by returning all possible valid IP address combinations. A valid IP address consists of exactly four integers (each integer is between 0 and 255) separated by single points. Solution: class Solution: def restoreIpAddresses(self, s: str) -> List[str]: l = len(s) if l 4*3: return [] ans = set() ..
- Total
- Today
- Yesterday
- kubernetes context
- palindrome
- Fine-Tuning
- collator
- leetcode
- lllm
- K8S
- docker
- Container
- csv
- 파이썬
- 나는리뷰어다
- Shell
- LLM
- 한빛미디어
- 책리뷰
- feed-forward
- Python
- AWS
- 키보드
- Algorithm
- Gemma
- go
- error
- Git
- book
- Kubernetes
- Binary
- BASIC
- kubens
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |