코딩 문제31 [LeetCode] 888. Fair Candy Swap, C Solution Get Total Sum of alice and bob candis number Calculate how many candies should be exchanged, to get equal num each other. But this method Runtime too much, only Beats 7.14% in Leet Code. Topics (presented in LeetCode) Hash Table Binary Search Sorting int* fairCandySwap( int* aliceSizes, int aliceSizesSize, int* bobSizes, int bobSizesSize, int* returnSize) { int i = 0; int aliceCandyNum .. 2022. 12. 31. [LeetCode] 1941. Check if All Characters Have Equal Number of Occurrences, C 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[NumOfCha.. 2022. 12. 31. [LeetCode] 383. Ransom Note, C Solution 1 using Hash Map Intuition Declare Hash Map represents charactoer 'a' to 'z' (size 26) Increase Hash Map Index which is in Magazine Note Decrease Hash Map Index which is in ransom Note If one of value in Hash Map under 0, Return false (it means character of Magazine Note doesn't represent ransom Note) When you use index, use should consider ASCII number of 'a' at inital index (97) bool .. 2022. 12. 30. [LeetCode] 876. Middle of the Linked List, C Idea When we need to find median value, index -> we can use this algorithms move two step forward agent, move onstep forward agent per scenario. /** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ struct ListNode* middleNode(struct ListNode* head){ struct ListNode* first = head; struct ListNode* second = head; while(first && first->next) { sec.. 2022. 12. 28. [LeetCode] 1342 Number of Steps to Reduce a Number to Zero, C Solution Simple sequential calculation Other Solution can use binary operation int numberOfSteps(int num) { int step = 0; while (num != 0) { if (num % 2 == 0) { num = num / 2; } else { num -= 1; } ++step; } return step; } 2022. 12. 28. [백준] 체스판 다시 칠하기, 1018, C/C++ 포인트 Brutal Force로 모든 케이스를 계산함 #include typedef signed long int int32_t; typedef char char_t; int32_t GetNeedColorChangeNumber(int32_t s32InitColumnIdx, int32_t s32InitRowIdx, char_t(*parchBadookPan)[50]); int main() { const int32_t s32ChessPanSize = 8; int32_t s32NumOfRow = 0, s32NumOfColumn = 0; char_t archBadookPan[50][50] = { 0 }; int32_t s32NumOfColumnCase = 0, s32NumOfRowCase = 0; int32_t s.. 2022. 11. 29. 이전 1 2 3 4 5 6 다음