Skip to content

Commit a68425a

Browse files
committed
2315.统计星号
1 parent 74e8519 commit a68425a

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@
206206
|2293|[极大极小游戏](https://leetcode.cn/problems/min-max-game/)|[JavaScript](./algorithms/min-max-game.js)|Easy|
207207
|2299|[强密码检验器 II](https://leetcode.cn/problems/strong-password-checker-ii/)|[JavaScript](./algorithms/strong-password-checker-ii.js)|Easy|
208208
|2309|[兼具大小写的最好英文字母](https://leetcode.cn/problems/greatest-english-letter-in-upper-and-lower-case/)|[JavaScript](./algorithms/greatest-english-letter-in-upper-and-lower-case.js)|Easy|
209+
|2315|[统计星号](https://leetcode.cn/problems/count-asterisks/)|[JavaScript](./algorithms/count-asterisks.js)|Easy|
209210
|2351|[第一个出现两次的字母](https://leetcode.cn/problems/first-letter-to-appear-twice/)|[JavaScript](./algorithms/first-letter-to-appear-twice.js)|Easy|
210211
|面试题 04.12|[面试题 04.12. 求和路径](https://leetcode.cn/problems/paths-with-sum-lcci/)|[JavaScript](./algorithms/paths-with-sum-lcci.js)|Medium|
211212
|面试题 02.07|[面试题 02.07. 链表相交](https://leetcode.cn/problems/intersection-of-two-linked-lists-lcci/)|[JavaScript](./algorithms/intersection-of-two-linked-lists-lcci.js)|Easy|

algorithms/count-asterisks.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* 2315. 统计星号
3+
* @param {string} s
4+
* @return {number}
5+
*/
6+
var countAsterisks = function(s) {
7+
let count = 0;
8+
let j = 0;
9+
10+
for (let i = 0; i < s.length; i++) {
11+
if (s[i] === '|') {
12+
j++;
13+
if (j === 2) {
14+
// reset
15+
j = 0
16+
}
17+
}
18+
if (s[i] === '*' && j === 0) {
19+
count++;
20+
}
21+
}
22+
return count;
23+
};

vs-lt/2315.统计星号.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* @lc app=leetcode.cn id=2315 lang=javascript
3+
*
4+
* [2315] 统计星号
5+
*/
6+
7+
// @lc code=start
8+
/**
9+
* @param {string} s
10+
* @return {number}
11+
*/
12+
var countAsterisks = function(s) {
13+
let count = 0;
14+
let j = 0;
15+
16+
for (let i = 0; i < s.length; i++) {
17+
if (s[i] === '|') {
18+
j++;
19+
if (j === 2) {
20+
// reset
21+
j = 0
22+
}
23+
}
24+
if (s[i] === '*' && j === 0) {
25+
count++;
26+
}
27+
}
28+
return count;
29+
};
30+
// @lc code=end
31+

0 commit comments

Comments
 (0)