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

Commit9171260

Browse files
authored
Create 0838-push-dominoes.kt
1 parent86eb47b commit9171260

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

‎kotlin/0838-push-dominoes.kt‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
classSolution {
2+
funpushDominoes(d:String):String {
3+
val domArr= d.toCharArray()
4+
val q=LinkedList<Pair<Int,Char>>()
5+
6+
for ((i, v)in domArr.withIndex()) {
7+
if (v!='.')
8+
q.addLast(i to v)
9+
}
10+
11+
while (q.isNotEmpty()) {
12+
val (i, v)= q.removeFirst()
13+
if (v=='L'&& i>0&& domArr[i-1]=='.') {
14+
q.addLast(i-1 to'L')
15+
domArr[i-1]='L'
16+
}elseif (v=='R') {
17+
if (i+1< domArr.size&& domArr[i+1]=='.') {
18+
if (i+2< domArr.size&& domArr[i+2]=='L') {
19+
q.removeFirst()
20+
}else {
21+
q.addLast(i+1 to'R')
22+
domArr[i+1]='R'
23+
}
24+
}
25+
}
26+
}
27+
28+
returnString(domArr)
29+
}
30+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp