MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / next_greater

Method next_greater

196-next-greater-element-i.rs:5–16  ·  view source on GitHub ↗
(num: i32, nums2: &[i32])

Source from the content-addressed store, hash-verified

3impl Solution {
4 pub fn next_greater_element(nums1: Vec<i32>, nums2: Vec<i32>) -> Vec<i32> {
5 pub fn next_greater(num: i32, nums2: &[i32]) -> i32 {
6 let mut flag = false;
7 for i in nums2 {
8 if i == &num {
9 flag = true;
10 }
11 if flag == true && i > &num {
12 return *i;
13 }
14 }
15 return -1;
16 }
17 nums1.iter().map(|num|next_greater(*num, &nums2)).collect::<Vec<i32>>()
18 }
19}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected