【1】Detect if a string has all unique characters
2013-04-09 21:40
357 查看
Question: Implement an algorithm to determine if a string has all unique characters. What if you can not use additional
data structures?
data structures?
package CareerCup; public class UniqueChar { public UniqueChar(){} public boolean Detect(String str) { boolean[] charList = new boolean[256]; for(int i=0;i<str.length();i++) { if(charList[str.charAt(i)]) return false; else charList[str.charAt(i)] = true; } return true; } public static void main(String[] args) { String str = "abcdaf"; UniqueChar uqc = new UniqueChar(); if(uqc.Detect(str)) System.out.println("String: "+str+" has all unique characters!"); else System.out.println("String: "+str+" has not all unique characters!"); } }
相关文章推荐
- 1.1 Implement an algorithm to determine if a string has all unique characters.
- 1.1 Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures.
- Determine if a string has all unique characters
- determine if a string has all unique characters
- Check if the string has unique char.
- [CareerCup] 1.1 Unique Characters of a String 字符串中不同的字符
- Rearrange a string so that all same characters become d distance away
- Unique Characters of a String
- 解决“error C3861: “pcap_findalldevs_ex”: 找不到标识符”以及“error C2065: “PCAP_SRC_IF_STRING”: 未声明的标识符”问题
- How To Detect If an Application Has Stopped Responding
- Rearrange a string so that all same characters become d distance away
- How To Detect If an Application Has Stopped Responding
- How To Detect If an Application Has Stopped Responding
- How To Detect If an Application Has Stopped Responding
- Rearrange a string so that all same characters become d distance away minDistance priority queue
- A string s is LUCKY if and only if the number of different characters in s is a fibonacci number. Gi
- Using BitSet to to judge if string a contains all letters in string b
- Return if string t contains all chars in s
- Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given the below binary tree andsum =
- //Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the in