当前位置:网站首页>leetcode540
leetcode540
2022-07-03 02:31:00 【Python's path to immortality】
Timeout speed pointer , But it timed out .. Purring
int singleNonDuplicate(int* nums, int numsSize){
// Speed pointer , If the previous bit is equal to the current one , That handle fast Assign a value to slow, Move forward
int slow=0,fast=1;
int ans=0;
int len=numsSize;
if(len==1)
{
return nums[0];
}
while(slow<len)
{
if(nums[slow]==nums[fast])
{
slow=fast;
}
else
{
ans=nums[slow];
break;
}
slow++;
fast+=2;// Take two steps at a time , Because the title says that every element will appear twice
// Find out that only 1 Time of , Can pass fast In even digits and fast Compare in odd digits
}
return ans;
}int singleNonDuplicate(int* nums, int numsSize){
for(int i=0;i<numsSize-1;i+=2)
{
if(nums[i]!=nums[i+1])
return nums[i];
}
return nums[numsSize-1];
}int singleNonDuplicate(int* nums, int numsSize){
int left=0;
int right=numsSize;
while(left<right)
{
int mid=left+(right-left)/2;
if(mid%2==0)//mid For even when , The second is on the right
{
if(mid+1<numsSize&&nums[mid]==nums[mid+1])
{
left=mid+1;
}
else{
right=mid;
}
}
else{// In an odd number of , The first one is on the left
if(mid-1>=0&&nums[mid-1]==nums[mid])
{
left=mid+1;
}
else{
right=mid;
}
}
}
return nums[right];
}边栏推荐
- Y54. Chapter III kubernetes from introduction to mastery -- ingress (27)
- Gbase 8C system table PG_ cast
- 通达OA v12流程中心
- Gbase 8C system table PG_ collation
- Current situation and future of Web3 in various countries
- Choose it when you decide
- 簡單理解svg
- Gbase 8C trigger (I)
- Startup mode and scope builder of collaboration in kotlin
- Error when installing MySQL in Linux: starting mysql The server quit without updating PID file ([FAILED]al/mysql/data/l.pid
猜你喜欢
![[fluent] listview list (map method description of list set | vertical list | horizontal list | code example)](/img/e5/c01f760b07b495f5b048ea367e0c21.gif)
[fluent] listview list (map method description of list set | vertical list | horizontal list | code example)

SPI机制
![[translation] modern application load balancing with centralized control plane](/img/b0/22e9bf098d580b2af67255ddcdc0d5.jpg)
[translation] modern application load balancing with centralized control plane

Summary of interview project technology stack

【翻译】后台项目加入了CNCF孵化器

《MATLAB 神经网络43个案例分析》:第43章 神经网络高效编程技巧——基于MATLAB R2012b新版本特性的探讨

random shuffle注意

内存池(内核角度理解new开辟空间的过程)

Choose it when you decide

Coroutinecontext in kotlin
随机推荐
[hcia]no.15 communication between VLANs
Qt之QComboBox添加QCheckBox(下拉列表框插入复选框,含源码+注释)
Gbase 8C system table PG_ constraint
Awk from introduction to earth (0) overview of awk
[Flutter] dart: class;abstract class;factory;类、抽象类、工厂构造函数
GBase 8c系统表-pg_auth_members
各国Web3现状与未来
What does "where 1=1" mean
awk从入门到入土(2)认识awk内置变量和变量的使用
GBase 8c 触发器(一)
Gbase 8C trigger (III)
GBase 8c 函数/存储过程参数(二)
Return a tree structure data
GBase 8c系统表-pg_constraint
GBase 8c系统表-pg_amproc
oauth2.0鉴权,登录访问 “/oauth/token”,请求头Authorization(basicToken)如何取值???
Basic operation of binary tree (C language version)
GBase 8c系统表-pg_aggregate
线程安全的单例模式
Gbase 8C trigger (II)