Skip to content

Commit 31708bc

Browse files
add test for 81
1 parent afccd11 commit 31708bc

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

src/main/java/com/fishercoder/solutions/_81.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,24 @@
33
/**
44
* 81. Search in Rotated Sorted Array II
55
*
6-
* Follow up for "Search in Rotated Sorted Array":
6+
* Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
77
*
8-
* What if duplicates are allowed?
8+
* (i.e., [0,0,1,2,2,5,6] might become [2,5,6,0,0,1,2]).
9+
*
10+
* You are given a target value to search. If found in the array return true, otherwise return false.
11+
*
12+
* Example 1:
13+
*
14+
* Input: nums = [2,5,6,0,0,1,2], target = 0
15+
* Output: true
16+
* Example 2:
17+
*
18+
* Input: nums = [2,5,6,0,0,1,2], target = 3
19+
* Output: false
20+
* Follow up:
21+
*
22+
* This is a follow up problem to Search in Rotated Sorted Array, where nums may contain duplicates.
923
* Would this affect the run-time complexity? How and why?
10-
* Write a function to determine if a given target is in the array.
1124
*/
1225
public class _81 {
1326

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._81;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _81Test {
10+
private static _81.Solution1 solution1;
11+
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _81.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(true, (solution1.search(new int[]{2, 5, 6, 0, 0, 1, 2}, 0)));
20+
}
21+
22+
@Test
23+
public void test2() {
24+
assertEquals(false, (solution1.search(new int[]{2, 5, 6, 0, 0, 1, 2}, 3)));
25+
}
26+
27+
}

0 commit comments

Comments
 (0)