136. Single Number

STM32 之十三 看门狗(WDG)及低功耗下的处理   最近在做低功耗项目时,遇到了看门狗不好处理的问题。在 ST 的各系列 MCU 中,看门狗应该算是使用配置起来最简单的一个外设了。我们通常仅需要配置很少的配置项,但是,一旦要配合低功耗模式则配置就比较麻烦了。MCU 中有两只狗,一只叫 Independent watchdog (IWDG);另一只叫 System window watchdog (WWDG)。下面是这两只狗的简单介绍! IWDG   IWDG 基本就等同于我们独立使用的看门狗芯片。最适合那些要求看门狗作为一个完全独立的进程在主应用程序之外 阅读详情

Given a non-empty array of integers, every element appears twice except for one. Find that single one.

Note:

Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

Example 1:

Input: [2,2,1]
Output: 1

Example 2:

Input: [4,1,2,1,2]
Output: 4

本菜鸟:

class Solution {
    public int singleNumber(int[] nums) {
         List<Integer> list= new ArrayList();  
    	 int sum = 0;
         for(int i=0;i<nums.length;i++){  
        	 sum += nums[i];
             if(!list.contains(nums[i])){  
                 list.add(nums[i]);  
             }  
         }  
         int res = 0;
         for (int i = 0; i < list.size(); i++) {
             res = list.get(i) + res;
         }
        return 2*res-sum;
    }
}

时间复杂度O(n^2),比较差,所以花费了166ms,效果倒数。

 

稍微改进一下的版本:

@akashs73
HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
 	    for(int i=0;i<nums.length;i++){
 	    int a = nums[i];
 	    if(map.containsKey(a)) {
 	    	map.remove(a);
 	    }else {
 	       map.put(a, 1);
 	    }
 	    	
 	  }
 	  return (int) map.keySet().toArray()[0];         

大神的代码:

int x = 0; for(int a: nums) x^=a;
return x;

仅仅两行,时间复杂度为O(n),比这道题的在线提交的100%java代码都快。

这里用到了异或的性质:x^y^x=y;

 

 

FAST-LIO论文公式解析 阅读详情

相关推荐

第一届“龙信杯”电子数据取证竞赛Writeup

第一届“龙信杯”电子数据取证竞赛Writeup

toto的博客 1万+

136. Single Number*

136. Single Number* https://leetcode.com/problems/single-number/ 题目描述 Given a non-empty array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should...

珍妮的选择的博客 427

银行客户投诉预测模型优化

在实际操作中,银行可以使用这个优化后的模型来识别那些可能引起客户不满的因素,并采取预防措施。例如,如果模型表明退款金额是一个很强的预测因子,银行可能会审查其退款政策,以确保它对客户是公平和透明的。在银行业务中,客户投诉是一个重要的指标,它直接关系到客户满意度和银行服务质量。某一个指标,比如:退款金额,本文假设退款金额对于预测投诉的权重应该高于赔偿金额。在每次迭代中,本文使用当前的权重组合来训练模型,并计算在测试集上的准确率。的可能值来搜索最佳的权重组合,并输出最佳准确率及对应的权重。来寻找最佳的权重组合。

weixin_57499254的博客 1708

[LeetCode]136. Single Number

