CareerCup1.1
2013-02-23 15:18
267 查看
Cracking the coding Interview 习题1.1:
Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures?
代码:
Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures?
代码:
#include "stdafx.h" #include <string> #include <iostream> bool HasDuplication(std::string); int main() { using namespace std; string str; cin>>str; bool res = HasDuplication(str); if(res) { cout<<"Has Duplication"<<endl; } else { cout<<"Has All unique characters"<<endl; } return 0; } bool HasDuplication(std::string str) { for(int i=0,size=str.size();i<size;i++) { for(int j=i+1;j<size;j++) { if(str[i]==str[j]) { return true; } } } return false; }
相关文章推荐
- career cup1.1 unique char
- Moderate 不用比较符返回较大的数 @CareerCup
- Hard 动态查找中位数 @CareerCup
- CareerCup Find the biggest interval that has all its members in list in O(n)
- CareerCup Finds all the elements that appear more than n/3 times in the list
- LinkLists 链表中返回倒数第n个元素 @CareerCup
- CareerCup The number of pairs (x, y) of distinct elements with condition x + y <= Threshold
- Tree_Graph Validate Binary Search Tree 检测一个BST是否有效 @CareerCup
- CareerCup Fermat point of a traingle
- CareerCup the Lexicographically Smallest Permutation
- CareerCup Find top k values (asec) which can either be the number from the array A
- Careercup - Google面试题 - 6332750214725632
- CareerCup之2.2 寻找单链表倒数第n个元素
- careercup3.5
- CareerCup1.5
- CareerCup 4.1 & 4.3
- Recursion 在数组中寻找神奇下标 @CareerCup
- Moderate 猜测序列hit或是pseudo-hit @CareerCup
- Hard 单词变型成另一个单词 @CareerCup
- CareerCup Eliminate all ‘b’ and ‘ac’ in an array of characters