summaryrefslogtreecommitdiff
path: root/find-in-mountain-array/src/main.rs
blob: 4fd6d7cdf65d84557fdaad60342fc05fc04aaa10 (plain)
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
fn main() {
    println!("Hello, world!");
}
/**
 * // This is the MountainArray's API interface.
 * // You should not implement it, or speculate about its implementation
 *  struct MountainArray;
 *  impl MountainArray {
 *     fn get(index:i32)->i32;
 *     fn length()->i32;
 * };
 */

struct MountainArray;

impl MountainArray {
    fn get(self, index:i32)->i32;
    fn length(self)->i32;
};

impl Solution {
    pub fn find_in_mountain_array(target: i32, mountainArr: &MountainArray) -> i32 {
        for i in 0..mountainArr.length() {
            if mountainArr.get(i) == target {return i;}
        }
        -1
    }
}