Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit07c3535

Browse files
authored
Create 1496-path-crossing.kt
1 parentdca6518 commit07c3535

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

‎kotlin/1496-path-crossing.kt‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
classSolution {
2+
funisPathCrossing(path:String):Boolean {
3+
var dirs=mapOf(
4+
'N' to intArrayOf(0,1),
5+
'S' to intArrayOf(0,-1),
6+
'E' to intArrayOf(1,0),
7+
'W' to intArrayOf(-1,0),
8+
)
9+
val visit=HashSet<Pair<Int,Int>>()
10+
var x=0
11+
var y=0
12+
13+
for (cin path) {
14+
visit.add(x to y)
15+
val (dx, dy)= dirs[c]!!
16+
x+= dx
17+
y+= dy
18+
if ((x to y)in visit)
19+
returntrue
20+
}
21+
22+
returnfalse
23+
}
24+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp