Skip to content

Latest commit

 

History

History
39 lines (33 loc) · 708 Bytes

2315.统计星号.md

File metadata and controls

39 lines (33 loc) · 708 Bytes

2315.统计星号

/*
 * @lc app=leetcode.cn id=2315 lang=typescript
 *
 * [2315] 统计星号
 */

// @lc code=start
function countAsterisks(s: string): number {}
// @lc code=end

解法 1: 模拟

function countAsterisks(s: string): number {
  let flag = false,
    res = 0
  for (let ch of s) {
    if (!flag && ch === '*') res++
    if (ch === '|') flag = !flag
  }
  return res
}

Case

test.each([
  { input: { s: 'l|*e*et|c**o|*de|' }, output: 2 },
  { input: { s: 'iamprogrammer' }, output: 0 },
  { input: { s: 'yo|uar|e**|b|e***au|tifu|l' }, output: 5 },
])('input: s = $input.s', ({ input: { s }, output }) => {
  expect(countAsterisks(s)).toEqual(output)
})