【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 ...
随机推荐
- WCF之MSMQ消息队列
一.MSMQ简介 MSMQ(微软消息队列)是Windows操作系统中消息应用程序的基础,是用于创建分布式.松散连接的消息通讯应用程序的开发工具. MSMQ与XML Web Services和.Net ...
- Vue -- filters 过滤器、倒计时效果
局部过滤器 时间.***号 <div id="wrapper" class="wrapper" style="display: none;&qu ...
- javax.persistence.TransactionRequiredException: Executing an update/delete query
最近在springboot中整合jpa的时候碰到一个异常,异常如下 javax.persistence.TransactionRequiredException: Executing an updat ...
- 使用MockMVC与Junit进行单体测试
1.pom.xml追加 junit spring-test 2.测试共通类 @ContextConfiguration(locations = { "classpath:springfram ...
- Ubuntu 14.04 源
清华源https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/ ubuntu 14.04 官方源 # deb cdrom:[Ubuntu 14.04.4 LT ...
- [线性代数] 矩阵代数基础 Basic Matrix Algebra
Overview: Matrix algebra Matrix algebra covers rules allowing matrices to be manipulated algebraical ...
- ICEMCFD中,face裂缝修复的小窍门【转载】
转载自:http://blog.sina.com.cn/s/blog_4a21884b010005ng.html 采用ICEMCFD画网格的初学者,都对由cad(proe/ug/solidworks) ...
- 查看linux系统版本相关信息
1.查看内核版本:cat /proc/version A机器 root@debian:~# cat /proc/version Linux version -- (ty@debian) ( (Debi ...
- scanf和fgets比较
scanf 长度限制 #include<stdio.h> int main() { char food[5]; printf("Enter food"); scanf( ...
- DNN在推荐系统中的应用参考资料
参考资料 DSSM算法计算文本相似度:https://www.cnblogs.com/wmx24/p/10157154.html Deep Neural Network for YouTube Rec ...