@Mr°骚年更新的第二题的代码。 /* 作者:Mr°骚年 链接:https://www.nowcoder.com/discuss/30398 来源:牛客网 */ #include <iostream> using namespace std; bool func(const string& s,const string& t) { if(s.empty() && t.empty()) return true; if(s.size() != t.size()) return false; int s_cnt[256]; int t_cnt[256]; for(int i=0;i<256;i++) { s_cnt[i] = t_cnt[i] = -1; } for(int i=0;i<s.size();i++) { if(s_cnt[s[i]] != t_cnt[t[i]]) { return false; } s_cnt[s[i]] = t_cnt[t[i]] = i; } return true; } void main() { cout<<func("book", "look")<<endl; cout<<func("aba", "abb")<<endl; system("pause"); return; }
点赞 评论

相关推荐

牛客网
牛客网在线编程
牛客网题解
牛客企业服务