728x90
반응형
Solution
- Simple Count of Max Depth
Time Complexity
O(n)
Space Complexity
O(n)
int maxDpeth(char* s);
int main()
{
char string[] = "(1)+((2))+(((3)))";
int RetVal;
RetVal = maxDpeth(string);
return 0;
}
int maxDpeth(char* s)
{
int Depth = 0;
int MaxDepth = 0;
int NumOfChar = 0;
while (s[NumOfChar] != '\0')
{
if (s[NumOfChar] == '(')
{
++Depth;
}
else if (s[NumOfChar] == ')')
{
--Depth;
}
else
{
// Do Nothing
}
if (Depth > MaxDepth)
{
MaxDepth = Depth;
}
else
{
// Do Nothing
}
++NumOfChar;
}
return MaxDepth;
}
728x90
반응형
'코딩 문제' 카테고리의 다른 글
[LeetCode] 1880. Check if Word Equals Summation of Two Words, C (0) | 2023.01.05 |
---|---|
[LeetCode] 2406. Divide Intervals Into Minimum Number of Groups, C (0) | 2023.01.02 |
[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] 1941. Check if All Characters Have Equal Number of Occurrences, C (0) | 2022.12.31 |