) -> i32 {
-
diff --git a/problems/0309.最佳买卖股票时机含冷冻期.md b/problems/0309.最佳买卖股票时机含冷冻期.md
index 0eb66fb5..9dc35bdf 100644
--- a/problems/0309.最佳买卖股票时机含冷冻期.md
+++ b/problems/0309.最佳买卖股票时机含冷冻期.md
@@ -457,6 +457,40 @@ function maxProfit(prices: number[]): number {
};
```
+### C:
+
+```c
+#define max(a, b) ((a) > (b) ? (a) : (b))
+
+/**
+ * 状态一:持有股票状态(今天买入股票,
+ * 或者是之前就买入了股票然后没有操作,一直持有)
+ * 不持有股票状态,这里就有两种卖出股票状态
+ * 状态二:保持卖出股票的状态(两天前就卖出了股票,度过一天冷冻期。
+ * 或者是前一天就是卖出股票状态,一直没操作)
+ * 状态三:今天卖出股票
+ * 状态四:今天为冷冻期状态,但冷冻期状态不可持续,只有一天!
+
+ */
+int maxProfit(int* prices, int pricesSize) {
+ if(pricesSize == 0){
+ return 0;
+ }
+ int dp[pricesSize][4];
+ memset(dp, 0, sizeof (int ) * pricesSize * 4);
+ dp[0][0] = -prices[0];
+ for (int i = 1; i < pricesSize; ++i) {
+ dp[i][0] = max(dp[i - 1][0], max(dp[i - 1][1] - prices[i], dp[i - 1][3] - prices[i]));
+ dp[i][1] = max(dp[i - 1][1], dp[i - 1][3]);
+ dp[i][2] = dp[i - 1][0] + prices[i];
+ dp[i][3] = dp[i - 1][2];
+ }
+ return max(dp[pricesSize - 1][1], max(dp[pricesSize - 1][2], dp[pricesSize - 1][3]));
+}
+```
+
+
+
### Rust:
```rust
@@ -486,4 +520,3 @@ impl Solution {
-
diff --git a/problems/0322.零钱兑换.md b/problems/0322.零钱兑换.md
index eae4ab3a..156b5ff3 100644
--- a/problems/0322.零钱兑换.md
+++ b/problems/0322.零钱兑换.md
@@ -352,6 +352,35 @@ func min(a, b int) int {
```
+## C
+
+```c
+#define min(a, b) ((a) > (b) ? (b) : (a))
+
+int coinChange(int* coins, int coinsSize, int amount) {
+ int* dp = (int*)malloc(sizeof(int) * (amount + 1));
+ for (int j = 0; j < amount + 1; j++) {
+ dp[j] = INT_MAX;
+ }
+ dp[0] = 0;
+ // 遍历背包
+ for(int i = 0; i <= amount; i++){
+ // 遍历物品
+ for(int j = 0; j < coinsSize; j++){
+ if(i - coins[j] >= 0 && dp[i - coins[j]] != INT_MAX){
+ dp[i] = min(dp[i], dp[i - coins[j]] + 1);
+ }
+ }
+ }
+ if(dp[amount] == INT_MAX){
+ return -1;
+ }
+ return dp[amount];
+}
+```
+
+
+
### Rust:
```rust
@@ -474,4 +503,3 @@ function coinChange(coins: number[], amount: number): number {
-
diff --git a/problems/0337.打家劫舍III.md b/problems/0337.打家劫舍III.md
index f616ec74..61b9f99c 100644
--- a/problems/0337.打家劫舍III.md
+++ b/problems/0337.打家劫舍III.md
@@ -490,6 +490,33 @@ function robNode(node: TreeNode | null): MaxValueArr {
}
```
+### C
+
+```c
+int *robTree(struct TreeNode *node) {
+ int* amounts = (int*) malloc(sizeof(int) * 2);
+ memset(amounts, 0, sizeof(int) * 2);
+ if(node == NULL){
+ return amounts;
+ }
+ int * left = robTree(node->left);
+ int * right = robTree(node->right);
+ // 偷当前节点
+ amounts[1] = node->val + left[0] + right[0];
+ // 不偷当前节点
+ amounts[0] = max(left[0], left[1]) + max(right[0], right[1]);
+ return amounts;
+}
+
+int rob(struct TreeNode* root) {
+ int * dp = robTree(root);
+ // 0代表不偷当前节点可以获得的最大值,1表示偷当前节点可以获取的最大值
+ return max(dp[0], dp[1]);
+}
+```
+
+
+
### Rust
动态规划:
@@ -523,4 +550,3 @@ impl Solution {
-
diff --git a/problems/0377.组合总和Ⅳ.md b/problems/0377.组合总和Ⅳ.md
index a840ec9b..6f81bffe 100644
--- a/problems/0377.组合总和Ⅳ.md
+++ b/problems/0377.组合总和Ⅳ.md
@@ -312,7 +312,28 @@ impl Solution {
}
}
```
+### C
+
+```c
+int combinationSum4(int* nums, int numsSize, int target) {
+ int dp[target + 1];
+ memset(dp, 0, sizeof (dp ));
+ dp[0] = 1;
+ for(int i = 0; i <= target; i++){
+ for(int j = 0; j < numsSize; j++){
+ if(i - nums[j] >= 0 && dp[i] < INT_MAX - dp[i - nums[j]]){
+ dp[i] += dp[i - nums[j]];
+ }
+ }
+ }
+ return dp[target];
+}
+```
+
+
+
### C#
+
```csharp
public class Solution
{
@@ -340,4 +361,3 @@ public class Solution
-
diff --git a/problems/0435.无重叠区间.md b/problems/0435.无重叠区间.md
index cf9996dd..b668e860 100644
--- a/problems/0435.无重叠区间.md
+++ b/problems/0435.无重叠区间.md
@@ -441,7 +441,37 @@ impl Solution {
}
}
```
+### C
+
+```c
+// 按照区间右边界排序
+int cmp(const void * var1, const void * var2){
+ return (*(int **) var1)[1] - (*(int **) var2)[1];
+}
+
+int eraseOverlapIntervals(int** intervals, int intervalsSize, int* intervalsColSize) {
+ if(intervalsSize == 0){
+ return 0;
+ }
+ qsort(intervals, intervalsSize, sizeof (int *), cmp);
+ // 记录非重叠的区间数量
+ int count = 1;
+ // 记录区间分割点
+ int end = intervals[0][1];
+ for(int i = 1; i < intervalsSize; i++){
+ if(end <= intervals[i][0]){
+ end = intervals[i][1];
+ count++;
+ }
+ }
+ return intervalsSize - count;
+}
+```
+
+
+
### C#
+
```csharp
public class Solution
{
@@ -468,3 +498,4 @@ public class Solution
+
diff --git a/problems/0474.一和零.md b/problems/0474.一和零.md
index 904d941e..af50fa5c 100644
--- a/problems/0474.一和零.md
+++ b/problems/0474.一和零.md
@@ -533,7 +533,41 @@ impl Solution {
}
}
```
+## C
+
+```c
+#define max(a, b) ((a) > (b) ? (a) : (b))
+
+int findMaxForm(char** strs, int strsSize, int m, int n) {
+ int dp[m + 1][n + 1];
+ memset(dp, 0, sizeof (int ) * (m + 1) * (n + 1));
+ for(int i = 0; i < strsSize; i++){
+ // 统计0和1的数量
+ int count0 = 0;
+ int count1 = 0;
+ char *str = strs[i];
+ while (*str != '\0'){
+ if(*str == '0'){
+ count0++;
+ } else{
+ count1++;
+ }
+ str++;
+ }
+ for(int j = m; j >= count0; j--){
+ for(int k = n; k >= count1; k--){
+ dp[j][k] = max(dp[j][k], dp[j - count0][k - count1] + 1);
+ }
+ }
+ }
+ return dp[m][n];
+}
+```
+
+
+
### C#
+
```csharp
public class Solution
{
diff --git a/problems/0494.目标和.md b/problems/0494.目标和.md
index e7a05d45..02edad4d 100644
--- a/problems/0494.目标和.md
+++ b/problems/0494.目标和.md
@@ -585,7 +585,44 @@ impl Solution {
}
}
```
+## C
+
+```c
+int getSum(int * nums, int numsSize){
+ int sum = 0;
+ for(int i = 0; i < numsSize; i++){
+ sum += nums[i];
+ }
+ return sum;
+}
+
+int findTargetSumWays(int* nums, int numsSize, int target) {
+ int sum = getSum(nums, numsSize);
+ int diff = sum - target;
+ // 两种情况不满足
+ if(diff < 0 || diff % 2 != 0){
+ return 0;
+ }
+ int bagSize = diff / 2;
+ int dp[numsSize + 1][bagSize + 1];
+ dp[0][0] = 1;
+ for(int i = 1; i <= numsSize; i++){
+ int num = nums[i - 1];
+ for(int j = 0; j <= bagSize; j++){
+ dp[i][j] = dp[i - 1][j];
+ if(j >= num){
+ dp[i][j] += dp[i - 1][j - num];
+ }
+ }
+ }
+ return dp[numsSize][bagSize];
+}
+```
+
+
+
### C#
+
```csharp
public class Solution
{
diff --git a/problems/0518.零钱兑换II.md b/problems/0518.零钱兑换II.md
index da1c4755..59fdf6cd 100644
--- a/problems/0518.零钱兑换II.md
+++ b/problems/0518.零钱兑换II.md
@@ -353,7 +353,28 @@ object Solution {
}
}
```
+## C
+
+```c
+int change(int amount, int* coins, int coinsSize) {
+ int dp[amount + 1];
+ memset(dp, 0, sizeof (dp));
+ dp[0] = 1;
+ // 遍历物品
+ for(int i = 0; i < coinsSize; i++){
+ // 遍历背包
+ for(int j = coins[i]; j <= amount; j++){
+ dp[j] += dp[j - coins[i]];
+ }
+ }
+ return dp[amount];
+}
+```
+
+
+
### C#
+
```csharp
public class Solution
{
@@ -378,3 +399,4 @@ public class Solution
+
diff --git a/problems/0674.最长连续递增序列.md b/problems/0674.最长连续递增序列.md
index 485e321c..ece62944 100644
--- a/problems/0674.最长连续递增序列.md
+++ b/problems/0674.最长连续递增序列.md
@@ -425,6 +425,57 @@ function findLengthOfLCIS(nums: number[]): number {
};
```
+### C:
+
+> 动态规划:
+
+```c
+int findLengthOfLCIS(int* nums, int numsSize) {
+ if(numsSize == 0){
+ return 0;
+ }
+ int dp[numsSize];
+ for(int i = 0; i < numsSize; i++){
+ dp[i] = 1;
+ }
+ int result = 1;
+ for (int i = 1; i < numsSize; ++i) {
+ if(nums[i] > nums[i - 1]){
+ dp[i] = dp[i - 1] + 1;
+ }
+ if(dp[i] > result){
+ result = dp[i];
+ }
+ }
+ return result;
+}
+```
+
+
+
+> 贪心:
+
+```c
+int findLengthOfLCIS(int* nums, int numsSize) {
+ int result = 1;
+ int count = 1;
+ if(numsSize == 0){
+ return result;
+ }
+ for (int i = 1; i < numsSize; ++i) {
+ if(nums[i] > nums[i - 1]){
+ count++;
+ } else{
+ count = 1;
+ }
+ if(count > result){
+ result = count;
+ }
+ }
+ return result;
+}
+```
+
@@ -432,4 +483,3 @@ function findLengthOfLCIS(nums: number[]): number {
-
diff --git a/problems/0714.买卖股票的最佳时机含手续费(动态规划).md b/problems/0714.买卖股票的最佳时机含手续费(动态规划).md
index 7e8e3d7c..88ba9271 100644
--- a/problems/0714.买卖股票的最佳时机含手续费(动态规划).md
+++ b/problems/0714.买卖股票的最佳时机含手续费(动态规划).md
@@ -247,7 +247,29 @@ function maxProfit(prices: number[], fee: number): number {
};
```
+### C:
+
+```c
+#define max(a, b) ((a) > (b) ? (a) : (b))
+
+// dp[i][0] 表示第i天持有股票所省最多现金。
+// dp[i][1] 表示第i天不持有股票所得最多现金
+int maxProfit(int* prices, int pricesSize, int fee) {
+ int dp[pricesSize][2];
+ dp[0][0] = -prices[0];
+ dp[0][1] = 0;
+ for (int i = 1; i < pricesSize; ++i) {
+ dp[i][0] = max(dp[i - 1][0], dp[i - 1][1] - prices[i]);
+ dp[i][1] = max(dp[i - 1][1], dp[i - 1][0] + prices[i] - fee);
+ }
+ return dp[pricesSize - 1][1];
+}
+```
+
+
+
### Rust:
+
**贪心**
```Rust
@@ -304,3 +326,4 @@ impl Solution {
+
diff --git a/problems/0718.最长重复子数组.md b/problems/0718.最长重复子数组.md
index 272cf2b2..e00b3ded 100644
--- a/problems/0718.最长重复子数组.md
+++ b/problems/0718.最长重复子数组.md
@@ -560,10 +560,30 @@ impl Solution {
}
```
+### C:
+
+```c
+int findLength(int* nums1, int nums1Size, int* nums2, int nums2Size) {
+ int dp[nums1Size + 1][nums2Size + 1];
+ memset(dp, 0, sizeof(dp));
+ int result = 0;
+ for (int i = 1; i <= nums1Size; ++i) {
+ for (int j = 1; j <= nums2Size; ++j) {
+ if(nums1[i - 1] == nums2[j - 1]){
+ dp[i][j] = dp[i - 1][j - 1] + 1;
+ }
+ if(dp[i][j] > result){
+ result = dp[i][j];
+ }
+ }
+ }
+ return result;
+}
+```
+
-
diff --git a/problems/0738.单调递增的数字.md b/problems/0738.单调递增的数字.md
index 400dc90d..4a8a6e08 100644
--- a/problems/0738.单调递增的数字.md
+++ b/problems/0738.单调递增的数字.md
@@ -392,7 +392,33 @@ impl Solution {
}
}
```
+### C
+
+```c
+int monotoneIncreasingDigits(int n) {
+ char str[11];
+ // 将数字转换为字符串
+ sprintf(str, "%d", n);
+ int len = strlen(str);
+ int flag = strlen(str);
+ for(int i = len - 1; i > 0; i--){
+ if(str[i] < str[i - 1]){
+ str[i - 1]--;
+ flag = i;
+ }
+ }
+ for(int i = flag; i < len; i++){
+ str[i] = '9';
+ }
+ // 字符串转数字
+ return atoi(str);
+}
+```
+
+
+
### C#
+
```csharp
public class Solution
{
@@ -421,4 +447,3 @@ public class Solution
-
diff --git a/problems/0763.划分字母区间.md b/problems/0763.划分字母区间.md
index 4e9ec578..8b0ca7b8 100644
--- a/problems/0763.划分字母区间.md
+++ b/problems/0763.划分字母区间.md
@@ -404,7 +404,38 @@ impl Solution {
}
}
```
+### C
+
+```c
+#define max(a, b) ((a) > (b) ? (a) : (b))
+
+int* partitionLabels(char* s, int* returnSize) {
+ // 记录每个字符最远出现的位置
+ int last[26] = {0};
+ int len = strlen(s);
+ for (int i = 0; i < len; ++i) {
+ last[s[i] - 'a'] = i;
+ }
+ int left = 0, right = 0;
+ int * partition = malloc(sizeof (int ) * len);
+ // 初始化值
+ *returnSize = 0;
+ for(int i = 0; i < len; i++){
+ right = max(right, last[s[i] - 'a']);
+ // 到达最远位置,加入答案,并且更新左边下标
+ if(i == right){
+ partition[(*returnSize)++] = right - left + 1;
+ left = i + 1;
+ }
+ }
+ return partition;
+}
+```
+
+
+
### C#
+
```csharp
public class Solution
{
@@ -435,4 +466,3 @@ public class Solution
-
diff --git a/problems/1143.最长公共子序列.md b/problems/1143.最长公共子序列.md
index f33391c3..12bd90f8 100644
--- a/problems/1143.最长公共子序列.md
+++ b/problems/1143.最长公共子序列.md
@@ -376,10 +376,32 @@ impl Solution {
}
```
+### C:
+
+```c
+#define max(a, b) ((a) > (b) ? (a) : (b))
+
+int longestCommonSubsequence(char* text1, char* text2) {
+ int text1Len = strlen(text1);
+ int text2Len = strlen(text2);
+ int dp[text1Len + 1][text2Len + 1];
+ memset(dp, 0, sizeof (dp));
+ for (int i = 1; i <= text1Len; ++i) {
+ for (int j = 1; j <= text2Len; ++j) {
+ if(text1[i - 1] == text2[j - 1]){
+ dp[i][j] = dp[i - 1][j - 1] + 1;
+ } else{
+ dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
+ }
+ }
+ }
+ return dp[text1Len][text2Len];
+}
+```
+
-