| https://leetcode.com/problems/path-crossing/description/ | Easy |
|---|
class Solution {
fun isPathCrossing(path: String): Boolean {
var x = 0
var y = 0
val visited = mutableSetOf<Pair<Int, Int>>()
visited.add(0 to 0)
for (c in path) {
when (c) {
'N' -> y++
'S' -> y--
'E' -> x++
'W' -> x--
}
if (!visited.add(x to y)) return true
}
return false
}
}