665. Non-decreasing Array Medium
1/**
2 * [665] Non-decreasing Array
3 *
4 * Given an array nums with n integers, your task is to check if it could become non-decreasing by modifying at most one element.
5 * We define an array is non-decreasing if nums[i] <= nums[i + 1] holds for every i (0-based) such that (0 <= i <= n - 2).
6 *
7 * Example 1:
8 *
9 * Input: nums = [4,2,3]
10 * Output: true
11 * Explanation: You could modify the first 4 to 1 to get a non-decreasing array.
12 *
13 * Example 2:
14 *
15 * Input: nums = [4,2,1]
16 * Output: false
17 * Explanation: You cannot get a non-decreasing array by modifying at most one element.
18 *
19 *
20 * Constraints:
21 *
22 * n == nums.length
23 * 1 <= n <= 10^4
24 * -10^5 <= nums[i] <= 10^5
25 *
26 */
27pub struct Solution {}
28
29// problem: https://leetcode.com/problems/non-decreasing-array/
30// discuss: https://leetcode.com/problems/non-decreasing-array/discuss/?currentPage=1&orderBy=most_votes&query=
31
32// submission codes start here
33
34impl Solution {
35 pub fn check_possibility(nums: Vec<i32>) -> bool {
36 false
37 }
38}
39
40// submission codes end
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45
46 #[test]
47 fn test_665() {
48 }
49}
50
Back
© 2025 bowen.ge All Rights Reserved.