This page documents the multi-language implementation strategy used throughout the doocs/leetcode repository, covering the architecture, file organization, and integration of 12+ programming language solutions. For language-specific idioms and data structure conventions, see Language Coverage and Conventions. For automated code formatting configuration, see Code Formatting System.
The repository provides functionally equivalent solutions for each problem in multiple programming languages, enabling developers to study algorithm implementations in their preferred language. Each solution follows a three-layer architecture:
This architecture allows the repository to serve both as an algorithm learning resource (focusing on approaches) and as a practical code reference (providing multi-language implementations).
Sources: High-level diagrams (Diagram 5)
The repository currently supports 12+ programming languages, organized into three categories:
| Category | Languages |
|---|---|
| Compiled Languages | Java, C++, Go, Rust, C#, Swift, C |
| Interpreted Languages | Python, JavaScript, TypeScript, PHP, Ruby |
| Special Purpose | SQL (for database problems), Nim |
Sources: High-level diagrams (Diagram 5), solution/0000-0099/0001.Two Sum/README.md78-337
Each problem directory contains solution files named according to the pattern Solution.<ext>, where <ext> is the language-specific file extension:
Sources: solution/0000-0099/0001.Two Sum/Solution.py1-8 solution/0000-0099/0001.Two Sum/Solution.java1-13 solution/0000-0099/0001.Two Sum/Solution.cpp1-14 solution/0000-0099/0001.Two Sum/Solution.go1-11 solution/0000-0099/0001.Two Sum/Solution.ts1-11 solution/0000-0099/0001.Two Sum/Solution.rs1-15 solution/0000-0099/0001.Two Sum/Solution.js1-16 solution/0000-0099/0001.Two Sum/Solution.cs1-15 solution/0000-0099/0001.Two Sum/Solution.php1-17 solution/0000-0099/0001.Two Sum/Solution.rb1-13 solution/0000-0099/0001.Two Sum/Solution.swift1-13 solution/0000-0099/0001.Two Sum/Solution.nim1-11
For problem 0001 (Two Sum), the directory structure is:
solution/0000-0099/0001.Two Sum/
├── README.md # Chinese problem description and solutions
├── README_EN.md # English problem description and solutions
├── Solution.py # Python implementation
├── Solution.java # Java implementation
├── Solution.cpp # C++ implementation
├── Solution.go # Go implementation
├── Solution.ts # TypeScript implementation
├── Solution.rs # Rust implementation
├── Solution.js # JavaScript implementation
├── Solution.cs # C# implementation
├── Solution.php # PHP implementation
├── Solution.rb # Ruby implementation
├── Solution.swift # Swift implementation
├── Solution.nim # Nim implementation
└── Solution.c # C implementation (when applicable)
This pattern repeats for all ~4000+ problems across the solution/, lcof/, lcci/, lcp/, and lcs/ directories.
Sources: solution/0000-0099/0001.Two Sum/README.md1-410 High-level diagrams (Diagram 3)
The following diagram maps the natural language concepts to actual code entities in the repository:
Sources: solution/0000-0099/0001.Two Sum/README.md71-77 solution/0000-0099/0001.Two Sum/Solution.py1-7 solution/0000-0099/0001.Two Sum/Solution.java1-12 solution/0000-0099/0001.Two Sum/Solution.cpp1-14 solution/0000-0099/0001.Two Sum/Solution.go1-11
Each language uses idiomatic data structures to implement the same algorithm. The following table shows equivalent constructs across languages for the Two Sum hash table solution:
| Concept | Python | Java | C++ | Go | Rust | TypeScript |
|---|---|---|---|---|---|---|
| Hash Map Declaration | d = {} | Map<Integer, Integer> d = new HashMap<>() | unordered_map<int, int> d | d := map[int]int{} | let mut d = HashMap::new() | const d = new Map<number, number>() |
| Check Key Exists | y in d | d.containsKey(y) | d.contains(y) | j, ok := d[y] | d.get(&y) | d.has(y) |
| Insert Key-Value | d[x] = i | d.put(x, i) | d[x] = i | d[x] = i | d.insert(x, i) | d.set(x, i) |
| Get Value | d[y] | d.get(y) | d[y] | d[y] | d[&y] | d.get(y)! |
| Return Type | List[int] | int[] | vector<int> | []int | Vec<i32> | number[] |
Sources: solution/0000-0099/0001.Two Sum/Solution.py3-7 solution/0000-0099/0001.Two Sum/Solution.java3-11 solution/0000-0099/0001.Two Sum/Solution.cpp4-13 solution/0000-0099/0001.Two Sum/Solution.go2-10 solution/0000-0099/0001.Two Sum/Solution.rs4-14 solution/0000-0099/0001.Two Sum/Solution.ts2-10
Each problem contains two parallel README files that provide identical technical content in different languages:
Sources: solution/0000-0099/0001.Two Sum/README.md1-17 solution/0000-0099/0001.Two Sum/README_EN.md1-17
Both README files use a special markdown syntax (<!-- tabs:start --> and <!-- tabs:end -->) to embed multi-language code snippets. The syntax structure is:
This syntax is processed by the MkDocs build system (see [Documentation Site Generation](#2.3)) to create interactive tabbed code displays on the published website.
**Sources:** <FileRef file-url="https://github.com/doocs/leetcode/blob/ae35e0ed/solution/0000-0099/0001.Two Sum/README.md#L79-L406" min=79 max=406 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>
### Frontmatter Metadata
Each README file begins with YAML frontmatter that defines:
- `comments`: Always `true` to enable comments on the website
- `difficulty`: Problem difficulty level (简单/Easy, 中等/Medium, 困难/Hard)
- `edit_url`: Direct GitHub link to edit the file
- `tags`: Array of topic tags in the appropriate language
Example from problem 0001:
```yaml
---
comments: true
difficulty: 简单
edit_url: https://github.com/doocs/leetcode/edit/main/solution/0000-0099/0001.Two%20Sum/README.md
tags:
- 数组
- 哈希表
---
Sources: solution/0000-0099/0001.Two Sum/README.md1-8 solution/0000-0099/0001.Two Sum/README_EN.md1-8
The multi-language solution files are processed by the MkDocs build system to generate the static website. The pipeline flow is:
The actual solution code files (Solution.py, Solution.java, etc.) are embedded directly into the README markdown files as code blocks within language tabs. During the build process, MkDocs renders these tabs as interactive elements on the website.
Sources: High-level diagrams (Diagram 2), solution/0000-0099/0001.Two Sum/README.md79-406
Python and Java serve as the primary reference implementations for most problems, as evidenced by their consistent presence and completeness across the solution set. These languages are typically the first to be implemented and most thoroughly documented.
For algorithmic patterns, the implementations prioritize:
Sources: High-level diagrams (Diagram 5), solution/0000-0099/0001.Two Sum/Solution.py1-7 solution/0000-0099/0001.Two Sum/Solution.java1-13
While the repository aims for comprehensive multi-language coverage, not all problems have implementations in all 12+ languages. The most complete coverage exists for:
Less common languages like Nim or language-specific problems (SQL) have more selective coverage based on problem applicability.
Sources: High-level diagrams (Diagram 3, Diagram 5)
To illustrate multi-language equivalence, here's how the two-pointers pattern is implemented in problem 0125 (Valid Palindrome):
The solution uses two pointers i and j pointing to both ends of the string, moving inward while:
false if mismatch found, true if pointers meetTime complexity: O(n), Space complexity: O(1)
Sources: solution/0100-0199/0125.Valid Palindrome/README.md67-78 solution/0100-0199/0125.Valid Palindrome/README_EN.md64-76
| Language | Character Check | Case Conversion | Loop Condition |
|---|---|---|---|
| Python | s[i].isalnum() | s[i].lower() | while i < j: |
| Java | Character.isLetterOrDigit(s.charAt(i)) | Character.toLowerCase(s.charAt(i)) | while (i < j) |
| C++ | isalnum(s[i]) | tolower(s[i]) | while (i < j) |
| Go | isalnum(s[i]) (custom) | tolower(s[i]) (custom) | for i < j |
| TypeScript | /[a-zA-Z0-9]/.test(s[i]) | s[i].toLowerCase() | while (i < j) |
Sources: solution/0100-0199/0125.Valid Palindrome/Solution.py2-13 solution/0100-0199/0125.Valid Palindrome/Solution.java2-17 solution/0100-0199/0125.Valid Palindrome/Solution.cpp3-18 solution/0100-0199/0125.Valid Palindrome/Solution.go1-25 solution/0100-0199/0125.Valid Palindrome/Solution.ts1-17
Each language has automated formatting enforced through CI/CD workflows (see Code Formatting System):
--skip-string-normalizationThese formatters ensure consistent code style across all language implementations.
Sources: High-level diagrams (Diagram 4), related page reference Code Formatting System
While the repository does not include explicit test suites in the source tree, each solution is validated against LeetCode's official test cases. The solutions are designed to be copy-pasteable into the LeetCode online judge, where they must pass all test cases to be considered correct.
Refresh this wiki
This wiki was recently refreshed. Please wait 2 days to refresh again.