Skip to content

Instantly share code, notes, and snippets.

View goish135's full-sized avatar

阿瑜 goish135

View GitHub Profile
#!/bin/python3
import math
import os
import random
import re
import sys
#testStr = '#ab!c#de!f'
#testStr = '##!r#po#'
testStr ='#a!b#c'
cnt=0
head = -1
tail = -1
ans = 0
for i in range(len(testStr)):
if testStr[i]=='#':
cnt+=1
'''Ex
testStr = "423692"
kb = "923857614"
'''
'''ex1
testStr = "5111"
kb = "752961348"
'''
'''
Ex:
talentsCount = 3
talent=[1,2,3,2,1]
'''
'''
talent=[1,2,3,2,1]
talentsCount = 3
'''
talent=[1,1,2,2,3,1,3,2]
@goish135
goish135 / L.C.-Rotate Image.py
Created August 20, 2021 03:25
#觀察題型 #簡單實作
class Solution:
def rotate(self, matrix: List[List[int]]) -> None:
"""
Do not return anything, modify matrix in-place instead.
"""
for i in range(len(matrix)):
for j in range(i+1,len(matrix)):
matrix[i][j],matrix[j][i] = matrix[j][i],matrix[i][j]
for k in range(len(matrix)):
def combinations(data, length):
def dfs(cur, pos):
if len(cur) == length:
yield cur
if pos == len(data):
return
if type(data) is list:
for i in range(pos, len(data)):
for j in dfs(cur + [data[i]], i + 1):
yield j
class Solution:
def countAndSay(self, n: int) -> str:
if n==1:
return "1"
first = 0
test = str(1)
for j in range(2,n+1):
ans = ""
# 0-1 Knapsack Problem 0-1 背包問題
'''
[0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 6, 6, 6, 6, 6]
[0, 0, 0, 0, 6, 6, 6, 6, 6]
[0, 0, 0, 0, 6, 6, 6, 6, 6]
[0, 0, 3, 3, 6, 6, 9, 9, 9]
[0, 0, 6, 6, 9, 9, 12, 12, 15]
ans: [0, 0, 6, 6, 9, 9, 12, 12, 15]
'''
weight = [4,5,6,2,2]
value = [6,4,5,3,6]
W = 8 # 負重
num = len(value)
# or num = len(weight)
# ans = 15 # 最大價值
# 0 1 2 3 4 5 6 7 8
# 370. Range addition
updates = [[1,3,2],[2,4,3],[0,2,-2]]
length = 5
# [-2,0,3,5,3]
initial_arr = [0]*length
for i in updates:
#print(i)
s,d,inc = i[0],i[1],i[2]
print(s,d,inc)