Compare commits
14 Commits
dc222231e6
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 6e2206cabe | |||
| 89a41445ef | |||
| cdb5602c47 | |||
| 3559f83475 | |||
| 6f30721f1b | |||
| 9a8260a3b6 | |||
| fc2fd50bac | |||
| aa3f652a8f | |||
| b6a1850f48 | |||
| 737c8e17dd | |||
| 2cf5db11bd | |||
| 7ae0aeb744 | |||
| cf633352b5 | |||
| 45162bb934 |
36
.gitea/workflows/test.yaml
Normal file
36
.gitea/workflows/test.yaml
Normal file
@@ -0,0 +1,36 @@
|
||||
name: Gitea CTest Workflow
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main", "master" ]
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
run: |
|
||||
git clone https://cantyonion.site/git/cantyonion/leetcode.git .
|
||||
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
sudo sed -i 's@//.*archive.ubuntu.com@//mirrors.ustc.edu.cn@g' /etc/apt/sources.list.d/ubuntu.sources
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y build-essential cmake
|
||||
|
||||
- name: Configure CMake
|
||||
# -B build 创建构建目录,-S . 指定源代码在当前目录
|
||||
run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
|
||||
|
||||
- name: Build with CMake
|
||||
# 使用 --parallel 充分利用 Runner 核心数
|
||||
run: cmake --build build --parallel $(nproc)
|
||||
|
||||
- name: Run CTest via CMake
|
||||
# 在 build 目录下运行 ctest
|
||||
# --output-on-failure 可以在测试失败时直接看到 log
|
||||
run: |
|
||||
cd build
|
||||
ctest --output-on-failure --parallel $(nproc)
|
||||
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.30)
|
||||
cmake_minimum_required(VERSION 3.25)
|
||||
project(leetcode C CXX)
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
@@ -7,6 +7,10 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
set(GTEST_VERSION 1.17.0)
|
||||
enable_testing()
|
||||
|
||||
if (MSVC)
|
||||
message(FATAL_ERROR "MSVC is not supported. Please use GCC or Clang.")
|
||||
endif ()
|
||||
|
||||
include_directories(include)
|
||||
|
||||
include(FetchContent)
|
||||
@@ -14,9 +18,6 @@ include(FetchContent)
|
||||
add_compile_options(
|
||||
-Wall
|
||||
-Wextra
|
||||
-O0
|
||||
-g3
|
||||
-fno-omit-frame-pointer
|
||||
)
|
||||
|
||||
if (UNIX)
|
||||
|
||||
14
include/solution/1137.h
Normal file
14
include/solution/1137.h
Normal file
@@ -0,0 +1,14 @@
|
||||
// This file is generated by mkfile.py
|
||||
// Date: 2025-12-05
|
||||
|
||||
#ifndef INC_1137_H
|
||||
#define INC_1137_H
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
int tribonacci(int n);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // INC_1137_H
|
||||
17
src/1137.c
Normal file
17
src/1137.c
Normal file
@@ -0,0 +1,17 @@
|
||||
// This file is generated by mkfile.py
|
||||
// Date: 2025-12-05
|
||||
|
||||
#include <solution/1137.h>
|
||||
int tribonacci(int n)
|
||||
{
|
||||
int dp[n + 1];
|
||||
dp[0] = 0;
|
||||
if (n >= 1)
|
||||
dp[1] = 1;
|
||||
if (n >= 2)
|
||||
dp[2] = 1;
|
||||
for (int i = 3; i <= n; i++)
|
||||
dp[i] = dp[i - 3] + dp[i - 2] + dp[i - 1];
|
||||
|
||||
return dp[n];
|
||||
}
|
||||
@@ -14,19 +14,20 @@ int maxRepeating(char *sequence, char *word)
|
||||
return 0;
|
||||
|
||||
int dp[n];
|
||||
memset(dp, 0, sizeof(dp));
|
||||
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])
|
||||
if (sequence[i - m + 1 + j] != word[j])
|
||||
{
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (valid)
|
||||
dp[i] = (i == m - 1 ? 0 : dp[i - m] + 1);
|
||||
dp[i] = (i == m - 1 ? 0 : dp[i - m]) + 1;
|
||||
}
|
||||
|
||||
int ret = dp[0];
|
||||
|
||||
41
tests/test_1137.cpp
Normal file
41
tests/test_1137.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
// This file is generated by mkfile.py
|
||||
// Date: 2025-12-05
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <solution/1137.h>
|
||||
|
||||
// Tests for tribonacci (LeetCode 1137)
|
||||
class TribonacciTest : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
void AssertTribo(int n, int expected)
|
||||
{
|
||||
ASSERT_EQ(tribonacci(n), expected);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(TribonacciTest, BaseCases)
|
||||
{
|
||||
AssertTribo(0, 0);
|
||||
AssertTribo(1, 1);
|
||||
AssertTribo(2, 1);
|
||||
}
|
||||
|
||||
TEST_F(TribonacciTest, SmallNumbers)
|
||||
{
|
||||
AssertTribo(3, 2);
|
||||
AssertTribo(4, 4);
|
||||
AssertTribo(5, 7);
|
||||
}
|
||||
|
||||
TEST_F(TribonacciTest, MediumNumbers)
|
||||
{
|
||||
AssertTribo(10, 149);
|
||||
AssertTribo(15, 3136);
|
||||
}
|
||||
|
||||
TEST_F(TribonacciTest, UpperBound)
|
||||
{
|
||||
AssertTribo(25, 1389537);
|
||||
AssertTribo(37, 2082876103);
|
||||
}
|
||||
Reference in New Issue
Block a user