摘要:
def str_to_int(string): if not string: # 空字符返回异常 raise Exception('string cannot be None', string) flag = 0 # 用来表示第一个字符是否为+、- ret = 0 # 结果 for k, s in enumerate(string): ... 阅读全文
摘要:
def aa(A): n=len(A) B=[1 for i in range(n)] for i in range(n): for j in range(n): if i !=j: B[i] *=A[j] return B print(aa([1,2,3]... 阅读全文
摘要:
def add(n,m): while m: summ=n^m carry=(n&m)<<1 m=carry n=summ return n print(add(3,4)) 阅读全文
摘要:
def aa(n): return sum(range(n+1)) print(aa(9)) 阅读全文
摘要:
def aa(nums): a,b=0,1 ret=[] leng=len(nums) for i in range(leng-1): for j in range(i+1,leng): ret.append(nums[j]-nums[i]) retur... 阅读全文
摘要:
def aa(n,m): ret=0 if n==1: return 0 for i in range(2,n+1): ret= (m+ret)%i return ret print(aa(5,3)) 阅读全文
摘要:
import random def is_continus(nums, k): data = [random.choice(nums) for _ in range(k)] data.sort() print data zero = data.count(0) small, big = zero, zero + 1 while big 1: ... 阅读全文
摘要:
import random def aa(n): q=0 while n: m=random.randint(1,6) q +=m n -=1 return q print(aa(5)) 阅读全文
摘要:
def aa(nums,s): i=0 leng=len(nums) ret=[] while i<leng-s+1: ret.append(max(nums[i:i+s])) i +=1 return ret print(aa([2,3,4,2,6,2,5,1],3)) 阅读全文
摘要:
def aa(s,n): #n%=len(s) return s[n:]+s[:n] print(aa('abddh',2)) 阅读全文
摘要:
def aa(string): if not string: return False a=string.split() return ' '.join(a[::-1]) print(aa('I am a engineer.')) 阅读全文
摘要:
def sum_to_s(s): a, b = 1, 2 ret = [] while a < s / 2 + 1: if sum(range(a, b+1)) == s: ret.append(range(a, b+1)) a += 1 elif sum(range(a, b+1)) < s... 阅读全文
摘要:
def aa(nums,s): left,right=0,len(nums)-1 while left s: right -=1 else : left +=1 return None print(aa([1,2,3,4,5],3)) 阅读全文
摘要:
def aa(nums): hashes={} for s in nums: hashes[s]=hashes[s]+1 if hashes.get(s) else 1 for s in nums: if hashes[s]==1: print (s) return print(... 阅读全文
摘要:
def aa(nums): hashes={} for s in nums: hashes[s]=hashes[s]+1 if hashes.get(s) else 1 for s in nums: if hashes[s]==1: print (s) return print(... 阅读全文
摘要:
def aa(nums): leng=len(nums) for i in range(leng): if i==nums[i]: print (i) i+=1 return None print(aa([0,1,2,3,4,5])) 阅读全文
摘要:
def aa(nums,n): for i in range(n): if i ==nums[i]: i +=1 else: return i print(aa([0,1,2,3,4,5,7],8)) 阅读全文
摘要:
def aa(nums): if not nums: return False hashes={} ret=[] for s in nums: hashes[s]=hashes[s]+1 if hashes.get(s) else 1 for s in nums: ret.append([s... 阅读全文
摘要:
class ListNode(object): def __init__(self,x): self.val=x self.next=None class Link(object): def __init__(self,values=None): self.nodes=self.set_link(values) i... 阅读全文
摘要:
def aa(nums): if not nums: return False leng=len(nums)-1 ret=[] for i in range(leng): for j in range(i,leng): if nums[i]>nums[j]: ret.appen... 阅读全文