From 379051dd9eb51927e0eecf90cb8576d0aec20a3f Mon Sep 17 00:00:00 2001 From: pixia1234 <61567631+pixia1234@users.noreply.github.com> Date: Sat, 29 Jun 2024 03:07:44 +0000 Subject: [PATCH] Solution to 1023 --- .../1023.camelcase-matching.jl | 22 ++++++++++++++++--- test/problems/1023.camelcase-matching.jl | 5 +++++ 2 files changed, 24 insertions(+), 3 deletions(-) rename src/{unresolved => problems}/1023.camelcase-matching.jl (80%) create mode 100644 test/problems/1023.camelcase-matching.jl diff --git a/src/unresolved/1023.camelcase-matching.jl b/src/problems/1023.camelcase-matching.jl similarity index 80% rename from src/unresolved/1023.camelcase-matching.jl rename to src/problems/1023.camelcase-matching.jl index b806bb37b..7a428f7e0 100644 --- a/src/unresolved/1023.camelcase-matching.jl +++ b/src/problems/1023.camelcase-matching.jl @@ -1,8 +1,8 @@ # --- # title: 1023. Camelcase Matching # id: problem1023 -# author: Tian Jun -# date: 2020-10-31 +# author: Pixia1234 +# date: 2024-06-29 # difficulty: Medium # categories: String, Trie # link: @@ -64,5 +64,21 @@ ## @lc code=start using LeetCode -## add your code here: +function matches(query, pattern) + i, j = 1, 1 + while i <= length(query) && j <= length(pattern) + if query[i] == pattern[j] + j += 1 + elseif isuppercase(query[i]) + return false + end + i += 1 + end + return j > length(pattern) && all(!isuppercase, query[i:end]) +end + +function camelMatch(queries, pattern) + return [matches(query, pattern) for query in queries] +end + ## @lc code=end diff --git a/test/problems/1023.camelcase-matching.jl b/test/problems/1023.camelcase-matching.jl new file mode 100644 index 000000000..2a5fe37b5 --- /dev/null +++ b/test/problems/1023.camelcase-matching.jl @@ -0,0 +1,5 @@ +@testset "1023.camelcase-matching.jl" begin + @test camelMatch(("FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"),"FB") == ("1,0,1,1,0") + @test camelMatch(("FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"),"FoBa") == ("1,0,1,0,0") + @test camelMatch(("FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"),"FoBaT") == ("0,1,0,0,0") +end