跳台阶扩展问题(找规律)
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
cout << (1 << (n - 1)) << endl;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
string s;
int len;
int Hash[26];
int main()
{
cin >> s;
for (int l = 0, r = 0, cnt = 0; r < s.size(); r++)
{
if (Hash[s[r] - 'a']++ == 0) cnt++;
while (cnt > 2)
{
if (--Hash[s[l++] - 'a'] == 0) cnt--;
}
len = max(len, r - l + 1);
}
cout << len << endl;
return 0;
}
class Solution {
vector<string> res;
string path;
bool used[11] = {};
public:
vector<string> Permutation(string str) {
sort(str.begin(), str.end());
dfs(str);
return res;
}
void dfs(const string &str)
{
if (path.size() == str.size())
{
res.push_back(path);
return;
}
for (int i = 0; i < str.size(); i++)
{
if (!used[i] && (i == 0 || str[i - 1] != str[i] || used[i - 1]))
{
used[i] = true;
path += str[i];
dfs(str);
path.pop_back();
used[i] = false;
}
}
}
};
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有