发信人: bigpanda2011 (panda), 信区: JobHunting
标 题: 一道JAVA coding question?
发信站: BBS 未名空间站 (Fri Sep 4 15:10:25 2015, 美东)
最近收到一道 java coding question:
Given a list of country names and an int value n, write a method that
determines if there is any
combination of three countries that when you sum up their occurrence it is
equal to n
Examples:
list = Italy, France, USA, UK, Germany, Italy, Mexico, USA, Canada, Italy
n = 7
result = return false
list = Greece, Spain, China, Norway, Russia, Greece, Portugal, China, Greece
, Portugal, China, Turkey, Greece, China
n =10
result = return true
思路是:吧这些 list 输入到hashmap 里,得出他们的出现次数。但是 如何得到 最多
的前3个出现的次数,难道对 hashmap 根据value 进行排序,然后计算 总和 嘛? 如
果您有更好的 办法,请指教, 谢谢。
Friday, September 4, 2015
一道JAVA coding question?
http://www.mitbbs.com/article_t/JobHunting/33046437.html
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment