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