Skip to content

Commit 4604294

Browse files
committed
Fix solutions for Codecov
1 parent b1c1428 commit 4604294

6 files changed

+35
-30
lines changed

src/problems/1022.sum-of-root-to-leaf-binary-numbers.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ end
7979
sum_root_to_leaf(root::TreeNode{Int}) = _sum_root_to_leaf(root)[1]
8080

8181
## BFS Algorithm
82-
sum_root_to_leaf_bfs(::Nothing) = 0
82+
## sum_root_to_leaf_bfs(::Nothing) = 0 # unnecessary
8383
function sum_root_to_leaf_bfs(root::TreeNode)
8484
queue, res = [(root.val, root)], 0
8585
while !isempty(queue)
@@ -88,9 +88,9 @@ function sum_root_to_leaf_bfs(root::TreeNode)
8888
if isnothing(node.left) && isnothing(node.right)
8989
res += val
9090
else
91-
val <<= 1
92-
!isnothing(node.left) && push!(queue, (val + node.left.val, node.left))
93-
!isnothing(node.right) && push!(queue, (val + node.right.val, node.right))
91+
!isnothing(node.left) && push!(queue, (val << 1 + node.left.val, node.left))
92+
!isnothing(node.right) &&
93+
push!(queue, (val << 1 + node.right.val, node.right))
9494
end
9595
end
9696
end

src/problems/486.predict-the-winner.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function is_ipv4(text::String)
6060
try
6161
all(0 <= parse(Int, x) <= 255 for x in data)
6262
catch
63-
false
63+
return false
6464
end
6565
end
6666

src/problems/623.add-one-row-to-tree.jl

+17-16
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,23 @@ function add_one_row!(root::TreeNode, val::Int, depth::Int)
8888
if depth == 1
8989
node = TreeNode(val)
9090
node.left = root
91-
return node
91+
node
92+
else
93+
queue = [root]
94+
for _ in 1:(depth - 2), _ in eachindex(queue)
95+
node = popfirst!(queue)
96+
isnothing(node.left) || (push!(queue, node.left))
97+
isnothing(node.right) || (push!(queue, node.right))
98+
end
99+
for node in queue
100+
left, right = node.left, node.right
101+
node.left = TreeNode(val)
102+
node.left.left = left
103+
node.right = TreeNode(val)
104+
node.right.right = right
105+
end
106+
root
92107
end
93-
queue = [root]
94-
for _ in 1:(depth-2), _ in eachindex(queue)
95-
node = popfirst!(queue)
96-
isnothing(node.left) || (push!(queue, node.left))
97-
isnothing(node.right) || (push!(queue, node.right))
98-
end
99-
for node in queue
100-
left, right = node.left, node.right
101-
node.left = TreeNode(val)
102-
node.left.left = left
103-
node.right = TreeNode(val)
104-
node.right.right = right
105-
end
106-
root
107108
end
108109

109-
## @lc code=end
110+
## @lc code=end

src/problems/929.unique-email-addresses.jl

+5-4
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ using LeetCode
6060

6161
function actual_email(email)
6262
name, domain = split(email, '@')
63-
name = first(split(replace(name, "."=>""), "+"))
63+
name = first(split(replace(name, "." => ""), "+"))
6464
return name * "@" * domain
6565
end
6666

67-
num_unique_emails(emails::Vector{String}) = length(unique(actual_email(email) for email in emails))
68-
69-
## @lc code=end
67+
function num_unique_emails(emails::Vector{String})
68+
return length(unique(actual_email(email) for email in emails))
69+
end
70+
## @lc code=end
+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@testset "486.predict-the-winner.jl" begin
22
@test valid_ip_address("172.16.254.1") == "IPv4"
33
@test valid_ip_address("2001:0db8:85a3:0:0:8A2E:0370:7334") == "IPv6"
4+
@test valid_ip_address("85a3.16.254.1") == "Neither"
45
@test valid_ip_address("256.256.256.256") == "Neither"
56
@test valid_ip_address("20EE:FGb8:85a3:0:0:8A2E:0370:7334") == "Neither"
67
end
+7-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
@testset "623.add-one-row-to-tree.jl" begin
22
@test begin
3-
root, val, depth = TreeNode{Int}([4,2,6,3,1,5]), 1, 2
4-
add_one_row!(root, val, depth) == TreeNode{Int}([4,1,1,2,nothing,nothing,6,3,1,5])
3+
root, val, depth = TreeNode{Int}([4, 2, 6, 3, 1, 5]), 1, 2
4+
add_one_row!(root, val, depth) ==
5+
TreeNode{Int}([4, 1, 1, 2, nothing, nothing, 6, 3, 1, 5])
56
end
67
@test begin
7-
root, val, depth = TreeNode{Int}([4,2,nothing,3,1]), 1, 3
8-
add_one_row!(root, val, depth) == TreeNode{Int}([4,2,nothing,1,1,3,nothing,nothing,1])
8+
root, val, depth = TreeNode{Int}([4, 2, nothing, 3, 1]), 1, 3
9+
add_one_row!(root, val, depth) ==
10+
TreeNode{Int}([4, 2, nothing, 1, 1, 3, nothing, nothing, 1])
911
end
10-
end
12+
end

0 commit comments

Comments
 (0)