Tuesday, January 3, 2023
Robot return to origin
Go
- Time complexity: - n is a length of a string
- Auxiliary space: - constant amount of space
import "strings"
func judgeCircle(moves string) bool {
ups := strings.Count(moves, "U")
downs := strings.Count(moves, "D")
if ups != downs {
return false
}
lefts := strings.Count(moves, "L")
rights := strings.Count(moves, "R")
if lefts != rights {
return false
}
return true
}