From 9dc004778d1b4d4e151ebeb13c490c9c8a128ea0 Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Sun, 27 Apr 2025 14:56:03 -0700 Subject: [PATCH 1/3] [LEET-3491] add 3491 --- .../algorithms/4th_thousand/README.md | 1 + .../solutions/fourththousand/_3491.java | 16 ++++++++++++++ .../fishercoder/fourththousand/_3491Test.java | 21 +++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 src/main/java/com/fishercoder/solutions/fourththousand/_3491.java create mode 100644 src/test/java/com/fishercoder/fourththousand/_3491Test.java diff --git a/paginated_contents/algorithms/4th_thousand/README.md b/paginated_contents/algorithms/4th_thousand/README.md index 835c3e4faa..424a1eedf5 100644 --- a/paginated_contents/algorithms/4th_thousand/README.md +++ b/paginated_contents/algorithms/4th_thousand/README.md @@ -1,6 +1,7 @@ | # | Title | Solutions | Video | Difficulty | Tag |------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|------------|---------------------------------------------------------------------- | 3502 | [Minimum Cost to Reach Every Position](https://leetcode.com/problems/minimum-cost-to-reach-every-position/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3502.java) | | Easy | +| 3491 | [Phone Number Prefix](https://leetcode.com/problems/phone-number-prefix/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3491.java) | | Easy | | 3471 | [Find the Largest Almost Missing Integer](https://leetcode.com/problems/find-the-largest-almost-missing-integer/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3471.java) | | Easy | | 3402 | [Minimum Operations to Make Columns Strictly Increasing](https://leetcode.com/problems/minimum-operations-to-make-columns-strictly-increasing/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3402.java) | | Easy | | 3396 | [Minimum Number of Operations to Make Elements in Array Distinct](https://leetcode.com/problems/minimum-number-of-operations-to-make-elements-in-array-distinct/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3396.java) | | Easy | diff --git a/src/main/java/com/fishercoder/solutions/fourththousand/_3491.java b/src/main/java/com/fishercoder/solutions/fourththousand/_3491.java new file mode 100644 index 0000000000..fecbad9937 --- /dev/null +++ b/src/main/java/com/fishercoder/solutions/fourththousand/_3491.java @@ -0,0 +1,16 @@ +package com.fishercoder.solutions.fourththousand; + +public class _3491 { + public static class Solution1 { + public boolean phonePrefix(String[] numbers) { + for (int i = 0; i < numbers.length; i++) { + for (int j = 0; j < numbers.length; j++) { + if (i != j && numbers[i].startsWith(numbers[j])) { + return false; + } + } + } + return true; + } + } +} diff --git a/src/test/java/com/fishercoder/fourththousand/_3491Test.java b/src/test/java/com/fishercoder/fourththousand/_3491Test.java new file mode 100644 index 0000000000..08a21eeddc --- /dev/null +++ b/src/test/java/com/fishercoder/fourththousand/_3491Test.java @@ -0,0 +1,21 @@ +package com.fishercoder.fourththousand; + +import com.fishercoder.solutions.fourththousand._3491; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class _3491Test { + private _3491.Solution1 solution1; + + @BeforeEach + public void setup() { + solution1 = new _3491.Solution1(); + } + + @Test + public void test1() { + assertEquals(true, solution1.phonePrefix(new String[]{"1", "2", "4", "3"})); + } +} From 7b5462190632d157c9f010931b73a00c35afeada Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Sun, 27 Apr 2025 14:58:41 -0700 Subject: [PATCH 2/3] [LEET-3491] fix unit test --- src/test/java/com/fishercoder/fourththousand/_3491Test.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/fishercoder/fourththousand/_3491Test.java b/src/test/java/com/fishercoder/fourththousand/_3491Test.java index 08a21eeddc..2e8d934bed 100644 --- a/src/test/java/com/fishercoder/fourththousand/_3491Test.java +++ b/src/test/java/com/fishercoder/fourththousand/_3491Test.java @@ -1,11 +1,11 @@ package com.fishercoder.fourththousand; +import static org.junit.jupiter.api.Assertions.assertEquals; + import com.fishercoder.solutions.fourththousand._3491; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; - public class _3491Test { private _3491.Solution1 solution1; @@ -16,6 +16,6 @@ public void setup() { @Test public void test1() { - assertEquals(true, solution1.phonePrefix(new String[]{"1", "2", "4", "3"})); + assertEquals(true, solution1.phonePrefix(new String[] {"1", "2", "4", "3"})); } } From dd67dd385c03586cb9169e82b10d9a7149dfa587 Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Sun, 27 Apr 2025 15:29:23 -0700 Subject: [PATCH 3/3] [LEET-3477] add 3477 --- .../algorithms/4th_thousand/README.md | 1 + .../solutions/fourththousand/_3477.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/main/java/com/fishercoder/solutions/fourththousand/_3477.java diff --git a/paginated_contents/algorithms/4th_thousand/README.md b/paginated_contents/algorithms/4th_thousand/README.md index 424a1eedf5..5237fed1ea 100644 --- a/paginated_contents/algorithms/4th_thousand/README.md +++ b/paginated_contents/algorithms/4th_thousand/README.md @@ -2,6 +2,7 @@ |------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|------------|---------------------------------------------------------------------- | 3502 | [Minimum Cost to Reach Every Position](https://leetcode.com/problems/minimum-cost-to-reach-every-position/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3502.java) | | Easy | | 3491 | [Phone Number Prefix](https://leetcode.com/problems/phone-number-prefix/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3491.java) | | Easy | +| 3477 | [Fruits Into Baskets II](https://leetcode.com/problems/fruits-into-baskets-ii/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3477.java) | | Easy | | 3471 | [Find the Largest Almost Missing Integer](https://leetcode.com/problems/find-the-largest-almost-missing-integer/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3471.java) | | Easy | | 3402 | [Minimum Operations to Make Columns Strictly Increasing](https://leetcode.com/problems/minimum-operations-to-make-columns-strictly-increasing/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3402.java) | | Easy | | 3396 | [Minimum Number of Operations to Make Elements in Array Distinct](https://leetcode.com/problems/minimum-number-of-operations-to-make-elements-in-array-distinct/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3396.java) | | Easy | diff --git a/src/main/java/com/fishercoder/solutions/fourththousand/_3477.java b/src/main/java/com/fishercoder/solutions/fourththousand/_3477.java new file mode 100644 index 0000000000..f2054202fa --- /dev/null +++ b/src/main/java/com/fishercoder/solutions/fourththousand/_3477.java @@ -0,0 +1,24 @@ +package com.fishercoder.solutions.fourththousand; + +public class _3477 { + public static class Solution1 { + public int numOfUnplacedFruits(int[] fruits, int[] baskets) { + for (int i = 0; i < fruits.length; i++) { + for (int j = 0; j < baskets.length; j++) { + if (fruits[i] <= baskets[j]) { + baskets[j] = -1; + fruits[i] = -1; + break; + } + } + } + int count = 0; + for (int i = 0; i < fruits.length; i++) { + if (fruits[i] > -1) { + count++; + } + } + return count; + } + } +}