当我使用时,for(i=0;i<strlen(s);i++)我收到时间限制超过错误。当我使用for(i=0;s[i]!='\0';i++)我的代码获得成功提交。为什么?
我还提供了来自 codechef 的问题链接 - https://www.codechef.com/problems/LCPESY
类型 1:
for (i = 0; i < strlen(s1); i++) {
f1[s1[i]]++;
}
for (i = 0; i < strlen(s2); i++) {
f2[s2[i]]++;
}
Run Code Online (Sandbox Code Playgroud)
类型 2:
for (i = 0; s1[i] != '\0'; i++) {
f1[s1[i]]++;
}
for (i = 0; s2[i] != '\0'; i++) {
f2[s2[i]]++;
}
Run Code Online (Sandbox Code Playgroud)
完整代码:
#include <stdio.h>
#include <string.h>
long int min(long int a, long int b) {
if (a >= b) …Run Code Online (Sandbox Code Playgroud)