Created
January 31, 2021 08:36
-
-
Save aryan-dixit-26/fc35fea7e807660dfb5de98a8e4c8c43 to your computer and use it in GitHub Desktop.
Answer : 3
Answer : 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.HashMap; | |
import java.util.Map; | |
class Duplicates { | |
public static Map<Character, Integer> countDuplicateCharacters(String string) { | |
var resultMap = new HashMap<Character, Integer>(); | |
for (int i = 0; i < string.length(); i++) { | |
int c = 0; | |
if(!Character.isWhitespace(string.charAt(i))) | |
{ | |
if(resultMap.get(string.charAt(i)) == null) | |
{ | |
resultMap.put(string.charAt(i),1); | |
} | |
else { | |
int x = 0; | |
x = resultMap.get(string.charAt(i)); | |
resultMap.put(string.charAt(i), x + 1); | |
} | |
} | |
} | |
return resultMap; | |
} | |
public static void main(String[] args) { | |
String message = "Competitive Programming Can Be A Little Bit Tricky!"; | |
System.out.println(countDuplicateCharacters(message)); | |
} | |
} | |
//Aryan Dixit | |
//191500156 | |
// G - 35 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment