Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c68e95a

Browse files
AC 392
1 parent 40a68aa commit c68e95a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

‎c/300-399/392-is-subsequence.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (C) 2022, Saul Lawliet <october dot sunbathe at gmail dot com>
3+
* All rights reserved.
4+
*
5+
* 双指针往前跑即可
6+
* PS: Copilot 真的猛, 在函数内直接补全了, 试试看的态度提交到 leetcode 上, 竟然 AC 了, 当然最后把代码删掉重写的.
7+
*/
8+
9+
#include <stdbool.h>
10+
#include "c/test.h"
11+
12+
bool isSubsequence(char *s, char *t) {
13+
while (*s != '0円' && *t != '0円') {
14+
if (*s == *t) s++;
15+
t++;
16+
}
17+
return *s == '0円';
18+
}
19+
20+
void test(bool expect, char *s, char *t) {
21+
EXPECT_EQ_INT(expect, isSubsequence(s, t));
22+
}
23+
24+
int main(void) {
25+
test(true, "abc", "ahbgdc");
26+
test(false, "axc", "ahbgdc");
27+
28+
return testOutput();
29+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /