1.题目
栈混洗甄别:要求时间复杂度为o(n)
2.数据结构与算法
DS:stack
Algorithm:模拟
3.源代码
#include "stdafx.h"
#include <iostream>
#include <string>
#include <stack>
using namespace std;
//栈混洗甄别:str2是否为str1的一个栈混洗
bool shuffling(string str1, string str2){
int len = str1.size();
stack<char> s1;
stack<char> s2;
while(len--){
s1.push(str1[len]);
}
int j = 0;
while(!s1.empty()){
s2.push(s1.top()); s1.pop();
while(true){
if(!s2.empty() && s2.top() == str2

这篇博客探讨了栈混洗的概念,介绍了栈混洗数的计算公式Catalan(n)=(2n!)/[(n+1)!n!],并讨论了如何利用栈结构在Ο(n)时间复杂度内进行栈混洗的甄别,对比了充要条件方法的Ο(n^3)时间复杂度。此外,还提到栈混洗数与n对括号合法表达式的对应关系。
最低0.47元/天 解锁文章
1694

被折叠的 条评论
为什么被折叠?



