mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-13 07:46:06 +00:00
Add figures to replace_linear_by_hashing.md
This commit is contained in:
@@ -1 +1 @@
|
||||
add_executable(leetcode_two_sum leetcode_two_sum.c)
|
||||
add_executable(two_sum two_sum.c)
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* File: leetcode_two_sum.c
|
||||
* File: two_sum.c
|
||||
* Created Time: 2023-01-19
|
||||
* Author: Reanon (793584285@qq.com)
|
||||
*/
|
||||
@@ -71,7 +71,7 @@ int *twoSumHashTable(int *nums, int numsSize, int target, int *returnSize) {
|
||||
int main() {
|
||||
// ======= Test Case =======
|
||||
int nums[] = {2, 7, 11, 15};
|
||||
int target = 9;
|
||||
int target = 13;
|
||||
// ====== Driver Code ======
|
||||
int returnSize;
|
||||
int *res = twoSumBruteForce(nums, sizeof(nums) / sizeof(int), target, &returnSize);
|
||||
@@ -1,3 +1,3 @@
|
||||
add_executable(hashing_search hashing_search.cpp)
|
||||
add_executable(leetcode_two_sum leetcode_two_sum.cpp)
|
||||
add_executable(two_sum two_sum.cpp)
|
||||
add_executable(linear_search linear_search.cpp)
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* File: leetcode_two_sum.cpp
|
||||
* File: two_sum.cpp
|
||||
* Created Time: 2022-11-25
|
||||
* Author: Krahets (krahets@163.com)
|
||||
*/
|
||||
@@ -38,7 +38,7 @@ vector<int> twoSumHashTable(vector<int> &nums, int target) {
|
||||
int main() {
|
||||
// ======= Test Case =======
|
||||
vector<int> nums = {2, 7, 11, 15};
|
||||
int target = 9;
|
||||
int target = 13;
|
||||
|
||||
// ====== Driver Code ======
|
||||
// 方法一
|
||||
+3
-3
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* File: leetcode_two_sum.cs
|
||||
* File: two_sum.cs
|
||||
* Created Time: 2022-12-23
|
||||
* Author: haptear (haptear@hotmail.com)
|
||||
*/
|
||||
|
||||
namespace hello_algo.chapter_searching;
|
||||
|
||||
public class leetcode_two_sum {
|
||||
public class two_sum {
|
||||
/* 方法一:暴力枚举 */
|
||||
public static int[] twoSumBruteForce(int[] nums, int target) {
|
||||
int size = nums.Length;
|
||||
@@ -39,7 +39,7 @@ public class leetcode_two_sum {
|
||||
public void Test() {
|
||||
// ======= Test Case =======
|
||||
int[] nums = { 2, 7, 11, 15 };
|
||||
int target = 9;
|
||||
int target = 13;
|
||||
|
||||
// ====== Driver Code ======
|
||||
// 方法一
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* File: leetcode_two_sum.dart
|
||||
* File: two_sum.dart
|
||||
* Created Time: 2023-2-11
|
||||
* Author: Jefferson (JeffersonHuang77@gmail.com)
|
||||
*/
|
||||
@@ -34,7 +34,7 @@ List<int> twoSumHashTable(List<int> nums, int target) {
|
||||
int main() {
|
||||
// ======= Test Case =======
|
||||
List<int> nums = [2, 7, 11, 15];
|
||||
int target = 9;
|
||||
int target = 13;
|
||||
|
||||
// ====== Driver Code ======
|
||||
// 方法一
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// File: leetcode_two_sum.go
|
||||
// File: two_sum.go
|
||||
// Created Time: 2022-11-25
|
||||
// Author: reanon (793584285@qq.com)
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
// File: leetcode_two_sum_test.go
|
||||
// File: two_sum_test.go
|
||||
// Created Time: 2022-11-25
|
||||
// Author: reanon (793584285@qq.com)
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
func TestTwoSum(t *testing.T) {
|
||||
// ======= Test Case =======
|
||||
nums := []int{2, 7, 11, 15}
|
||||
target := 9
|
||||
target := 13
|
||||
|
||||
// ====== Driver Code ======
|
||||
// 方法一:暴力解法
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* File: leetcode_two_sum.java
|
||||
* File: two_sum.java
|
||||
* Created Time: 2022-11-25
|
||||
* Author: Krahets (krahets@163.com)
|
||||
*/
|
||||
@@ -8,7 +8,7 @@ package chapter_searching;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class leetcode_two_sum {
|
||||
public class two_sum {
|
||||
/* 方法一:暴力枚举 */
|
||||
static int[] twoSumBruteForce(int[] nums, int target) {
|
||||
int size = nums.length;
|
||||
@@ -40,7 +40,7 @@ public class leetcode_two_sum {
|
||||
public static void main(String[] args) {
|
||||
// ======= Test Case =======
|
||||
int[] nums = { 2, 7, 11, 15 };
|
||||
int target = 9;
|
||||
int target = 13;
|
||||
|
||||
// ====== Driver Code ======
|
||||
// 方法一
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* File: leetcode_two_sum.js
|
||||
* File: two_sum.js
|
||||
* Created Time: 2022-12-15
|
||||
* Author: gyt95 (gytkwan@gmail.com)
|
||||
*/
|
||||
@@ -36,7 +36,7 @@ function twoSumHashTable(nums, target) {
|
||||
/* Driver Code */
|
||||
// 方法一
|
||||
const nums = [2, 7, 11, 15],
|
||||
target = 9;
|
||||
target = 13;
|
||||
|
||||
let res = twoSumBruteForce(nums, target);
|
||||
console.log('方法一 res = ', res);
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
"""
|
||||
File: leetcode_two_sum.py
|
||||
File: two_sum.py
|
||||
Created Time: 2022-11-25
|
||||
Author: Krahets (krahets@163.com)
|
||||
"""
|
||||
@@ -31,7 +31,7 @@ def two_sum_hash_table(nums: list[int], target: int) -> list[int]:
|
||||
if __name__ == "__main__":
|
||||
# ======= Test Case =======
|
||||
nums = [2, 7, 11, 15]
|
||||
target = 9
|
||||
target = 13
|
||||
|
||||
# ====== Driver Code ======
|
||||
# 方法一
|
||||
@@ -19,10 +19,10 @@ path = "chapter_computational_complexity/worst_best_time_complexity.rs"
|
||||
name = "space_complexity"
|
||||
path = "chapter_computational_complexity/space_complexity.rs"
|
||||
|
||||
# Run Command: cargo run --bin leetcode_two_sum
|
||||
# Run Command: cargo run --bin two_sum
|
||||
[[bin]]
|
||||
name = "leetcode_two_sum"
|
||||
path = "chapter_computational_complexity/leetcode_two_sum.rs"
|
||||
name = "two_sum"
|
||||
path = "chapter_computational_complexity/two_sum.rs"
|
||||
|
||||
# Run Command: cargo run --bin array
|
||||
[[bin]]
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* File: leetcode_two_sum.rs
|
||||
* File: two_sum.rs
|
||||
* Created Time: 2023-01-14
|
||||
* Author: xBLACICEx (xBLACKICEx@outlook.com), sjinzh (sjinzh@gmail.com)
|
||||
*/
|
||||
@@ -39,7 +39,7 @@ pub fn two_sum_hash_table(nums: &Vec<i32>, target: i32) -> Option<Vec<i32>> {
|
||||
fn main() {
|
||||
// ======= Test Case =======
|
||||
let nums = vec![ 2, 7, 11, 15 ];
|
||||
let target = 9;
|
||||
let target = 13;
|
||||
|
||||
// ====== Driver Code ======
|
||||
// 方法一
|
||||
@@ -43,7 +43,7 @@ let package = Package(
|
||||
.executable(name: "graph_bfs", targets: ["graph_bfs"]),
|
||||
.executable(name: "graph_dfs", targets: ["graph_dfs"]),
|
||||
// chapter_searching
|
||||
.executable(name: "leetcode_two_sum", targets: ["leetcode_two_sum"]),
|
||||
.executable(name: "two_sum", targets: ["two_sum"]),
|
||||
.executable(name: "linear_search", targets: ["linear_search"]),
|
||||
.executable(name: "hashing_search", targets: ["hashing_search"]),
|
||||
// chapter_sorting
|
||||
@@ -104,7 +104,7 @@ let package = Package(
|
||||
.executableTarget(name: "graph_bfs", dependencies: ["utils", "graph_adjacency_list_target"], path: "chapter_graph", sources: ["graph_bfs.swift"]),
|
||||
.executableTarget(name: "graph_dfs", dependencies: ["utils", "graph_adjacency_list_target"], path: "chapter_graph", sources: ["graph_dfs.swift"]),
|
||||
// chapter_searching
|
||||
.executableTarget(name: "leetcode_two_sum", path: "chapter_searching", sources: ["leetcode_two_sum.swift"]),
|
||||
.executableTarget(name: "two_sum", path: "chapter_searching", sources: ["two_sum.swift"]),
|
||||
.executableTarget(name: "linear_search", dependencies: ["utils"], path: "chapter_searching", sources: ["linear_search.swift"]),
|
||||
.executableTarget(name: "hashing_search", dependencies: ["utils"], path: "chapter_searching", sources: ["hashing_search.swift"]),
|
||||
// chapter_sorting
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* File: leetcode_two_sum.swift
|
||||
* File: two_sum.swift
|
||||
* Created Time: 2023-01-03
|
||||
* Author: nuomi1 (nuomi1@qq.com)
|
||||
*/
|
||||
@@ -37,7 +37,7 @@ enum LeetcodeTwoSum {
|
||||
static func main() {
|
||||
// ======= Test Case =======
|
||||
let nums = [2, 7, 11, 15]
|
||||
let target = 9
|
||||
let target = 13
|
||||
// ====== Driver Code ======
|
||||
// 方法一
|
||||
var res = twoSumBruteForce(nums: nums, target: target)
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* File: leetcode_two_sum.ts
|
||||
* File: two_sum.ts
|
||||
* Created Time: 2022-12-15
|
||||
* Author: gyt95 (gytkwan@gmail.com)
|
||||
*/
|
||||
@@ -37,7 +37,7 @@ function twoSumHashTable(nums: number[], target: number): number[] {
|
||||
/* Driver Code */
|
||||
// 方法一
|
||||
const nums = [2, 7, 11, 15],
|
||||
target = 9;
|
||||
target = 13;
|
||||
|
||||
let res = twoSumBruteForce(nums, target);
|
||||
console.log('方法一 res = ', res);
|
||||
+12
-12
@@ -52,18 +52,18 @@ pub fn build(b: *std.build.Builder) void {
|
||||
run_step_space_complexity.dependOn(&run_cmd_space_complexity.step);
|
||||
|
||||
// Section: "Space Time Tradeoff"
|
||||
// Source File: "chapter_computational_complexity/leetcode_two_sum.zig"
|
||||
// Run Command: zig build run_leetcode_two_sum
|
||||
const exe_leetcode_two_sum = b.addExecutable("leetcode_two_sum", "chapter_computational_complexity/leetcode_two_sum.zig");
|
||||
exe_leetcode_two_sum.addPackagePath("include", "include/include.zig");
|
||||
exe_leetcode_two_sum.setTarget(target);
|
||||
exe_leetcode_two_sum.setBuildMode(mode);
|
||||
exe_leetcode_two_sum.install();
|
||||
const run_cmd_leetcode_two_sum = exe_leetcode_two_sum.run();
|
||||
run_cmd_leetcode_two_sum.step.dependOn(b.getInstallStep());
|
||||
if (b.args) |args| run_cmd_leetcode_two_sum.addArgs(args);
|
||||
const run_step_leetcode_two_sum = b.step("run_leetcode_two_sum", "Run leetcode_two_sum");
|
||||
run_step_leetcode_two_sum.dependOn(&run_cmd_leetcode_two_sum.step);
|
||||
// Source File: "chapter_computational_complexity/two_sum.zig"
|
||||
// Run Command: zig build run_two_sum
|
||||
const exe_two_sum = b.addExecutable("two_sum", "chapter_computational_complexity/two_sum.zig");
|
||||
exe_two_sum.addPackagePath("include", "include/include.zig");
|
||||
exe_two_sum.setTarget(target);
|
||||
exe_two_sum.setBuildMode(mode);
|
||||
exe_two_sum.install();
|
||||
const run_cmd_two_sum = exe_two_sum.run();
|
||||
run_cmd_two_sum.step.dependOn(b.getInstallStep());
|
||||
if (b.args) |args| run_cmd_two_sum.addArgs(args);
|
||||
const run_step_two_sum = b.step("run_two_sum", "Run two_sum");
|
||||
run_step_two_sum.dependOn(&run_cmd_two_sum.step);
|
||||
|
||||
// Section: "Array"
|
||||
// Source File: "chapter_array_and_linkedlist/array.zig"
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// File: leetcode_two_sum.zig
|
||||
// File: two_sum.zig
|
||||
// Created Time: 2023-01-07
|
||||
// Author: sjinzh (sjinzh@gmail.com)
|
||||
|
||||
Reference in New Issue
Block a user