From ce5a80aaf7a03e092973db738c854c9606b2623d Mon Sep 17 00:00:00 2001 From: Renkin <906155099@qq.com> Date: Mon, 13 Nov 2023 16:05:50 +0800 Subject: [PATCH 1/3] feat: i18n update --- src/locales/en.js | 53 ++++++++++++++++++ src/locales/zh.js | 58 ++++++++++++++++++++ src/roadmap/roadmap.jsx | 117 +++++++++++++++++++--------------------- 3 files changed, 165 insertions(+), 63 deletions(-) diff --git a/src/locales/en.js b/src/locales/en.js index 804fdd2..fcee689 100644 --- a/src/locales/en.js +++ b/src/locales/en.js @@ -60,13 +60,28 @@ const en = { notYet: "Not yet", }, problem: { + 69: "69. Sqrt(x)", + 278: "278. First Bad Version", + "278_desc": "The idea of the leftmost and rightmost is the same. Everyone can practice two questions. The actual situation can use different binary search according to the meaning of the question.", + 327: "327. Count of Range Sum", + 493: "493. Reverse Pairs", 743: "743. Network Delay Time", + 778: "778. Swim in Rising Water", + "778_desc": "DFS + binary search, there are many similar questions, such as the 1439th question. This kind of question routine is very similar, and the difficulty is not big.", 1109: "1109. Corporate Flight Bookings", 1314: "1314. Matrix Block Sum", 1462: "1462. Course Schedule IV", 1480: "1480. Running Sum of 1d Array", 1584: "1584. Min Cost to Connect All Points", 2536: "2536. Increment Submatrices by One", + minimumLightRadius: "Minimum Light Radius", + minimumLightRadius_desc: "Classic ability detection binary search, leetcode also has a similar topic", + kthPairDistance: "Kth Smallest Distance Pair", + kthPairDistance_desc: "Typical counting binary search, which is essentially an ability test, but the number of questions is large, so it is separated.", + JZ51: "Sword Offer 51. Reverse pairs in an array", + + longestIncreasingSubsequence: "Longest Increasing Subsequence Series", + longestIncreasingSubsequence_desc: "Series classic topic, worth doing", }, codeTemplate: { name: "Code Template", @@ -137,6 +152,44 @@ const en = { }, learningRoute: { name: "Learning Route", + dp: "Dynamic Programming", + binarySearch: "Binary Search", + binarySearchDesc:` + If you ask me to summarize binary search in one sentence, I would say that binary search is an algorithm that makes the unknown world inorganic. That is, no matter what, we can discard half of the solutions, that is, we can cut the solution space in half. + The difficulty is two points: **what conditions** and **which part to discard**. This is the core problem that binary search needs to solve. + + There are two basic types of tactics, namely the leftmost insertion binary search and the rightmost insertion binary search. + + There are four basic types of strategies: ability detection binary search, prefix sum binary search, insertion sort binary search, and counting binary search. + + These two parts are very practical. While understanding these two parts, please keep in mind a central point **half**. + + For more information, please visit: https://lucifer.ren/blog/2021/03/08/binary-search-1`, + binarySearch_item1: "Leftmost/Rightmost Binary Search", + binarySearch_item1_text: "Code reference: Code templates - Binary", + binarySearch_item1_keys: ` + 1. shrink the right boundary continuously and finally return the left boundary + 2. shrink the left boundary continuously and finally return the right boundary + `, + binarySearch_item2: "Ability Detection Binary Search", + binarySearch_item2_keys: `Define the function that the possible argument is mid and the return value is a Boolean value. The outer layer adjusts according to the return value "; Solution space" . The sample code is an example of the leftmost binary. + `, + binarySearch_item3: "Prefix Sum Binary Search", + binarySearch_item3_keys: ` + If the array is non-negative, then the prefix sum is a monotone non-decrement array, and we can sometimes make dichotomies based on it. + `, + binarySearch_item4: "Insertion Sort Binary Search", + binarySearch_item4_keys: ` + Continuously insert and maintain the ordered sequence, and then use the ordered sequence to do something. + `, + binarySearch_item5: "Counting Binary Search", + binarySearch_item5_keys: `The essence is also ability detection, so it is basically the same as the ability detection framework. Everyone compares and understands. + `, + + tree: "Tree", + linkedList: "Linked List", + clickToEnlarge: "Click to enlarge", + recommendedProblems:"Recommended Problems", }, checkForUpdates: { name: "Check for Updates", diff --git a/src/locales/zh.js b/src/locales/zh.js index 615d071..80fe3dc 100644 --- a/src/locales/zh.js +++ b/src/locales/zh.js @@ -57,13 +57,31 @@ const zh = { notYet: "暂无", }, problem: { + 69: "69. x 的平方根", + 278: "278. 第一个错误的版本", + "278_desc": + "最左最右思路一样,大家练习两道,实际情况根据题意使用不同的二分即可。", + 327: "327. 区间和的个数", + 493: "493. 翻转对", 743: "743. 网络延迟时间", + 778: "778. 水位上升的泳池中游泳", + "778_desc": + "DFS + 二分,类似的题目有很多,比如第 1439 题。这种题套路都很像,难度其实也不算大。", 1109: "1109. 航班预订统计", 1314: "1314. 矩阵区域和", 1462: "1462. 课程表 IV", 1480: "1480. 一维数组的动态和", 1584: "1584. 连接所有点的最小费用", 2536: "2536. 子矩阵元素加 1", + + minimumLightRadius: "最小光照半径", + minimumLightRadius_desc: "经典能力检测二分,力扣也有一道类似题", + kthPairDistance: "第 K 小的距离对", + kthPairDistance_desc: "典型的计数二分,本质上也是能力检测,只不过题量大,单独拆出来。", + JZ51: "剑指 Offer 51. 数组中的逆序对", + + longestIncreasingSubsequence: "最长上升子序列系列", + longestIncreasingSubsequence_desc: "系列经典题目,值得一做", }, codeTemplate: { name: "代码模板", @@ -130,6 +148,46 @@ const zh = { }, learningRoute: { name: "学习路线", + dp: "动态规划", + binarySearch: "二分查找", + binarySearchDesc: ` + 如果让我用一句话总结二分法,我会说**二分法是一种让未知世界无机可乘的算法**。即二分法无论如何我们都可以舍弃一半解,也就是无论如何都可以将解空间砍半。 + 难点就是两点:**什么条件** 和 **舍弃哪部分**。这是二分法核心要解决的问题。 + + 从战术上有两种基本类型,分别是最左插入二分和最右插入二分。 + + 从战略上有四种基本类型,能力检测二分,前缀和二分,插入排序二分和计数二分。 + + 两种类型(最左和最右插入)主要解决的的是:**解空间已经明确出来了,如何用代码找出具体的解**。而四大应用主要解决的是:**如何构造解空间**。更多的情况则是如何构建有序序列。 + + 这两部分都是实操性很强的内容,在理解这两部分内容的同时,请大家务必牢记一个中心**折半**。 + + 更多内容请访问:https://lucifer.ren/blog/2021/03/08/binary-search-1`, + binarySearch_item1: "最左/最右二分", + binarySearch_item1_text: "代码参考:代码模板 - 二分法", + binarySearch_item1_keys: ` + 1. 最左二分不断收缩右边界,最终返回左边界 + 2. 最右二分不断收缩左边界,最终返回右边界 + `, + binarySearch_item2: "能力检测二分", + binarySearch_item2_keys: `定义函数 possible 参数是 mid,返回值是布尔值。外层根据返回值调整"解空间"。示例代码是以最左二分为例的。 + `, + binarySearch_item3: "前缀和二分", + binarySearch_item3_keys: ` + 如果数组是非负的,那么前缀和就是一个单调不递减数组,我们有时候可以基于它来做二分。 + `, + binarySearch_item4: "插入排序二分", + binarySearch_item4_keys: ` + 不断插入并维护序列有序,进而利用有序做一些事情。 + `, + binarySearch_item5: "计数二分", + binarySearch_item5_keys: `本质也是能力检测,因此和能力检测框架基本一致,大家对比理解一下。 + `, + + tree: "树", + linkedList: "链表", + clickToEnlarge: "单击可放大", + recommendedProblems: "推荐题目", }, checkForUpdates: { name: "检查更新", diff --git a/src/roadmap/roadmap.jsx b/src/roadmap/roadmap.jsx index d8deaa1..3d37c54 100644 --- a/src/roadmap/roadmap.jsx +++ b/src/roadmap/roadmap.jsx @@ -3,7 +3,7 @@ import { Radio, Image } from "antd"; import Codes from "../components/codes"; import TagOrLink from "../components/TagOrLink"; - +import { t, auto_detect_languange } from "../locales" const dpSingleCode = ` dp = [0] * (n + 1) for i in range(1, n + 1): @@ -15,7 +15,7 @@ const dpDoubleCode = ` dp = [[0 for _ in range(n + 1)] for _ in range(m + 1)] for i in range(1, m + 1): for j in range(1, n + 1): - if 一定条件: + if Certain conditions: dp[i][j] = dp[i - 1][j - 1] + 1 else: dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) @@ -26,12 +26,12 @@ class Solution: def solve(self, s): n = len(s) dp = [[0] * n for _ in range(n)] - # 右边界倒序遍历 + # Traverse in reverse order from the right boundary for i in range(n - 1, -1, -1): - # 左边界正序遍历 + # Traverse in forward order from the left boundary for j in range(i + 1, n): # do something - return dp[0][m-1] # 一般都是使用这个区间作为答案 + return dp[0][m-1] # Typically, this interval is used as the answer. `; const dpRangeCodeRecur = ` class Solution: @@ -48,60 +48,43 @@ class Solution: const roadmaps = { "binary-search": { - desc: ` - 如果让我用一句话总结二分法,我会说**二分法是一种让未知世界无机可乘的算法**。即二分法无论如何我们都可以舍弃一半解,也就是无论如何都可以将解空间砍半。 - 难点就是两点:**什么条件** 和 **舍弃哪部分**。这是二分法核心要解决的问题。 - - 从战术上有两种基本类型,分别是最左插入二分和最右插入二分。 - - 从战略上有四种基本类型,能力检测二分,前缀和二分,插入排序二分和计数二分。 - - 两种类型(最左和最右插入)主要解决的的是:**解空间已经明确出来了,如何用代码找出具体的解**。而四大应用主要解决的是:**如何构造解空间**。更多的情况则是如何构建有序序列。 - - 这两部分都是实操性很强的内容,在理解这两部分内容的同时,请大家务必牢记一个中心**折半**。 - - 更多内容请访问:https://lucifer.ren/blog/2021/03/08/binary-search-1`, + desc: t("Locale.learningRoute.binarySearchDesc"), items: [ { - title: "最左/最右二分", + title: t("Locale.learningRoute.binarySearch_item1"), pic: void 0, problems: [ { link: "https://leetcode-cn.com/problems/sqrtx", - text: "69. x 的平方根", + text: t("Locale.problem.69"), }, { link: "https://leetcode-cn.com/problems/first-bad-version/", - text: "278. 第一个错误的版本", - desc: - "最左最右思路一样,大家练习两道,实际情况根据题意使用不同的二分即可。", + text: t("Locale.problem.278"), + desc: t("Locale.problem.278_desc"), }, ], code: { language: "py", - text: "代码参考:代码模板 - 二分法", + text: t("Locale.learningRoute.binarySearch_item1_text"), }, keys: [ - ` - 1. 最左二分不断收缩右边界,最终返回左边界 - 2. 最右二分不断收缩左边界,最终返回右边界 - `, + t("Locale.learningRoute.binarySearch_item1_keys"), ], }, { - title: "能力检测二分", + title: t("Locale.learningRoute.binarySearch_item2"), pic: void 0, problems: [ { link: "https://binarysearch.com/problems/Minimum-Light-Radius", - text: "最小灯半径", - desc: "经典能力检测二分,力扣也有一道类似题", + text: t("Locale.problem.minimumLightRadius"), + desc: t("Locale.problem.minimumLightRadius_desc"), }, { link: "https://leetcode-cn.com/problems/swim-in-rising-water", - text: "778. 水位上升的泳池中游泳", - desc: - "DFS + 二分,类似的题目有很多,比如第 1439 题。这种题套路都很像,难度其实也不算大。", + text: t("Locale.problem.778"), + desc: t("Locale.problem.778_desc"), }, ], code: { @@ -113,50 +96,55 @@ def ability_test_bs(nums): l, r = 0, len(A) - 1 while l <= r: mid = (l + r) // 2 - # 只有这里和最左二分不一样 + # The only difference is here and in the leftmost binary search. if possible(mid): l = mid + 1 else: r = mid - 1 return l `, }, keys: [ - `定义函数 possible 参数是 mid,返回值是布尔值。外层根据返回值调整"解空间"。示例代码是以最左二分为例的。 - `, + // `定义函数 possible 参数是 mid,返回值是布尔值。外层根据返回值调整"解空间"。示例代码是以最左二分为例的。 + // `, + t("Locale.learningRoute.binarySearch_item2_keys") ], }, { - title: "前缀和二分", + title: t("Locale.learningRoute.binarySearch_item3"), pic: void 0, problems: [ { link: "https://leetcode-cn.com/problems/count-of-range-sum/", - text: "327. 区间和的个数", + text: t("Locale.problem.327"), }, ], keys: [ - ` - 如果数组是非负的,那么前缀和就是一个单调不递减数组,我们有时候可以基于它来做二分。 - `, + // ` + // 如果数组是非负的,那么前缀和就是一个单调不递减数组,我们有时候可以基于它来做二分。 + // `, + t("Locale.learningRoute.binarySearch_item3_keys"), + ], }, { - title: "插入排序二分", + title: t("Locale.learningRoute.binarySearch_item4"), pic: void 0, problems: [ { link: "https://leetcode-cn.com/problems/reverse-pairs", - text: "493. 翻转对", + text: t("Locale.problem.493"), }, { link: "https://leetcode-cn.com/problems/shu-zu-zhong-de-ni-xu-dui-lcof", - text: "剑指 Offer 51. 数组中的逆序对", + // text: "剑指 Offer 51. 数组中的逆序对", + text:t("Locale.problem.JZ51") }, { link: "https://lucifer.ren/blog/2020/06/20/LIS/", - text: "最长上升子序列系列", - desc: "系列经典题目,值得一做", + // text: "最长上升子序列系列", + text: t("Locale.problem.longestIncreasingSubsequence"), + desc: t("Locale.problem.longestIncreasingSubsequence_desc"), }, ], code: { @@ -171,20 +159,22 @@ def ability_test_bs(nums): d.append(a)`, }, keys: [ - ` - 不断插入并维护序列有序,进而利用有序做一些事情。 - `, + // ` + // 不断插入并维护序列有序,进而利用有序做一些事情。 + // `, + t("Locale.learningRoute.binarySearch_item4_keys") ], }, { - title: "计数二分", + // title: "计数二分", + title: t("Locale.learningRoute.binarySearch_item5"), pic: void 0, problems: [ { link: "https://binarysearch.com/problems/Kth-Pair-Distance", - text: "第k小的距离对", - desc: - "典型的计数二分,本质上也是能力检测,只不过题量大,单独拆出来。", + // text: "第k小的距离对", + text: t("Locale.problem.kthPairDistance"), + desc:t("Locale.problem.kthPairDistance_desc"), }, ], code: { @@ -196,15 +186,16 @@ def count_bs(nums, k): l, r = 0, len(A) - 1 while l <= r: mid = (l + r) // 2 - # 只有这里和最左二分不一样 + # Only this is different from the leftmost binary if count_not_greater(mid) > k: r = mid - 1 else: l = mid + 1 return l `, }, keys: [ - `本质也是能力检测,因此和能力检测框架基本一致,大家对比理解一下。 - `, + // `本质也是能力检测,因此和能力检测框架基本一致,大家对比理解一下。 + // `, + t("Locale.learningRoute.binarySearch_item5_keys") ], }, ], @@ -548,13 +539,13 @@ export default function RoadMap() { value={topic} buttonStyle="solid" > - 动态规划 - 二分 + {t("Locale.learningRoute.dp")} + {t("Locale.learningRoute.binarySearch")} - 树 + {t("Locale.learningRoute.tree")} - 链表 + {t("Locale.learningRoute.linkedList")}
@@ -571,11 +562,11 @@ export default function RoadMap() { {item.pic && ( <> - (单击可放大) + ({t("Locale.learningRoute.clickToEnlarge")}) )} {item.code && } - 推荐题目: + { t("Locale.learningRoute.recommendedProblems")}: