From 4b0a6a01b051a4ebfbc17661d14cb23fe4f275fb Mon Sep 17 00:00:00 2001 From: Orangerot Date: Thu, 27 Jun 2024 11:30:16 +0200 Subject: Initial commit --- find-in-mountain-array/src/main.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 find-in-mountain-array/src/main.rs (limited to 'find-in-mountain-array/src') diff --git a/find-in-mountain-array/src/main.rs b/find-in-mountain-array/src/main.rs new file mode 100644 index 0000000..4fd6d7c --- /dev/null +++ b/find-in-mountain-array/src/main.rs @@ -0,0 +1,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 + } +} -- cgit v1.2.3