Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func kangaroo(x1: Int, v1: Int, x2: Int, v2: Int) -> String {
- var currentLocation1 = x1
- var currentLocation2 = x2
- guard v2 < v1 else { return "NO" }
- while(differenceInLocations >= 0) {
- if differenceInLocations == 0 {
- return "YES"
- }
- currentLocation1 = currentLocation1 + v1
- currentLocation2 = currentLocation2 + v2
- if differenceInLocations > currentLocation2 - currentLocation1 {
- differenceInLocations = currentLocation2 - currentLocation1
- }
- return "NO"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement