From 1c6c3760a157d9461da736d53021c3074c8fce2e Mon Sep 17 00:00:00 2001 From: Hy <107110503+whanyu1212@users.noreply.github.com> Date: Tue, 9 Jul 2024 05:31:17 +0000 Subject: [PATCH] setting up folder directory using placeholders --- src/kattis/placeholder.py | 0 src/leetcode/twoSum.jl | 9 +++++++++ tests/kattis/test_placeholder.py | 0 tests/leetcode/testTwoSum.jl | 9 +++++++++ 4 files changed, 18 insertions(+) create mode 100644 src/kattis/placeholder.py create mode 100644 src/leetcode/twoSum.jl create mode 100644 tests/kattis/test_placeholder.py create mode 100644 tests/leetcode/testTwoSum.jl diff --git a/src/kattis/placeholder.py b/src/kattis/placeholder.py new file mode 100644 index 0000000..e69de29 diff --git a/src/leetcode/twoSum.jl b/src/leetcode/twoSum.jl new file mode 100644 index 0000000..044d65e --- /dev/null +++ b/src/leetcode/twoSum.jl @@ -0,0 +1,9 @@ +function twoSum(nums::Vector{Int}, target::Int) + dict = Dict{Int, Int}() + for (i, num) in enumerate(nums) + if haskey(dict, target - num) + return [dict[target - num], i] + end + dict[num] = i + end +end \ No newline at end of file diff --git a/tests/kattis/test_placeholder.py b/tests/kattis/test_placeholder.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/leetcode/testTwoSum.jl b/tests/leetcode/testTwoSum.jl new file mode 100644 index 0000000..53b9145 --- /dev/null +++ b/tests/leetcode/testTwoSum.jl @@ -0,0 +1,9 @@ +using Test +include("../../src/leetcode/twoSum.jl") + + +@testset "twoSum" begin + @test twoSum([2, 7, 11, 15], 9) == [1, 2] + @test twoSum([3, 2, 4], 6) == [2, 3] + @test twoSum([3, 3], 6) == [1, 2] +end