-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
59 lines (51 loc) · 869 Bytes
/
main.go
File metadata and controls
59 lines (51 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import "fmt"
/*
*
*
* this func for is Subsequence
* for two string
*
* args :
* s string
* t string
*
* return value:
* bool
*
*
*/
func isSubsequence(s, t string) bool {
// if length s is zero return true
// empty s alway in t
if len(s) == 0 {
return true
}
// if length t is zero return false
// because nothing can find in empty
if len(t) == 0 {
return false
}
// loop to main string < t >
for i, j := 0, 0; i < len(t); i++ {
// if t[i] is equal s[j]
// go to next string in s[j]
if t[i] == s[j] {
j++
}
// if j equal to len s
// return true
// this show find all
// s string in t!
if j > len(s)-1 {
return true
}
}
// if exit from loop return false
// this show not match or found s in t string
return false
}
func main() {
// very simple test
fmt.Println(isSubsequence("abc", "ahbgdc"))
}