Advertisement
x3r

arrayPreviousLess

x3r
Feb 17th, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. def arrayPreviousLess(items):
  2.     arr=[] #empty array for the result
  3.    
  4.     for i in range(len(items)):
  5.         tmp = -1 #tmp value that we will append later
  6.         for j in range(i-1,-1,-1): #let's go backwards!
  7.             if items[j]<items[i]: #have we find that smaller value yet?
  8.                 tmp = items[j] # yes! assign tmp to that value we found
  9.                 break #break the loop 'cause we already find the value!
  10.         arr.append(tmp) #append that value to our array
  11.     return arr #return it!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement