Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions leetcode2/1easy/조은비/2843.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Solution:
def check_sym(self, num):
s_num = str(num)
n = len(s_num)
if n % 2 != 0:
return False

half = n // 2

if sum(map(int, s_num[:half])) == sum(map(int, s_num[half:])):
# print(num, sum(map(int, s_num[:half])))
return True

return False

def countSymmetricIntegers(self, low: int, high: int) -> int:
cnt = 0

# 앞자리 절반이랑 뒷자리 절반의 합이 같은지 체크
for num in range(low, high+1):
if self.check_sym(num):
cnt += 1

return cnt
23 changes: 23 additions & 0 deletions leetcode2/2medium/조은비/1461.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Solution:
def hasAllCodes(self, s: str, k: int) -> bool:
# sting s가 길이가 k인 모든 binary string 조합을 포함하는지?
# 아 k길이에서 생성할 수 있는 서브 스트링 수 다 나왔는지 체크??
total = 2**k

# sub string set 만들고 확인
# 1칸씩 k만큼 윈도우 잡으면서 이동
sub_str = set()
# 001101[10] - 7개 8-2+1
# 0110 - 4개
# 01[10] - 3개 4-2+1
for i in range(len(s) - k + 1):
sub_str.add(s[i:i+k])

# substring 다 있는지 확인
if len(sub_str) == total:
return True
# print(len(sub_str), total, sub_str)
# return len(sub_str) == total

return False

53 changes: 53 additions & 0 deletions leetcode2/3hard/조은비/1028.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right

class Solution:
def recoverFromPreorder(self, traversal: str) -> Optional[TreeNode]:
# 주어진대로 트리를 만들고 preoder로 순환??
i = 0
d = 0
n = len(traversal)
tree = {}

while i < n:
d = 0
while i < n and traversal[i] == '-':
d += 1
i += 1

val_s = i
while i < n and traversal[i] != '-':
i += 1
val = int(traversal[val_s:i])

print(d, ' >> ', val)
node = TreeNode(val)

# d 가 0이면 루트
if d == 0:
tree[0] = node
else:
parent = tree[d-1]
if parent.left == None:
parent.left = node
else:
parent.right = node
tree[d] = node
# print(tree)

return tree[0]



# 디 = 0에 1 - 루트
# 디 = 1에 2 - 왼
# 디 = 2에 3 - 왼
# 디 = 2에 4 - 오
# 디 = 1에 5 - 오

# 대시가 나오면 이동