We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 90b92c9 commit a5ee0a0Copy full SHA for a5ee0a0
scripts/algorithms/B/Backspace String Compare/Backspace String Compare.rs
@@ -0,0 +1,37 @@
1
+// Runtime: 1 ms (Top 82.5%) | Memory: 2.40 MB (Top 32.5%)
2
+
3
+impl Solution {
4
+ pub fn backspace_compare(s: String, t: String) -> bool {
5
+ let mut s_chars: Vec<char> = s.chars().collect();
6
+ let mut t_chars: Vec<char> = t.chars().collect();
7
8
+ let k = Self::process_string(&mut s_chars);
9
+ let p = Self::process_string(&mut t_chars);
10
11
+ if k != p {
12
+ return false;
13
+ }
14
15
+ for i in 0..k {
16
+ if s_chars[i] != t_chars[i] {
17
18
19
20
21
+ true
22
23
24
+ fn process_string(chars: &mut Vec<char>) -> usize {
25
+ let chars_copy = chars.clone();
26
+ let mut k = 0;
27
+ for &c in chars_copy.iter() {
28
+ if c != '#' {
29
+ chars[k] = c;
30
+ k += 1;
31
+ } else if k > 0 {
32
+ k -= 1;
33
34
35
+ k
36
37
+}
0 commit comments