This document details the programming languages supported in the doocs/leetcode repository and the conventions used for implementing solutions across different languages. It covers file naming standards, language-specific idioms, data structure equivalents, and coding patterns that maintain algorithmic consistency while respecting each language's best practices.
For information about the automated formatting system that enforces these conventions, see Code Formatting System.
The repository provides functionally equivalent solutions for each problem in 12+ programming languages. Each language follows idiomatic patterns while implementing the same algorithmic approach.
| Language | File Extension | Primary Use Case |
|---|---|---|
| Python | .py | Reference implementation, scripting |
| Java | .java | Enterprise, object-oriented patterns |
| C++ | .cpp | Performance-critical implementations |
| Go | .go | Concurrent systems, simplicity |
| Rust | .rs | Memory safety, systems programming |
| TypeScript | .ts | Type-safe JavaScript |
| JavaScript | .js | Web development, Node.js |
| C# | .cs | .NET ecosystem |
| PHP | .php | Web backend |
| Ruby | .rb | Scripting, web frameworks |
| Swift | .swift | iOS/macOS development |
| Nim | .nim | Performance with Python-like syntax |
| C | .c | Low-level systems programming |
| Scala | .scala | JVM functional programming |
| Kotlin | .kt | Modern JVM language |
| Cangjie | .cj | Emerging language support |
Sources: solution/0000-0099/0001.Two Sum/README.md79-403 solution/0000-0099/0001.Two Sum/README_EN.md76-401
All solution files follow the pattern Solution.<extension> within each problem directory:
solution/0000-0099/0001.Two Sum/
├── README.md
├── README_EN.md
├── Solution.py
├── Solution.java
├── Solution.cpp
├── Solution.go
├── Solution.rs
├── Solution.ts
├── Solution.js
├── Solution.cs
├── Solution.php
├── Solution.rb
├── Solution.swift
├── Solution.nim
└── Solution.c
When a problem has multiple solution approaches, they are documented in the same Solution.<extension> file using language-specific mechanisms:
Sources: solution/0000-0099/0001.Two Sum/ file structure observation
Sources: solution/0000-0099/0001.Two Sum/README.md1-410 solution/0000-0099/0001.Two Sum/README_EN.md1-407
Different languages use different native constructs for key-value mappings:
| Language | Data Structure | Declaration Syntax | Key Example |
|---|---|---|---|
| Python | dict | d = {} | if (y := target - x) in d: |
| Java | HashMap | Map<Integer, Integer> d = new HashMap<>() | d.containsKey(y) |
| C++ | unordered_map | unordered_map<int, int> d; | d.contains(y) |
| Go | map | d := map[int]int{} | if j, ok := d[y]; ok |
| Rust | HashMap | let mut d = HashMap::new(); | if let Some(&j) = d.get(&y) |
| TypeScript | Map | const d = new Map<number, number>() | d.has(y) |
| JavaScript | Map | const d = new Map() | d.has(y) |
| C# | Dictionary | var d = new Dictionary<int, int>() | d.TryGetValue(y, out j) |
| PHP | array | $d = [] | isset($d[$y]) |
| Ruby | Hash | d = {} | d.key?(y) |
| Swift | Dictionary | var d = <FileRef file-url="https://github.com/doocs/leetcode/blob/ae35e0ed/Int#LNaN-LNaN" NaN file-path="Int">Hii</FileRef> | if let j = d[y] |
| Nim | Table | var d = initTable<FileRef file-url="https://github.com/doocs/leetcode/blob/ae35e0ed/int, int" undefined file-path="int, int">Hii</FileRef> | d.hasKey(y) |
Sources: solution/0000-0099/0001.Two Sum/Solution.py3-7 solution/0000-0099/0001.Two Sum/Solution.java3-10 solution/0000-0099/0001.Two Sum/Solution.cpp4-11 solution/0000-0099/0001.Two Sum/Solution.go2-10 solution/0000-0099/0001.Two Sum/Solution.rs4-13
Sources: solution/0000-0099/0001.Two Sum/Solution.py4-6
Sources: solution/0000-0099/0001.Two Sum/Solution.java4-9
Sources: solution/0000-0099/0001.Two Sum/Solution.rs6-10
Sources: solution/0000-0099/0001.Two Sum/Solution.go3-8
Different languages handle character checking and case conversion differently:
Sources: solution/0100-0199/0125.Valid Palindrome/Solution.py5-9
Sources: solution/0100-0199/0125.Valid Palindrome/Solution.java5-9
Sources: solution/0100-0199/0125.Valid Palindrome/Solution.cpp5-9
Sources: solution/0100-0199/0125.Valid Palindrome/Solution.go17-26
Sources: solution/0000-0099/0001.Two Sum/Solution.java2 solution/0000-0099/0001.Two Sum/Solution.cpp3 solution/0000-0099/0001.Two Sum/Solution.rs4 solution/0000-0099/0001.Two Sum/Solution.py2
malloc/free calls
Sources: solution/0000-0099/0001.Two Sum/Solution.c363-400
Sources: solution/0000-0099/0001.Two Sum/Solution.rs6-7
| Language | Return Type | Construction Syntax |
|---|---|---|
| Python | List[int] | return [d[y], i] |
| Java | int[] | return new int[] {d.get(y), i}; |
| C++ | vector<int> | return {d[y], i}; |
| Go | []int | return []int{j, i} |
| Rust | Vec<i32> | return vec![j as i32, i as i32]; |
| TypeScript | number[] | return [d.get(y)!, i]; |
| JavaScript | Array | return [d.get(y), i]; |
| C# | int[] | return new [] {j, i}; |
| PHP | Integer[] | return [$d[$y], $i]; |
| Ruby | Array | return [d[y], i] |
| Swift | [Int] | return [j, i] |
Sources: solution/0000-0099/0001.Two Sum/Solution.py6 solution/0000-0099/0001.Two Sum/Solution.java8 solution/0000-0099/0001.Two Sum/Solution.cpp9 solution/0000-0099/0001.Two Sum/Solution.go7
Different languages handle edge cases and errors differently:
Sources: solution/0000-0099/0001.Two Sum/Solution.go1-11 solution/0000-0099/0001.Two Sum/Solution.java4 solution/0000-0099/0001.Two Sum/Solution.rs13 solution/0000-0099/0001.Two Sum/Solution.ts7
Sources: solution/0000-0099/0001.Two Sum/Solution.java1-13
Sources: solution/0000-0099/0001.Two Sum/Solution.go1-11
Python uses classes to match LeetCode's interface but methods are essentially functional.
Sources: solution/0000-0099/0001.Two Sum/Solution.py1-7
Each problem directory contains:
README.md: Chinese documentation with problem description and solutionsREADME_EN.md: English documentation with identical structureBoth files reference the same solution files using tab-delimited code blocks:
**Sources:** <FileRef file-url="https://github.com/doocs/leetcode/blob/ae35e0ed/solution/0000-0099/0001.Two Sum/README.md#L79-L405" min=79 max=405 file-path="solution/0000-0099/0001.Two Sum/README.md">Hii</FileRef> <FileRef file-url="https://github.com/doocs/leetcode/blob/ae35e0ed/solution/0000-0099/0001.Two Sum/README_EN.md#L76-L402" min=76 max=402 file-path="solution/0000-0099/0001.Two Sum/README_EN.md">Hii</FileRef>
---
## Language Selection Guidelines
### Performance-Critical Problems
- Prefer: **C++, Rust, C**
- Used for: Problems with tight time constraints, large input sizes
### Rapid Prototyping
- Prefer: **Python, JavaScript, Ruby**
- Used for: Testing algorithmic ideas, clear demonstrations
### Type Safety
- Prefer: **TypeScript, Rust, Swift**
- Used for: Problems where type errors could introduce subtle bugs
### Concurrency
- Prefer: **Go, Rust**
- Used for: Multi-threaded or parallel algorithm implementations
### Enterprise Integration
- Prefer: **Java, C#**
- Used for: Solutions that need to integrate with existing enterprise systems
**Sources:** Context from multiple solution files across <FileRef file-url="https://github.com/doocs/leetcode/blob/ae35e0ed/solution/0000-0099/0001.Two Sum/" undefined file-path="solution/0000-0099/0001.Two Sum/">Hii</FileRef>
---
## Consistency Principles
All language implementations maintain:
1. **Algorithmic Equivalence**: Same time/space complexity across languages
2. **Idiomatic Code**: Each solution uses language-specific best practices
3. **Naming Consistency**: Variable names remain similar (e.g., `d` for dictionary/map)
4. **Comment Patterns**: Minimal comments; code should be self-documenting
5. **Test Compatibility**: All solutions pass the same LeetCode test cases
**Sources:** <FileRef file-url="https://github.com/doocs/leetcode/blob/ae35e0ed/solution/0000-0099/0001.Two Sum/README.md#L68-L77" min=68 max=77 file-path="solution/0000-0099/0001.Two Sum/README.md">Hii</FileRef> <FileRef file-url="https://github.com/doocs/leetcode/blob/ae35e0ed/solution/0000-0099/0001.Two Sum/README_EN.md#L66-L74" min=66 max=74 file-path="solution/0000-0099/0001.Two Sum/README_EN.md">Hii</FileRef>
Refresh this wiki
This wiki was recently refreshed. Please wait 2 days to refresh again.