Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit37b806b

Browse files
add 1826
1 parent8a4b97d commit37b806b

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ _If you like this project, please leave me a star._ ★
3636
|1829|[Maximum XOR for Each Query](https://leetcode.com/problems/maximum-xor-for-each-query/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1829.java)||Medium|Bit Manipulation|
3737
|1828|[Queries on Number of Points Inside a Circle](https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1828.java)|[:tv:](https://youtu.be/fU4oOBSsVMg)|Medium|Math|
3838
|1827|[Minimum Operations to Make the Array Increasing](https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1827.java)||Easy|Array, Greedy|
39+
|1826|[Faulty Sensor](https://leetcode.com/problems/faulty-sensor/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1826.java)||Easy|Array, Two Pointers|
3940
|1823|[Find the Winner of the Circular Game](https://leetcode.com/problems/find-the-winner-of-the-circular-game/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1823.java)||Medium|Array|
4041
|1822|[Sign of the Product of an Array](https://leetcode.com/problems/sign-of-the-product-of-an-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1822.java)||Easy|Math|
4142
|1817|[Finding the Users Active Minutes](https://leetcode.com/problems/finding-the-users-active-minutes/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1817.java)||Medium|HashTable|
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
packagecom.fishercoder.solutions;
2+
3+
publicclass_1826 {
4+
publicstaticclassSolution1 {
5+
publicintbadSensor(int[]sensor1,int[]sensor2) {
6+
//check if sensor2 is faulty
7+
inti =0,j =0;
8+
for (;i <sensor1.length &&j <sensor2.length -1; ) {
9+
if (sensor1[i] !=sensor2[j]) {
10+
i++;
11+
}else {
12+
i++;
13+
j++;
14+
}
15+
}
16+
booleansensor2Faulty =false;
17+
if (j ==sensor2.length -1 &&i ==sensor1.length) {
18+
sensor2Faulty =true;
19+
}
20+
//check sensor1
21+
i =0;
22+
j =0;
23+
for (;i <sensor1.length -1 &&j <sensor2.length; ) {
24+
if (sensor1[i] !=sensor2[j]) {
25+
j++;
26+
}else {
27+
i++;
28+
j++;
29+
}
30+
}
31+
booleansensor1Faulty =false;
32+
if (i ==sensor1.length -1 &&j ==sensor2.length) {
33+
sensor1Faulty =true;
34+
}
35+
if (sensor1Faulty &&sensor2Faulty) {
36+
return -1;
37+
}elseif (sensor1Faulty) {
38+
return1;
39+
}elseif (sensor2Faulty) {
40+
return2;
41+
}
42+
return -1;
43+
}
44+
}
45+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1826;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_1826Test {
10+
privatestatic_1826.Solution1solution1;
11+
12+
@BeforeClass
13+
publicstaticvoidsetup() {
14+
solution1 =new_1826.Solution1();
15+
}
16+
17+
@Test
18+
publicvoidtest1() {
19+
assertEquals(1,solution1.badSensor(newint[]{2,3,4,5},newint[]{2,1,3,4}));
20+
}
21+
22+
@Test
23+
publicvoidtest2() {
24+
assertEquals(-1,solution1.badSensor(newint[]{2,2,2,2,2},newint[]{2,2,2,2,5}));
25+
}
26+
27+
@Test
28+
publicvoidtest3() {
29+
assertEquals(2,solution1.badSensor(newint[]{2,3,2,2,3,2},newint[]{2,3,2,3,2,7}));
30+
}
31+
32+
@Test
33+
publicvoidtest4() {
34+
assertEquals(-1,solution1.badSensor(newint[]{1,2,3,2,3,2},newint[]{1,2,3,3,2,3}));
35+
}
36+
37+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp