@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; }
点赞 评论

相关推荐

点赞 评论 收藏
分享
10-28 10:48
已编辑
门头沟学院 Java
孩子我想要offer:发笔试后还没笔试把我挂了,然后邮箱一直让我测评没测,后面不知道干嘛又给我捞起来下轮笔试,做完测评笔试又挂了😅
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务