Compare commits
2 Commits
7619dbdaaa
...
aabf07d9ec
Author | SHA1 | Date | |
---|---|---|---|
aabf07d9ec | |||
33a8c8b586 |
@ -13,15 +13,19 @@ add_compile_options(
|
|||||||
-Wextra
|
-Wextra
|
||||||
-O0
|
-O0
|
||||||
-g3
|
-g3
|
||||||
-fsanitize=address
|
|
||||||
-fsanitize=undefined
|
|
||||||
-fno-omit-frame-pointer
|
-fno-omit-frame-pointer
|
||||||
)
|
)
|
||||||
|
|
||||||
add_link_options(
|
if (UNIX)
|
||||||
-fsanitize=address
|
add_compile_options(
|
||||||
-fsanitize=undefined
|
-fsanitize=address
|
||||||
)
|
-fsanitize=undefined
|
||||||
|
)
|
||||||
|
add_link_options(
|
||||||
|
-fsanitize=address
|
||||||
|
-fsanitize=undefined
|
||||||
|
)
|
||||||
|
endif ()
|
||||||
|
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
googletest
|
googletest
|
||||||
|
25
src/119.c
Normal file
25
src/119.c
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Note: The returned array must be malloced, assume caller calls free().
|
||||||
|
*/
|
||||||
|
int *getRow(int rowIndex, int *returnSize)
|
||||||
|
{
|
||||||
|
int *ret = NULL;
|
||||||
|
|
||||||
|
*returnSize = sizeof(int) * rowIndex + 1;
|
||||||
|
ret = (int *)malloc(*returnSize);
|
||||||
|
|
||||||
|
if (rowIndex == 0)
|
||||||
|
ret[0] = 1;
|
||||||
|
else if (rowIndex == 1)
|
||||||
|
ret[0] = ret[1] = 1;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
}
|
38
src/168.c
Normal file
38
src/168.c
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
char *convertToTitle(int columnNumber)
|
||||||
|
{
|
||||||
|
char *ret = malloc(2);
|
||||||
|
int size = 1;
|
||||||
|
|
||||||
|
while (columnNumber > 0)
|
||||||
|
{
|
||||||
|
columnNumber--;
|
||||||
|
const int mod = columnNumber % 26;
|
||||||
|
columnNumber /= 26;
|
||||||
|
ret[size - 1] = 'A' + mod;
|
||||||
|
|
||||||
|
size++;
|
||||||
|
ret = realloc(ret, size + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret[size - 1] = '\0';
|
||||||
|
|
||||||
|
for (int i = 0, j = size - 2; i < j; i++, j--)
|
||||||
|
{
|
||||||
|
const char tmp = ret[i];
|
||||||
|
ret[i] = ret[j];
|
||||||
|
ret[j] = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
char *ans = convertToTitle(2147483647);
|
||||||
|
printf("%s\n", ans);
|
||||||
|
free(ans);
|
||||||
|
return 0;
|
||||||
|
}
|
32
src/219.c
Normal file
32
src/219.c
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
//
|
||||||
|
// Created by xfj12 on 2025/3/24.
|
||||||
|
//
|
||||||
|
#include <assert.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
bool containsNearbyDuplicate(int *nums, int numsSize, int k)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < numsSize; i++)
|
||||||
|
{
|
||||||
|
for (int j = i; j < numsSize; j++)
|
||||||
|
{
|
||||||
|
if (abs(i - j) > k)
|
||||||
|
continue;
|
||||||
|
if (nums[i] == nums[j] && i != j)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int nums1[] = {1, 2, 3, 1};
|
||||||
|
assert(containsNearbyDuplicate(nums1, sizeof(nums1) / sizeof(int), 3) == true);
|
||||||
|
int nums2[] = {1, 0, 1, 1};
|
||||||
|
assert(containsNearbyDuplicate(nums2, sizeof(nums2) / sizeof(int), 1) == true);
|
||||||
|
int nums3[] = {1, 2, 3, 1, 2, 3};
|
||||||
|
assert(containsNearbyDuplicate(nums3, sizeof(nums3) / sizeof(int), 2) == false);
|
||||||
|
}
|
15
src/258.c
Normal file
15
src/258.c
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
//
|
||||||
|
// Created by xfj12 on 2025/3/24.
|
||||||
|
//
|
||||||
|
int addDigits(int num)
|
||||||
|
{
|
||||||
|
int total = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
|
||||||
|
} while ();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
}
|
21
src/3110.c
Normal file
21
src/3110.c
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#include <assert.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <string.h>
|
||||||
|
//
|
||||||
|
// Created by xfj12 on 2025/3/24.
|
||||||
|
//
|
||||||
|
|
||||||
|
int scoreOfString(char *s)
|
||||||
|
{
|
||||||
|
int score = 0;
|
||||||
|
for (int i = 0; i < strlen(s) - 1; i++)
|
||||||
|
score += abs(s[i] - s[i + 1]);
|
||||||
|
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
assert(scoreOfString("hello") == 13);
|
||||||
|
assert(scoreOfString("zaz") == 50);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user