C++,

time: O(n^2)

space: O(0)

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

C++,

time: O(n)

space: O(n)

 class Solution {
public:
/**
* @param str: a string
* @return: a boolean
*/
bool isUnique(string &str) {
// write your code here
string tmp;
for (int i=; i<str.size(); i++) {
if (- == tmp.find(str[i])) {
tmp.push_back(str[i]);
} else {
return false;
}
}
return true;
}
};

LintCode: Unique Characters的更多相关文章

  1. 157. Unique Characters 【LintCode by java】

    Description Implement an algorithm to determine if a string has all unique characters. Example Given ...

  2. [CareerCup] 1.1 Unique Characters of a String 字符串中不同的字符

    1.1 Implement an algorithm to determine if a string has all unique characters. What if you cannot us ...

  3. LeetCode 1239. Maximum Length of a Concatenated String with Unique Characters

    原题链接在这里:https://leetcode.com/problems/maximum-length-of-a-concatenated-string-with-unique-characters ...

  4. 【leetcode】1239. Maximum Length of a Concatenated String with Unique Characters

    题目如下: Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have ...

  5. lintcode:Unique Characters 判断字符串是否没有重复字符

    题目: 判断字符串是否没有重复字符 实现一个算法确定字符串中的字符是否均唯一出现 样例 给出"abc",返回 true 给出"aab",返回 false 挑战 ...

  6. Lintcode: Unique Paths

    C++ dp 递推式:dp[i][j] = dp[i-1][j] + dp[i][j-1] 初值:dp[i][j] = 1,i=0 or j=0 空间优化:省掉一维 class Solution { ...

  7. [LintCode]——目录

    Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (20 ...

  8. Longest Substring with At Most K Distinct Characters

    Given a string, find the longest substring that contains only two unique characters. For example, gi ...

  9. [Swift]LeetCode828. 独特字符串 | Unique Letter String

    A character is unique in string S if it occurs exactly once in it. For example, in string S = " ...

随机推荐

  1. 在ASP.NET MVC中使用Castle Windsor

    平常用Inject比较多,今天接触到了Castle Windsor.本篇就来体验其在ASP.NET MVC中的应用过程. Visual Studio 2012创建一个ASP.NET MVC 4网站. ...

  2. [转发]将Delphi的对象方法设为回调函数

    心血来潮,为了实现更好的通用性和封装性,需要把类方法作为回调函数,搜得一篇好文,节选转发.命名似乎应该是MethodToCallback才合适,可惜调试时总是报错,debugging. 原文地址:ht ...

  3. javascript: break跳出多重循环以及退出each循环

    先来看一个小例子: <html> <body> <script type="text/javascript"> for(j=0;j<2;j ...

  4. Sales Order ORA-04062 FRM-40815 in EBS R12.2.4

    [oracle@ebs ~]$ su - oracle [oracle@ebs ~]$ source /u01/install/VISION/fs1/EBSapps/appl/APPSEBSDB_eb ...

  5. Windows下安装WebLogic

    WebLogic安装结束 以下是进入MyEclipse启动配置WebLogic

  6. 猫都能学会的Unity3D Shader入门指南(一)

    动机 自己使用Unity3D也有一段时间了,但是很多时候是流于表面,更多地是把这个引擎简单地用作脚本控制,而对更深入一些的层次几乎没有了解.虽然说Unity引擎设计的初衷就是创建简单的不需要开发者操心 ...

  7. Android加密解密

    随笔分类 - Android加密解密 Android数据加密之异或加密算法 摘要: 前言: 这几天被公司临时拉到去做Android IM即时通信协议实现,大致看了下他们定的协议,由于之前没有参与,据说 ...

  8. HttpURLConnection和HttpClient的简单用法

    HttpURLConnection的简单用法:先通过一个URL创建一个conn对象,然后就是可以设置get或者是post方法,接着用流来读取响应结果即可 String html = null; lon ...

  9. TextView中文文档

    十分感谢农民伯伯的翻译:http://www.cnblogs.com/over140/archive/2010/08/27/1809745.html xml 属性: 属性名称 描述  android: ...

  10. POI Excel 合并数据相同的行

    import java.io.Serializable; /** * POI Excel报表导出,列合并实体<br> * * @author WQ * */ public class Po ...