본문 바로가기

C18

[MATLAB] mex 파일이란 mex 파일이란 MATLAB에서 command line으로 호출 가능한 C 프로그램, 함수를 말한다. 사용 이유 C 언어로 작성된 함수가 다른 언어 대비 low level에서 빠른 수행 시간을 보이므로, High Level Application인 MATLAB에서 빠른 연산을 위해 사용한다. 2023. 6. 27.
[LeetCode] 1880. Check if Word Equals Summation of Two Words, C Solution Use ASCII transformation lower case english letter to integer #include int GetNumericValue(char* ArrWord); bool isSumEqual(char* firstWord, char* secondWord, char* targetWord) { bool RetVal = true; int fisrtWordNumericValue = GetNumericValue(firstWord); int secondWordNumericValue = GetNumericValue(secondWord); int targetWordNumericValue = GetNumericValue(targetWord); if (targetWordNumer.. 2023. 1. 5.
[LeetCode] 2406. Divide Intervals Into Minimum Number of Groups, C Solution - Use qsort(2D array, 2 column) & Greedy Algorithms - Time Limit Exceed int minGroups(int** intervals, int intervalsSize, int* intervalsColsize) { int i = 0; int** RefArr; int RefArrSize = intervalsSize; int** TmpArr; int TmpArrSize = intervalsSize; int NumOfGroup = 0; int StartIndex = 0; int EndIndex = 0; // Sort qsort(intervals, intervalsSize, sizeof(intervals[0]), compare2Darray2Colu.. 2023. 1. 2.
qsort This contents is referenced from here : (https://en.cppreference.com/w/c/algorithm/qsort) There is default qsort() function in c and cpp basic library. If you don't have good function for sorting, qsort is great alternatives. qsort - Sorts elements of given array point in ascending order void qsort(void *ptr, size_t count, size_t size, int (*comp)(const void *, const void *) ); parameters ptr - .. 2023. 1. 2.
[LeetCode] 1614. Maximum Nesting Depth of the Parenthesesm, C 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 {.. 2023. 1. 1.
[LeetCode] 2283. Check if Number Has Equal Digit Count and Digit Value, C Solution - Use Hash Table Time Complexity O(n) Space Complexity O(n) #include 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[NumOfC.. 2023. 1. 1.