mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-26 14:03:50 +08:00
Retranslate the complete Japanese online edition from Chinese (#2008)
* Retranslate the complete Japanese online edition from Chinese * Fit Japanese homepage labels and localize heading permalinks * Point Japanese contribution instructions to the Japanese preview * Replace locale conditionals with multilingual UI tables
This commit is contained in:
@@ -7,7 +7,7 @@ Author: krahets (krahets@163.com)
|
||||
|
||||
def two_sum_brute_force(nums: list[int], target: int) -> list[int]:
|
||||
"""方法 1:総当たり列挙"""
|
||||
# 2重ループのため、時間計算量は O(n^2)
|
||||
# 二重ループのため、時間計算量は O(n^2)
|
||||
for i in range(len(nums) - 1):
|
||||
for j in range(i + 1, len(nums)):
|
||||
if nums[i] + nums[j] == target:
|
||||
@@ -17,9 +17,9 @@ def two_sum_brute_force(nums: list[int], target: int) -> list[int]:
|
||||
|
||||
def two_sum_hash_table(nums: list[int], target: int) -> list[int]:
|
||||
"""方法 2:補助ハッシュテーブル"""
|
||||
# 補助ハッシュテーブルを使用し、空間計算量は O(n)
|
||||
# 補助ハッシュテーブルの空間計算量は O(n)
|
||||
dic = {}
|
||||
# 単一ループで、時間計算量は O(n)
|
||||
# 一重ループのため、時間計算量は O(n)
|
||||
for i in range(len(nums)):
|
||||
if target - nums[i] in dic:
|
||||
return [dic[target - nums[i]], i]
|
||||
@@ -27,16 +27,16 @@ def two_sum_hash_table(nums: list[int], target: int) -> list[int]:
|
||||
return []
|
||||
|
||||
|
||||
"""Driver Code"""
|
||||
"""実行用コード"""
|
||||
if __name__ == "__main__":
|
||||
# ======= Test Case =======
|
||||
# ======= テストケース =======
|
||||
nums = [2, 7, 11, 15]
|
||||
target = 13
|
||||
|
||||
# ====== Driver Code ======
|
||||
# ====== 実行用コード ======
|
||||
# 方法 1
|
||||
res: list[int] = two_sum_brute_force(nums, target)
|
||||
print("方法1 res =", res)
|
||||
print("方法 1 res =", res)
|
||||
# 方法 2
|
||||
res: list[int] = two_sum_hash_table(nums, target)
|
||||
print("方法2 res =", res)
|
||||
print("方法 2 res =", res)
|
||||
|
||||
Reference in New Issue
Block a user