Skip to content

Commit

Permalink
Update 1826.Faulty-Sensor.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
wisdompeak authored May 1, 2022
1 parent 95106d2 commit 4991013
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions Others/1826.Faulty-Sensor/1826.Faulty-Sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,29 @@ class Solution {
}
if (i>=n-1) return -1;

int flag = 1;
int flag1 = 1;
for (int j=i; j<n-1; j++)
{
if (sensor1[j]!=sensor2[j+1])
{
flag = 0;
flag1 = 0;
break;
}
}
if (flag==1) return 1;
else return 2;

int flag2 = 1;
for (int j=i; j<n-1; j++)
{
if (sensor1[j+1]!=sensor2[j])
{
flag2 = 0;
break;
}
}

if (flag1 && flag2) return -1;
else if (!flag1 && !flag2) return -1;
else if (flag1) return 1;
else return 2;
}
};

0 comments on commit 4991013

Please sign in to comment.