P14233 [GeeksforGeeks] The penalty shootout3810
普及-
题目描述

Given a string S contains 0's, 1's, and 2's, the task is to find the number of goals on the penalty.
'1' stands for "goal".
'0' stands for "no goal".
'2' stands for a foul which gives a penalty.
Example 1:
Input: S = "1012012112110"
Output: 2
Explanation: There are 3 penalties,
of which he scores only 2.
1012012112110
Example 2:
Input: S = "111122"
Output: 0
Explanation: No goal on penalty
Your Task:
You don't need to read input or print anything. Your task is to complete the function penaltyScore() which takes a string S as input and returns the goals count on the penalty.
Expected Time Complexity: O(|S|).
Expected Auxiliary Space: O(1).
Constraints:
1 <= |N| <= 10^{5}

输入格式

见题面

输出格式

见题面

样例输入
S = "1012012112110"
样例输出
2