IT评测·应用市场-qidao123.com

标题: c++11: all_of 、 any_of 和 none_of [打印本页]

作者: 钜形不锈钢水箱    时间: 2023-5-30 11:34
标题: c++11: all_of 、 any_of 和 none_of
  1. class Solution {
  2. public:
  3.     bool isAnagram(string s, string t) {
  4.         if(s.size()!=t.size())
  5.             return false;
  6.         int ans[26]={0};
  7.         for(auto& ch:s){
  8.             ++ans[ch-'a'];
  9.         }
  10.         for(auto& ch:t){
  11.             --ans[ch-'a'];
  12.         }
  13.         return all_of(ans,ans+26,[](int i){return i==0;});
  14.     }
  15. };
复制代码
C++11 中提供了一些用于检查序列中元素的算法,包括:

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!




欢迎光临 IT评测·应用市场-qidao123.com (https://dis.qidao123.com/) Powered by Discuz! X3.4