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. Unity3D实践系列05,为GameObject添加额外属性

    在Unity中,通常通过脚本为GameObject添加额外的属性.具体有2种方式:一种是通过硬编码为脚本字段赋值,另一种是通过反射在运行时给脚本字段赋值. 脚本通过字段硬编码为GameObject添加 ...

  2. SQLCE使用本地数据库优化

    一.数据绑定 1.使用数据虚拟化和SKIP/TAKE 使用 Skip 和 Take 方法可确保直到需要在 ListBox 控件中显示数据时才将数据库中的数据加载到内存中. 例如,以下代码显示了如何从数 ...

  3. .net项目中使用Quartz

    (1)在web.config中进行相关配置 <configSections> <section name="quartz" type="System.C ...

  4. 用xcode 5 开发访问IOS 7上面的通讯录有问题

    NSMutableArray *addressBookTemp = [NSMutableArray array]; ABAddressBookRef addressBooks = ABAddressB ...

  5. 【linux】find命令仅返回文件名 不用返回完整的文件路径

    正常查询 find /apps/swapping -name '*swapping*.jar' 在/apps/swapping 目录下 查找 文件名为 '包含swapping的并且以.java结尾的文 ...

  6. HDU 1575 Tr A(矩阵高速幂)

    题目地址:HDU 1575 矩阵高速幂裸题. 初学矩阵高速幂.曾经学过高速幂.今天一看矩阵高速幂,原来其原理是一样的,这就好办多了.都是利用二分的思想不断的乘.仅仅只是把数字变成了矩阵而已. 代码例如 ...

  7. 好用的批量改名工具——文件批量改名工具V2.0 绿色版

    我找了一个绿色免安装的软件来实现批量改名要求 下载地址:http://www.orsoon.com/Soft/14049.html#xiazai 添加图片后,开始改名.通过输入a#就可以将这些图片进行 ...

  8. 解决Installation error: INSTALL_FAILED_VERSION_DOWNGRADE错误

    Installation error: INSTALL_FAILED_VERSION_DOWNGRADE 说明你手机里已经装的软件版本比你要安装的软件版本要高,所以不能安装. 你只要删除你安装的应用便 ...

  9. [转]使用mysql profiles 来查看sql 语句执行计划

    From : http://blog.csdn.net/radkitty/article/details/4632289 要使用该功能,mysql的版本必须在5.0.37版本以上.否则只能使用expl ...

  10. 使用jstl标签时提示The absolute uri: http://java.sun.com/jsp/jstl/core cannot

    http://www.360doc.com/content/11/1219/15/1007797_173395882.shtml 检查应用目录下WEB-INF的lib里是否有jstl.jar和stan ...