This repository contains solutions to various LeetCode problems implemented in both TypeScript and Python.
leetcode-tests/
├── javascript/ # TypeScript implementations
│ ├── duplicate_integer/
│ ├── top_k_elements_list/
│ ├── two_integer_sum/
│ ├── valid_anagram/
│ ├── package.json
│ ├── package-lock.json
│ └── tsconfig.json
├── python/ # Python implementations
│ ├── duplicate_integer/
│ ├── top_k_elements_list/
│ ├── two_integer_sum/
│ └── valid_anagram/
└── README.md
-
Navigate to the JavaScript directory:
cd javascript
-
Install dependencies:
npm install
You have several options to run the TypeScript implementations:
# Run individual files
npx ts-node duplicate_integer/index.ts
npx ts-node top_k_elements_list/index.ts
npx ts-node two_integer_sum/index.ts
npx ts-node valid_anagram/index.ts
# Compile all TypeScript files
npm run build
# Run the compiled JavaScript files
node duplicate_integer/index.js
node top_k_elements_list/index.js
node two_integer_sum/index.js
node valid_anagram/index.js
# Install ts-node globally
npm install -g ts-node
# Then run directly
ts-node duplicate_integer/index.ts
Python files can be run directly without any additional setup:
# Navigate to the python directory
cd python
# Run individual files
python duplicate_integer/index.py
python top_k_elements_list/index.py
python two_integer_sum/index.py
python valid_anagram/index.py
File: duplicate_integer/index.*
- Problem: Given an integer array, return
true
if any value appears more than once. - Time Complexity: O(n)
- Space Complexity: O(n)
File: top_k_elements_list/index.*
- Problem: Given an integer array and an integer k, return the k most frequent elements.
- Time Complexity: O(n log n)
- Space Complexity: O(n)
File: two_integer_sum/index.*
- Problem: Given an array of integers and a target, return indices of two numbers that add up to the target.
- Time Complexity: O(n²)
- Space Complexity: O(1)
File: valid_anagram/index.*
- Problem: Given two strings, return
true
if they are anagrams of each other. - Time Complexity: O(n log n)
- Space Complexity: O(n)
The project uses the following TypeScript configuration:
- Target: ES2020
- Module: CommonJS
- Module Resolution: Bundler
- Strict mode: Enabled
- TypeScript: ^5.1.6
- ts-node: ^10.9.1
- @types/node: ^20.5.0
cd javascript
npx ts-node duplicate_integer/index.ts
cd python
python duplicate_integer/index.py
Both implementations will run their respective test cases and display the results in the console.