G2A Many GEOs
SHARE
TWEET

adding numbers in two lists

1sairandhri Apr 8th, 2020 134 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #a = [9,9,9]
  2. #b = [1,1]
  3. #[1, 0, 2, 0]
  4. def sol(a,b):
  5.     a,b = a[::-1], b[::-1]
  6.     if len(b)>len(a):
  7.         a,b = b,a
  8.     b.extend([0]*(len(a)-len(b)))
  9.     res = [0]*len(a)
  10.     for i in range(len(a)-1):
  11.         temp=res[i]+a[i]+b[i]
  12.         res[i]+=temp%10
  13.         res[i+1]=temp//10  
  14.     temp = res[-1]+ a[-1]+b[-1]
  15.     res[-1] = temp%10
  16.     if temp>9:    
  17.         res.append(temp//10)
  18.     return res[::-1]
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top