summaryrefslogtreecommitdiff
path: root/rust/src/bin/p0028.rs
blob: c830ac4de9252a7fd6d525279dd1a1685ed47722 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
impl Solution {
    pub fn str_str(haystack: String, needle: String) -> i32 {
        if needle.len() > haystack.len() { return -1; }
        for i in 0..haystack.len() - needle.len()+1 {
            let mut failed = false;
            for j in 0..needle.len() {
                if haystack.as_bytes()[i+j] != needle.as_bytes()[j] {
                    failed = true;
                    break;
                }
            }
            if !failed { return i as i32; }
        }
        -1
    }
}
struct Solution { }
fn main() {
    println!("{}", Solution::str_str("abaaa".to_string(), "abb".to_string()));
}