Skip to content

Commit 863a34a

Browse files
committed
feat: add solutions to lc problem: No.2315
No.2315.Count Asterisks
1 parent 3e9c3ec commit 863a34a

File tree

5 files changed

+132
-0
lines changed

5 files changed

+132
-0
lines changed

solution/2300-2399/2315.Count Asterisks/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,54 @@ func countAsterisks(s string) int {
130130
### **TypeScript**
131131

132132
```ts
133+
function countAsterisks(s: string): number {
134+
let ans = 0;
135+
let flag = true;
136+
for (const c of s) {
137+
if (c === '|') {
138+
flag = !flag;
139+
} else if (c === '*' && flag) {
140+
ans++;
141+
}
142+
}
143+
return ans;
144+
}
145+
```
133146

147+
### **Rust**
148+
149+
```rust
150+
impl Solution {
151+
pub fn count_asterisks(s: String) -> i32 {
152+
let mut ans = 0;
153+
let mut flag = true;
154+
for &c in s.as_bytes() {
155+
if c == b'|' {
156+
flag = !flag;
157+
} else if c == b'*' && flag {
158+
ans += 1;
159+
}
160+
}
161+
ans
162+
}
163+
}
164+
```
165+
166+
### **C**
167+
168+
```c
169+
int countAsterisks(char *s) {
170+
int ans = 0;
171+
int flag = 1;
172+
for (int i = 0; s[i]; i++) {
173+
if (s[i] == '|') {
174+
flag = !flag;
175+
} else if (s[i] == '*' && flag) {
176+
ans++;
177+
}
178+
}
179+
return ans;
180+
}
134181
```
135182
136183
### **...**

solution/2300-2399/2315.Count Asterisks/README_EN.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,54 @@ func countAsterisks(s string) int {
123123
### **TypeScript**
124124

125125
```ts
126+
function countAsterisks(s: string): number {
127+
let ans = 0;
128+
let flag = true;
129+
for (const c of s) {
130+
if (c === '|') {
131+
flag = !flag;
132+
} else if (c === '*' && flag) {
133+
ans++;
134+
}
135+
}
136+
return ans;
137+
}
138+
```
126139

140+
### **Rust**
141+
142+
```rust
143+
impl Solution {
144+
pub fn count_asterisks(s: String) -> i32 {
145+
let mut ans = 0;
146+
let mut flag = true;
147+
for &c in s.as_bytes() {
148+
if c == b'|' {
149+
flag = !flag;
150+
} else if c == b'*' && flag {
151+
ans += 1;
152+
}
153+
}
154+
ans
155+
}
156+
}
157+
```
158+
159+
### **C**
160+
161+
```c
162+
int countAsterisks(char *s) {
163+
int ans = 0;
164+
int flag = 1;
165+
for (int i = 0; s[i]; i++) {
166+
if (s[i] == '|') {
167+
flag = !flag;
168+
} else if (s[i] == '*' && flag) {
169+
ans++;
170+
}
171+
}
172+
return ans;
173+
}
127174
```
128175
129176
### **...**
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
int countAsterisks(char *s) {
2+
int ans = 0;
3+
int flag = 1;
4+
for (int i = 0; s[i]; i++) {
5+
if (s[i] == '|') {
6+
flag = !flag;
7+
} else if (s[i] == '*' && flag) {
8+
ans++;
9+
}
10+
}
11+
return ans;
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
impl Solution {
2+
pub fn count_asterisks(s: String) -> i32 {
3+
let mut ans = 0;
4+
let mut flag = true;
5+
for &c in s.as_bytes() {
6+
if c == b'|' {
7+
flag = !flag;
8+
} else if c == b'*' && flag {
9+
ans += 1;
10+
}
11+
}
12+
ans
13+
}
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function countAsterisks(s: string): number {
2+
let ans = 0;
3+
let flag = true;
4+
for (const c of s) {
5+
if (c === '|') {
6+
flag = !flag;
7+
} else if (c === '*' && flag) {
8+
ans++;
9+
}
10+
}
11+
return ans;
12+
}

0 commit comments

Comments
 (0)