We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Is it necessary to check if value > 0 or we can just add it to totalCount? If we add 0 to totalCount nothing changes and all tests passed. But I'm not sure which option is more complex.
I'm talking about code like that:
int value = map.getOrDefault(currentSubString, 0);
totalCount += value;
map.put(currentSubString, ++value);
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and Anagrams
You are viewing a single comment's thread. Return to all comments →
Is it necessary to check if value > 0 or we can just add it to totalCount? If we add 0 to totalCount nothing changes and all tests passed. But I'm not sure which option is more complex.
I'm talking about code like that: