Cracking the Coding Interview 1-1

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

bool StringIsUnique(string s) {
  sort(s.begin(),s.end());
  for (auto p = s.begin(); p != s.end()-1;) {
    if (*p == *++p) return false;
  }
  return true;
}

int main(int argc, const char * argv[]) {
  
  string s = "akjnsdkjahrj";
  cout << StringIsUnique(s) << endl;
  string s2 = "qwertyuiop";
  cout << StringIsUnique(s2) << endl;
  return 0;
}

 

posted @ 2014-08-31 05:42  vindicated  阅读(88)  评论(0)    收藏  举报