Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def search(matrix,value):
- sizex = len(matrix[0])-1
- sizey = len(matrix)-1
- initialx = sizex
- initialy = 0
- while initialx >= 0 and initialy <= sizey:
- if matrix[initialy][initialx] == value:
- return initialx,initialy
- elif matrix[initialy][initialx] > value:
- initialx -= 1
- elif matrix[initialy][initialx] <= value:
- initialy += 1
- else:
- return -1,-1
- return -1,-1
- M = [ [ 1, 5, 7, 9 ],
- [ 4, 6, 10, 15 ],
- [ 8, 11, 12, 19 ],
- [ 14, 16, 18, 21 ] ]
- value = 12
- print(search(M,value))
- value = 17
- print(search(M,value))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement