【Leetcode_easy】1089. Duplicate Zeros
problem
题意:
solution: 其中关于虚拟新数组的下标的计算还是有点迷糊。。。
class Solution {
public:
void duplicateZeros(vector<int>& arr) {
int n = arr.size();
int m = n + count(arr.begin(), arr.end(), );
for(int i=n-; i>=; i--)
{
if((--m) <n) //err....
{
arr[m] = arr[i];
}
if(arr[i]== && (--m) <n) //errr...
{
arr[m] = ;
}
}
}
};
参考
1. Leetcode_easy_1089. Duplicate Zeros;
2. discuss;
完
【Leetcode_easy】1089. Duplicate Zeros的更多相关文章
- 【leetcode】1089. Duplicate Zeros
题目如下: Given a fixed length array arr of integers, duplicate each occurrence of zero, shifting the re ...
- 【原创】<Debug> “duplicate connection name”
[Problem] duplicate connection name [Solution] 在Qt上使用SQLite的时候,如果第二次使用QSqlDatabase::addDatabase()方式时 ...
- 【51NOD-0】1089 最长回文子串 V2(Manacher算法)
[算法]回文树 #include<cstdio> #include<algorithm> #include<cstring> using namespace std ...
- 【axc】关于duplicate symbols for architecture x86_64错误的第三种可能及其解决办法
今天分析一下duplicate symbols for architecture x86_64错误 也是困扰我一段时间 不过很幸运 在半个小时内找到了解决方案 百度上对于duplicate sy ...
- 【转】XCode: duplicate symbol 解决方案
遇到引用库重复定义的问题,需要解决. 项目需要,同时引用ZBar和QQ授权登录SDK,由于二者均使用了Base64处理数据,XCode编译时报错: duplicate symbol _base64_e ...
- 【BZOJ】1089: [SCOI2003]严格n元树(递推+高精度/fft)
http://www.lydsy.com/JudgeOnline/problem.php?id=1089 题意:求深度为d的n元树数目.(0<n<=32, 0<=d<=16) ...
- 【leetcode】Contains Duplicate & Rectangle Area(easy)
Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your funct ...
- leetcode【sql】 Delete Duplicate Emails
Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...
- 【SQL】182. Duplicate Emails
Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...
随机推荐
- Django中出现:TemplateDoesNotExist at
setting文件中加入:
- python - scrapy 爬虫框架 ( redis去重 )
1. 使用内置,并加以修改 ( 自定义 redis 存储的 keys ) settings 配置 # ############### scrapy redis连接 ################# ...
- java前后分离了 controller接口GET和POST
通用 @RestController GET @RequestMapping("userbase/{userId}") public User selectById(@PathVa ...
- learning scala How To Create Variable Argument Function - varargs :_ *
Scala collection such as List or Sequence or even an Array to variable argument function using the s ...
- 关于item的prevvalue
一个数据库大小监控项的更新周期是86400.一天,使用的最新值减去上次数值来显示变化值,一直就是10g-0 变化值为10g. 在更新时间为一天的时候prevvalue是0,不能显示上次的数值 当吧更新 ...
- leetcode解题报告(14):Max Consecutive Ones
描述 Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: ...
- 修改rabbitmq web-UI端口号
一.拷贝配置文件 [root@test03 ~]# cd /usr/share/doc/rabbitmq-server-3.6.15/ [root@test03 rabbitmq-server-3.6 ...
- 【SPOJ】Longest Common Substring II
[SPOJ]Longest Common Substring II 多个字符串求最长公共子串 还是将一个子串建SAM,其他字符串全部跑一边,记录每个点的最大贡献 由于是所有串,要对每个点每个字符串跑完 ...
- [Shell]CVE-2017-8464漏洞复现
0x01 漏洞原理 Windows系统通过解析 .LNK 后缀文件时,是使用二进制来解析的,而当恶意的二进制代码被系统识别执行的时候就可以实现远程代码执行,由于是在explorer.exe进程中运行的 ...
- js对元素判断
$("input[type='text']").attr("readonly","readonly"); $("textarea& ...