当前位置:网站首页>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];
}边栏推荐
- MATLAB小技巧(24)RBF,GRNN,PNN-神经网络
- [tutorial] chrome turns off cross domain policies CORS and samesite, and brings cookies across domains
- 各国Web3现状与未来
- Unrecognized SSL message, plaintext connection?
- The data in servlet is transferred to JSP page, and the problem cannot be displayed using El expression ${}
- GBase 8c系统表-pg_auth_members
- 8 free, HD, copyright free video material download websites are recommended
- 【教程】chrome關閉跨域策略cors、samesite,跨域帶上cookie
- 为什么会选择框架?选择什么样的框架
- Job object of collaboration in kotlin
猜你喜欢
随机推荐
Servlet中数据传到JSP页面使用el表达式${}无法显示问题
GBase 8c系统表-pg_collation
The sandbox explains its vision for the meta universe platform
簡單理解svg
How to change the panet layer in yolov5 to bifpn
Exception handling in kotlin process
定了,就选它
[tutorial] chrome turns off cross domain policies CORS and samesite, and brings cookies across domains
Word word word
【教程】chrome关闭跨域策略cors、samesite,跨域带上cookie
GBase 8c系统表-pg_constraint
Machine learning process and method
Gbase 8C function / stored procedure definition
[Flutter] dart: class; abstract class; factory; Class, abstract class, factory constructor
Random Shuffle attention
cvpr2022去雨去雾
oauth2.0鉴权,登录访问 “/oauth/token”,请求头Authorization(basicToken)如何取值???
Mathematical statistics -- Sampling and sampling distribution
awk从入门到入土(1)awk初次会面
Gbase 8C system table PG_ database







