当前位置:网站首页>Number II that occurs only once (hash, bit operation, logic circuit, finite state automata)
Number II that occurs only once (hash, bit operation, logic circuit, finite state automata)
2022-04-21 13:39:00 【4nc414g0n】
A number that appears only once II
Topic link
Title Description:
Give you an array of integers nums , Except that one element only appears once Outside , Every other element just happens to appear Three times . Please find and return the element that only appears once
Method 1: Hash
Ideas:
- Create a number to map the number of times
- The number of iterations is 1 Of
Method 2: Bit operation
Ideas:
- With [2,2,3,2] For example :
- Because other numbers are 3 individual , Fill in the sum of each binary bit of each number 32 Array of elements
- Traverse %3, That's the number
The code is as follows :class Solution { public: int singleNumber(vector<int>& nums) { vector<int> bit_arr(32,0); for(int i=0;i<nums.size();i++) { int bit=32; while(bit--) { bit_arr[bit]+= (1&(nums[i]>>bit)); } } int ret=0; for(int i=0;i<32;i++) { if(bit_arr[i]%3==1) { ret|=(1<<i);// For example, move left 3 position 0000001000, Press the bit or achieve the effect } } return ret; } };
Method 3: logical circuit
Reference resources : Official problem solving ideas
Method 4: Finite state automata
Reference resources : Krahets How to solve the problem
版权声明
本文为[4nc414g0n]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211217327742.html
边栏推荐
- Tailwind核心理念——响应式设计
- Installing and configuring canal
- Open mmlab / mmpose installation and use tutorial
- 【栈和队列专题】—— 双队列模拟栈
- Upgrade the jdbc driver to version 8.0.28 and connect the pit record of MySQL
- [C#]给地球来点光
- Peking University ACM problems 1011: sticks
- 专家系统实例及其骨架系统
- A great peripheral driver library! (based on stm32f4)
- STM32驱动ST7789V2 tft屏幕
猜你喜欢

微信隐藏功能系列:微信定时提醒,2个步骤,让忙碌中的自己松口气

Forced to choose an outsourcing company

Last online class can be "distracted" by AI analysis. Intel's emotional detection AI is on fire

HCIP之路OSPF拓展配置

单体测试使用Assert.assertThat(expected,Matcher matcher)来对比结果和预期

运动耳机什么样的舒服、运动健身耳机推荐

If the field lines are the same, they will be merged into another field SQL statement?

Establishment of binary tree and its cueing

Achieve random labels, font size, color random display

leetcode:513. 找树左下角的值【简单bfs找每层第一个】
随机推荐
[traitement du signal numérique] coefficient de corrélation (analyse conceptuelle du coefficient de corrélation | constante d'énergie du signal | séquence conjuguée | corrélation de la séquence au mêm
哈夫曼編碼
What is federal learning?
北京大学ACM Problems 1010:STAMPS
微信隐藏功能系列:微信定时提醒,2个步骤,让忙碌中的自己松口气
程序员爆出自己的薪资税前月薪15000
Do self media and short videos, and don't trust those mutual relations and mutual praise
做自媒体、短视频,不用自己拍视频,大周教你一个快速起号的方法
【數字信號處理】相關系數 ( 相關系數概念解析 | 信號能量常數 | 共軛序列 | 序列在相同時刻的相關性 )
BUUCTF [第三章 web进阶]逻辑漏洞
专家系统实例及其骨架系统
上周国外互联网产品新闻简编 - Angel
MySQL analysis on how to reduce conflict and improve performance of row lock
Go language file operation
Peking University ACM problems 1012: Maya calendar
Why does MySQL driver rely on protobuf
【数字信号处理】线性常系数差分方程 ( 使用 matlab 求解 “ 线性常系数差分方程 “ 示例 | A 向量分析 | B 向量分析 | 输入序列分析 | matlab 代码 )
Peking University ACM problems 1008: Maya calendar
一份很棒的外设驱动库!(基于STM32F4)
Hcip road OSPF expansion configuration
