Skip to content

Commit

Permalink
Solution to 1023 (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
pixia1234 authored Jul 2, 2024
1 parent e5daa11 commit 2eabb4f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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: <https://leetcode.com/problems/camelcase-matching/description/>
Expand Down Expand Up @@ -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
5 changes: 5 additions & 0 deletions test/problems/1023.camelcase-matching.jl
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2eabb4f

Please sign in to comment.