Skip to content

Instantly share code, notes, and snippets.

Created June 15, 2014 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/efaa69ffe8d5af283ff1 to your computer and use it in GitHub Desktop.
Save anonymous/efaa69ffe8d5af283ff1 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cstring>
using namespace std;
bool Unique(string str)
{
bool b[256] = {0};
int len = str.length();
for (int i = 0; i < len; ++i)
{
int temp = str[i];
if (b[temp]) return false;
b[temp] = true;
}
return true;
}
int main()
{
string str1 = "hello", str2 = "abcd";
cout <<Unique(str1) << " " << endl;
cout <<Unique(str2) << " " << endl;
return 0;
}
@raymondino
Copy link

你好,能解释一下第七行是怎么实现给bool b数组的全部元素赋值的么?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment