题解 | #牛群的配对#
牛群的配对
https://www.nowcoder.com/practice/c6677c8bd0d946e191051f19100c5cf5
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param s string字符串
* @return bool布尔型
*/
bool isValidPairing(string s) {
// write code here
std::stack<char> m_stack;
for(int i = 0; i < s.length(); ++i)
{
if(!m_stack.empty() &&((m_stack.top() == 'A'&&s[i] == 'B')||
(m_stack.top() == 'C'&&s[i] == 'D')))
{
m_stack.pop();
}
else
{
m_stack.push(s[i]);
}
}
return m_stack.empty();
}
};


