Compare commits
3 Commits
36c5339b1f
...
e862aea336
| Author | SHA1 | Date | |
|---|---|---|---|
| e862aea336 | |||
| e580f911cb | |||
| 727096b8e6 |
16
include/solution/1025.h
Normal file
16
include/solution/1025.h
Normal file
@@ -0,0 +1,16 @@
|
||||
// This file is generated by mkfile.py
|
||||
// Date: 2025-12-05
|
||||
|
||||
#ifndef INC_1025_H
|
||||
#define INC_1025_H
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
bool divisorGame(int n);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // INC_1025_H
|
||||
14
include/solution/1668.h
Normal file
14
include/solution/1668.h
Normal file
@@ -0,0 +1,14 @@
|
||||
// This file is generated by mkfile.py
|
||||
// Date: 2025-12-05
|
||||
|
||||
#ifndef INC_1668_H
|
||||
#define INC_1668_H
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
int maxRepeating(char *sequence, char *word);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // INC_1668_H
|
||||
14
include/solution/509.h
Normal file
14
include/solution/509.h
Normal file
@@ -0,0 +1,14 @@
|
||||
// This file is generated by mkfile.py
|
||||
// Date: 2025-12-05
|
||||
|
||||
#ifndef INC_509_H
|
||||
#define INC_509_H
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
int fib(int n);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // INC_509_H
|
||||
7
src/1025.c
Normal file
7
src/1025.c
Normal file
@@ -0,0 +1,7 @@
|
||||
// This file is generated by mkfile.py
|
||||
// Date: 2025-12-05
|
||||
#include <solution/1025.h>
|
||||
bool divisorGame(int n)
|
||||
{
|
||||
return n % 2 == 0;
|
||||
}
|
||||
37
src/1668.c
Normal file
37
src/1668.c
Normal file
@@ -0,0 +1,37 @@
|
||||
// This file is generated by mkfile.py
|
||||
// Date: 2025-12-05
|
||||
|
||||
#include <solution/1668.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#define max(x, y) ((x) > (y) ? (x) : (y))
|
||||
|
||||
int maxRepeating(char *sequence, char *word)
|
||||
{
|
||||
int n = strlen(sequence), m = strlen(word);
|
||||
if (n < m)
|
||||
return 0;
|
||||
|
||||
int dp[n];
|
||||
for (int i = m - 1; i < n; i++)
|
||||
{
|
||||
bool valid = true;
|
||||
for (int j = 0; j < m; j++)
|
||||
{
|
||||
if (sequence[i - m + 1] != word[j])
|
||||
{
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (valid)
|
||||
dp[i] = (i == m - 1 ? 0 : dp[i - m] + 1);
|
||||
}
|
||||
|
||||
int ret = dp[0];
|
||||
for (int i = 1; i < n; i++)
|
||||
ret = max(ret, dp[i]);
|
||||
|
||||
return ret;
|
||||
}
|
||||
14
src/509.c
Normal file
14
src/509.c
Normal file
@@ -0,0 +1,14 @@
|
||||
// This file is generated by mkfile.py
|
||||
// Date: 2025-12-05
|
||||
|
||||
#include <solution/509.h>
|
||||
int fib(int n)
|
||||
{
|
||||
int dp[n + 1];
|
||||
dp[0] = 0;
|
||||
if (n >= 1)
|
||||
dp[1] = 1;
|
||||
for (int i = 2; i <= n; i++)
|
||||
dp[i] = dp[i - 1] + dp[i - 2];
|
||||
return dp[n];
|
||||
}
|
||||
45
tests/test_1025.cpp
Normal file
45
tests/test_1025.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
// This file is generated by mkfile.py
|
||||
// Date: 2025-12-05
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <solution/1025.h>
|
||||
|
||||
// Tests for divisorGame (LeetCode 1025)
|
||||
class DivisorGameTest : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
void AssertDivisorGame(int n, bool expected)
|
||||
{
|
||||
ASSERT_EQ(divisorGame(n), expected);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(DivisorGameTest, One)
|
||||
{
|
||||
AssertDivisorGame(1, false);
|
||||
}
|
||||
|
||||
TEST_F(DivisorGameTest, Two)
|
||||
{
|
||||
AssertDivisorGame(2, true);
|
||||
}
|
||||
|
||||
TEST_F(DivisorGameTest, Three)
|
||||
{
|
||||
AssertDivisorGame(3, false);
|
||||
}
|
||||
|
||||
TEST_F(DivisorGameTest, Four)
|
||||
{
|
||||
AssertDivisorGame(4, true);
|
||||
}
|
||||
|
||||
TEST_F(DivisorGameTest, LargeEven)
|
||||
{
|
||||
AssertDivisorGame(100, true);
|
||||
}
|
||||
|
||||
TEST_F(DivisorGameTest, LargeOdd)
|
||||
{
|
||||
AssertDivisorGame(101, false);
|
||||
}
|
||||
49
tests/test_1668.cpp
Normal file
49
tests/test_1668.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
// This file is generated by mkfile.py
|
||||
// Date: 2025-12-05
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <solution/1668.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
// Tests for maxRepeating (LeetCode 1668)
|
||||
class MaxRepeatingTest : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
void AssertMaxRepeating(const std::string &sequence, const std::string &word, int expected)
|
||||
{
|
||||
int result = maxRepeating(const_cast<char *>(sequence.c_str()), const_cast<char *>(word.c_str()));
|
||||
ASSERT_EQ(result, expected);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(MaxRepeatingTest, Example1)
|
||||
{
|
||||
AssertMaxRepeating("ababc", "ab", 2);
|
||||
}
|
||||
|
||||
TEST_F(MaxRepeatingTest, Example2)
|
||||
{
|
||||
AssertMaxRepeating("ababc", "ba", 1);
|
||||
}
|
||||
|
||||
TEST_F(MaxRepeatingTest, RepeatedMany)
|
||||
{
|
||||
AssertMaxRepeating("abababab", "ab", 4);
|
||||
}
|
||||
|
||||
TEST_F(MaxRepeatingTest, OverlappingNotAllowed)
|
||||
{
|
||||
// word = "aa", repeated twice is "aaaa" which appears, so answer 2
|
||||
AssertMaxRepeating("aaaaa", "aa", 2);
|
||||
}
|
||||
|
||||
TEST_F(MaxRepeatingTest, ShorterThanWord)
|
||||
{
|
||||
AssertMaxRepeating("a", "aa", 0);
|
||||
}
|
||||
|
||||
TEST_F(MaxRepeatingTest, SingleCharWord)
|
||||
{
|
||||
AssertMaxRepeating("aaaa", "a", 4);
|
||||
}
|
||||
39
tests/test_509.cpp
Normal file
39
tests/test_509.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
// This file is generated by mkfile.py
|
||||
// Date: 2025-12-05
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <solution/509.h>
|
||||
// Tests for fib (LeetCode 509)
|
||||
class FibTest : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
void AssertFib(int n, int expected)
|
||||
{
|
||||
ASSERT_EQ(fib(n), expected);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(FibTest, Zero)
|
||||
{
|
||||
AssertFib(0, 0);
|
||||
}
|
||||
|
||||
TEST_F(FibTest, One)
|
||||
{
|
||||
AssertFib(1, 1);
|
||||
}
|
||||
|
||||
TEST_F(FibTest, Two)
|
||||
{
|
||||
AssertFib(2, 1);
|
||||
}
|
||||
|
||||
TEST_F(FibTest, Ten)
|
||||
{
|
||||
AssertFib(10, 55);
|
||||
}
|
||||
|
||||
TEST_F(FibTest, Twenty)
|
||||
{
|
||||
AssertFib(20, 6765);
|
||||
}
|
||||
Reference in New Issue
Block a user