From f9e7ee72aa3e1f5c54bdc70a741700287c0270dc Mon Sep 17 00:00:00 2001 From: pixia1234 Date: Fri, 19 Jul 2024 12:00:17 +0000 Subject: [PATCH 1/4] modify --- .../28.implement-strstr.jl | 15 +++++++- .../29.divide-two-integers.jl | 18 ++++++++- .../38.count-and-say.jl | 22 ++++++++++- .../40.combination-sum-ii.jl | 37 +++++++++++++++++-- .../46.permutations.jl | 31 ++++++++++++++-- .../47.permutations-ii.jl | 24 +++++++++++- test/problems/1023.camelcase-matching.jl | 12 ++++-- test/problems/28.implement-strstr.jl | 6 +++ test/problems/29.divide-two-integers.jl | 6 +++ test/problems/38.count-and-say.jl | 4 ++ test/problems/40.combination-sum-ii.jl | 5 +++ test/problems/46.permutations.jl | 6 +++ test/problems/47.permutations-ii.jl | 5 +++ 13 files changed, 175 insertions(+), 16 deletions(-) rename src/{unresolved => problems}/28.implement-strstr.jl (78%) rename src/{unresolved => problems}/29.divide-two-integers.jl (76%) rename src/{unresolved => problems}/38.count-and-say.jl (81%) rename src/{unresolved => problems}/40.combination-sum-ii.jl (55%) rename src/{unresolved => problems}/46.permutations.jl (51%) rename src/{unresolved => problems}/47.permutations-ii.jl (53%) create mode 100644 test/problems/28.implement-strstr.jl create mode 100644 test/problems/29.divide-two-integers.jl create mode 100644 test/problems/38.count-and-say.jl create mode 100644 test/problems/40.combination-sum-ii.jl create mode 100644 test/problems/46.permutations.jl create mode 100644 test/problems/47.permutations-ii.jl diff --git a/src/unresolved/28.implement-strstr.jl b/src/problems/28.implement-strstr.jl similarity index 78% rename from src/unresolved/28.implement-strstr.jl rename to src/problems/28.implement-strstr.jl index c86c7c83f..94ad58d31 100644 --- a/src/unresolved/28.implement-strstr.jl +++ b/src/problems/28.implement-strstr.jl @@ -1,8 +1,8 @@ # --- # title: 28. Implement strStr() # id: problem28 -# author: Tian Jun -# date: 2020-10-31 +# author: Pixia1234 +# date: 2024-07-13 # difficulty: Easy # categories: Two Pointers, String # link: @@ -61,5 +61,16 @@ ## @lc code=start using LeetCode +function strStr(haystack::String, needle::String) + if needle == "" + return 0 + end + for i in 1:(length(haystack) - length(needle) + 1) + if haystack[i:(i + length(needle) - 1)] == needle + return i - 1 # Notice that Julia is 1-indexed, and here we need 0-indexed so minus 1 + end + end + return -1 +end ## add your code here: ## @lc code=end diff --git a/src/unresolved/29.divide-two-integers.jl b/src/problems/29.divide-two-integers.jl similarity index 76% rename from src/unresolved/29.divide-two-integers.jl rename to src/problems/29.divide-two-integers.jl index 7bdd22816..23cb3651e 100644 --- a/src/unresolved/29.divide-two-integers.jl +++ b/src/problems/29.divide-two-integers.jl @@ -1,8 +1,8 @@ # --- # title: 29. Divide Two Integers # id: problem29 -# author: Tian Jun -# date: 2020-10-31 +# author: Pixia1234 +# date: 2024-07-17 # difficulty: Medium # categories: Math, Binary Search # link: @@ -69,5 +69,19 @@ ## @lc code=start using LeetCode +function divide(dividend::Int, divisor::Int)::Int + sign = (dividend < 0) ⊻ (divisor < 0) + dividend, divisor = abs(dividend), abs(divisor) + result = 0 + while dividend >= divisor + shift = 0 + while dividend >= (divisor << shift) + shift += 1 + end + dividend -= divisor << (shift - 1) + result += 1 << (shift - 1) + end + return sign ? -result : result +end ## add your code here: ## @lc code=end diff --git a/src/unresolved/38.count-and-say.jl b/src/problems/38.count-and-say.jl similarity index 81% rename from src/unresolved/38.count-and-say.jl rename to src/problems/38.count-and-say.jl index ad4aa4b73..a8e41d61b 100644 --- a/src/unresolved/38.count-and-say.jl +++ b/src/problems/38.count-and-say.jl @@ -1,8 +1,8 @@ # --- # title: 38. Count and Say # id: problem38 -# author: Tian Jun -# date: 2020-10-31 +# author: Pixia1234 +# date: 2024-07-17 # difficulty: Easy # categories: String # link: @@ -62,5 +62,23 @@ ## @lc code=start using LeetCode +function countandsay(n::Int) + if n == 1 + return "1" + end + s = countandsay(n - 1) + i = 1 + j = 1 + res = "" + while j <= length(s) + if s[j] != s[i] + res *= string(j - i) * string(s[i]) + i = j + end + j += 1 + end + res *= string(j - i) * string(s[i]) + return res +end ## add your code here: ## @lc code=end diff --git a/src/unresolved/40.combination-sum-ii.jl b/src/problems/40.combination-sum-ii.jl similarity index 55% rename from src/unresolved/40.combination-sum-ii.jl rename to src/problems/40.combination-sum-ii.jl index 6051eb3d7..6f7f0bba4 100644 --- a/src/unresolved/40.combination-sum-ii.jl +++ b/src/problems/40.combination-sum-ii.jl @@ -1,8 +1,8 @@ # --- # title: 40. Combination Sum II # id: problem40 -# author: Tian Jun -# date: 2020-10-31 +# author: Pixia1234 +# date: 2024-07-18 # difficulty: Medium # categories: Array, Backtracking # link: @@ -57,5 +57,36 @@ ## @lc code=start using LeetCode -## add your code here: +function dfs( + candidates::Vector{Int}, + target::Int, + path::Vector{Int}, + start::Int, + res::Vector{Vector{Int}}, +) + if target == 0 + push!(res, copy(path)) + return nothing + end + for i in start:length(candidates) + if i > start && candidates[i] == candidates[i - 1] + continue + end + if target - candidates[i] < 0 + break + end + push!(path, candidates[i]) + dfs(candidates, target - candidates[i], path, i + 1, res) + pop!(path) + end +end ## We use dfs here and for sure there exists more ways to solve the problem. + +function combinationSum(candidates::Vector{Int}, target::Int) + res = Vector{Vector{Int}}() + sort!(candidates) + path = Int[] + dfs(candidates, target, path, 1, res) + return res +end + ## @lc code=end diff --git a/src/unresolved/46.permutations.jl b/src/problems/46.permutations.jl similarity index 51% rename from src/unresolved/46.permutations.jl rename to src/problems/46.permutations.jl index 9c8989eab..69ad6360d 100644 --- a/src/unresolved/46.permutations.jl +++ b/src/problems/46.permutations.jl @@ -1,8 +1,8 @@ # --- # title: 46. Permutations # id: problem46 -# author: Tian Jun -# date: 2020-10-31 +# author: Pixia1234 +# date: 2024-07-19 # difficulty: Medium # categories: Backtracking # link: @@ -50,5 +50,30 @@ ## @lc code=start using LeetCode -## add your code here: +function permutation(nums::Vector{Int})::Vector{Vector{Int}} + res = Vector{Vector{Int}}() + n = length(nums) + sizehint!(res, factorial(n)) + function dfs(nums::Vector{Int}, path::Vector{Int}, used::Vector{Bool}) + if length(path) == n + push!(res, copy(path)) + return nothing + end + for i in 1:n + if !used[i] + if i > 1 && nums[i] == nums[i - 1] && !used[i - 1] + continue + end + used[i] = true + push!(path, nums[i]) + dfs(nums, path, used) + pop!(path) + used[i] = false + end + end + end + sort!(nums) + dfs(nums, Int[], fill(false, n)) + return res +end ## @lc code=end diff --git a/src/unresolved/47.permutations-ii.jl b/src/problems/47.permutations-ii.jl similarity index 53% rename from src/unresolved/47.permutations-ii.jl rename to src/problems/47.permutations-ii.jl index 5a7df9f5e..c7aa5bbc2 100644 --- a/src/unresolved/47.permutations-ii.jl +++ b/src/problems/47.permutations-ii.jl @@ -44,5 +44,27 @@ ## @lc code=start using LeetCode -## add your code here: +function permutationII(nums::Vector{Int})::Vector{Vector{Int}} + res = Vector{Vector{Int}}() + n = length(nums) + function dfs(nums::Vector{Int}, path::Vector{Int}, used::Vector{Bool}) + if length(path) == n + push!(res, copy(path)) + return nothing + end + @inbounds for i in 1:n + if used[i] || (i > 1 && nums[i] == nums[i - 1] && !used[i - 1]) + continue + end + push!(path, nums[i]) + used[i] = true + dfs(nums, path, used) + pop!(path) + used[i] = false + end + end + sort!(nums) + dfs(nums, Vector{Int}(), fill(false, n)) + return res +end ## @lc code=end diff --git a/test/problems/1023.camelcase-matching.jl b/test/problems/1023.camelcase-matching.jl index 2a5fe37b5..474a668ee 100644 --- a/test/problems/1023.camelcase-matching.jl +++ b/test/problems/1023.camelcase-matching.jl @@ -1,5 +1,11 @@ @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") + @test camelMatch( + ("FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"), "FB" + ) == Bool[1, 0, 1, 1, 0] + @test camelMatch( + ("FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"), "FoBa" + ) == Bool[1, 0, 1, 0, 0] + @test camelMatch( + ("FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"), "FoBaT" + ) == Bool[0, 1, 0, 0, 0] end diff --git a/test/problems/28.implement-strstr.jl b/test/problems/28.implement-strstr.jl new file mode 100644 index 000000000..4a6299b01 --- /dev/null +++ b/test/problems/28.implement-strstr.jl @@ -0,0 +1,6 @@ +@testset "28.implement-strstr.jl" begin + @test strStr("hello", "ll") == 2 + @test strStr("aaaaa", "bba") == -1 + @test strStr("sadbutsad", "sad") == 0 + @test strStr("leetcode", "leeto") == -1 +end diff --git a/test/problems/29.divide-two-integers.jl b/test/problems/29.divide-two-integers.jl new file mode 100644 index 000000000..77c434765 --- /dev/null +++ b/test/problems/29.divide-two-integers.jl @@ -0,0 +1,6 @@ +@testset "29.divide-two-integers.jl" begin + @test divide(10, 3) == 3 + @test divide(7, -3) == -2 + @test divide(0, 1) == 0 + @test divide(1, 1) == 1 +end diff --git a/test/problems/38.count-and-say.jl b/test/problems/38.count-and-say.jl new file mode 100644 index 000000000..5cb283bc7 --- /dev/null +++ b/test/problems/38.count-and-say.jl @@ -0,0 +1,4 @@ +@testset "38.count-and-say.jl" begin + @test countandsay(1) == "1" + @test countandsay(4) == "1211" +end diff --git a/test/problems/40.combination-sum-ii.jl b/test/problems/40.combination-sum-ii.jl new file mode 100644 index 000000000..dfc5f928e --- /dev/null +++ b/test/problems/40.combination-sum-ii.jl @@ -0,0 +1,5 @@ +@testset "40.combination-sum-ii.jl" begin + @test combinationSum([10, 1, 2, 7, 6, 1, 5], 8) == + [[1, 1, 6], [1, 2, 5], [1, 7], [2, 6]] + @test combinationSum([2, 5, 2, 1, 2], 5) == [[1, 2, 2], [5]] +end diff --git a/test/problems/46.permutations.jl b/test/problems/46.permutations.jl new file mode 100644 index 000000000..c113def66 --- /dev/null +++ b/test/problems/46.permutations.jl @@ -0,0 +1,6 @@ +@testset "46.permutations.jl" begin + @test permutation([1, 2, 3]) == + [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]] + @test permutation([0, 1]) == [[0, 1], [1, 0]] + @test permutation([1]) == [[1]] +end diff --git a/test/problems/47.permutations-ii.jl b/test/problems/47.permutations-ii.jl new file mode 100644 index 000000000..a1541455e --- /dev/null +++ b/test/problems/47.permutations-ii.jl @@ -0,0 +1,5 @@ +@testset "47.permutations-ii.jl" begin + @test permutationII([1, 1, 2]) == [[1, 1, 2], [1, 2, 1], [2, 1, 1]] + @test permutationII([1, 2, 3]) == + [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]] +end From 853f2f8d84d9edbe4631485211b8e2d4846e424d Mon Sep 17 00:00:00 2001 From: RexWzh <1073853456@qq.com> Date: Fri, 19 Jul 2024 22:50:49 +0800 Subject: [PATCH 2/4] use @view method, simplify border case --- src/problems/1023.camelcase-matching.jl | 6 ++---- src/problems/28.implement-strstr.jl | 20 +++++++++----------- test/problems/1023.camelcase-matching.jl | 12 +++--------- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/problems/1023.camelcase-matching.jl b/src/problems/1023.camelcase-matching.jl index 7a428f7e0..9f6721d8a 100644 --- a/src/problems/1023.camelcase-matching.jl +++ b/src/problems/1023.camelcase-matching.jl @@ -74,11 +74,9 @@ function matches(query, pattern) end i += 1 end - return j > length(pattern) && all(!isuppercase, query[i:end]) + return j > length(pattern) && all(islowercase, @view(query[i:end])) end -function camelMatch(queries, pattern) - return [matches(query, pattern) for query in queries] -end +camelMatch(queries, pattern) = matches.(queries, Ref(pattern)) ## @lc code=end diff --git a/src/problems/28.implement-strstr.jl b/src/problems/28.implement-strstr.jl index 94ad58d31..a8068eed1 100644 --- a/src/problems/28.implement-strstr.jl +++ b/src/problems/28.implement-strstr.jl @@ -61,16 +61,14 @@ ## @lc code=start using LeetCode -function strStr(haystack::String, needle::String) - if needle == "" - return 0 - end - for i in 1:(length(haystack) - length(needle) + 1) - if haystack[i:(i + length(needle) - 1)] == needle - return i - 1 # Notice that Julia is 1-indexed, and here we need 0-indexed so minus 1 - end - end - return -1 +function strStr(haystack::AbstractString, needle::AbstractString) + # border case + isempty(needle) && return 0 + length(needle) > length(haystack) && return -1 + # match needle + needle == @view(haystack[1:length(needle)]) && return 0 + # recursive search + ind = @views strStr(haystack[2:end], needle) + return ind == -1 ? -1 : ind + 1 end -## add your code here: ## @lc code=end diff --git a/test/problems/1023.camelcase-matching.jl b/test/problems/1023.camelcase-matching.jl index 474a668ee..04c59f063 100644 --- a/test/problems/1023.camelcase-matching.jl +++ b/test/problems/1023.camelcase-matching.jl @@ -1,11 +1,5 @@ @testset "1023.camelcase-matching.jl" begin - @test camelMatch( - ("FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"), "FB" - ) == Bool[1, 0, 1, 1, 0] - @test camelMatch( - ("FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"), "FoBa" - ) == Bool[1, 0, 1, 0, 0] - @test camelMatch( - ("FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"), "FoBaT" - ) == Bool[0, 1, 0, 0, 0] + @test camelMatch(["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"],"FB") == [true,false,true,true,false] + @test camelMatch(["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"],"FoBa") == [true,false,true,false,false] + @test camelMatch(["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"],"FoBaT") == [false,true,false,false,false] end From a402273f6d5c6137e2b22506e099b98e65cf5e0b Mon Sep 17 00:00:00 2001 From: RexWzh <1073853456@qq.com> Date: Fri, 19 Jul 2024 23:10:39 +0800 Subject: [PATCH 3/4] fix problem 38 --- src/problems/29.divide-two-integers.jl | 1 - src/problems/38.count-and-say.jl | 33 ++++++++++++++------------ test/problems/38.count-and-say.jl | 2 ++ 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/problems/29.divide-two-integers.jl b/src/problems/29.divide-two-integers.jl index 23cb3651e..e64f3f42f 100644 --- a/src/problems/29.divide-two-integers.jl +++ b/src/problems/29.divide-two-integers.jl @@ -83,5 +83,4 @@ function divide(dividend::Int, divisor::Int)::Int end return sign ? -result : result end -## add your code here: ## @lc code=end diff --git a/src/problems/38.count-and-say.jl b/src/problems/38.count-and-say.jl index a8e41d61b..504634a2c 100644 --- a/src/problems/38.count-and-say.jl +++ b/src/problems/38.count-and-say.jl @@ -63,22 +63,25 @@ using LeetCode function countandsay(n::Int) - if n == 1 - return "1" - end - s = countandsay(n - 1) - i = 1 - j = 1 - res = "" - while j <= length(s) - if s[j] != s[i] - res *= string(j - i) * string(s[i]) - i = j + # Base case + n == 1 && return "1" + # Get the previous term + previous_term = countandsay(n - 1) + # Generate the current term by "saying" the previous term + current_term = "" + count = 0 + current_char = previous_term[1] + + for char in previous_term + if char == current_char + count += 1 + else + current_term *= string(count) * current_char + current_char = char + count = 1 end - j += 1 end - res *= string(j - i) * string(s[i]) - return res + # Append the last group + current_term * string(count) * current_char end -## add your code here: ## @lc code=end diff --git a/test/problems/38.count-and-say.jl b/test/problems/38.count-and-say.jl index 5cb283bc7..78b7de06e 100644 --- a/test/problems/38.count-and-say.jl +++ b/test/problems/38.count-and-say.jl @@ -1,4 +1,6 @@ @testset "38.count-and-say.jl" begin @test countandsay(1) == "1" @test countandsay(4) == "1211" + @test countandsay(5) == "111221" + @test countandsay(6) == "312211" end From 20e440dd0135ce1588bcd41520d5c657ef972769 Mon Sep 17 00:00:00 2001 From: RexWzh <1073853456@qq.com> Date: Sat, 20 Jul 2024 00:15:06 +0800 Subject: [PATCH 4/4] use some style tricks --- src/problems/28.implement-strstr.jl | 16 ++++++++-- src/problems/40.combination-sum-ii.jl | 43 +++++++++++---------------- src/problems/46.permutations.jl | 26 +++++++--------- test/problems/28.implement-strstr.jl | 4 +++ test/problems/46.permutations.jl | 2 +- 5 files changed, 47 insertions(+), 44 deletions(-) diff --git a/src/problems/28.implement-strstr.jl b/src/problems/28.implement-strstr.jl index a8068eed1..5d30b1c39 100644 --- a/src/problems/28.implement-strstr.jl +++ b/src/problems/28.implement-strstr.jl @@ -61,14 +61,24 @@ ## @lc code=start using LeetCode -function strStr(haystack::AbstractString, needle::AbstractString) +function strStr(haystack::String, needle::String) + needle == "" && return 0 + for i in 1:(length(haystack) - length(needle) + 1) + if @view(haystack[i:(i + length(needle) - 1)]) == needle + return i - 1 # Notice that Julia is 1-indexed, and here we need 0-indexed so minus 1 + end + end + return -1 +end + +function strStr2(haystack::AbstractString, needle::AbstractString) # border case - isempty(needle) && return 0 + isempty(needle) && return 0 length(needle) > length(haystack) && return -1 # match needle needle == @view(haystack[1:length(needle)]) && return 0 # recursive search - ind = @views strStr(haystack[2:end], needle) + ind = @views strStr2(haystack[2:end], needle) return ind == -1 ? -1 : ind + 1 end ## @lc code=end diff --git a/src/problems/40.combination-sum-ii.jl b/src/problems/40.combination-sum-ii.jl index 6f7f0bba4..563a24267 100644 --- a/src/problems/40.combination-sum-ii.jl +++ b/src/problems/40.combination-sum-ii.jl @@ -57,35 +57,28 @@ ## @lc code=start using LeetCode -function dfs( - candidates::Vector{Int}, +function combinationSum(candidates::AbstractVector{Int}, target::Int) + res = Vector{Vector{Int}}() + return combinationSum!(sort(candidates), target, Int[], res) +end + +function combinationSum!( + candidates::AbstractVector{Int}, target::Int, - path::Vector{Int}, - start::Int, + path::AbstractVector{Int}, res::Vector{Vector{Int}}, ) - if target == 0 - push!(res, copy(path)) - return nothing - end - for i in start:length(candidates) - if i > start && candidates[i] == candidates[i - 1] - continue - end - if target - candidates[i] < 0 - break - end - push!(path, candidates[i]) - dfs(candidates, target - candidates[i], path, i + 1, res) - pop!(path) - end -end ## We use dfs here and for sure there exists more ways to solve the problem. + # if the target is 0, we find a solution + target == 0 && return push!(res, copy(path)) + length(candidates) == 0 || target < first(candidates) && return res -function combinationSum(candidates::Vector{Int}, target::Int) - res = Vector{Vector{Int}}() - sort!(candidates) - path = Int[] - dfs(candidates, target, path, 1, res) + # use @view to avoid copying the array + for (i, candidate) in enumerate(candidates) + i > 1 && candidate == candidates[i - 1] && continue + candidate > target && break + subcandidates = @view(candidates[1:length(candidate) .!= i]) # skip the current candidate + combinationSum!(subcandidates, target - candidate, push!(path, candidate), res) + end return res end diff --git a/src/problems/46.permutations.jl b/src/problems/46.permutations.jl index 69ad6360d..ce01193cc 100644 --- a/src/problems/46.permutations.jl +++ b/src/problems/46.permutations.jl @@ -50,30 +50,26 @@ ## @lc code=start using LeetCode -function permutation(nums::Vector{Int})::Vector{Vector{Int}} +permutation(nums::Vector{Int}) = permutation!(copy(nums)) +function permutation!(nums::Vector{Int}) + sort!(nums) res = Vector{Vector{Int}}() n = length(nums) sizehint!(res, factorial(n)) - function dfs(nums::Vector{Int}, path::Vector{Int}, used::Vector{Bool}) - if length(path) == n + function dfs(nums::Vector{Int}, path::Vector{Int}, used::Vector{Bool}, len::Int) + if len == n # alternatively, len = sum(used) push!(res, copy(path)) return nothing end for i in 1:n - if !used[i] - if i > 1 && nums[i] == nums[i - 1] && !used[i - 1] - continue - end - used[i] = true - push!(path, nums[i]) - dfs(nums, path, used) - pop!(path) - used[i] = false - end + used[i] && continue + used[i] = true + path[len + 1] = nums[i] + dfs(nums, path, used, len + 1) + used[i] = false end end - sort!(nums) - dfs(nums, Int[], fill(false, n)) + dfs(nums, Vector{Int}(undef, n), fill(false, n), 0) return res end ## @lc code=end diff --git a/test/problems/28.implement-strstr.jl b/test/problems/28.implement-strstr.jl index 4a6299b01..407b0df69 100644 --- a/test/problems/28.implement-strstr.jl +++ b/test/problems/28.implement-strstr.jl @@ -3,4 +3,8 @@ @test strStr("aaaaa", "bba") == -1 @test strStr("sadbutsad", "sad") == 0 @test strStr("leetcode", "leeto") == -1 + @test strStr2("hello", "ll") == 2 + @test strStr2("aaaaa", "bba") == -1 + @test strStr2("sadbutsad", "sad") == 0 + @test strStr2("leetcode", "leeto") == -1 end diff --git a/test/problems/46.permutations.jl b/test/problems/46.permutations.jl index c113def66..f9ce03c17 100644 --- a/test/problems/46.permutations.jl +++ b/test/problems/46.permutations.jl @@ -1,5 +1,5 @@ @testset "46.permutations.jl" begin - @test permutation([1, 2, 3]) == + @test sort!(permutation([1, 3, 2])) == [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]] @test permutation([0, 1]) == [[0, 1], [1, 0]] @test permutation([1]) == [[1]]