We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b1c1428 commit 4604294Copy full SHA for 4604294
src/problems/1022.sum-of-root-to-leaf-binary-numbers.jl
@@ -79,7 +79,7 @@ end
79
sum_root_to_leaf(root::TreeNode{Int}) = _sum_root_to_leaf(root)[1]
80
81
## BFS Algorithm
82
-sum_root_to_leaf_bfs(::Nothing) = 0
+## sum_root_to_leaf_bfs(::Nothing) = 0 # unnecessary
83
function sum_root_to_leaf_bfs(root::TreeNode)
84
queue, res = [(root.val, root)], 0
85
while !isempty(queue)
@@ -88,9 +88,9 @@ function sum_root_to_leaf_bfs(root::TreeNode)
88
if isnothing(node.left) && isnothing(node.right)
89
res += val
90
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))
+ !isnothing(node.left) && push!(queue, (val << 1 + node.left.val, node.left))
+ !isnothing(node.right) &&
+ push!(queue, (val << 1 + node.right.val, node.right))
94
end
95
96
src/problems/486.predict-the-winner.jl
@@ -60,7 +60,7 @@ function is_ipv4(text::String)
60
try
61
all(0 <= parse(Int, x) <= 255 for x in data)
62
catch
63
- false
+ return false
64
65
66
src/problems/623.add-one-row-to-tree.jl
@@ -88,22 +88,23 @@ function add_one_row!(root::TreeNode, val::Int, depth::Int)
if depth == 1
node = TreeNode(val)
node.left = root
- return node
+ node
+ else
+ queue = [root]
+ for _ in 1:(depth - 2), _ in eachindex(queue)
+ node = popfirst!(queue)
+ 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
106
+ root
107
- queue = [root]
- for _ in 1:(depth-2), _ in eachindex(queue)
- node = popfirst!(queue)
- isnothing(node.left) || (push!(queue, node.left))
- isnothing(node.right) || (push!(queue, node.right))
- end
- for node in queue
- left, right = node.left, node.right
- node.left = TreeNode(val)
- node.left.left = left
- node.right = TreeNode(val)
- node.right.right = right
- root
108
109
-## @lc code=end
110
+## @lc code=end
src/problems/929.unique-email-addresses.jl
@@ -60,10 +60,11 @@ using LeetCode
function actual_email(email)
name, domain = split(email, '@')
- name = first(split(replace(name, "."=>""), "+"))
+ name = first(split(replace(name, "." => ""), "+"))
return name * "@" * domain
67
-num_unique_emails(emails::Vector{String}) = length(unique(actual_email(email) for email in emails))
68
-
69
+function num_unique_emails(emails::Vector{String})
+ return length(unique(actual_email(email) for email in emails))
+end
70
test/problems/486.predict-the-winner.jl
@@ -1,6 +1,7 @@
1
@testset "486.predict-the-winner.jl" begin
2
@test valid_ip_address("172.16.254.1") == "IPv4"
3
@test valid_ip_address("2001:0db8:85a3:0:0:8A2E:0370:7334") == "IPv6"
4
+ @test valid_ip_address("85a3.16.254.1") == "Neither"
5
@test valid_ip_address("256.256.256.256") == "Neither"
6
@test valid_ip_address("20EE:FGb8:85a3:0:0:8A2E:0370:7334") == "Neither"
7
test/problems/623.add-one-row-to-tree.jl
@@ -1,10 +1,12 @@
@testset "623.add-one-row-to-tree.jl" begin
@test begin
- root, val, depth = TreeNode{Int}([4,2,6,3,1,5]), 1, 2
- add_one_row!(root, val, depth) == TreeNode{Int}([4,1,1,2,nothing,nothing,6,3,1,5])
+ root, val, depth = TreeNode{Int}([4, 2, 6, 3, 1, 5]), 1, 2
+ add_one_row!(root, val, depth) ==
+ TreeNode{Int}([4, 1, 1, 2, nothing, nothing, 6, 3, 1, 5])
- 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])
+ root, val, depth = TreeNode{Int}([4, 2, nothing, 3, 1]), 1, 3
9
10
+ TreeNode{Int}([4, 2, nothing, 1, 1, 3, nothing, nothing, 1])
11
-end
12
0 commit comments