157 判断字符串是否没有重复字符

原题网址:http://www.lintcode.com/zh-cn/problem/unique-characters/

实现一个算法确定字符串中的字符是否均唯一出现

样例

给出"abc",返回 true

给出"aab",返回 false

挑战 

如果不使用额外的存储空间,你的算法该如何改变?

 1 class Solution {
 2 public:
 3     /*
 4      * @param str: A string
 5      * @return: a boolean
 6      */
 7     bool isUnique(string &str) {
 8         // write your code here
 9         int size=str.size();
10     for (int i=0;i<size;i++)
11     {
12         for (int j=i+1;j<size;j++)
13         {
14             if (str[i]==str[j])
15             {
16                 return false;
17             }
18         }
19     }
20     return true;
21     }
22 };

参考:

https://blog.csdn.net/wutingyehe/article/details/46646665

posted @ 2018-03-26 16:42  eeeeeeee鹅  阅读(333)  评论(0编辑  收藏  举报