Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def pairOfShoes(shoes)
- shoes = shoes.sort
- # check for equal number of left and right shoes
- x = 0
- left = 0
- right = 0
- while (x < shoes.length)
- if shoes[x][0] == 0 then
- left = left + 1
- end
- if shoes[x][0] == 1 then
- right = right + 1
- end
- x = x + 1
- end
- if left != right then
- return false
- end
- # check to see if shoe size has a matching size for left and right
- x = 0
- while (shoes[x][0] == 0)
- value = shoes[x][1]
- y = 0
- found = false
- while (y < shoes.length)
- if shoes[y][0] == 1 and shoes[y][1] == value then
- found = true
- end
- y = y + 1
- end
- if found == false then
- return false
- end
- x = x + 1
- end
- return true
- end
Advertisement
Add Comment
Please, Sign In to add comment