838. Push Dominoes Medium

@problem@discussion
#Two Pointers#String#Dynamic Programming



1/**
2 * [838] Push Dominoes
3 *
4 * There are n dominoes in a line, and we place each domino vertically upright. In the beginning, we simultaneously push some of the dominoes either to the left or to the right.
5 * After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right.
6 * When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces.
7 * For the purposes of this question, we will consider that a falling domino expends no additional force to a falling or already fallen domino.
8 * You are given a string dominoes representing the initial state where:
9 * 
10 * 	dominoes[i] = 'L', if the i^th domino has been pushed to the left,
11 * 	dominoes[i] = 'R', if the i^th domino has been pushed to the right, and
12 * 	dominoes[i] = '.', if the i^th domino has not been pushed.
13 * 
14 * Return a string representing the final state.
15 *  
16 * Example 1:
17 * 
18 * Input: dominoes = "RR.L"
19 * Output: "RR.L"
20 * Explanation: The first domino expends no additional force on the second domino.
21 * 
22 * Example 2:
23 * <img alt="" src="https://s3-lc-upload.s3.amazonaws.com/uploads/2018/05/18/domino.png" style="height: 196px; width: 512px;" />
24 * Input: dominoes = ".L.R...LR..L.."
25 * Output: "LL.RR.LLRRLL.."
26 * 
27 *  
28 * Constraints:
29 * 
30 * 	n == dominoes.length
31 * 	1 <= n <= 10^5
32 * 	dominoes[i] is either 'L', 'R', or '.'.
33 * 
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/push-dominoes/
38// discuss: https://leetcode.com/problems/push-dominoes/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43    pub fn push_dominoes(dominoes: String) -> String {
44        String::new()
45    }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn test_838() {
56    }
57}
58


Back
© 2025 bowen.ge All Rights Reserved.