LintCode: Unique Characters
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的更多相关文章
- 157. Unique Characters 【LintCode by java】
Description Implement an algorithm to determine if a string has all unique characters. Example Given ...
- [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 ...
- LeetCode 1239. Maximum Length of a Concatenated String with Unique Characters
原题链接在这里:https://leetcode.com/problems/maximum-length-of-a-concatenated-string-with-unique-characters ...
- 【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 ...
- lintcode:Unique Characters 判断字符串是否没有重复字符
题目: 判断字符串是否没有重复字符 实现一个算法确定字符串中的字符是否均唯一出现 样例 给出"abc",返回 true 给出"aab",返回 false 挑战 ...
- 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 { ...
- [LintCode]——目录
Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (20 ...
- Longest Substring with At Most K Distinct Characters
Given a string, find the longest substring that contains only two unique characters. For example, gi ...
- [Swift]LeetCode828. 独特字符串 | Unique Letter String
A character is unique in string S if it occurs exactly once in it. For example, in string S = " ...
随机推荐
- Informix存储过程
一.存储过程概述 存储过程是一个用户定义的函数,由存储过程语句(SPL) 和一组SQL语句组成,以可以执行代码形式存储在数据库中,和表.视图.索引等一样,是数据库的一种对象. 存储过程语言SPL(St ...
- Android实现对HOME键的捕获和屏蔽
1.1. 在AndroidManifest.xml中加上权限,禁止HOME键. <uses-permission android:name="android.permission.DI ...
- ibatis.net:在VS中支持xml智能提示
下载ibatis.net,在其解压目录下有几个后缀为“.xsd”的文件,将他们拷贝到如下目录:
- C#学习笔记:预处理指令
C#和C/C++一样,也支持预处理指令,下面我们来看看C#中的预处理指令. #region 代码折叠功能,配合#endregion使用,如下: 点击后如下: 条件预处理 条件预处理可以根据给出的条件决 ...
- cocos2d-x绑lua的开发环境
2013年是手游开发井喷的一年,也是手游市场竞争最为激烈的一年,ios市场除了刷榜.刷榜,还是刷榜,而android有点像黑市的感觉,水太深(很多渠道商已经从上游控制了流量的入口).而cocos2d- ...
- crm操作产品实体
using System; using Microsoft.Xrm.Sdk; using Microsoft.Crm.Sdk.Messages; /// <summary> ...
- python的重试库tenacity用法以及类似库retry、requests实现
介绍 tenacity is an Apache 2.0 licensed general-purpose retrying library, written in Python, to simpli ...
- Reloading Java Classes 101: Objects, Classes and ClassLoaders Translation
The original link: http://zeroturnaround.com/rebellabs/reloading-objects-classes-classloaders/ A Bir ...
- N体运动的程序模拟
这依然是与<三体>有关的一篇文章.空间中三个星体在万有引力作用下的运动被称之为三体问题,参见我的上一篇文章:三体运动的程序模拟.而这一节,对三体问题进行了扩展,实现了空间中N个星体在万有引 ...
- 搭建MySQL高可用负载均衡集群(转)
阅读目录 1.简介 2.基本环境 3.配置MySQL主主复制 4.中间件简述 4.1.Haproxy介绍 4.2.keepalived介绍 5.中间件的安装与配置(haproxy.keepalived ...