본문 바로가기
python-algorithm

leetcode 2315. Count Asterisks

by 무적김두칠 2023. 1. 9.

https://leetcode.com/problems/count-asterisks/description/

 

Count Asterisks - LeetCode

Count Asterisks - 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

leetcode.com

 

1
2
3
4
5
6
7
class Solution:
    def countAsterisks(self, s: str-> int:
        converted_s = s.split('|')
        converted_s = ''.join(converted_s[::2])
        answer = converted_s.count('*')
 
        return answer
cs
반응형

댓글