码迷,mamicode.com
首页 > 其他好文 > 详细

LintCode

时间:2018-01-28 22:00:57      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:lint   int   rac   char   ble   ret   ane   lin   zh-cn   

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

 

样例

给出"abc",返回 true

给出"aab",返回 false

挑战 

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

class Solution {
public:
    /*
     * @param str: A string
     * @return: a boolean
     */
     
    bool isUnique(string &str) {
        // write your code here
        sort(str.begin(),str.end());
        for(int i=1,sz=str.size();i<sz;i++)
        {
            if(str[i]==str[i-1])
                return false;
        }
        return true;
    }
};

 

LintCode

标签:lint   int   rac   char   ble   ret   ane   lin   zh-cn   

原文地址:https://www.cnblogs.com/zslhg903/p/8372356.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!