728x90
반응형
Solution
- Use Hash Table
Time Complexity
O(n)
Space Complexity
O(n)
#include <stdbool.h>
bool digitCount(char* pnum);
int main()
{
char string[] = "030";
bool RetVal;
RetVal = digitCount(string);
return 0;
}
bool digitCount(char* pnum)
{
bool bRetVal = true;
const int ASCIINumberInit = 48;
int i = 0;
int NumOfChar = 0;
int arrHashTable[10] = { 0 };
while (pnum[NumOfChar] != '\0')
{
arrHashTable[pnum[NumOfChar] - ASCIINumberInit] += 1;
++NumOfChar;
}
for (i = 0; i != NumOfChar; ++i)
{
if (arrHashTable[i] != (pnum[i] - ASCIINumberInit))
{
bRetVal = false;
break;
}
else
{
// Do Nothing
}
}
return bRetVal;
}
728x90
반응형
'코딩 문제' 카테고리의 다른 글
[LeetCode] 2406. Divide Intervals Into Minimum Number of Groups, C (0) | 2023.01.02 |
---|---|
[LeetCode] 1614. Maximum Nesting Depth of the Parenthesesm, C (0) | 2023.01.01 |
[LeetCode] 888. Fair Candy Swap, C (0) | 2022.12.31 |
[LeetCode] 1941. Check if All Characters Have Equal Number of Occurrences, C (0) | 2022.12.31 |
[LeetCode] 383. Ransom Note, C (0) | 2022.12.30 |