1 Star 0 Fork 0

阿狸/rust_leetcode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
915_partition_disjoint.rs 760 Bytes
一键复制 编辑 原始数据 按行查看 历史
wh.huajieyu 提交于 2022-10-24 14:14 . add 915_partition_disjoint
#! /usr/bin/env rust-script
use std::cmp;
struct Solution;
impl Solution {
pub fn partition_disjoint(nums: Vec<i32>) -> i32 {
let n = nums.len();
let mut min_right = vec![nums[n-1]; n];
let mut max = 0;
for i in (0..n-1).rev() {
println!("{},{} ,{}", i, nums[i], min_right[i+1]);
min_right[i] = cmp::min(nums[i], min_right[i+1]);
}
println!("{:?}", min_right);
for i in 0..n {
max = cmp::max(max, nums[i]);
if max <= min_right[i+1] {
return (i+1) as i32;
}
}
-1
}
}
fn main() {
let nums = vec![90,47,69,10,43,92,31,73,61,97];
let ans = Solution::partition_disjoint(nums);
assert_eq!(ans, 3);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/MYAL/rust_leetcode.git
[email protected]:MYAL/rust_leetcode.git
MYAL
rust_leetcode
rust_leetcode
master

搜索帮助