From 32fcb817fbddf63ae9eb18deb4adafbe7dff9acc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 26 Feb 2026 01:12:08 +0000 Subject: [PATCH 1/2] Initial plan From acb3cc9c9f65e0327d64384eece713f5239e5c20 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 26 Feb 2026 01:24:45 +0000 Subject: [PATCH 2/2] Fix test method names and update complexity docstring for CountAsterisks2315 Co-authored-by: kobukuro <9405082+kobukuro@users.noreply.github.com> --- src/main/java/com/leetcode/easy/CountAsterisks2315.java | 9 +++++---- .../java/com/leetcode/easy/CountAsterisks2315Test.java | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/leetcode/easy/CountAsterisks2315.java b/src/main/java/com/leetcode/easy/CountAsterisks2315.java index 7633841..c395850 100644 --- a/src/main/java/com/leetcode/easy/CountAsterisks2315.java +++ b/src/main/java/com/leetcode/easy/CountAsterisks2315.java @@ -3,15 +3,16 @@ public class CountAsterisks2315 { /** + * Let n = s.length() and m = words.length (the number of split segments), where m <= n + 1. * Time complexity: O(n) * Breakdown: * - Split operation: s.split("\\|") iterates through the entire string - O(n) - * - Outer loop: Iterates through half of the segments - O(n/2) - * - Inner loop: Total characters checked is at most n - O(n) + * - Outer loop: Iterates through about half of the segments - O(m/2) = O(m) + * - Inner loop: Across all iterations, the total number of characters checked is at most n - O(n) + * Overall: O(n) *

* Space complexity: O(n) - * Breakdown: - * - Array storage: String[] words stores segments - O(n) + * - Array storage: String[] words holds m references to substrings whose total length is O(n) - O(n) */ public int countAsterisks(String s) { String[] words = s.split("\\|"); diff --git a/src/test/java/com/leetcode/easy/CountAsterisks2315Test.java b/src/test/java/com/leetcode/easy/CountAsterisks2315Test.java index 3100e56..d2129b0 100644 --- a/src/test/java/com/leetcode/easy/CountAsterisks2315Test.java +++ b/src/test/java/com/leetcode/easy/CountAsterisks2315Test.java @@ -14,7 +14,7 @@ void setUp() { } @Test - void testTwoSum_Example1() { + void testCountAsterisks_Example1() { String s = "l|*e*et|c**o|*de|"; int result = solution.countAsterisks(s); @@ -23,7 +23,7 @@ void testTwoSum_Example1() { } @Test - void testTwoSum_Example2() { + void testCountAsterisks_Example2() { String s = "iamprogrammer"; int result = solution.countAsterisks(s); @@ -32,7 +32,7 @@ void testTwoSum_Example2() { } @Test - void testTwoSum_Example3() { + void testCountAsterisks_Example3() { String s = "yo|uar|e**|b|e***au|tiful"; int result = solution.countAsterisks(s);