目前我认为最重要的拐点将会出现在# Stock
b*1
1 楼
最近收到一道 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 进行排序,然后计算 总和 嘛? 如
果您有更好的 办法,请指教, 谢谢。
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 进行排序,然后计算 总和 嘛? 如
果您有更好的 办法,请指教, 谢谢。