Compare commits
10 Commits
a37e8ccf01
...
b81a37a484
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b81a37a484 | ||
|
|
dac4da1dd6 | ||
|
|
dede0dca01 | ||
|
|
e3c6c8b32a | ||
|
|
a493536ad8 | ||
|
|
8533316c30 | ||
|
|
61ff1028f6 | ||
|
|
335508c78d | ||
|
|
50aee26efd | ||
|
|
f3aed8d1f6 |
11
boj/10781.py
Normal file
11
boj/10781.py
Normal file
@@ -0,0 +1,11 @@
|
||||
n,x=map(int,input().split())
|
||||
a=list(map(int,input().split()))
|
||||
r=[]
|
||||
|
||||
for i in a:
|
||||
if i<x:
|
||||
r.append(i)
|
||||
|
||||
for i in r:
|
||||
print(i,end=" ")
|
||||
|
||||
8
leetcode/1.py
Normal file
8
leetcode/1.py
Normal file
@@ -0,0 +1,8 @@
|
||||
class Solution:
|
||||
def twoSum(self, nums: List[int], target: int) -> List[int]:
|
||||
answer=()
|
||||
for i in range(len(nums)):
|
||||
for j in range(i+1,len(nums)):
|
||||
if nums[i]+nums[j]==target:
|
||||
answer=(i,j)
|
||||
return list(answer)
|
||||
38
leetcode/101.py
Normal file
38
leetcode/101.py
Normal file
@@ -0,0 +1,38 @@
|
||||
# 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 leftSearch(self,stack:List[TreeNode],now:Optional[TreeNode]):
|
||||
if now==None:
|
||||
stack.append(None)
|
||||
else:
|
||||
stack.append(now.val)
|
||||
self.leftSearch(stack,now.left)
|
||||
self.leftSearch(stack,now.right)
|
||||
def rightSearch(self,stack:List[TreeNode],now:Optional[TreeNode]) -> bool:
|
||||
if len(stack)<1:
|
||||
return False
|
||||
if now==None:
|
||||
if not(stack.pop()==now):
|
||||
return False
|
||||
return True
|
||||
elif not self.rightSearch(stack,now.left):
|
||||
return False
|
||||
elif not self.rightSearch(stack,now.right):
|
||||
return False
|
||||
elif not stack.pop()==now.val:
|
||||
return False
|
||||
return True
|
||||
|
||||
def isSymmetric(self, root: Optional[TreeNode]) -> bool:
|
||||
stack=[]
|
||||
self.leftSearch(stack,root.left)
|
||||
isSym=self.rightSearch(stack,root.right)
|
||||
|
||||
if isSym and len(stack)==0:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
13
leetcode/104.py
Normal file
13
leetcode/104.py
Normal file
@@ -0,0 +1,13 @@
|
||||
# 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 depth(self,now:Optional[TreeNode],depth:int):
|
||||
if now==None:
|
||||
return depth-1
|
||||
return max(self.depth(now.left,depth+1),self.depth(now.right,depth+1),depth)
|
||||
def maxDepth(self, root: Optional[TreeNode]) -> int:
|
||||
return self.depth(root,1)
|
||||
11
leetcode/118.py
Normal file
11
leetcode/118.py
Normal file
@@ -0,0 +1,11 @@
|
||||
class Solution:
|
||||
def generate(self, numRows: int) -> List[List[int]]:
|
||||
arr=[[1]]
|
||||
|
||||
for r in range(2,numRows+1):
|
||||
nr=[1]
|
||||
for i in range(1,r-1):
|
||||
nr.append(arr[r-2][i-1]+arr[r-2][i])
|
||||
nr.append(1)
|
||||
arr.append(nr)
|
||||
return arr
|
||||
9
leetcode/121.py
Normal file
9
leetcode/121.py
Normal file
@@ -0,0 +1,9 @@
|
||||
class Solution:
|
||||
def maxProfit(self, prices: List[int]) -> int:
|
||||
result=0
|
||||
mi=prices[0]
|
||||
|
||||
for i in range(1,len(prices)):
|
||||
mi=min(prices[i],mi)
|
||||
result=max(prices[i]-mi,result)
|
||||
return result
|
||||
11
leetcode/125.py
Normal file
11
leetcode/125.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import re
|
||||
class Solution:
|
||||
def isPalindrome(self, s: str) -> bool:
|
||||
ns=re.sub(r"[^A-Za-z0-9]","",s).lower()
|
||||
|
||||
isPal=True
|
||||
for i in range(len(ns)//2):
|
||||
if not ns[i]==ns[-i-1]:
|
||||
isPal=False
|
||||
break
|
||||
return isPal
|
||||
16
leetcode/13.py
Normal file
16
leetcode/13.py
Normal file
@@ -0,0 +1,16 @@
|
||||
class Solution:
|
||||
def romanToInt(self, s: str) -> int:
|
||||
sv={'M':1000,'D':500,'C':100,'L':50,'X':10,'V':5,'I':1}
|
||||
msv={'C':set(['D','M']),'X':set(['L','C']),'I':set(['V','X'])}
|
||||
r=0
|
||||
mc=''
|
||||
|
||||
for c in s:
|
||||
r+=sv[c]
|
||||
if mc in msv and c in msv[mc]:
|
||||
r-=(sv[mc]*2)
|
||||
if c in msv:
|
||||
mc=c
|
||||
else:
|
||||
mc=''
|
||||
return r
|
||||
15
leetcode/136.py
Normal file
15
leetcode/136.py
Normal file
@@ -0,0 +1,15 @@
|
||||
class Solution:
|
||||
def singleNumber(self, nums: List[int]) -> int:
|
||||
nums.sort()
|
||||
last=nums[0]
|
||||
count=1
|
||||
|
||||
for i in range(1,len(nums)):
|
||||
if not last==nums[i]:
|
||||
if count==1:
|
||||
break
|
||||
last=nums[i]
|
||||
count=1
|
||||
else:
|
||||
count+=1
|
||||
return last
|
||||
14
leetcode/14.py
Normal file
14
leetcode/14.py
Normal file
@@ -0,0 +1,14 @@
|
||||
class Solution:
|
||||
def longestCommonPrefix(self, strs: List[str]) -> str:
|
||||
last=strs[0]
|
||||
for i in range(1,len(strs)):
|
||||
if len(last)<1:
|
||||
break
|
||||
|
||||
for j in range(min(len(last),len(strs[i]))):
|
||||
if not last[j]==strs[i][j]:
|
||||
last=last[0:j]
|
||||
break
|
||||
if len(last)>len(strs[i]):
|
||||
last=last[0:len(strs[i])]
|
||||
return last
|
||||
15
leetcode/141.py
Normal file
15
leetcode/141.py
Normal file
@@ -0,0 +1,15 @@
|
||||
# Definition for singly-linked list.
|
||||
# class ListNode:
|
||||
# def __init__(self, x):
|
||||
# self.val = x
|
||||
# self.next = None
|
||||
|
||||
class Solution:
|
||||
def hasCycle(self, head: Optional[ListNode]) -> bool:
|
||||
h2=head
|
||||
while h2 and h2.next:
|
||||
head=head.next
|
||||
h2=h2.next.next
|
||||
if head==h2:
|
||||
return True
|
||||
return False
|
||||
23
leetcode/160.py
Normal file
23
leetcode/160.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# Definition for singly-linked list.
|
||||
# class ListNode:
|
||||
# def __init__(self, x):
|
||||
# self.val = x
|
||||
# self.next = None
|
||||
|
||||
class Solution:
|
||||
def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> Optional[ListNode]:
|
||||
al=set()
|
||||
|
||||
r=None
|
||||
a=headA
|
||||
b=headB
|
||||
while a:
|
||||
al.add(a)
|
||||
a=a.next
|
||||
while b:
|
||||
if b in al:
|
||||
r=b
|
||||
break
|
||||
b=b.next
|
||||
|
||||
return r
|
||||
16
leetcode/169.py
Normal file
16
leetcode/169.py
Normal file
@@ -0,0 +1,16 @@
|
||||
class Solution:
|
||||
def majorityElement(self, nums: List[int]) -> int:
|
||||
nums.sort()
|
||||
print(nums)
|
||||
last=(nums[0],1)
|
||||
mx=last
|
||||
|
||||
for i in range(1,len(nums)):
|
||||
if nums[i]==last[0]:
|
||||
last=(last[0],last[1]+1)
|
||||
else:
|
||||
last=(nums[i],1)
|
||||
|
||||
if mx[1]<last[1]:
|
||||
mx=last
|
||||
return mx[0]
|
||||
11
leetcode/171.py
Normal file
11
leetcode/171.py
Normal file
@@ -0,0 +1,11 @@
|
||||
class Solution:
|
||||
def titleToNumber(self, columnTitle: str) -> int:
|
||||
dnum={}
|
||||
for i in range(26):
|
||||
dnum[chr(ord('A')+i)]=i+1
|
||||
|
||||
result=0
|
||||
for i in range(1,len(columnTitle)+1):
|
||||
c=columnTitle[-i]
|
||||
result+=dnum[c]*(26**(i-1))
|
||||
return result
|
||||
11
leetcode/190.py
Normal file
11
leetcode/190.py
Normal file
@@ -0,0 +1,11 @@
|
||||
class Solution:
|
||||
def reverseBits(self, n: int) -> int:
|
||||
r=""
|
||||
b=bin(n)
|
||||
|
||||
for i in range(1,32+1):
|
||||
if i>len(b)-2:
|
||||
r+="0"
|
||||
else:
|
||||
r+=b[-i]
|
||||
return int(r,2)
|
||||
9
leetcode/191.py
Normal file
9
leetcode/191.py
Normal file
@@ -0,0 +1,9 @@
|
||||
class Solution:
|
||||
def hammingWeight(self, n: int) -> int:
|
||||
count=0
|
||||
b=bin(n)
|
||||
|
||||
for i in range(2,len(b)):
|
||||
if b[i]=="1":
|
||||
count+=1
|
||||
return count
|
||||
26
leetcode/2.py
Normal file
26
leetcode/2.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# Definition for singly-linked list.
|
||||
# class ListNode:
|
||||
# def __init__(self, val=0, next=None):
|
||||
# self.val = val
|
||||
# self.next = next
|
||||
class Solution:
|
||||
def addTwoNumbers(self, l1: Optional[ListNode], l2: Optional[ListNode]) -> Optional[ListNode]:
|
||||
v1=""
|
||||
v2=""
|
||||
|
||||
while not l1==None:
|
||||
v1=str(l1.val)+v1
|
||||
l1=l1.next
|
||||
while not l2==None:
|
||||
v2=str(l2.val)+v2
|
||||
l2=l2.next
|
||||
|
||||
vr=str(int(v1)+int(v2))
|
||||
r=ListNode()
|
||||
now=r
|
||||
for i in range(1,len(vr)+1):
|
||||
now.val=vr[-i]
|
||||
if i<len(vr):
|
||||
now.next=ListNode()
|
||||
now=now.next
|
||||
return r
|
||||
21
leetcode/20.py
Normal file
21
leetcode/20.py
Normal file
@@ -0,0 +1,21 @@
|
||||
class Solution:
|
||||
def isValid(self, s: str) -> bool:
|
||||
arr=[]
|
||||
|
||||
for c in s:
|
||||
if c in ['(','{','[']:
|
||||
arr.append(c)
|
||||
continue
|
||||
|
||||
if c in [')','}',']']:
|
||||
if len(arr)<0+1:
|
||||
return False
|
||||
p=arr.pop()
|
||||
|
||||
if not((c==')' and p=='(') or (c=='}' and p=='{') or (c==']' and p=='[')):
|
||||
return False
|
||||
|
||||
if len(arr)>0:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
13
leetcode/202.py
Normal file
13
leetcode/202.py
Normal file
@@ -0,0 +1,13 @@
|
||||
class Solution:
|
||||
def isHappy(self, n: int) -> bool:
|
||||
s=str(n)
|
||||
while not len(s)==1:
|
||||
r=0
|
||||
for i in range(len(s)):
|
||||
r+=int(s[i])**2
|
||||
s=str(r)
|
||||
|
||||
if s=="1" or s=="7":
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
19
leetcode/206.py
Normal file
19
leetcode/206.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# 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: Optional[ListNode]) -> Optional[ListNode]:
|
||||
l=[]
|
||||
while not head==None:
|
||||
n=ListNode(head.val)
|
||||
l.append(n)
|
||||
head=head.next
|
||||
|
||||
r=ListNode()
|
||||
rt=r
|
||||
while len(l)>0:
|
||||
rt.next=l.pop()
|
||||
rt=rt.next
|
||||
return r.next
|
||||
37
leetcode/21.py
Normal file
37
leetcode/21.py
Normal file
@@ -0,0 +1,37 @@
|
||||
# Definition for singly-linked list.
|
||||
# class ListNode:
|
||||
# def __init__(self, val=0, next=None):
|
||||
# self.val = val
|
||||
# self.next = next
|
||||
class Solution:
|
||||
def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]:
|
||||
result=ListNode()
|
||||
re=result
|
||||
li1=list1
|
||||
li2=list2
|
||||
|
||||
while not li1==None and not li2==None:
|
||||
n=ListNode()
|
||||
if li1.val<li2.val:
|
||||
n.val=li1.val
|
||||
li1=li1.next
|
||||
else:
|
||||
n.val=li2.val
|
||||
li2=li2.next
|
||||
re.next=n
|
||||
re=re.next
|
||||
|
||||
while not li1==None:
|
||||
n=ListNode()
|
||||
n.val=li1.val
|
||||
re.next=n
|
||||
re=re.next
|
||||
li1=li1.next
|
||||
while not li2==None:
|
||||
n=ListNode()
|
||||
n.val=li2.val
|
||||
re.next=n
|
||||
re=re.next
|
||||
li2=li2.next
|
||||
|
||||
return result.next
|
||||
11
leetcode/217.py
Normal file
11
leetcode/217.py
Normal file
@@ -0,0 +1,11 @@
|
||||
class Solution:
|
||||
def containsDuplicate(self, nums: List[int]) -> bool:
|
||||
l=set()
|
||||
isDu=False
|
||||
for i in nums:
|
||||
if i in l:
|
||||
isDu=True
|
||||
break
|
||||
else:
|
||||
l.add(i)
|
||||
return isDu
|
||||
16
leetcode/234.py
Normal file
16
leetcode/234.py
Normal file
@@ -0,0 +1,16 @@
|
||||
# Definition for singly-linked list.
|
||||
# class ListNode:
|
||||
# def __init__(self, val=0, next=None):
|
||||
# self.val = val
|
||||
# self.next = next
|
||||
class Solution:
|
||||
def isPalindrome(self, head: Optional[ListNode]) -> bool:
|
||||
l=[]
|
||||
while not head==None:
|
||||
l.append(head.val)
|
||||
head=head.next
|
||||
|
||||
for i in range(len(l)//2):
|
||||
if not l[i]==l[-i-1]:
|
||||
return False
|
||||
return True
|
||||
14
leetcode/237.py
Normal file
14
leetcode/237.py
Normal file
@@ -0,0 +1,14 @@
|
||||
# Definition for singly-linked list.
|
||||
# class ListNode(object):
|
||||
# def __init__(self, x):
|
||||
# self.val = x
|
||||
# self.next = None
|
||||
|
||||
class Solution(object):
|
||||
def deleteNode(self, node):
|
||||
"""
|
||||
:type node: ListNode
|
||||
:rtype: void Do not return anything, modify node in-place instead.
|
||||
"""
|
||||
node.val=node.next.val
|
||||
node.next=node.next.next
|
||||
21
leetcode/242.py
Normal file
21
leetcode/242.py
Normal file
@@ -0,0 +1,21 @@
|
||||
class Solution:
|
||||
def isAnagram(self, s: str, t: str) -> bool:
|
||||
d={}
|
||||
|
||||
if not len(s)==len(t):
|
||||
return False
|
||||
for i in s:
|
||||
if i in d:
|
||||
d[i]+=1
|
||||
else:
|
||||
d[i]=1
|
||||
for i in t:
|
||||
if i in d:
|
||||
d[i]-=1
|
||||
else:
|
||||
return False
|
||||
|
||||
for i in d.keys():
|
||||
if not d[i]==0:
|
||||
return False
|
||||
return True
|
||||
8
leetcode/26.py
Normal file
8
leetcode/26.py
Normal file
@@ -0,0 +1,8 @@
|
||||
class Solution:
|
||||
def removeDuplicates(self, nums: List[int]) -> int:
|
||||
arr=sorted(list(set(nums)))
|
||||
count=len(arr)
|
||||
|
||||
for i in range(count):
|
||||
nums[i]=arr[i]
|
||||
return count
|
||||
11
leetcode/268.py
Normal file
11
leetcode/268.py
Normal file
@@ -0,0 +1,11 @@
|
||||
class Solution:
|
||||
def missingNumber(self, nums: List[int]) -> int:
|
||||
last=-1
|
||||
nums.sort()
|
||||
for i in range(len(nums)):
|
||||
if not last+1==nums[i]:
|
||||
break
|
||||
else:
|
||||
last+=1
|
||||
|
||||
return last+1
|
||||
3
leetcode/28.py
Normal file
3
leetcode/28.py
Normal file
@@ -0,0 +1,3 @@
|
||||
class Solution:
|
||||
def strStr(self, haystack: str, needle: str) -> int:
|
||||
return haystack.find(needle)
|
||||
17
leetcode/283.py
Normal file
17
leetcode/283.py
Normal file
@@ -0,0 +1,17 @@
|
||||
class Solution:
|
||||
def moveZeroes(self, nums: List[int]) -> None:
|
||||
"""
|
||||
Do not return anything, modify nums in-place instead.
|
||||
"""
|
||||
s=0
|
||||
z=0
|
||||
for i in range(len(nums)):
|
||||
v=nums[i]
|
||||
|
||||
if v==0:
|
||||
z+=1
|
||||
else:
|
||||
nums[s]=v
|
||||
s+=1
|
||||
for i in range(1,z+1):
|
||||
nums[-i]=0
|
||||
9
leetcode/326.py
Normal file
9
leetcode/326.py
Normal file
@@ -0,0 +1,9 @@
|
||||
class Solution:
|
||||
def isPowerOfThree(self, n: int) -> bool:
|
||||
last=1
|
||||
while last<n:
|
||||
last*=3
|
||||
if last==n:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
7
leetcode/344.py
Normal file
7
leetcode/344.py
Normal file
@@ -0,0 +1,7 @@
|
||||
class Solution:
|
||||
def reverseString(self, s: List[str]) -> None:
|
||||
"""
|
||||
Do not return anything, modify s in-place instead.
|
||||
"""
|
||||
for i in range(len(s)//2):
|
||||
s[i],s[-i-1]=s[-i-1],s[i]
|
||||
15
leetcode/350.py
Normal file
15
leetcode/350.py
Normal file
@@ -0,0 +1,15 @@
|
||||
class Solution:
|
||||
def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:
|
||||
result=[]
|
||||
check={}
|
||||
|
||||
for i in nums1:
|
||||
if i in check:
|
||||
check[i]+=1
|
||||
else:
|
||||
check[i]=1
|
||||
for i in nums2:
|
||||
if i in check and check[i]>0:
|
||||
check[i]-=1
|
||||
result.append(i)
|
||||
return result
|
||||
15
leetcode/387.py
Normal file
15
leetcode/387.py
Normal file
@@ -0,0 +1,15 @@
|
||||
class Solution:
|
||||
def firstUniqChar(self, s: str) -> int:
|
||||
d={}
|
||||
|
||||
|
||||
for i in range(len(s)):
|
||||
if s[i] in d:
|
||||
d[s[i]]=-1
|
||||
else:
|
||||
d[s[i]]=i
|
||||
|
||||
for i in d.values():
|
||||
if i>-1:
|
||||
return i
|
||||
return -1
|
||||
13
leetcode/412.py
Normal file
13
leetcode/412.py
Normal file
@@ -0,0 +1,13 @@
|
||||
class Solution:
|
||||
def fizzBuzz(self, n: int) -> List[str]:
|
||||
result=[]
|
||||
for i in range(1,n+1):
|
||||
s=""
|
||||
if i%3==0:
|
||||
s+="Fizz"
|
||||
if i%5==0:
|
||||
s+="Buzz"
|
||||
if s=="":
|
||||
s=str(i)
|
||||
result.append(s)
|
||||
return result
|
||||
21
leetcode/66.py
Normal file
21
leetcode/66.py
Normal file
@@ -0,0 +1,21 @@
|
||||
class Solution:
|
||||
def plusOne(self, digits: List[int]) -> List[int]:
|
||||
arr=[]
|
||||
isUp=False
|
||||
|
||||
digits[-1]+=1
|
||||
for i in range(1,len(digits)+1):
|
||||
if isUp:
|
||||
digits[-i]+=1
|
||||
isUp=False
|
||||
|
||||
if digits[-i]>9:
|
||||
isUp=True
|
||||
digits[-i]=0
|
||||
|
||||
if isUp:
|
||||
arr.append(1)
|
||||
for i in digits:
|
||||
arr.append(i)
|
||||
|
||||
return arr
|
||||
8
leetcode/70.py
Normal file
8
leetcode/70.py
Normal file
@@ -0,0 +1,8 @@
|
||||
class Solution:
|
||||
def climbStairs(self, n: int) -> int:
|
||||
dp=[0,1,2]
|
||||
|
||||
for i in range(3,n+1):
|
||||
dp.append(dp[i-2]+dp[i-1])
|
||||
|
||||
return dp[n]
|
||||
24
leetcode/88.py
Normal file
24
leetcode/88.py
Normal file
@@ -0,0 +1,24 @@
|
||||
class Solution:
|
||||
def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:
|
||||
narr=[]
|
||||
cnt1=0
|
||||
cnt2=0
|
||||
|
||||
while cnt1<m and cnt2<n:
|
||||
v=0
|
||||
if nums1[cnt1]<nums2[cnt2]:
|
||||
v=nums1[cnt1]
|
||||
cnt1+=1
|
||||
else:
|
||||
v=nums2[cnt2]
|
||||
cnt2+=1
|
||||
narr.append(v)
|
||||
while cnt1<m:
|
||||
narr.append(nums1[cnt1])
|
||||
cnt1+=1
|
||||
while cnt2<n:
|
||||
narr.append(nums2[cnt2])
|
||||
cnt2+=1
|
||||
|
||||
for i in range(n+m):
|
||||
nums1[i]=narr[i]
|
||||
20
leetcode/94.py
Normal file
20
leetcode/94.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# 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 inorder(self, now: Optional[TreeNode], result: List[int]):
|
||||
if not now.left==None:
|
||||
self.inorder(now.left,result)
|
||||
result.append(now.val)
|
||||
if not now.right==None:
|
||||
self.inorder(now.right,result)
|
||||
|
||||
def inorderTraversal(self, root: Optional[TreeNode]) -> List[int]:
|
||||
result=[]
|
||||
if not root==None:
|
||||
self.inorder(root,result)
|
||||
|
||||
return result
|
||||
14
swea/21425.py
Normal file
14
swea/21425.py
Normal file
@@ -0,0 +1,14 @@
|
||||
t=int(input())
|
||||
|
||||
for _ in range(t):
|
||||
count=0
|
||||
x,y,n=map(int,input().split())
|
||||
|
||||
while(x<=n and y<=n):
|
||||
count+=1
|
||||
if(x<y):
|
||||
x+=y
|
||||
else:
|
||||
y+=x
|
||||
|
||||
print(count)
|
||||
13
swea/3307.py
Normal file
13
swea/3307.py
Normal file
@@ -0,0 +1,13 @@
|
||||
t=int(input())
|
||||
for tc in range(1,t+1):
|
||||
n=int(input())
|
||||
arr=list(map(int,input().split()))
|
||||
dp=[1]*n
|
||||
mx=0
|
||||
|
||||
for i in range(1,n):
|
||||
for j in range(i):
|
||||
if arr[i]>arr[j]:
|
||||
dp[i]=max(dp[i],dp[j]+1)
|
||||
mx=max(dp[i],mx)
|
||||
print("#"+str(tc),mx)
|
||||
16
swea/3499.py
Normal file
16
swea/3499.py
Normal file
@@ -0,0 +1,16 @@
|
||||
t=int(input())
|
||||
for tc in range(1,t+1):
|
||||
n=int(input())
|
||||
arr=list(map(str,input().split()))
|
||||
narr=[]
|
||||
si=n//2
|
||||
|
||||
for i in range(si):
|
||||
narr.append(arr[i])
|
||||
if n%2==1:
|
||||
narr.append(arr[si+i+1])
|
||||
else:
|
||||
narr.append(arr[si+i])
|
||||
if n%2==1:
|
||||
narr.append(arr[si])
|
||||
print("#"+str(tc),*narr)
|
||||
14
swea/3750.py
Normal file
14
swea/3750.py
Normal file
@@ -0,0 +1,14 @@
|
||||
t=int(input())
|
||||
pr=[]
|
||||
for tc in range(1,t+1):
|
||||
n=input()
|
||||
while len(n)>1:
|
||||
r=0
|
||||
for c in n:
|
||||
v=int(c)
|
||||
r+=v
|
||||
n=str(r)
|
||||
pr.append("#{} {}".format(tc,n))
|
||||
|
||||
for p in pr:
|
||||
print(p)
|
||||
24
swea/4047.py
Normal file
24
swea/4047.py
Normal file
@@ -0,0 +1,24 @@
|
||||
t=int(input())
|
||||
for tc in range(1,t+1):
|
||||
isCo=True
|
||||
c=set()
|
||||
d={}
|
||||
p=input()
|
||||
pl=len(p)//3
|
||||
for i in range(pl):
|
||||
v=p[i*3:i*3+3]
|
||||
if v in c:
|
||||
isCo=False
|
||||
break
|
||||
c.add(v)
|
||||
d[v[0]]=d.get(v[0],0)+1
|
||||
|
||||
if not isCo:
|
||||
print("#"+str(tc),"ERROR")
|
||||
continue
|
||||
cs=13-d.get('S',0)
|
||||
cd=13-d.get('D',0)
|
||||
ch=13-d.get('H',0)
|
||||
cc=13-d.get('C',0)
|
||||
|
||||
print("#"+str(tc),cs,cd,ch,cc)
|
||||
13
swea/5356.py
Normal file
13
swea/5356.py
Normal file
@@ -0,0 +1,13 @@
|
||||
t=int(input())
|
||||
for tc in range(1,t+1):
|
||||
arr=[]
|
||||
s=""
|
||||
mx=0
|
||||
for i in range(5):
|
||||
arr.append(list(input()))
|
||||
mx=max(len(arr[-1]),mx)
|
||||
for i in range(mx):
|
||||
for j in range(5):
|
||||
if len(arr[j])>i:
|
||||
s+=arr[j][i]
|
||||
print("#"+str(tc),s)
|
||||
15
swea/5789.py
Normal file
15
swea/5789.py
Normal file
@@ -0,0 +1,15 @@
|
||||
t=int(input())
|
||||
for tc in range(1,t+1):
|
||||
n,q=map(int,input().split())
|
||||
d={}
|
||||
for i in range(1,n+1):
|
||||
d[i]=0
|
||||
for i in range(q):
|
||||
s,e=map(int,input().split())
|
||||
|
||||
for j in range(s,e+1):
|
||||
d[j]=i+1
|
||||
rs="#"+str(tc)+" "
|
||||
for i in range(1,n+1):
|
||||
rs+=str(d[i])+" "
|
||||
print(rs)
|
||||
Reference in New Issue
Block a user