由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - input a string "hello word", print l:3 o:2 e:1 d:1 h:1 r:1 w:1.不知道哪错了
相关主题
面经(L)问个最近面试里的题目
Amazon first phone interview问一道编程题--java
share int2roman and roman2int java versionG等消息中 求bless
问一下OJ的Anagrams那道题怎么结果就不对呢
lengthOfLongestSubstring 最后一个test case总是超时L家的高频题merge k sorted arrays giving iterators求讨论!
Apple Siri 组 Java 测试题Bloomberg 电面
Dream company Onsite被搞了(少量面经)算法题
问一个anagram的题an interview question, find mode in a rolling window along data sequence
相关话题的讨论汇总
话题: character话题: string话题: integer话题: import话题: temp
进入JobHunting版参与讨论
1 (共1页)
s******d
发帖数: 61
1
我的返回结果是这个,不知道哪里错了
d:1e:1h:1l:1o:1r:1w:1
import java.util.Collection;
import java.util.Collections;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
public class Findfrequency {
public String find(String s){
char[] ch=s.toCharArray();
Hashtable hash=new Hashtable();
for(int i=0;i Character temp=new Character(ch[i]);
if(!hash.contains(temp)){
hash.put(temp, new Integer(1));
}
else{
Integer in=hash.get(temp);
in++;
hash.put(temp, new Integer(in));
}
}
Vector v=new Vector(hash.keySet());
Collections.sort(v);
Iterator it=v.iterator();
String str="";
while(it.hasNext()){
Character element=(Character)it.next();
int a=hash.get(element).intValue();
str+=element+":"+a;
}
return str;
}
public static void main(String[] args){
Findfrequency f=new Findfrequency();
System.out.println( f.find("hello world"));
}
}
h*********n
发帖数: 915
2
you should debug yourself to get improved.

【在 s******d 的大作中提到】
: 我的返回结果是这个,不知道哪里错了
: d:1e:1h:1l:1o:1r:1w:1
: import java.util.Collection;
: import java.util.Collections;
: import java.util.Hashtable;
: import java.util.Iterator;
: import java.util.Vector;
: public class Findfrequency {
: public String find(String s){
: char[] ch=s.toCharArray();

1 (共1页)
进入JobHunting版参与讨论
相关主题
an interview question, find mode in a rolling window along data sequencelengthOfLongestSubstring 最后一个test case总是超时
大牛帮我看看这哪错了? iterative inorder traversalApple Siri 组 Java 测试题
谁来解释下hashtable的iterator是怎么实现的Dream company Onsite被搞了(少量面经)
讨论一个题目问一个anagram的题
面经(L)问个最近面试里的题目
Amazon first phone interview问一道编程题--java
share int2roman and roman2int java versionG等消息中 求bless
问一下OJ的Anagrams那道题怎么结果就不对呢
相关话题的讨论汇总
话题: character话题: string话题: integer话题: import话题: temp