From 82f60099967d4648dd528055343744515e4ba3cf Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Sat, 12 Oct 2019 07:25:16 -0700 Subject: [PATCH 01/17] refactor 24 --- .../java/com/fishercoder/solutions/_24.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/fishercoder/solutions/_24.java b/src/main/java/com/fishercoder/solutions/_24.java index 5d04c4e311..e7b07e484c 100644 --- a/src/main/java/com/fishercoder/solutions/_24.java +++ b/src/main/java/com/fishercoder/solutions/_24.java @@ -14,16 +14,17 @@ */ public class _24 { - - public ListNode swapPairs(ListNode head) { - if (head == null || head.next == null) { - return head; + public static class Solution1 { + public ListNode swapPairs(ListNode head) { + if (head == null || head.next == null) { + return head; + } + ListNode second = head.next; + ListNode third = second.next; + second.next = head; + head.next = swapPairs(third); + return second; } - ListNode second = head.next; - ListNode third = second.next; - second.next = head; - head.next = swapPairs(third); - return second; } } From 961e476af468d82c5fb33dce524afc48c42c5993 Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Sun, 13 Oct 2019 07:29:43 -0700 Subject: [PATCH 02/17] add test for 24 --- src/test/java/com/fishercoder/_24Test.java | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/test/java/com/fishercoder/_24Test.java diff --git a/src/test/java/com/fishercoder/_24Test.java b/src/test/java/com/fishercoder/_24Test.java new file mode 100644 index 0000000000..98a53a8aa5 --- /dev/null +++ b/src/test/java/com/fishercoder/_24Test.java @@ -0,0 +1,26 @@ +package com.fishercoder; + +import com.fishercoder.common.classes.ListNode; +import com.fishercoder.common.utils.CommonUtils; +import com.fishercoder.solutions._24; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.Arrays; + +public class _24Test { + private static _24.Solution1 solution1; + private static ListNode head; + + @BeforeClass + public static void setup() { + solution1 = new _24.Solution1(); + } + + @Test + public void test1() { + head = ListNode.createSinglyLinkedList(Arrays.asList(1, 2, 3, 4)); + CommonUtils.printList(solution1.swapPairs(head)); + } + +} \ No newline at end of file From a842574ee94731cc8b0c6bdf08b91513697903ad Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Mon, 14 Oct 2019 07:12:52 -0700 Subject: [PATCH 03/17] add test for 29 --- src/test/java/com/fishercoder/_29Test.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/test/java/com/fishercoder/_29Test.java diff --git a/src/test/java/com/fishercoder/_29Test.java b/src/test/java/com/fishercoder/_29Test.java new file mode 100644 index 0000000000..9f9ebc10c7 --- /dev/null +++ b/src/test/java/com/fishercoder/_29Test.java @@ -0,0 +1,21 @@ +package com.fishercoder; + +import com.fishercoder.solutions._29; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class _29Test { + private static _29.Solution1 solution1; + + @BeforeClass + public static void setup() { + solution1 = new _29.Solution1(); + } + + @Test + public void test1() { + assertEquals(1, solution1.divide(4, 3)); + } +} From 2f38a39da39be05e803f92b813c35d694c9af6f2 Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Tue, 15 Oct 2019 06:34:12 -0700 Subject: [PATCH 04/17] add test for 31 --- src/test/java/com/fishercoder/_31Test.java | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/test/java/com/fishercoder/_31Test.java diff --git a/src/test/java/com/fishercoder/_31Test.java b/src/test/java/com/fishercoder/_31Test.java new file mode 100644 index 0000000000..98ee63a8e1 --- /dev/null +++ b/src/test/java/com/fishercoder/_31Test.java @@ -0,0 +1,23 @@ +package com.fishercoder; + +import com.fishercoder.common.utils.CommonUtils; +import com.fishercoder.solutions._31; +import org.junit.BeforeClass; +import org.junit.Test; + +public class _31Test { + private static _31.Solution1 solution1; + private static int[] nums; + + @BeforeClass + public static void setup() { + solution1 = new _31.Solution1(); + } + + @Test + public void test1() { + nums = new int[]{1, 2, 3}; + solution1.nextPermutation(nums); + CommonUtils.printArray(nums); + } +} From de76b610efeaa72b0fbfb93fec907e06b97edf0e Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Wed, 16 Oct 2019 06:59:55 -0700 Subject: [PATCH 05/17] add test for 32 --- src/test/java/com/fishercoder/_32Test.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/test/java/com/fishercoder/_32Test.java diff --git a/src/test/java/com/fishercoder/_32Test.java b/src/test/java/com/fishercoder/_32Test.java new file mode 100644 index 0000000000..c1db3cfae9 --- /dev/null +++ b/src/test/java/com/fishercoder/_32Test.java @@ -0,0 +1,21 @@ +package com.fishercoder; + +import com.fishercoder.solutions._32; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class _32Test { + private static _32.Solution1 solution1; + + @BeforeClass + public static void setup() { + solution1 = new _32.Solution1(); + } + + @Test + public void test1() { + assertEquals(2, solution1.longestValidParentheses("(()")); + } +} From bc2c5646eaa6743d5602b653a03a7f38bf1248f5 Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Thu, 17 Oct 2019 07:20:48 -0700 Subject: [PATCH 06/17] add test for 33 --- src/test/java/com/fishercoder/_33Test.java | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/test/java/com/fishercoder/_33Test.java diff --git a/src/test/java/com/fishercoder/_33Test.java b/src/test/java/com/fishercoder/_33Test.java new file mode 100644 index 0000000000..aa0e6f14cd --- /dev/null +++ b/src/test/java/com/fishercoder/_33Test.java @@ -0,0 +1,26 @@ +package com.fishercoder; + +import com.fishercoder.solutions._33; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class _33Test { + private static _33.Solution1 solution1; + private static _33.Solution2 solution2; + private static int[] nums; + + @BeforeClass + public static void setup() { + solution1 = new _33.Solution1(); + solution2 = new _33.Solution2(); + } + + @Test + public void test1() { + nums = new int[]{4, 5, 6, 7, 0, 1, 2}; + assertEquals(3, solution1.search(nums, 7)); + assertEquals(3, solution2.search(nums, 7)); + } +} From 402a44dba88510e4533941feccc600ed6614e5f4 Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Fri, 18 Oct 2019 06:40:59 -0700 Subject: [PATCH 07/17] refactor 35 --- src/main/java/com/fishercoder/solutions/_35.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/fishercoder/solutions/_35.java b/src/main/java/com/fishercoder/solutions/_35.java index 318db230dc..ea88dc9669 100644 --- a/src/main/java/com/fishercoder/solutions/_35.java +++ b/src/main/java/com/fishercoder/solutions/_35.java @@ -18,14 +18,16 @@ public class _35 { - public int searchInsert(int[] nums, int target) { - int len = nums.length; - for (int i = 0; i < len; i++) { - if (target <= nums[i]) { - return i; + public static class Solution1 { + public int searchInsert(int[] nums, int target) { + int len = nums.length; + for (int i = 0; i < len; i++) { + if (target <= nums[i]) { + return i; + } } + return len; } - return len; } } From 722f746fb6f00e7edd18b71c5b6232485800b306 Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Sat, 19 Oct 2019 17:15:33 -0700 Subject: [PATCH 08/17] add test for 35 --- src/test/java/com/fishercoder/_35Test.java | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/test/java/com/fishercoder/_35Test.java diff --git a/src/test/java/com/fishercoder/_35Test.java b/src/test/java/com/fishercoder/_35Test.java new file mode 100644 index 0000000000..3062dcd46a --- /dev/null +++ b/src/test/java/com/fishercoder/_35Test.java @@ -0,0 +1,23 @@ +package com.fishercoder; + +import com.fishercoder.solutions._35; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class _35Test { + private static _35.Solution1 solution1; + private static int[] nums; + + @BeforeClass + public static void setup() { + solution1 = new _35.Solution1(); + } + + @Test + public void test1() { + nums = new int[]{1, 3, 5, 6}; + assertEquals(2, solution1.searchInsert(nums, 5)); + } +} From e25522772edf3f35f0cfdc3c4898a83614ee163e Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Sun, 20 Oct 2019 07:07:59 -0700 Subject: [PATCH 09/17] add a util method --- .../java/com/fishercoder/common/utils/CommonUtils.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/fishercoder/common/utils/CommonUtils.java b/src/main/java/com/fishercoder/common/utils/CommonUtils.java index e969aa8f96..87fd300b31 100644 --- a/src/main/java/com/fishercoder/common/utils/CommonUtils.java +++ b/src/main/java/com/fishercoder/common/utils/CommonUtils.java @@ -221,4 +221,14 @@ public static void printArrayArray(int[][] arrayArrays) { } System.out.println(); } + + public static void print2DCharArray(char[][] arrayArrays) { + for (char[] array : arrayArrays) { + for (char i : array) { + System.out.print(i + ", "); + } + System.out.println(); + } + System.out.println(); + } } From 8d22998f4978e1e33da1b5a5920d28912efbba4e Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Sun, 20 Oct 2019 07:08:21 -0700 Subject: [PATCH 10/17] refactor 37 --- .../java/com/fishercoder/solutions/_37.java | 50 +++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/fishercoder/solutions/_37.java b/src/main/java/com/fishercoder/solutions/_37.java index 92d4c15282..3f7fcbf8c5 100644 --- a/src/main/java/com/fishercoder/solutions/_37.java +++ b/src/main/java/com/fishercoder/solutions/_37.java @@ -3,9 +3,53 @@ /** * 37. Sudoku Solver * - * Write a program to solve a Sudoku puzzle by filling the empty cells. - * Empty cells are indicated by the character '.'. - * You may assume that there will be only one unique solution. + * Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: + * + * Each row must contain the digits 1-9 without repetition. + * Each column must contain the digits 1-9 without repetition. + * Each of the 9 3x3 sub-boxes of the grid must contain the digits 1-9 without repetition. + * + * The Sudoku board could be partially filled, where empty cells are filled with the character '.'. + * + * Example 1: + * + * Input: + * [ + * ["5","3",".",".","7",".",".",".","."], + * ["6",".",".","1","9","5",".",".","."], + * [".","9","8",".",".",".",".","6","."], + * ["8",".",".",".","6",".",".",".","3"], + * ["4",".",".","8",".","3",".",".","1"], + * ["7",".",".",".","2",".",".",".","6"], + * [".","6",".",".",".",".","2","8","."], + * [".",".",".","4","1","9",".",".","5"], + * [".",".",".",".","8",".",".","7","9"] + * ] + * Output: true + * Example 2: + * + * Input: + * [ + * ["8","3",".",".","7",".",".",".","."], + * ["6",".",".","1","9","5",".",".","."], + * [".","9","8",".",".",".",".","6","."], + * ["8",".",".",".","6",".",".",".","3"], + * ["4",".",".","8",".","3",".",".","1"], + * ["7",".",".",".","2",".",".",".","6"], + * [".","6",".",".",".",".","2","8","."], + * [".",".",".","4","1","9",".",".","5"], + * [".",".",".",".","8",".",".","7","9"] + * ] + * Output: false + * Explanation: Same as Example 1, except with the 5 in the top left corner being + * modified to 8. Since there are two 8's in the top left 3x3 sub-box, it is invalid. + * Note: + * + * A Sudoku board (partially filled) could be valid but is not necessarily solvable. + * Only the filled cells need to be validated according to the mentioned rules. + * The given board contain only digits 1-9 and the character '.'. + * The given board size is always 9x9. + * */ public class _37 { From 465944d8f879fb69da502934a003664da5cf588c Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Sun, 20 Oct 2019 07:17:08 -0700 Subject: [PATCH 11/17] add test for 37 --- src/test/java/com/fishercoder/_37Test.java | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/test/java/com/fishercoder/_37Test.java diff --git a/src/test/java/com/fishercoder/_37Test.java b/src/test/java/com/fishercoder/_37Test.java new file mode 100644 index 0000000000..c058a24a6b --- /dev/null +++ b/src/test/java/com/fishercoder/_37Test.java @@ -0,0 +1,34 @@ +package com.fishercoder; + +import com.fishercoder.common.utils.CommonUtils; +import com.fishercoder.solutions._37; +import org.junit.BeforeClass; +import org.junit.Test; + +public class _37Test { + private static _37.Solution1 solution1; + private static char[][] board; + + @BeforeClass + public static void setup() { + solution1 = new _37.Solution1(); + } + + @Test + public void test1() { + board = new char[][]{ + {'5', '3', '.', '.', '7', '.', '.', '.', '.'}, + {'6', '.', '.', '1', '9', '5', '.', '.', '.'}, + {'.', '9', '8', '.', '.', '.', '.', '6', '.'}, + {'8', '3', '.', '.', '6', '.', '.', '.', '3'}, + {'4', '.', '.', '8', '.', '3', '.', '.', '1'}, + {'7', '.', '.', '.', '2', '.', '.', '.', '6'}, + {'.', '6', '.', '.', '7', '.', '2', '8', '.'}, + {'.', '.', '.', '4', '1', '9', '.', '.', '5'}, + {'.', '.', '.', '.', '8', '.', '.', '7', '9'} + }; + CommonUtils.print2DCharArray(board); + solution1.solveSudoku(board); + CommonUtils.print2DCharArray(board); + } +} From 916f28fcd12b605fc7787bcbafa437a9f634add5 Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Mon, 21 Oct 2019 06:41:36 -0700 Subject: [PATCH 12/17] add test for 38 --- src/test/java/com/fishercoder/_38Test.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/test/java/com/fishercoder/_38Test.java diff --git a/src/test/java/com/fishercoder/_38Test.java b/src/test/java/com/fishercoder/_38Test.java new file mode 100644 index 0000000000..d2d2644546 --- /dev/null +++ b/src/test/java/com/fishercoder/_38Test.java @@ -0,0 +1,21 @@ +package com.fishercoder; + +import com.fishercoder.solutions._38; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class _38Test { + private static _38.Solution1 solution1; + + @BeforeClass + public static void setup() { + solution1 = new _38.Solution1(); + } + + @Test + public void test1() { + assertEquals("21", solution1.countAndSay(3)); + } +} From 0a2c0dd74bc9d9e8cf3a5b6f9afa48991d9f23e6 Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Tue, 22 Oct 2019 05:34:53 -0700 Subject: [PATCH 13/17] add test for 46 --- src/test/java/com/fishercoder/_46Test.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/test/java/com/fishercoder/_46Test.java diff --git a/src/test/java/com/fishercoder/_46Test.java b/src/test/java/com/fishercoder/_46Test.java new file mode 100644 index 0000000000..506567ecc5 --- /dev/null +++ b/src/test/java/com/fishercoder/_46Test.java @@ -0,0 +1,20 @@ +package com.fishercoder; + +import com.fishercoder.common.utils.CommonUtils; +import com.fishercoder.solutions._46; +import org.junit.BeforeClass; +import org.junit.Test; + +public class _46Test { + private static _46.Solution1 solution1; + + @BeforeClass + public static void setup() { + solution1 = new _46.Solution1(); + } + + @Test + public void test1() { + CommonUtils.printListList(solution1.permute(new int[]{1, 2, 3})); + } +} From 59ed7da6c51962ba811579ecdfd3a2c4778bb2a0 Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Thu, 24 Oct 2019 06:42:29 -0700 Subject: [PATCH 14/17] add test for 58 --- src/test/java/com/fishercoder/_58Test.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/test/java/com/fishercoder/_58Test.java diff --git a/src/test/java/com/fishercoder/_58Test.java b/src/test/java/com/fishercoder/_58Test.java new file mode 100644 index 0000000000..9dca450c7a --- /dev/null +++ b/src/test/java/com/fishercoder/_58Test.java @@ -0,0 +1,21 @@ +package com.fishercoder; + +import com.fishercoder.solutions._58; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class _58Test { + private static _58.Solution1 solution1; + + @BeforeClass + public static void setup() { + solution1 = new _58.Solution1(); + } + + @Test + public void test1() { + assertEquals(5, solution1.lengthOfLastWord("Hello World")); + } +} From 3deaa8747798fb28e2810e37ca45dcde82a504b7 Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Fri, 25 Oct 2019 07:33:17 -0700 Subject: [PATCH 15/17] add test for 59 --- src/test/java/com/fishercoder/_59Test.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/test/java/com/fishercoder/_59Test.java diff --git a/src/test/java/com/fishercoder/_59Test.java b/src/test/java/com/fishercoder/_59Test.java new file mode 100644 index 0000000000..dc31098345 --- /dev/null +++ b/src/test/java/com/fishercoder/_59Test.java @@ -0,0 +1,22 @@ +package com.fishercoder; + +import com.fishercoder.common.utils.CommonUtils; +import com.fishercoder.solutions._59; +import org.junit.BeforeClass; +import org.junit.Test; + +public class _59Test { + private static _59.Solution1 solution1; + private static int[][] matrix; + + @BeforeClass + public static void setup() { + solution1 = new _59.Solution1(); + } + + @Test + public void test1() { + matrix = solution1.generateMatrix(6); + CommonUtils.print2DIntArray(matrix); + } +} From 1738e2787dabada1e40cac072f458dfdb9294454 Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Sat, 26 Oct 2019 09:39:10 -0700 Subject: [PATCH 16/17] add test for 60 --- src/test/java/com/fishercoder/_60Test.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/test/java/com/fishercoder/_60Test.java diff --git a/src/test/java/com/fishercoder/_60Test.java b/src/test/java/com/fishercoder/_60Test.java new file mode 100644 index 0000000000..0c28e11bb6 --- /dev/null +++ b/src/test/java/com/fishercoder/_60Test.java @@ -0,0 +1,21 @@ +package com.fishercoder; + +import com.fishercoder.solutions._60; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class _60Test { + private static _60.Solution1 solution1; + + @BeforeClass + public static void setup() { + solution1 = new _60.Solution1(); + } + + @Test + public void test1() { + assertEquals("231", solution1.getPermutation(3, 4)); + } +} From a7aaf47546438ae6b897ddc41f1b30384a7d13ac Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Sat, 26 Oct 2019 09:59:41 -0700 Subject: [PATCH 17/17] add 1207 --- README.md | 1 + .../java/com/fishercoder/solutions/_1207.java | 43 +++++++++++++++++++ src/test/java/com/fishercoder/_1207Test.java | 35 +++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 src/main/java/com/fishercoder/solutions/_1207.java create mode 100644 src/test/java/com/fishercoder/_1207Test.java diff --git a/README.md b/README.md index 89473655c0..85f52b63e3 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Your ideas/fixes/algorithms are more than welcome! | # | Title | Solutions | Time | Space | Video | Difficulty | Tag |-----|----------------|---------------|---------------|---------------|--------|-------------|------------- +|1207|[Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1207.java) | O(n) | O(1) | |Easy|| |1160|[Find Words That Can Be Formed by Characters](https://leetcode.com/problems/find-words-that-can-be-formed-by-characters/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1160.java) | O(n) | O(m) | |Easy|| |1154|[Day of the Year](https://leetcode.com/problems/day-of-the-year/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1154.java) | O(1) | O(1) | |Easy|| |1137|[N-th Tribonacci Number](https://leetcode.com/problems/n-th-tribonacci-number/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1137.java) | O(n) | O(n) | |Easy|| diff --git a/src/main/java/com/fishercoder/solutions/_1207.java b/src/main/java/com/fishercoder/solutions/_1207.java new file mode 100644 index 0000000000..0d432c54fe --- /dev/null +++ b/src/main/java/com/fishercoder/solutions/_1207.java @@ -0,0 +1,43 @@ +package com.fishercoder.solutions; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * 1207. Unique Number of Occurrences + * + * Given an array of integers arr, + * write a function that returns true if and only if the number of occurrences of each value in the array is unique. + * + * Example 1: + * Input: arr = [1,2,2,1,1,3] + * Output: true + * Explanation: The value 1 has 3 occurrences, 2 has 2 and 3 has 1. No two values have the same number of occurrences. + * + * Example 2: + * Input: arr = [1,2] + * Output: false + * + * Example 3: + * Input: arr = [-3,0,1,-3,1,1,1,-3,10,0] + * Output: true + * + * Constraints: + * 1 <= arr.length <= 1000 + * -1000 <= arr[i] <= 1000 + * */ +public class _1207 { + public static class Solution1 { + public boolean uniqueOccurrences(int[] arr) { + Map map = new HashMap<>(); + Arrays.stream(arr).forEach(num -> { + map.put(num, map.containsKey(num) ? map.get(num) + 1 : 1); + }); + Set set = new HashSet<>(); + return map.keySet().stream().mapToInt(key -> key).allMatch(key -> set.add(map.get(key))); + } + } +} diff --git a/src/test/java/com/fishercoder/_1207Test.java b/src/test/java/com/fishercoder/_1207Test.java new file mode 100644 index 0000000000..8b3e326fac --- /dev/null +++ b/src/test/java/com/fishercoder/_1207Test.java @@ -0,0 +1,35 @@ +package com.fishercoder; + +import com.fishercoder.solutions._1207; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class _1207Test { + private static _1207.Solution1 solution1; + private static int[] arr; + + @BeforeClass + public static void setup() { + solution1 = new _1207.Solution1(); + } + + @Test + public void test1() { + arr = new int[]{1, 2, 2, 1, 1, 3}; + assertEquals(true, solution1.uniqueOccurrences(arr)); + } + + @Test + public void test2() { + arr = new int[]{1, 2}; + assertEquals(false, solution1.uniqueOccurrences(arr)); + } + + @Test + public void test3() { + arr = new int[]{-3, 0, 1, -3, 1, 1, 1, -3, 10, 0}; + assertEquals(true, solution1.uniqueOccurrences(arr)); + } +}