開學了,
結果事情接踵而來...
好想一直睡覺啊 qwq
Simple, given a string of words, return the length of the shortest word(s).
String will never be empty and you do not need to account for different data types.
最間單的方法就是將字串切開,
一個一個去比對XD
def find_short(s):
l = 999999
s = s.split()
for i in s:
if l > len(i): l = len(i)
return l
看了解答,
原來
min(len(x) for x in s.split())
就可以辦到了XD
果然還是不熟悉這種寫法呀...
Find the greatest common divisor of two positive integers. The integers can be large, so you need to find a clever solution.
The inputs x and y are always greater or equal to 1, so the the greatest common divisor will always be an integer that is also greater or equal to 1.
簡單講就是找最大公因數,
使用輾轉相除法即可~
def mygcd(x,y):
while y > 0:
t = y
y = x % y
x = t
return x
今天就先這樣子,
要來去備課了 qq