Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ofoe-fiergbor/7d3cb3c524041eb7ab75a559532f84f2 to your computer and use it in GitHub Desktop.
Save ofoe-fiergbor/7d3cb3c524041eb7ab75a559532f84f2 to your computer and use it in GitHub Desktop.
Cassidoo: parensSubstring
public class ParensSubstring {
public int parensSubstring(String parens) {
Map<Character, Integer> map = new HashMap<>();
for (char paren: parens.toCharArray()) {
map.put(paren, map.getOrDefault(paren, 0) + 1);
}
int result = 0;
for(int value: map.values()) {
result += value % 2 == 0 ? value : value - 1;
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment