mirror of
https://git.wolves.top/wolves/leetcode.git
synced 2025-11-04 17:26:32 +08:00
init
This commit is contained in:
39
24/06/520.c
Normal file
39
24/06/520.c
Normal file
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// Created by 李洋 on 2024/6/23.
|
||||
//
|
||||
|
||||
#ifndef LEETCODE_C_520_CPP
|
||||
#define LEETCODE_C_520_CPP
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "ctype.h"
|
||||
#include "stdbool.h"
|
||||
#include "string.h"
|
||||
|
||||
char *toLowerCase(const char *str) {
|
||||
char *result = (char *) malloc(sizeof(char) * strlen(str));
|
||||
for (int i = 0; i < strlen(str); i++) {
|
||||
result[i]= tolower(str[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// 通过数值判断
|
||||
bool detectCapitalUse(char *word) {
|
||||
char *lower = toLowerCase(word);
|
||||
int count = 0;
|
||||
for (int i = 0; i < strlen(word); ++i) {
|
||||
count += lower[i] - word[i];
|
||||
}
|
||||
int interval = 'a' - 'A';
|
||||
if ((count == interval && word[0] >= 'A' && word[0] <= 'Z') || count == interval * strlen(word) || count == 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run() {
|
||||
return detectCapitalUse("USA");
|
||||
}
|
||||
|
||||
#endif //LEETCODE_C_520_CPP
|
||||
30
24/06/LCP61.h
Normal file
30
24/06/LCP61.h
Normal file
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// Created by 李洋 on 2024/6/21.
|
||||
//
|
||||
|
||||
#ifndef LEETCODE_C_LCP61_H
|
||||
#define LEETCODE_C_LCP61_H
|
||||
|
||||
# include <math.h>
|
||||
|
||||
int getTemper(int *temperA, int i) {
|
||||
if (temperA[i + 1] == temperA[i]) {
|
||||
return 0;
|
||||
}
|
||||
return temperA[i + 1] < temperA[i] ? -1 : 1;
|
||||
}
|
||||
|
||||
int temperatureTrend(int *temperatureA, int temperatureASize, int *temperatureB, int temperatureBSize) {
|
||||
int ans = 0, count = 0;
|
||||
for (int i = 0; i+1 < temperatureASize; ++i) {
|
||||
int a = getTemper(temperatureA, i);
|
||||
int b = getTemper(temperatureB, i);
|
||||
if (a == b) {
|
||||
count++;
|
||||
ans = fmax(ans, count);
|
||||
} else count = 0;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
#endif //LEETCODE_C_LCP61_H
|
||||
Reference in New Issue
Block a user