Skip to content

Commit ad13f4d

Browse files
authored
Added solution for 2315
1 parent 1da56ea commit ad13f4d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

02315. Count Asterisks.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
impl Solution {
2+
// Iterate through the string chars and maintain a boolean that keeps a track of whether we are inside a vertical bar pair. If we are not inside a vertical bar pair, count the asterisk for the final result.
3+
pub fn count_asterisks(s: String) -> i32 {
4+
let mut asterisks = 0;
5+
let mut are_we_inside_bar_pair = false;
6+
for c in s.chars() {
7+
if c == '|' {
8+
are_we_inside_bar_pair = !are_we_inside_bar_pair;
9+
}
10+
if c == '*' && !are_we_inside_bar_pair {
11+
asterisks += 1;
12+
}
13+
}
14+
return asterisks;
15+
}
16+
}

0 commit comments

Comments
 (0)