[LeetCode]136. Single Number题目描述思路对于相同的数 异或结果是0 那么将数组中的数去异或结果,即为所求代码class Solution { public: int singleNumber(vector<int>& nums) { int res = 0; for (int p : nums) { res

Lcharon的博客 3091

Manimgl 进阶笔记

目录 一、调整视频输出的纵横比 二、调整预览窗口的尺寸 三、在开发工具中直接调试 一、调整视频输出的纵横比 调整输出视频的纵横比,在日常开发中属于比较基本的需求。要使用 Manimgl 得到期望的分辨率的视频输出需要修改以下几个地方: 第一步:在 custom_config.yml 配置文件中通过 camera_qualities设置视频的输出分辨率。manimlib 框架已经在 default_config.yml 文件中设置了四种视频输出分辨率,default_qualities 参数.

gunnery的专栏 2859

从SolidWorks到Simscape:URDF导出模型错位的5个常见原因及修复方法

本文深入分析了从SolidWorks导出URDF模型到Simscape时出现模型错位的5个常见原因,包括坐标系定义、RPY角陷阱、轴方向统一、质量属性导出和层次结构错乱,并提供了详细的修复方法和实战技巧,帮助工程师高效解决模型错位问题。

weixin_30664051的博客 443

LeetCode - 136. Single Number

题目 LeetCode - 136. Single Number 题目链接 https://leetcode.com/problems/single-number/ 参考博客 解题思路 解题源码 class Solution { public: int singleNumber(vector<int>& nums) { map<int, int&g...

virgilshi的博客 118

[Adaptive Autosar]深入理解--Time Synchronization

目录 1.TS典型应用场景 2.CP和AP时间同步对比 3.时间同步基础知识 4.TBR部分参数说明 5. TS功能说明 5.1 基本说明 5.2 时间纠正计算说明 5.3 时间验证 Time Synchronization 时间同步,后面简称TS 1.TS典型应用场景 时间同步,典型应用就是在自动驾驶领域,自动驾驶领域涉及到各个传感器的数据采集,如IMU采集当前车身姿态和运动信息,毫米波雷达-超声波雷达-环视摄像头-前视摄像头...等等传感器捕获的数据,在算法中需要精确知道每个数.

AgingMoon的博客 3997

Leetcode 136 Single Number

Leetcode 136 Single Number 题目描述 Given a non-empty array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Cou...

qq_43271202的博客 289

LeRobot 入门教程(十)LIBERO 机器人终身学习评估

LIBERO是一项专注于机器人终身学习(LLDM)的基准测试平台,包含130项任务,分为5大套件(空间推理、物体操作、目标约束等)。LeRobot框架已集成LIBERO,支持单/多套件评估,并兼容SmolVLA模型。训练需使用预处理数据集(HuggingFaceVLA/libero),观测数据需符合规范(8维状态+双摄像头图像)。该平台采用MuJoCo模拟,支持无头服务器运行,旨在推动机器人持续学习算法的发展与标准化评估。

2506_90492529的博客 1664

温升试验详解

温升试验是电子设备可靠性验证的重要手段,用于评估器件在正常工作或极限条件下的热稳定性。试验通过测量器件表面或关键点温度与环境温度的差值(ΔT),判断是否存在过热风险。主要依据行业标准,采用热电偶、热像仪等设备测量稳态温度。热阻分析可建立温升与功耗的关系,指导器件选型、PCB热设计和散热结构优化。典型应用包括电源模块和LED电路测试。温升试验通过系统性热分析,能有效提升产品在高负载、高温环境下的可靠性和安全性,对现代小型化、高密度电子设备尤为重要。

硬核科技 1332

leetcode (136) Single Number js代码实现

Single Number Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement i

张小水儿的博客 875

从 Open SQL JOIN 走向 ABAP CDS Association:把查询写成可复用的数据模型

摘要: 本文通过飞行模型示例,对比了ABAP中三种表关联实现方式:Open SQL JOIN、CDS显式JOIN和CDS Association。重点解析了Association的本质是将表关系声明为数据模型语言,使用时通过路径表达式按需展开为JOIN。文章指出路径表达式在不同位置会默认展开为不同JOIN类型(如SELECT列表默认为LEFT OUTER),并演示了如何用[inner]强制指定INNER JOIN。最后结合S/4HANA实际案例,说明Association通过中心化关系定义和路径复用,能有效

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 384

136 Single Number

题目链接:https://leetcode.com/problems/single-number/题目:Given an array of integers, every element appears twice except for one. Find that single one.Note: Your algorithm should have a linear runtime comple

再见了,过去的名字,新的奋斗开始啦! 471

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

leetcode 136. Single Number

/* leetcode 136. Single Number Given an array of integers, every element appears twice except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you imple

编码之路 536

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

LeetCode-136. Single Number [C++][Java]

Given anon-emptyarray of integersnums, every element appearstwiceexcept for one. Find that single one. You mustimplement a solution with a linear runtime complexity and useonly constantextra space.

贫道绝缘子的博客 849

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

LeetCode 136. Single Number 题解

本题是一个经典的问题,主要考察对哈希表或异或运算的理解和使用。通过使用哈希表,我们可以统计每个元素的出现次数,然后找到只出现一次的元素。通过使用异或运算,我们可以更高效地解决这个问题,只需要遍历数组一次,且不需要额外的空间。异或运算的核心思想是:利用异或运算的性质,将所有元素进行异或运算,最终结果就是只出现一次的元素。这种方法不仅适用于只出现一次的数字问题,还可以应用于许多其他需要查找唯一元素的问题。掌握异或运算的使用,对于解决这类问题非常重要。

cannonjinx的博客 4188

Leetcode 136. Single Number

Leetcode 136. Single Number Given an array of integers, every element appears twice except for one. Find that single one. This question is so intended to examine about the bit manipulation, beca

Hanwenwangad的专栏 440

136. Single Number - Java

文章目录136. Single NumberDescriptionSolutionsSubmissionsSummary 136. Single Number https://leetcode.com/problems/single-number/ Description Given a non-empty array of integers, every element appears twic...

La La Land 236

LeetCode 136.Single Number

LeetCode 136.Single NumberDescription: Given an array of integers, every element appears twice except for one. Find that single one. 分析: 首先给数组按从小到大排序,然后遍历该数组,判断相邻之间的数是否相等; 若不等,则把标记flag置为true,可用来

My Blog 265

Leetcode136. Single Number

Leetcode136. Single Number Given a non-empty array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could ...

magic_jiayu的博客 206

LeetCode 136 Single Number

136. Single Number (Bit Manipulation) Given a non-empty array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexit...

C linux kernel 215

【leetcode】【easy】【每日一题】136. Single Number​​​​​​​

136. Single Number Given anon-emptyarray of integers, every element appearstwiceexcept for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? Example 1: Inpu...

lemonade13的博客 195

leetcode.136.Single Number

Given an array of integers, every element appears twice except for one. Find that single one.

RaymondWong的博客 230

LeetCode: 136. Single Number

LeetCode: 136. Single Number Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could

qha0731的专栏 413

LeetCode 136. Single Number

题目来源:https://leetcode.com/problems/single-number/ 问题描述 136.Single Number Easy Given anon-emptyarray of integers, every element appearstwiceexcept for one. Find that single one. Note: You...

da_kao_la的博客 165
上一篇: 7. Reverse Integer
下一篇: 709. To Lower Case
有书就看
博客等级 码龄9年 1粉丝 14原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值