feat: 2025-10-27打卡
This commit is contained in:
57
838.push-dominoes.java
Normal file
57
838.push-dominoes.java
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* @lc app=leetcode id=838 lang=java
|
||||
*
|
||||
* [838] Push Dominoes
|
||||
*/
|
||||
|
||||
// @lc code=start
|
||||
class Solution {
|
||||
public String pushDominoes(String dominoes) {
|
||||
final int N = dominoes.length();
|
||||
int[] states = new int[dominoes.length()];
|
||||
for(int i = 0; i<dominoes.length(); i++) {
|
||||
if(dominoes.charAt(i) == 'L') {
|
||||
states[i] -= N;
|
||||
int j = i-1;
|
||||
int fluence = N;
|
||||
while(j>=0) {
|
||||
--fluence;
|
||||
states[j] -= fluence;
|
||||
if(dominoes.charAt(j) !='.') {
|
||||
break;
|
||||
}
|
||||
j--;
|
||||
}
|
||||
} else if(dominoes.charAt(i) == 'R') {
|
||||
states[i] += N;
|
||||
int j = i+1;
|
||||
int fluence = N;
|
||||
while(j < dominoes.length()) {
|
||||
--fluence;
|
||||
states[j] += fluence;
|
||||
if(dominoes.charAt(j) != '.') {
|
||||
break;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(int i = 0; i<states.length; i++) {
|
||||
if(states[i] < 0) {
|
||||
sb.append('L');
|
||||
} else if(states[i] > 0) {
|
||||
sb.append('R');
|
||||
} else {
|
||||
sb.append('.');
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
|
||||
}
|
||||
}
|
||||
// @lc code=end
|
||||
|
||||
Reference in New Issue
Block a user