Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Rabbits in forest (leetod)
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; class Rextester { public int numRabbits(int[] answers) { Map<Integer, Integer> count = new HashMap<Integer, Integer>(); int ans = 0; for(int i : answers) { if(i == 0 ) {ans++; continue; } if(!count.containsKey(i)) { count.put(i, i); ans++; } else { count.put(i, count.get(i)-1); if(count.get(i) == 0) count.remove(i); ans++; } } for(int j : count.values()) { ans += j; } return ans; } public static void main(String args[]) { System.out.println("Hello, World!"); } }
run
|
edit
|
history
|
help
0
java - preethika
mp1
Problem: rstring
or You Over the hill
project euler 12, java
1B
bookstore (shopping,user,personal,borrowing)
reverse integer
exp 4
Print String in Reverse