-2

比如n=11的意思,那么map应该有0-1, 1-4, 2-1, 3-1, 4-1, 5-1, 6-1, 7-1, 8-1, 9 -1

 public void countDigits(int n, Map map) {
          while (n != 0) {
            int d = n%10;
            n /= 10;
            map.put(d,map.get(d)++);
          }
          return result;
        }

除上述方法外。我想得到从 1 到 N 的所有数字。

4

1 回答 1

0

您的代码根本无法编译。尝试替换map.put(d,map.get(d)++);

Integer tmp = (Integer)map.get(d);
if(tmp == null) tmp = 0;
tmp++;
map.put(d,tmp);
于 2015-02-09T17:19:03.287 回答