【Leetcode_easy】665. Non-decreasing Array
problem
题意:是否能够将数组转换为非减数组。
solution:
难点在于理解如何对需要修改的元素进行赋值;
class Solution {
public:
bool checkPossibility(vector<int>& nums) {
int cnt = , n = nums.size();
for(int i=; i<n; i++)
{
if(nums[i] < nums[i-])
{
if(cnt==) return false;
if(i== || nums[i-] <= nums[i]) nums[i-] = nums[i];//err..
else nums[i] = nums[i-];//err.
cnt--;
}
}
return true;
}
};
参考
1. Leetcode_easy_665. Non-decreasing Array;
完
【Leetcode_easy】665. Non-decreasing Array的更多相关文章
- 【Leetcode_easy】941. Valid Mountain Array
problem 941. Valid Mountain Array solution: class Solution { public: bool validMountainArray(vector& ...
- 【Leetcode_easy】1122. Relative Sort Array
problem 1122. Relative Sort Array 参考 1. Leetcode_easy_1122. Relative Sort Array; 2. helloacm; 完
- 【转】python之模块array
[转]python之模块array >>> import array#定义了一种序列数据结构 >>> help(array) #创建数组,相当于初始化一个数组,如: ...
- 【题解】[CF718C Sasha and Array]
[题解]CF718C Sasha and Array 对于我这种喜欢写结构体封装起来的选手这道题真是太对胃了\(hhh\) 一句话题解:直接开一颗线段树的矩阵然后暴力维护还要卡卡常数 我们来把\(2 ...
- 【LeetCode】数组-6(561)-Array Partition I(比较抽象的题目)
题目描述:两句话发人深思啊.... Given an array of 2n integers, your task is to group these integers into n pairs o ...
- 【VBA】利用Range声明Array(一维/二维)
[说明] B2开始到B?(中间不能有空格),定义一维数组Arr_approver() Dim R_sh As Worksheet Set R_sh = ThisWorkbook.Sheets(&quo ...
- 【LeetCode】665. 非递减数列 Non-decreasing Array(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 公众号:每日算法题 本文关键词:数组,array,非递减,遍历,python,C++ 目录 题目描述 题目大意 解题方法 一.错误代码 二.举例分析 ...
- 【Leetcode_easy】977. Squares of a Sorted Array
problem 977. Squares of a Sorted Array solution: class Solution { public: vector<int> sortedSq ...
- 【Leetcode_easy】961. N-Repeated Element in Size 2N Array
problem 961. N-Repeated Element in Size 2N Array solution: class Solution { public: int repeatedNTim ...
随机推荐
- python类内置方法之__call__
在python中自定义类时,如果该类实现了一个特殊方法__call__(),那么该类的实例则变成一个可调用的实例对象 如下 In [1]: class A():# 自定义一个A ...: def __ ...
- [Angular] Lazy Load CSS at runtime with the Angular CLI
Ever had the need for multiple "app themes", or even to completely dynamically load CSS ba ...
- jquery 使用off移除事件 使用one绑定一次事件,on绑定事件后触发多次相同的事件的异常
<!-- jquery 移除事件,绑定一次事件,搜狗 one --> <!DOCTYPE html> <html lang="en"> < ...
- python 装饰器之应用示例
import time import hashlib import pickle import threading #装饰函数缓存应用 cache ={} def is_obsolete(entry, ...
- sql server 存储过程中,调用事务 tran
Sql Server 2005/2008中提供了begin tran,commit tran和rollback tran来使用事务. begin tran表示开始事务, commit tran表示 ...
- Linux分区格式化
格式化(format)是指对磁盘或磁盘中的分区(partition)进行初始化的一种操作,这种操作通常会导致现有的磁盘或分区中所有的文件被清除.格式化通常分为低级格式化和高级格式化.如果没有特别指明, ...
- dp * 3
cf 467 C 从序列中选出 \(k\) 段连续的 \(m\) 个数 最大化总和 \(f_{i, j}\) 表示前 \(i\) 个位置中选出了 \(j\) 段 转移显然 #include <b ...
- fgetc,getc,fputc,putc,putchar,getchar
转自 http://blog.csdn.net/todd911/article/details/8952565 输入输出函数家族 家族名 目的 ...
- jquery validate 表单验证插件 代码
/* 表单验证 */ var signupFormValidator = $("#signupForm").validate({ /* 自定义验证规则 */ rules : { o ...
- CF1174D Ehab and the Expected XOR Problem(二进制)
做法 求出答案序列的异或前缀和\(sum_i\),\([l,r]\)子段异或和可表示为\(sum_r\bigoplus sum_{l-1}\) 故转换问题为,填\(sum\)数组,数组内的元素不为\( ...