From cff85a0488aa45561125bccedb18f49341f6b4e4 Mon Sep 17 00:00:00 2001 From: Cal Barkman Date: Sun, 19 Oct 2025 21:40:21 -0700 Subject: [PATCH] Problem 026 quick and dirty, but executes very fast --- problem_026/solution.py | 36 ++++++++++++++++++++++++++++++++++++ problem_026/test_inputs.json | 13 +++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 problem_026/solution.py create mode 100644 problem_026/test_inputs.json diff --git a/problem_026/solution.py b/problem_026/solution.py new file mode 100644 index 0000000..dcad5c4 --- /dev/null +++ b/problem_026/solution.py @@ -0,0 +1,36 @@ +# Extra header to ensure that tests can run individually and as a suite +# ------------------------------------------------------------------- +import sys +from pathlib import Path +# Add the project root folder to the Python path +sys.path.append(str(Path(__file__).resolve().parents[1])) +# ------------------------------------------------------------------- + +# Now you can import your wrapper +from test_runner.wrapper import run_tests +from typing import List + +class Solution: + def removeDuplicates(self, nums: List[int]) -> int: + # Remove duplicates by creating a set + nums_set = set(nums) + # Get the length for a return value + k = len(nums_set) + # Create a temporary list (bad for memory complexity, good for writing quickly) + temp_list = list(nums_set) + # Sort that list for how the answer expects the results + temp_list.sort() + # Replace in memory the values of nums with temp_list + nums[:] = temp_list + return k + + +if __name__ == "__main__": + # Get the directory where this solution.py script lives + script_dir = Path(__file__).parent + + # Join the script's directory with the JSON filename to create a full path + # Make sure your file is actually named "test_inputs.json"! + test_file_path = script_dir / "test_inputs.json" + + run_tests(Solution, test_file_path) \ No newline at end of file diff --git a/problem_026/test_inputs.json b/problem_026/test_inputs.json new file mode 100644 index 0000000..7ea624f --- /dev/null +++ b/problem_026/test_inputs.json @@ -0,0 +1,13 @@ +{ + "method": "removeDuplicates", + "tests": [ + { + "Input": "[1,1,2]", + "Output": "2" + }, + { + "Input": "[0,0,1,1,1,2,2,3,3,4]", + "Output": "5" + } + ] +} \ No newline at end of file