728x90
반응형
Solution
- Use Hash Map
- Compare Counting Number of each Character (except 0 occurence character)
#define NumOfLowerCaseEnglishLetter 26
#define ASCII_INIT_NUM_IDX 97
bool areOccurrencesEqual(char* s) {
long int NumOfChar = 0;
int RefNum = 0;
int arr[NumOfLowerCaseEnglishLetter] = { 0 }; // consists of lowercase English letters
bool RetVal = true;
while (s[NumOfChar] != '\0')
{
++arr[s[NumOfChar] - NumOfLowerCaseEnglishLetter];
++NumOfChar;
}
for (long int i = 0; i != NumOfLowerCaseEnglishLetter; ++i)
{
if (RefNum == 0 && arr[i] != 0)
{
RefNum = arr[i];
}
else if (RefNum != 0 && arr[i] != 0)
{
if (RefNum != arr[i])
{
RetVal = false;
}
else
{
// Do Nothing
}
}
}
return RetVal;
}
728x90
반응형
'코딩 문제' 카테고리의 다른 글
[LeetCode] 2283. Check if Number Has Equal Digit Count and Digit Value, C (0) | 2023.01.01 |
---|---|
[LeetCode] 888. Fair Candy Swap, C (0) | 2022.12.31 |
[LeetCode] 383. Ransom Note, C (0) | 2022.12.30 |
[LeetCode] 876. Middle of the Linked List, C (0) | 2022.12.28 |
[LeetCode] 1342 Number of Steps to Reduce a Number to Zero, C (0) | 2022.12.28 |