当前位置:网站首页>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];
}
边栏推荐
- GBase 8c 函数/存储过程定义
- Oauth2.0 authentication, login and access "/oauth/token", how to get the value of request header authorization (basictoken)???
- Interview stereotyped version
- "Analysis of 43 cases of MATLAB neural network": Chapter 43 efficient programming skills of neural network -- Discussion Based on the characteristics of the new version of MATLAB r2012b
- Detailed analysis of micro service component sentinel (hystrix)
- [translation] the background project has joined the CNCF incubator
- GBase 8c系统表-pg_authid
- Codeforces Round #418 (Div. 2) D. An overnight dance in discotheque
- GBase 8c系统表pg_database
- 通达OA 首页门户工作台
猜你喜欢
8 free, HD, copyright free video material download websites are recommended
where 1=1 是什么意思
Servlet中数据传到JSP页面使用el表达式${}无法显示问题
Return a tree structure data
《MATLAB 神经网络43个案例分析》:第43章 神经网络高效编程技巧——基于MATLAB R2012b新版本特性的探讨
Restcloud ETL cross database data aggregation operation
Detailed analysis of micro service component sentinel (hystrix)
PyTorch 卷积网络正则化 DropBlock
xiaodi-笔记
Flink CDC mongoDB 使用及Flink sql解析monggo中复杂嵌套JSON数据实现
随机推荐
Monitoring and management of JVM
4. Classes and objects
返回一个树形结构数据
HW-初始准备
"Analysis of 43 cases of MATLAB neural network": Chapter 43 efficient programming skills of neural network -- Discussion Based on the characteristics of the new version of MATLAB r2012b
【ROS进阶篇】第六讲 ROS中的录制与回放(rosbag)
GBase 8c系统表-pg_amproc
cvpr2022去雨去雾
Simple understanding of SVG
Gbase 8C system table PG_ constraint
Gbase 8C trigger (II)
Kotlin middle process understanding and Practice (I)
Detailed introduction to the deployment and usage of the Nacos registry
[tutorial] chrome turns off cross domain policies CORS and samesite, and brings cookies across domains
微服务组件Sentinel (Hystrix)详细分析
awk从入门到入土(2)认识awk内置变量和变量的使用
Create + register sub apps_ Define routes, global routes and sub routes
Gbase 8C trigger (III)
Y54. Chapter III kubernetes from introduction to mastery -- ingress (27)
Gbase 8C function / stored procedure parameters (I)