当前位置:网站首页>296 · array de duplication
296 · array de duplication
2022-04-22 07:31:00 【yinhua405】
describe
Given a length of NNN Array of integers for arrarrarr, Returns the array after removing duplicate elements ( The relative order of array elements remains unchanged before and after removing duplicate elements )
Wechat plus jiuzhang15 Send verification information 【 video 】 Lead the test center of real questions 、 Interview tips and other free video lessons
1≤N≤1051 \leq N \leq 10^51≤N≤105
−109≤arr[i]≤109-10^9 \leq arr[i] \leq 10^9−109≤arr[i]≤109
Examples
Input :[3,4,3,6]
Output :[3,4,6]
explain : Elements 3 repeat , So just keep one element 3
And the relative order of array elements before and after de duplication remains the same , So the element 4 Still element 3 Back , Elements 6 Still element 3,4 Backstruct Data
{
vector<int>vec;
};vector<int> getUniqueArray(vector<int> &arr) {
// write your code here
int cur = 0;
vector<int> ret;
int size = arr.size();
vector<bool> visited(size, false);vector<Data>dataVec(size);
for (int i = 0; i < size; i++)
{
int key = arr[i] % size;
if (key < 0)
{
key = key *-1;
}
if (dataVec[key].vec.size() == 0)
{
ret.push_back(arr[i]);
dataVec[key].vec.push_back(arr[i]);
}
else
{
vector<int> tmpVec = dataVec[key].vec;
bool bFind = false;
for (int k = 0; k < tmpVec.size(); k++)
{
if (tmpVec[k] == arr[i])
{
bFind = true;
break;
}
}
if (false == bFind)
{
ret.push_back(arr[i]);
dataVec[key].vec.push_back(arr[i]);
}
}
}return ret;
}
版权声明
本文为[yinhua405]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220613324384.html
边栏推荐
- Recursive search sequence set
- E.Figure Skating (字符串排序/签到) (2021年度训练联盟热身训练赛第五场 )
- blog同步更新通知
- Redis進階
- L2-005 集合相似度(set判重)
- 332 · recovery array
- Leetcode - 6 - (string multiplication, next larger element < Ⅰ Ⅱ Ⅲ >, K sets of inverted linked list)
- 838 · 子数组和为K
- Detailed tree array template -- Theory and code implementation
- Codeforces Round #780 (Div. 3)
猜你喜欢

Binary tree chain structure operation leetcode + Niuke (detailed explanation)

L1-071 前世档案 (20 分) (类似二分)

并发编程的艺术(6):详解ReentrantLock的原理
![[DRC RTSTAT-1] Unrouted nets: 1 net(s) are unrouted](/img/bf/0851c85f766432f6d6306d52e67188.png)
[DRC RTSTAT-1] Unrouted nets: 1 net(s) are unrouted

内部类使用说明(静态、实例、局部)

This关键字详细概述

Redis进阶

(5) Use Navicat to create database data table and set ID auto increment

重写与重载的定义与区别

Two algorithm questions for Microsoft intern interview -- 20220119
随机推荐
A. Binary seating (the fifth game of 2021 training League warm-up training competition)
CF1547E Air Conditioners
Codeforces Round #623
并发编程的艺术(5):ReentrantLock的使用
L2-005 集合相似度(set判重)
LeetCode - 4 - (接雨水、无重复字符的最长子串、分发糖果、二叉树的<前中后层>序遍历)
Educational Codeforces Round 122 (Rated for Div. 2)
Hand tearing algorithm -- LRU cache elimination strategy, asked so often
Codeforces Round #774 (Div. 2)
76 · 最长上升子序列
CodeTON Round 1 (Div. 1 + Div. 2, Rated, Prizes)
843 · 数字翻转
Codeforces Round #610 (Div. 2)
最小圆覆盖(计算几何基础)
189. 轮转数组
LeetCode - 5 - (重复的子字符串<kmp>、最长回文子串、转置矩阵、二叉树的(左右)视图)
带环链表详解
In the process of class loading, the allocation area of class variables is different from that of instance variables
[solution] Luogu p6186 [noi online 1 improvement group] bubble sorting: [bubble sorting] and [reverse order pair] problems
Escape analysis in JVM can realize that memory is not allocated on the heap