最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

LeetCode 2315. Count Asterisks

2023-03-27 10:04 作者:您是打尖兒還是住店呢  | 我要投稿

You are given a string?s, where every?two?consecutive vertical bars?'|'?are grouped into a?pair. In other words, the 1st?and 2nd?'|'?make a pair, the 3rd?and 4th?'|'?make a pair, and so forth.

Return?the number of?'*'?in?s,?excluding?the?'*'?between each pair of?'|'.

Note?that each?'|'?will belong to?exactly?one pair.

?

Example 1:

Input: s = "l|*e*et|c**o|*de|"

Output: 2

Explanation: The considered characters are underlined: "l|*e*et|c**o|*de|".?

The characters between the first and second '|' are excluded from the answer.?

Also, the characters between the third and fourth '|' are excluded from the answer.?

There are 2 asterisks considered. Therefore, we return 2.

Example 2:

Input: s = "iamprogrammer"

Output: 0

Explanation: In this example, there are no asterisks in s. Therefore, we return 0.

Example 3:

Input: s = "yo|uar|e**|b|e***au|tifu|l"

Output: 5

Explanation: The considered characters are underlined: "yo|uar|e**|b|e***au|tifu|l". There are 5 asterisks considered. Therefore, we return 5.

其實(shí)就是判斷是否有| 有的時(shí)候,用一個(gè)變量存出線多少次了,奇數(shù)次的時(shí)候,就要把非*的字母換掉,偶數(shù)是不用管的。

最后判斷一下*出線的次數(shù)即可。

?

Constraints:

  • 1 <= s.length <= 1000

  • s?consists of lowercase English letters, vertical bars?'|', and asterisks?'*'.

  • s?contains an?even?number of vertical bars?'|'.


Runtime:?1 ms, faster than?99.68%?of?Java?online submissions for?Count Asterisks.

Memory Usage:?40.8 MB, less than?26.44%?of?Java?online submissions for?Count Asterisks.


LeetCode 2315. Count Asterisks的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
富民县| 华安县| 富阳市| 读书| 北宁市| 沽源县| 尼勒克县| 宜都市| 兖州市| 竹溪县| 寿光市| 靖江市| 阿拉善右旗| 大荔县| 钟山县| 明光市| 张家口市| 治多县| 原阳县| 漠河县| 苏尼特右旗| 南川市| 宝鸡市| 鱼台县| 绵竹市| 绥棱县| 白银市| 越西县| 瓦房店市| 冕宁县| 九龙县| 定襄县| 安陆市| 长白| 南通市| 安泽县| 上虞市| 东莞市| 合水县| 巴彦淖尔市| 肇庆市|