From e6fccf0f8a7fdef518e637763f8ce6456fbb5aea Mon Sep 17 00:00:00 2001 From: Yangshun Date: Wed, 7 May 2025 10:02:07 +0800 Subject: [PATCH] [qns] algo: i18n --- .../locales/zh-CN.json | 8 + .../array-find-duplicate/locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../array-reachable-end/locales/zh-CN.json | 8 + .../array-rotated-find/locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../binary-search-tree/locales/zh-CN.json | 8 + .../algo/binary-search/locales/zh-CN.json | 8 + .../algo/binary-tree-equal/locales/zh-CN.json | 8 + .../algo/binary-tree-flip/locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../binary-tree-subtree/locales/zh-CN.json | 8 + .../algo/binary-tree/locales/zh-CN.json | 8 + .../algo/bit-counting/locales/zh-CN.json | 8 + .../algo/bit-reversal/locales/zh-CN.json | 8 + .../breadth-first-search/locales/en-US.json | 2 +- .../breadth-first-search/locales/zh-CN.json | 8 + .../algo/bubble-sort/locales/zh-CN.json | 8 + .../algo/coin-change/locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../count-ones-in-binary/locales/zh-CN.json | 8 + .../algo/course-dependency/locales/zh-CN.json | 8 + .../depth-first-search/locales/zh-CN.json | 8 + .../algo/dijkstra/locales/zh-CN.json | 8 + .../disjoint-intervals/locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../algo/graph-clone/locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../algo/graph-is-tree/locales/zh-CN.json | 8 + .../grid-count-islands/locales/zh-CN.json | 8 + .../grid-distinct-paths/locales/zh-CN.json | 8 + .../algo/grid-find-word/locales/zh-CN.json | 8 + .../algo/grid-find-words/locales/zh-CN.json | 8 + .../algo/heap-sort/locales/zh-CN.json | 8 + .../questions/algo/heap/locales/zh-CN.json | 8 + .../algo/insertion-sort/locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../intervals-merge-new/locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../linked-list-rearrange/locales/zh-CN.json | 8 + .../linked-list-reversal/locales/zh-CN.json | 8 + .../algo/linked-list/locales/zh-CN.json | 8 + .../questions/algo/list.zh-CN.json | 3164 +++++++++ .../locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../algo/matrix-rotation/locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../algo/matrix-zeroing/locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../algo/merge-sort/locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../neighborhood-theft/locales/zh-CN.json | 8 + .../number-stream-median/locales/zh-CN.json | 8 + .../algo/ocean-flow/locales/zh-CN.json | 8 + .../optimal-stock-trading/locales/zh-CN.json | 8 + .../algo/pair-sum/locales/zh-CN.json | 8 + .../questions/algo/queue/locales/zh-CN.json | 8 + .../algo/quick-sort/locales/en-US.json | 4 +- .../algo/quick-sort/locales/zh-CN.json | 8 + .../algo/selection-sort/locales/zh-CN.json | 8 + .../questions/algo/stack/locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../string-anagram-groups/locales/zh-CN.json | 8 + .../algo/string-anagram/locales/zh-CN.json | 8 + .../string-decode-message/locales/zh-CN.json | 8 + .../algo/string-palindrome/locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../string-segment-words/locales/zh-CN.json | 8 + .../locales/zh-CN.json | 8 + .../sum-without-addition/locales/zh-CN.json | 8 + .../algo/task-coordination/locales/zh-CN.json | 8 + .../algo/topological-sort/locales/zh-CN.json | 8 + .../algo/trie-prefix-tree/locales/zh-CN.json | 8 + .../algo/triplet-sum/locales/zh-CN.json | 8 + .../algo/word-finder/locales/zh-CN.json | 8 + .../questions/coding/list.zh-CN.json | 6128 ++++++++--------- apps/web/src/scripts/questions-algo-setup.ts | 14 +- .../src/scripts/questions-javascript-setup.ts | 8 +- apps/web/src/scripts/questions-metadata.ts | 10 +- apps/web/src/scripts/questions-quiz-setup.ts | 7 +- .../scripts/questions-system-design-setup.ts | 7 +- .../description/en-US.langnostic.json | 35 + .../description/zh-CN.mdx | 26 + .../solution/en-US.langnostic.json | 40 + .../solution/zh-CN.mdx | 38 + .../description/en-US.langnostic.json | 31 + .../description/zh-CN.mdx | 20 + .../solution/en-US.langnostic.json | 62 + .../array-find-duplicate/solution/zh-CN.mdx | 72 + .../description/en-US.langnostic.json | 31 + .../description/zh-CN.mdx | 20 + .../solution/en-US.langnostic.json | 60 + .../solution/zh-CN.mdx | 74 + .../description/en-US.langnostic.json | 37 + .../description/zh-CN.mdx | 27 + .../solution/en-US.langnostic.json | 62 + .../solution/zh-CN.mdx | 77 + .../description/en-US.langnostic.json | 33 + .../description/zh-CN.mdx | 22 + .../solution/en-US.langnostic.json | 46 + .../solution/zh-CN.mdx | 48 + .../description/en-US.langnostic.json | 31 + .../description/zh-CN.mdx | 23 + .../solution/en-US.langnostic.json | 60 + .../solution/zh-CN.mdx | 72 + .../description/en-US.langnostic.json | 35 + .../description/zh-CN.mdx | 25 + .../solution/en-US.langnostic.json | 50 + .../solution/zh-CN.mdx | 65 + .../description/en-US.langnostic.json | 33 + .../array-reachable-end/description/zh-CN.mdx | 22 + .../solution/en-US.langnostic.json | 62 + .../array-reachable-end/solution/zh-CN.mdx | 81 + .../description/en-US.langnostic.json | 37 + .../array-rotated-find/description/zh-CN.mdx | 28 + .../solution/en-US.langnostic.json | 52 + .../array-rotated-find/solution/zh-CN.mdx | 77 + .../description/en-US.langnostic.json | 35 + .../description/zh-CN.mdx | 24 + .../solution/en-US.langnostic.json | 36 + .../solution/zh-CN.mdx | 35 + .../description/en-US.langnostic.json | 37 + .../description/zh-CN.mdx | 32 + .../solution/en-US.langnostic.json | 58 + .../solution/zh-CN.mdx | 67 + .../description/en-US.langnostic.json | 43 + .../description/zh-CN.mdx | 42 + .../solution/en-US.langnostic.json | 62 + .../solution/zh-CN.mdx | 70 + .../description/en-US.langnostic.json | 41 + .../description/zh-CN.mdx | 38 + .../solution/en-US.langnostic.json | 64 + .../solution/zh-CN.mdx | 82 + .../description/en-US.langnostic.json | 25 + .../binary-search-tree/description/zh-CN.mdx | 23 + .../solution/en-US.langnostic.json | 46 + .../binary-search-tree/solution/zh-CN.mdx | 41 + .../description/en-US.langnostic.json | 31 + .../algo/binary-search/description/zh-CN.mdx | 25 + .../solution/en-US.langnostic.json | 58 + .../algo/binary-search/solution/zh-CN.mdx | 51 + .../description/en-US.langnostic.json | 39 + .../binary-tree-equal/description/zh-CN.mdx | 35 + .../solution/en-US.langnostic.json | 52 + .../algo/binary-tree-equal/solution/zh-CN.mdx | 59 + .../description/en-US.langnostic.json | 37 + .../binary-tree-flip/description/zh-CN.mdx | 32 + .../solution/en-US.langnostic.json | 50 + .../algo/binary-tree-flip/solution/zh-CN.mdx | 52 + .../description/en-US.langnostic.json | 37 + .../description/zh-CN.mdx | 32 + .../solution/en-US.langnostic.json | 46 + .../solution/zh-CN.mdx | 47 + .../description/en-US.langnostic.json | 37 + .../description/zh-CN.mdx | 32 + .../solution/en-US.langnostic.json | 46 + .../solution/zh-CN.mdx | 49 + .../description/en-US.langnostic.json | 39 + .../description/zh-CN.mdx | 34 + .../solution/en-US.langnostic.json | 32 + .../solution/zh-CN.mdx | 24 + .../description/en-US.langnostic.json | 31 + .../description/zh-CN.mdx | 22 + .../solution/en-US.langnostic.json | 34 + .../solution/zh-CN.mdx | 29 + .../description/en-US.langnostic.json | 43 + .../description/zh-CN.mdx | 38 + .../solution/en-US.langnostic.json | 46 + .../solution/zh-CN.mdx | 47 + .../description/en-US.langnostic.json | 41 + .../binary-tree-subtree/description/zh-CN.mdx | 38 + .../solution/en-US.langnostic.json | 56 + .../binary-tree-subtree/solution/zh-CN.mdx | 65 + .../description/en-US.langnostic.json | 31 + .../algo/binary-tree/description/zh-CN.mdx | 39 + .../solution/en-US.langnostic.json | 42 + .../algo/binary-tree/solution/zh-CN.mdx | 64 + .../description/en-US.langnostic.json | 31 + .../algo/bit-counting/description/zh-CN.mdx | 19 + .../solution/en-US.langnostic.json | 64 + .../algo/bit-counting/solution/zh-CN.mdx | 80 + .../description/en-US.langnostic.json | 31 + .../algo/bit-reversal/description/zh-CN.mdx | 19 + .../solution/en-US.langnostic.json | 50 + .../algo/bit-reversal/solution/zh-CN.mdx | 67 + .../description/en-US.langnostic.json | 51 + .../description/en-US.mdx | 8 +- .../description/zh-CN.mdx | 83 + .../solution/en-US.langnostic.json | 54 + .../breadth-first-search/solution/zh-CN.mdx | 49 + .../description/en-US.langnostic.json | 37 + .../algo/bubble-sort/description/zh-CN.mdx | 27 + .../solution/en-US.langnostic.json | 54 + .../algo/bubble-sort/solution/zh-CN.mdx | 48 + .../description/en-US.langnostic.json | 33 + .../algo/coin-change/description/zh-CN.mdx | 24 + .../solution/en-US.langnostic.json | 46 + .../algo/coin-change/solution/zh-CN.mdx | 53 + .../description/en-US.langnostic.json | 35 + .../description/zh-CN.mdx | 28 + .../solution/en-US.langnostic.json | 52 + .../solution/zh-CN.mdx | 58 + .../description/en-US.langnostic.json | 31 + .../description/zh-CN.mdx | 19 + .../solution/en-US.langnostic.json | 32 + .../count-ones-in-binary/solution/zh-CN.mdx | 26 + .../description/en-US.langnostic.json | 33 + .../course-dependency/description/zh-CN.mdx | 26 + .../solution/en-US.langnostic.json | 54 + .../algo/course-dependency/solution/zh-CN.mdx | 80 + .../description/en-US.langnostic.json | 33 + .../depth-first-search/description/zh-CN.mdx | 58 + .../solution/en-US.langnostic.json | 38 + .../depth-first-search/solution/zh-CN.mdx | 33 + .../description/en-US.langnostic.json | 45 + .../algo/dijkstra/description/zh-CN.mdx | 71 + .../dijkstra/solution/en-US.langnostic.json | 42 + .../algo/dijkstra/solution/zh-CN.mdx | 35 + .../description/en-US.langnostic.json | 37 + .../disjoint-intervals/description/zh-CN.mdx | 28 + .../solution/en-US.langnostic.json | 32 + .../disjoint-intervals/solution/zh-CN.mdx | 26 + .../description/en-US.langnostic.json | 33 + .../description/zh-CN.mdx | 23 + .../solution/en-US.langnostic.json | 36 + .../solution/zh-CN.mdx | 38 + .../description/en-US.langnostic.json | 43 + .../algo/graph-clone/description/zh-CN.mdx | 40 + .../solution/en-US.langnostic.json | 52 + .../algo/graph-clone/solution/zh-CN.mdx | 63 + .../description/en-US.langnostic.json | 33 + .../description/zh-CN.mdx | 27 + .../solution/en-US.langnostic.json | 52 + .../solution/zh-CN.mdx | 67 + .../description/en-US.langnostic.json | 37 + .../algo/graph-is-tree/description/zh-CN.mdx | 33 + .../solution/en-US.langnostic.json | 58 + .../algo/graph-is-tree/solution/zh-CN.mdx | 79 + .../description/en-US.langnostic.json | 33 + .../grid-count-islands/description/zh-CN.mdx | 22 + .../solution/en-US.langnostic.json | 52 + .../grid-count-islands/solution/zh-CN.mdx | 62 + .../description/en-US.langnostic.json | 33 + .../grid-distinct-paths/description/zh-CN.mdx | 23 + .../solution/en-US.langnostic.json | 52 + .../grid-distinct-paths/solution/zh-CN.mdx | 56 + .../description/en-US.langnostic.json | 33 + .../algo/grid-find-word/description/zh-CN.mdx | 24 + .../solution/en-US.langnostic.json | 36 + .../algo/grid-find-word/solution/zh-CN.mdx | 36 + .../description/en-US.langnostic.json | 35 + .../grid-find-words/description/zh-CN.mdx | 30 + .../solution/en-US.langnostic.json | 36 + .../algo/grid-find-words/solution/zh-CN.mdx | 36 + .../description/en-US.langnostic.json | 41 + .../algo/heap-sort/description/zh-CN.mdx | 36 + .../heap-sort/solution/en-US.langnostic.json | 72 + .../algo/heap-sort/solution/zh-CN.mdx | 83 + .../heap/description/en-US.langnostic.json | 25 + .../questions/algo/heap/description/zh-CN.mdx | 29 + .../algo/heap/solution/en-US.langnostic.json | 48 + .../questions/algo/heap/solution/zh-CN.mdx | 39 + .../description/en-US.langnostic.json | 39 + .../algo/insertion-sort/description/zh-CN.mdx | 29 + .../solution/en-US.langnostic.json | 62 + .../algo/insertion-sort/solution/zh-CN.mdx | 61 + .../description/en-US.langnostic.json | 33 + .../description/zh-CN.mdx | 23 + .../solution/en-US.langnostic.json | 50 + .../solution/zh-CN.mdx | 60 + .../description/en-US.langnostic.json | 31 + .../description/zh-CN.mdx | 21 + .../solution/en-US.langnostic.json | 48 + .../solution/zh-CN.mdx | 48 + .../description/en-US.langnostic.json | 31 + .../intervals-merge-new/description/zh-CN.mdx | 22 + .../solution/en-US.langnostic.json | 48 + .../intervals-merge-new/solution/zh-CN.mdx | 61 + .../description/en-US.langnostic.json | 31 + .../description/zh-CN.mdx | 21 + .../solution/en-US.langnostic.json | 52 + .../solution/zh-CN.mdx | 61 + .../description/en-US.langnostic.json | 37 + .../description/zh-CN.mdx | 32 + .../solution/en-US.langnostic.json | 56 + .../solution/zh-CN.mdx | 68 + .../description/en-US.langnostic.json | 37 + .../description/zh-CN.mdx | 32 + .../solution/en-US.langnostic.json | 52 + .../solution/zh-CN.mdx | 59 + .../description/en-US.langnostic.json | 37 + .../description/zh-CN.mdx | 32 + .../solution/en-US.langnostic.json | 66 + .../solution/zh-CN.mdx | 77 + .../description/en-US.langnostic.json | 39 + .../description/zh-CN.mdx | 33 + .../solution/en-US.langnostic.json | 64 + .../solution/zh-CN.mdx | 70 + .../description/en-US.langnostic.json | 45 + .../description/zh-CN.mdx | 39 + .../solution/en-US.langnostic.json | 40 + .../linked-list-rearrange/solution/zh-CN.mdx | 42 + .../description/en-US.langnostic.json | 37 + .../description/zh-CN.mdx | 31 + .../solution/en-US.langnostic.json | 64 + .../linked-list-reversal/solution/zh-CN.mdx | 70 + .../description/en-US.langnostic.json | 25 + .../algo/linked-list/description/zh-CN.mdx | 31 + .../solution/en-US.langnostic.json | 68 + .../algo/linked-list/solution/zh-CN.mdx | 57 + .../description/en-US.langnostic.json | 35 + .../description/zh-CN.mdx | 25 + .../solution/en-US.langnostic.json | 62 + .../solution/zh-CN.mdx | 78 + .../description/en-US.langnostic.json | 35 + .../description/zh-CN.mdx | 24 + .../solution/en-US.langnostic.json | 64 + .../solution/zh-CN.mdx | 84 + .../description/en-US.langnostic.json | 33 + .../description/zh-CN.mdx | 22 + .../solution/en-US.langnostic.json | 54 + .../solution/zh-CN.mdx | 60 + .../description/en-US.langnostic.json | 33 + .../description/zh-CN.mdx | 22 + .../solution/en-US.langnostic.json | 50 + .../solution/zh-CN.mdx | 55 + .../description/en-US.langnostic.json | 35 + .../description/zh-CN.mdx | 24 + .../solution/en-US.langnostic.json | 64 + .../solution/zh-CN.mdx | 86 + .../description/en-US.langnostic.json | 33 + .../description/zh-CN.mdx | 23 + .../solution/en-US.langnostic.json | 50 + .../solution/zh-CN.mdx | 68 + .../description/en-US.langnostic.json | 31 + .../matrix-rotation/description/zh-CN.mdx | 22 + .../solution/en-US.langnostic.json | 56 + .../algo/matrix-rotation/solution/zh-CN.mdx | 72 + .../description/en-US.langnostic.json | 31 + .../description/zh-CN.mdx | 20 + .../solution/en-US.langnostic.json | 56 + .../solution/zh-CN.mdx | 82 + .../description/en-US.langnostic.json | 31 + .../algo/matrix-zeroing/description/zh-CN.mdx | 21 + .../solution/en-US.langnostic.json | 58 + .../algo/matrix-zeroing/solution/zh-CN.mdx | 70 + .../description/en-US.langnostic.json | 31 + .../description/zh-CN.mdx | 20 + .../solution/en-US.langnostic.json | 50 + .../solution/zh-CN.mdx | 58 + .../description/en-US.langnostic.json | 33 + .../algo/merge-sort/description/zh-CN.mdx | 23 + .../merge-sort/solution/en-US.langnostic.json | 54 + .../algo/merge-sort/solution/zh-CN.mdx | 48 + .../description/en-US.langnostic.json | 37 + .../description/zh-CN.mdx | 26 + .../solution/en-US.langnostic.json | 62 + .../solution/zh-CN.mdx | 87 + .../description/en-US.langnostic.json | 37 + .../neighborhood-theft/description/zh-CN.mdx | 26 + .../solution/en-US.langnostic.json | 76 + .../neighborhood-theft/solution/zh-CN.mdx | 104 + .../description/en-US.langnostic.json | 43 + .../description/zh-CN.mdx | 36 + .../solution/en-US.langnostic.json | 66 + .../number-stream-median/solution/zh-CN.mdx | 82 + .../description/en-US.langnostic.json | 37 + .../algo/ocean-flow/description/zh-CN.mdx | 26 + .../ocean-flow/solution/en-US.langnostic.json | 58 + .../algo/ocean-flow/solution/zh-CN.mdx | 83 + .../description/en-US.langnostic.json | 31 + .../description/zh-CN.mdx | 20 + .../solution/en-US.langnostic.json | 54 + .../optimal-stock-trading/solution/zh-CN.mdx | 60 + .../description/en-US.langnostic.json | 35 + .../algo/pair-sum/description/zh-CN.mdx | 27 + .../pair-sum/solution/en-US.langnostic.json | 68 + .../algo/pair-sum/solution/zh-CN.mdx | 82 + .../queue/description/en-US.langnostic.json | 25 + .../algo/queue/description/zh-CN.mdx | 29 + .../algo/queue/solution/en-US.langnostic.json | 48 + .../questions/algo/queue/solution/zh-CN.mdx | 37 + .../description/en-US.langnostic.json | 31 + .../algo/quick-sort/description/en-US.mdx | 2 +- .../algo/quick-sort/description/zh-CN.mdx | 21 + .../quick-sort/solution/en-US.langnostic.json | 72 + .../algo/quick-sort/solution/en-US.mdx | 2 +- .../algo/quick-sort/solution/zh-CN.mdx | 72 + .../description/en-US.langnostic.json | 35 + .../algo/selection-sort/description/zh-CN.mdx | 29 + .../solution/en-US.langnostic.json | 60 + .../algo/selection-sort/solution/zh-CN.mdx | 59 + .../stack/description/en-US.langnostic.json | 25 + .../algo/stack/description/zh-CN.mdx | 27 + .../algo/stack/solution/en-US.langnostic.json | 44 + .../questions/algo/stack/solution/zh-CN.mdx | 35 + .../description/en-US.langnostic.json | 31 + .../description/zh-CN.mdx | 19 + .../solution/en-US.langnostic.json | 62 + .../solution/zh-CN.mdx | 71 + .../description/en-US.langnostic.json | 33 + .../description/zh-CN.mdx | 23 + .../solution/en-US.langnostic.json | 48 + .../string-anagram-groups/solution/zh-CN.mdx | 60 + .../description/en-US.langnostic.json | 33 + .../algo/string-anagram/description/zh-CN.mdx | 23 + .../solution/en-US.langnostic.json | 50 + .../algo/string-anagram/solution/zh-CN.mdx | 55 + .../description/en-US.langnostic.json | 43 + .../description/zh-CN.mdx | 35 + .../solution/en-US.langnostic.json | 66 + .../string-decode-message/solution/zh-CN.mdx | 88 + .../description/en-US.langnostic.json | 33 + .../string-palindrome/description/zh-CN.mdx | 22 + .../solution/en-US.langnostic.json | 46 + .../algo/string-palindrome/solution/zh-CN.mdx | 52 + .../description/en-US.langnostic.json | 35 + .../description/zh-CN.mdx | 24 + .../solution/en-US.langnostic.json | 68 + .../solution/zh-CN.mdx | 98 + .../description/en-US.langnostic.json | 37 + .../description/zh-CN.mdx | 29 + .../solution/en-US.langnostic.json | 50 + .../string-segment-words/solution/zh-CN.mdx | 60 + .../description/en-US.langnostic.json | 37 + .../description/zh-CN.mdx | 27 + .../solution/en-US.langnostic.json | 50 + .../solution/zh-CN.mdx | 69 + .../description/en-US.langnostic.json | 31 + .../description/zh-CN.mdx | 20 + .../solution/en-US.langnostic.json | 36 + .../sum-without-addition/solution/zh-CN.mdx | 32 + .../description/en-US.langnostic.json | 33 + .../task-coordination/description/zh-CN.mdx | 24 + .../solution/en-US.langnostic.json | 50 + .../algo/task-coordination/solution/zh-CN.mdx | 56 + .../description/en-US.langnostic.json | 45 + .../topological-sort/description/zh-CN.mdx | 69 + .../solution/en-US.langnostic.json | 54 + .../algo/topological-sort/solution/zh-CN.mdx | 48 + .../description/en-US.langnostic.json | 39 + .../trie-prefix-tree/description/zh-CN.mdx | 33 + .../solution/en-US.langnostic.json | 34 + .../algo/trie-prefix-tree/solution/zh-CN.mdx | 41 + .../description/en-US.langnostic.json | 35 + .../algo/triplet-sum/description/zh-CN.mdx | 24 + .../solution/en-US.langnostic.json | 46 + .../algo/triplet-sum/solution/zh-CN.mdx | 59 + .../description/en-US.langnostic.json | 37 + .../algo/word-finder/description/zh-CN.mdx | 30 + .../solution/en-US.langnostic.json | 34 + .../algo/word-finder/solution/zh-CN.mdx | 36 + 472 files changed, 23205 insertions(+), 3095 deletions(-) create mode 100644 apps/web/src/__generated__/questions/algo/array-balanced-brackets/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/array-find-duplicate/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/array-find-missing-number-in-sequence/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/array-maximum-product-contiguous/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/array-maximum-sum-contiguous/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/array-most-common-elements/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/array-product-excluding-current/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/array-reachable-end/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/array-rotated-find/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/array-smallest-in-rotated/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/binary-search-tree-kth-smallest/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/binary-search-tree-lowest-common-ancestor/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/binary-search-tree-validate/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/binary-search-tree/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/binary-search/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/binary-tree-equal/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/binary-tree-flip/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/binary-tree-level-order-traversal/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/binary-tree-maximum-depth/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/binary-tree-maximum-total-path/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/binary-tree-rebuilding-from-traversals/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/binary-tree-serialization-deserialization/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/binary-tree-subtree/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/binary-tree/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/bit-counting/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/bit-reversal/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/breadth-first-search/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/bubble-sort/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/coin-change/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/combinations-target-sum/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/count-ones-in-binary/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/course-dependency/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/depth-first-search/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/dijkstra/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/disjoint-intervals/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/extraterrestrial-language/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/graph-clone/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/graph-count-connected-components/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/graph-is-tree/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/grid-count-islands/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/grid-distinct-paths/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/grid-find-word/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/grid-find-words/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/heap-sort/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/heap/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/insertion-sort/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/intervals-combine-overlapping/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/intervals-meeting-calendar/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/intervals-merge-new/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/intervals-minimum-meeting-rooms/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/linked-list-combine-k-sorted/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/linked-list-combine-two-sorted/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/linked-list-delete-nth-from-end/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/linked-list-detect-cycle/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/linked-list-rearrange/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/linked-list-reversal/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/linked-list/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/list.zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/longest-common-subsequence/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/longest-consecutive-number-sequence/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/longest-increasing-subsequence/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/longest-non-repeating-substring/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/longest-palindromic-substring/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/longest-repeating-substring-after-replacements/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/matrix-rotation/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/matrix-spiral-traversal/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/matrix-zeroing/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/maximum-water-between-walls/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/merge-sort/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/neighborhood-theft-circular/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/neighborhood-theft/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/number-stream-median/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/ocean-flow/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/optimal-stock-trading/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/pair-sum/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/queue/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/quick-sort/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/selection-sort/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/stack/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/staircase-climbing-combinations/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/string-anagram-groups/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/string-anagram/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/string-decode-message/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/string-palindrome/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/string-palindromic-substrings/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/string-segment-words/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/string-shortest-substring-containing-characters/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/sum-without-addition/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/task-coordination/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/topological-sort/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/trie-prefix-tree/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/triplet-sum/locales/zh-CN.json create mode 100644 apps/web/src/__generated__/questions/algo/word-finder/locales/zh-CN.json create mode 100644 contents/questions/algo/array-balanced-brackets/description/en-US.langnostic.json create mode 100644 contents/questions/algo/array-balanced-brackets/description/zh-CN.mdx create mode 100644 contents/questions/algo/array-balanced-brackets/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/array-balanced-brackets/solution/zh-CN.mdx create mode 100644 contents/questions/algo/array-find-duplicate/description/en-US.langnostic.json create mode 100644 contents/questions/algo/array-find-duplicate/description/zh-CN.mdx create mode 100644 contents/questions/algo/array-find-duplicate/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/array-find-duplicate/solution/zh-CN.mdx create mode 100644 contents/questions/algo/array-find-missing-number-in-sequence/description/en-US.langnostic.json create mode 100644 contents/questions/algo/array-find-missing-number-in-sequence/description/zh-CN.mdx create mode 100644 contents/questions/algo/array-find-missing-number-in-sequence/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/array-find-missing-number-in-sequence/solution/zh-CN.mdx create mode 100644 contents/questions/algo/array-maximum-product-contiguous/description/en-US.langnostic.json create mode 100644 contents/questions/algo/array-maximum-product-contiguous/description/zh-CN.mdx create mode 100644 contents/questions/algo/array-maximum-product-contiguous/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/array-maximum-product-contiguous/solution/zh-CN.mdx create mode 100644 contents/questions/algo/array-maximum-sum-contiguous/description/en-US.langnostic.json create mode 100644 contents/questions/algo/array-maximum-sum-contiguous/description/zh-CN.mdx create mode 100644 contents/questions/algo/array-maximum-sum-contiguous/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/array-maximum-sum-contiguous/solution/zh-CN.mdx create mode 100644 contents/questions/algo/array-most-common-elements/description/en-US.langnostic.json create mode 100644 contents/questions/algo/array-most-common-elements/description/zh-CN.mdx create mode 100644 contents/questions/algo/array-most-common-elements/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/array-most-common-elements/solution/zh-CN.mdx create mode 100644 contents/questions/algo/array-product-excluding-current/description/en-US.langnostic.json create mode 100644 contents/questions/algo/array-product-excluding-current/description/zh-CN.mdx create mode 100644 contents/questions/algo/array-product-excluding-current/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/array-product-excluding-current/solution/zh-CN.mdx create mode 100644 contents/questions/algo/array-reachable-end/description/en-US.langnostic.json create mode 100644 contents/questions/algo/array-reachable-end/description/zh-CN.mdx create mode 100644 contents/questions/algo/array-reachable-end/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/array-reachable-end/solution/zh-CN.mdx create mode 100644 contents/questions/algo/array-rotated-find/description/en-US.langnostic.json create mode 100644 contents/questions/algo/array-rotated-find/description/zh-CN.mdx create mode 100644 contents/questions/algo/array-rotated-find/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/array-rotated-find/solution/zh-CN.mdx create mode 100644 contents/questions/algo/array-smallest-in-rotated/description/en-US.langnostic.json create mode 100644 contents/questions/algo/array-smallest-in-rotated/description/zh-CN.mdx create mode 100644 contents/questions/algo/array-smallest-in-rotated/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/array-smallest-in-rotated/solution/zh-CN.mdx create mode 100644 contents/questions/algo/binary-search-tree-kth-smallest/description/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-search-tree-kth-smallest/description/zh-CN.mdx create mode 100644 contents/questions/algo/binary-search-tree-kth-smallest/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-search-tree-kth-smallest/solution/zh-CN.mdx create mode 100644 contents/questions/algo/binary-search-tree-lowest-common-ancestor/description/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-search-tree-lowest-common-ancestor/description/zh-CN.mdx create mode 100644 contents/questions/algo/binary-search-tree-lowest-common-ancestor/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-search-tree-lowest-common-ancestor/solution/zh-CN.mdx create mode 100644 contents/questions/algo/binary-search-tree-validate/description/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-search-tree-validate/description/zh-CN.mdx create mode 100644 contents/questions/algo/binary-search-tree-validate/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-search-tree-validate/solution/zh-CN.mdx create mode 100644 contents/questions/algo/binary-search-tree/description/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-search-tree/description/zh-CN.mdx create mode 100644 contents/questions/algo/binary-search-tree/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-search-tree/solution/zh-CN.mdx create mode 100644 contents/questions/algo/binary-search/description/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-search/description/zh-CN.mdx create mode 100644 contents/questions/algo/binary-search/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-search/solution/zh-CN.mdx create mode 100644 contents/questions/algo/binary-tree-equal/description/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-tree-equal/description/zh-CN.mdx create mode 100644 contents/questions/algo/binary-tree-equal/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-tree-equal/solution/zh-CN.mdx create mode 100644 contents/questions/algo/binary-tree-flip/description/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-tree-flip/description/zh-CN.mdx create mode 100644 contents/questions/algo/binary-tree-flip/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-tree-flip/solution/zh-CN.mdx create mode 100644 contents/questions/algo/binary-tree-level-order-traversal/description/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-tree-level-order-traversal/description/zh-CN.mdx create mode 100644 contents/questions/algo/binary-tree-level-order-traversal/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-tree-level-order-traversal/solution/zh-CN.mdx create mode 100644 contents/questions/algo/binary-tree-maximum-depth/description/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-tree-maximum-depth/description/zh-CN.mdx create mode 100644 contents/questions/algo/binary-tree-maximum-depth/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-tree-maximum-depth/solution/zh-CN.mdx create mode 100644 contents/questions/algo/binary-tree-maximum-total-path/description/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-tree-maximum-total-path/description/zh-CN.mdx create mode 100644 contents/questions/algo/binary-tree-maximum-total-path/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-tree-maximum-total-path/solution/zh-CN.mdx create mode 100644 contents/questions/algo/binary-tree-rebuilding-from-traversals/description/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-tree-rebuilding-from-traversals/description/zh-CN.mdx create mode 100644 contents/questions/algo/binary-tree-rebuilding-from-traversals/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-tree-rebuilding-from-traversals/solution/zh-CN.mdx create mode 100644 contents/questions/algo/binary-tree-serialization-deserialization/description/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-tree-serialization-deserialization/description/zh-CN.mdx create mode 100644 contents/questions/algo/binary-tree-serialization-deserialization/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-tree-serialization-deserialization/solution/zh-CN.mdx create mode 100644 contents/questions/algo/binary-tree-subtree/description/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-tree-subtree/description/zh-CN.mdx create mode 100644 contents/questions/algo/binary-tree-subtree/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-tree-subtree/solution/zh-CN.mdx create mode 100644 contents/questions/algo/binary-tree/description/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-tree/description/zh-CN.mdx create mode 100644 contents/questions/algo/binary-tree/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/binary-tree/solution/zh-CN.mdx create mode 100644 contents/questions/algo/bit-counting/description/en-US.langnostic.json create mode 100644 contents/questions/algo/bit-counting/description/zh-CN.mdx create mode 100644 contents/questions/algo/bit-counting/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/bit-counting/solution/zh-CN.mdx create mode 100644 contents/questions/algo/bit-reversal/description/en-US.langnostic.json create mode 100644 contents/questions/algo/bit-reversal/description/zh-CN.mdx create mode 100644 contents/questions/algo/bit-reversal/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/bit-reversal/solution/zh-CN.mdx create mode 100644 contents/questions/algo/breadth-first-search/description/en-US.langnostic.json create mode 100644 contents/questions/algo/breadth-first-search/description/zh-CN.mdx create mode 100644 contents/questions/algo/breadth-first-search/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/breadth-first-search/solution/zh-CN.mdx create mode 100644 contents/questions/algo/bubble-sort/description/en-US.langnostic.json create mode 100644 contents/questions/algo/bubble-sort/description/zh-CN.mdx create mode 100644 contents/questions/algo/bubble-sort/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/bubble-sort/solution/zh-CN.mdx create mode 100644 contents/questions/algo/coin-change/description/en-US.langnostic.json create mode 100644 contents/questions/algo/coin-change/description/zh-CN.mdx create mode 100644 contents/questions/algo/coin-change/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/coin-change/solution/zh-CN.mdx create mode 100644 contents/questions/algo/combinations-target-sum/description/en-US.langnostic.json create mode 100644 contents/questions/algo/combinations-target-sum/description/zh-CN.mdx create mode 100644 contents/questions/algo/combinations-target-sum/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/combinations-target-sum/solution/zh-CN.mdx create mode 100644 contents/questions/algo/count-ones-in-binary/description/en-US.langnostic.json create mode 100644 contents/questions/algo/count-ones-in-binary/description/zh-CN.mdx create mode 100644 contents/questions/algo/count-ones-in-binary/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/count-ones-in-binary/solution/zh-CN.mdx create mode 100644 contents/questions/algo/course-dependency/description/en-US.langnostic.json create mode 100644 contents/questions/algo/course-dependency/description/zh-CN.mdx create mode 100644 contents/questions/algo/course-dependency/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/course-dependency/solution/zh-CN.mdx create mode 100644 contents/questions/algo/depth-first-search/description/en-US.langnostic.json create mode 100644 contents/questions/algo/depth-first-search/description/zh-CN.mdx create mode 100644 contents/questions/algo/depth-first-search/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/depth-first-search/solution/zh-CN.mdx create mode 100644 contents/questions/algo/dijkstra/description/en-US.langnostic.json create mode 100644 contents/questions/algo/dijkstra/description/zh-CN.mdx create mode 100644 contents/questions/algo/dijkstra/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/dijkstra/solution/zh-CN.mdx create mode 100644 contents/questions/algo/disjoint-intervals/description/en-US.langnostic.json create mode 100644 contents/questions/algo/disjoint-intervals/description/zh-CN.mdx create mode 100644 contents/questions/algo/disjoint-intervals/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/disjoint-intervals/solution/zh-CN.mdx create mode 100644 contents/questions/algo/extraterrestrial-language/description/en-US.langnostic.json create mode 100644 contents/questions/algo/extraterrestrial-language/description/zh-CN.mdx create mode 100644 contents/questions/algo/extraterrestrial-language/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/extraterrestrial-language/solution/zh-CN.mdx create mode 100644 contents/questions/algo/graph-clone/description/en-US.langnostic.json create mode 100644 contents/questions/algo/graph-clone/description/zh-CN.mdx create mode 100644 contents/questions/algo/graph-clone/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/graph-clone/solution/zh-CN.mdx create mode 100644 contents/questions/algo/graph-count-connected-components/description/en-US.langnostic.json create mode 100644 contents/questions/algo/graph-count-connected-components/description/zh-CN.mdx create mode 100644 contents/questions/algo/graph-count-connected-components/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/graph-count-connected-components/solution/zh-CN.mdx create mode 100644 contents/questions/algo/graph-is-tree/description/en-US.langnostic.json create mode 100644 contents/questions/algo/graph-is-tree/description/zh-CN.mdx create mode 100644 contents/questions/algo/graph-is-tree/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/graph-is-tree/solution/zh-CN.mdx create mode 100644 contents/questions/algo/grid-count-islands/description/en-US.langnostic.json create mode 100644 contents/questions/algo/grid-count-islands/description/zh-CN.mdx create mode 100644 contents/questions/algo/grid-count-islands/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/grid-count-islands/solution/zh-CN.mdx create mode 100644 contents/questions/algo/grid-distinct-paths/description/en-US.langnostic.json create mode 100644 contents/questions/algo/grid-distinct-paths/description/zh-CN.mdx create mode 100644 contents/questions/algo/grid-distinct-paths/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/grid-distinct-paths/solution/zh-CN.mdx create mode 100644 contents/questions/algo/grid-find-word/description/en-US.langnostic.json create mode 100644 contents/questions/algo/grid-find-word/description/zh-CN.mdx create mode 100644 contents/questions/algo/grid-find-word/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/grid-find-word/solution/zh-CN.mdx create mode 100644 contents/questions/algo/grid-find-words/description/en-US.langnostic.json create mode 100644 contents/questions/algo/grid-find-words/description/zh-CN.mdx create mode 100644 contents/questions/algo/grid-find-words/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/grid-find-words/solution/zh-CN.mdx create mode 100644 contents/questions/algo/heap-sort/description/en-US.langnostic.json create mode 100644 contents/questions/algo/heap-sort/description/zh-CN.mdx create mode 100644 contents/questions/algo/heap-sort/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/heap-sort/solution/zh-CN.mdx create mode 100644 contents/questions/algo/heap/description/en-US.langnostic.json create mode 100644 contents/questions/algo/heap/description/zh-CN.mdx create mode 100644 contents/questions/algo/heap/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/heap/solution/zh-CN.mdx create mode 100644 contents/questions/algo/insertion-sort/description/en-US.langnostic.json create mode 100644 contents/questions/algo/insertion-sort/description/zh-CN.mdx create mode 100644 contents/questions/algo/insertion-sort/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/insertion-sort/solution/zh-CN.mdx create mode 100644 contents/questions/algo/intervals-combine-overlapping/description/en-US.langnostic.json create mode 100644 contents/questions/algo/intervals-combine-overlapping/description/zh-CN.mdx create mode 100644 contents/questions/algo/intervals-combine-overlapping/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/intervals-combine-overlapping/solution/zh-CN.mdx create mode 100644 contents/questions/algo/intervals-meeting-calendar/description/en-US.langnostic.json create mode 100644 contents/questions/algo/intervals-meeting-calendar/description/zh-CN.mdx create mode 100644 contents/questions/algo/intervals-meeting-calendar/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/intervals-meeting-calendar/solution/zh-CN.mdx create mode 100644 contents/questions/algo/intervals-merge-new/description/en-US.langnostic.json create mode 100644 contents/questions/algo/intervals-merge-new/description/zh-CN.mdx create mode 100644 contents/questions/algo/intervals-merge-new/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/intervals-merge-new/solution/zh-CN.mdx create mode 100644 contents/questions/algo/intervals-minimum-meeting-rooms/description/en-US.langnostic.json create mode 100644 contents/questions/algo/intervals-minimum-meeting-rooms/description/zh-CN.mdx create mode 100644 contents/questions/algo/intervals-minimum-meeting-rooms/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/intervals-minimum-meeting-rooms/solution/zh-CN.mdx create mode 100644 contents/questions/algo/linked-list-combine-k-sorted/description/en-US.langnostic.json create mode 100644 contents/questions/algo/linked-list-combine-k-sorted/description/zh-CN.mdx create mode 100644 contents/questions/algo/linked-list-combine-k-sorted/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/linked-list-combine-k-sorted/solution/zh-CN.mdx create mode 100644 contents/questions/algo/linked-list-combine-two-sorted/description/en-US.langnostic.json create mode 100644 contents/questions/algo/linked-list-combine-two-sorted/description/zh-CN.mdx create mode 100644 contents/questions/algo/linked-list-combine-two-sorted/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/linked-list-combine-two-sorted/solution/zh-CN.mdx create mode 100644 contents/questions/algo/linked-list-delete-nth-from-end/description/en-US.langnostic.json create mode 100644 contents/questions/algo/linked-list-delete-nth-from-end/description/zh-CN.mdx create mode 100644 contents/questions/algo/linked-list-delete-nth-from-end/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/linked-list-delete-nth-from-end/solution/zh-CN.mdx create mode 100644 contents/questions/algo/linked-list-detect-cycle/description/en-US.langnostic.json create mode 100644 contents/questions/algo/linked-list-detect-cycle/description/zh-CN.mdx create mode 100644 contents/questions/algo/linked-list-detect-cycle/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/linked-list-detect-cycle/solution/zh-CN.mdx create mode 100644 contents/questions/algo/linked-list-rearrange/description/en-US.langnostic.json create mode 100644 contents/questions/algo/linked-list-rearrange/description/zh-CN.mdx create mode 100644 contents/questions/algo/linked-list-rearrange/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/linked-list-rearrange/solution/zh-CN.mdx create mode 100644 contents/questions/algo/linked-list-reversal/description/en-US.langnostic.json create mode 100644 contents/questions/algo/linked-list-reversal/description/zh-CN.mdx create mode 100644 contents/questions/algo/linked-list-reversal/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/linked-list-reversal/solution/zh-CN.mdx create mode 100644 contents/questions/algo/linked-list/description/en-US.langnostic.json create mode 100644 contents/questions/algo/linked-list/description/zh-CN.mdx create mode 100644 contents/questions/algo/linked-list/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/linked-list/solution/zh-CN.mdx create mode 100644 contents/questions/algo/longest-common-subsequence/description/en-US.langnostic.json create mode 100644 contents/questions/algo/longest-common-subsequence/description/zh-CN.mdx create mode 100644 contents/questions/algo/longest-common-subsequence/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/longest-common-subsequence/solution/zh-CN.mdx create mode 100644 contents/questions/algo/longest-consecutive-number-sequence/description/en-US.langnostic.json create mode 100644 contents/questions/algo/longest-consecutive-number-sequence/description/zh-CN.mdx create mode 100644 contents/questions/algo/longest-consecutive-number-sequence/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/longest-consecutive-number-sequence/solution/zh-CN.mdx create mode 100644 contents/questions/algo/longest-increasing-subsequence/description/en-US.langnostic.json create mode 100644 contents/questions/algo/longest-increasing-subsequence/description/zh-CN.mdx create mode 100644 contents/questions/algo/longest-increasing-subsequence/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/longest-increasing-subsequence/solution/zh-CN.mdx create mode 100644 contents/questions/algo/longest-non-repeating-substring/description/en-US.langnostic.json create mode 100644 contents/questions/algo/longest-non-repeating-substring/description/zh-CN.mdx create mode 100644 contents/questions/algo/longest-non-repeating-substring/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/longest-non-repeating-substring/solution/zh-CN.mdx create mode 100644 contents/questions/algo/longest-palindromic-substring/description/en-US.langnostic.json create mode 100644 contents/questions/algo/longest-palindromic-substring/description/zh-CN.mdx create mode 100644 contents/questions/algo/longest-palindromic-substring/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/longest-palindromic-substring/solution/zh-CN.mdx create mode 100644 contents/questions/algo/longest-repeating-substring-after-replacements/description/en-US.langnostic.json create mode 100644 contents/questions/algo/longest-repeating-substring-after-replacements/description/zh-CN.mdx create mode 100644 contents/questions/algo/longest-repeating-substring-after-replacements/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/longest-repeating-substring-after-replacements/solution/zh-CN.mdx create mode 100644 contents/questions/algo/matrix-rotation/description/en-US.langnostic.json create mode 100644 contents/questions/algo/matrix-rotation/description/zh-CN.mdx create mode 100644 contents/questions/algo/matrix-rotation/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/matrix-rotation/solution/zh-CN.mdx create mode 100644 contents/questions/algo/matrix-spiral-traversal/description/en-US.langnostic.json create mode 100644 contents/questions/algo/matrix-spiral-traversal/description/zh-CN.mdx create mode 100644 contents/questions/algo/matrix-spiral-traversal/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/matrix-spiral-traversal/solution/zh-CN.mdx create mode 100644 contents/questions/algo/matrix-zeroing/description/en-US.langnostic.json create mode 100644 contents/questions/algo/matrix-zeroing/description/zh-CN.mdx create mode 100644 contents/questions/algo/matrix-zeroing/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/matrix-zeroing/solution/zh-CN.mdx create mode 100644 contents/questions/algo/maximum-water-between-walls/description/en-US.langnostic.json create mode 100644 contents/questions/algo/maximum-water-between-walls/description/zh-CN.mdx create mode 100644 contents/questions/algo/maximum-water-between-walls/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/maximum-water-between-walls/solution/zh-CN.mdx create mode 100644 contents/questions/algo/merge-sort/description/en-US.langnostic.json create mode 100644 contents/questions/algo/merge-sort/description/zh-CN.mdx create mode 100644 contents/questions/algo/merge-sort/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/merge-sort/solution/zh-CN.mdx create mode 100644 contents/questions/algo/neighborhood-theft-circular/description/en-US.langnostic.json create mode 100644 contents/questions/algo/neighborhood-theft-circular/description/zh-CN.mdx create mode 100644 contents/questions/algo/neighborhood-theft-circular/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/neighborhood-theft-circular/solution/zh-CN.mdx create mode 100644 contents/questions/algo/neighborhood-theft/description/en-US.langnostic.json create mode 100644 contents/questions/algo/neighborhood-theft/description/zh-CN.mdx create mode 100644 contents/questions/algo/neighborhood-theft/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/neighborhood-theft/solution/zh-CN.mdx create mode 100644 contents/questions/algo/number-stream-median/description/en-US.langnostic.json create mode 100644 contents/questions/algo/number-stream-median/description/zh-CN.mdx create mode 100644 contents/questions/algo/number-stream-median/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/number-stream-median/solution/zh-CN.mdx create mode 100644 contents/questions/algo/ocean-flow/description/en-US.langnostic.json create mode 100644 contents/questions/algo/ocean-flow/description/zh-CN.mdx create mode 100644 contents/questions/algo/ocean-flow/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/ocean-flow/solution/zh-CN.mdx create mode 100644 contents/questions/algo/optimal-stock-trading/description/en-US.langnostic.json create mode 100644 contents/questions/algo/optimal-stock-trading/description/zh-CN.mdx create mode 100644 contents/questions/algo/optimal-stock-trading/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/optimal-stock-trading/solution/zh-CN.mdx create mode 100644 contents/questions/algo/pair-sum/description/en-US.langnostic.json create mode 100644 contents/questions/algo/pair-sum/description/zh-CN.mdx create mode 100644 contents/questions/algo/pair-sum/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/pair-sum/solution/zh-CN.mdx create mode 100644 contents/questions/algo/queue/description/en-US.langnostic.json create mode 100644 contents/questions/algo/queue/description/zh-CN.mdx create mode 100644 contents/questions/algo/queue/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/queue/solution/zh-CN.mdx create mode 100644 contents/questions/algo/quick-sort/description/en-US.langnostic.json create mode 100644 contents/questions/algo/quick-sort/description/zh-CN.mdx create mode 100644 contents/questions/algo/quick-sort/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/quick-sort/solution/zh-CN.mdx create mode 100644 contents/questions/algo/selection-sort/description/en-US.langnostic.json create mode 100644 contents/questions/algo/selection-sort/description/zh-CN.mdx create mode 100644 contents/questions/algo/selection-sort/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/selection-sort/solution/zh-CN.mdx create mode 100644 contents/questions/algo/stack/description/en-US.langnostic.json create mode 100644 contents/questions/algo/stack/description/zh-CN.mdx create mode 100644 contents/questions/algo/stack/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/stack/solution/zh-CN.mdx create mode 100644 contents/questions/algo/staircase-climbing-combinations/description/en-US.langnostic.json create mode 100644 contents/questions/algo/staircase-climbing-combinations/description/zh-CN.mdx create mode 100644 contents/questions/algo/staircase-climbing-combinations/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/staircase-climbing-combinations/solution/zh-CN.mdx create mode 100644 contents/questions/algo/string-anagram-groups/description/en-US.langnostic.json create mode 100644 contents/questions/algo/string-anagram-groups/description/zh-CN.mdx create mode 100644 contents/questions/algo/string-anagram-groups/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/string-anagram-groups/solution/zh-CN.mdx create mode 100644 contents/questions/algo/string-anagram/description/en-US.langnostic.json create mode 100644 contents/questions/algo/string-anagram/description/zh-CN.mdx create mode 100644 contents/questions/algo/string-anagram/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/string-anagram/solution/zh-CN.mdx create mode 100644 contents/questions/algo/string-decode-message/description/en-US.langnostic.json create mode 100644 contents/questions/algo/string-decode-message/description/zh-CN.mdx create mode 100644 contents/questions/algo/string-decode-message/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/string-decode-message/solution/zh-CN.mdx create mode 100644 contents/questions/algo/string-palindrome/description/en-US.langnostic.json create mode 100644 contents/questions/algo/string-palindrome/description/zh-CN.mdx create mode 100644 contents/questions/algo/string-palindrome/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/string-palindrome/solution/zh-CN.mdx create mode 100644 contents/questions/algo/string-palindromic-substrings/description/en-US.langnostic.json create mode 100644 contents/questions/algo/string-palindromic-substrings/description/zh-CN.mdx create mode 100644 contents/questions/algo/string-palindromic-substrings/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/string-palindromic-substrings/solution/zh-CN.mdx create mode 100644 contents/questions/algo/string-segment-words/description/en-US.langnostic.json create mode 100644 contents/questions/algo/string-segment-words/description/zh-CN.mdx create mode 100644 contents/questions/algo/string-segment-words/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/string-segment-words/solution/zh-CN.mdx create mode 100644 contents/questions/algo/string-shortest-substring-containing-characters/description/en-US.langnostic.json create mode 100644 contents/questions/algo/string-shortest-substring-containing-characters/description/zh-CN.mdx create mode 100644 contents/questions/algo/string-shortest-substring-containing-characters/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/string-shortest-substring-containing-characters/solution/zh-CN.mdx create mode 100644 contents/questions/algo/sum-without-addition/description/en-US.langnostic.json create mode 100644 contents/questions/algo/sum-without-addition/description/zh-CN.mdx create mode 100644 contents/questions/algo/sum-without-addition/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/sum-without-addition/solution/zh-CN.mdx create mode 100644 contents/questions/algo/task-coordination/description/en-US.langnostic.json create mode 100644 contents/questions/algo/task-coordination/description/zh-CN.mdx create mode 100644 contents/questions/algo/task-coordination/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/task-coordination/solution/zh-CN.mdx create mode 100644 contents/questions/algo/topological-sort/description/en-US.langnostic.json create mode 100644 contents/questions/algo/topological-sort/description/zh-CN.mdx create mode 100644 contents/questions/algo/topological-sort/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/topological-sort/solution/zh-CN.mdx create mode 100644 contents/questions/algo/trie-prefix-tree/description/en-US.langnostic.json create mode 100644 contents/questions/algo/trie-prefix-tree/description/zh-CN.mdx create mode 100644 contents/questions/algo/trie-prefix-tree/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/trie-prefix-tree/solution/zh-CN.mdx create mode 100644 contents/questions/algo/triplet-sum/description/en-US.langnostic.json create mode 100644 contents/questions/algo/triplet-sum/description/zh-CN.mdx create mode 100644 contents/questions/algo/triplet-sum/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/triplet-sum/solution/zh-CN.mdx create mode 100644 contents/questions/algo/word-finder/description/en-US.langnostic.json create mode 100644 contents/questions/algo/word-finder/description/zh-CN.mdx create mode 100644 contents/questions/algo/word-finder/solution/en-US.langnostic.json create mode 100644 contents/questions/algo/word-finder/solution/zh-CN.mdx diff --git a/apps/web/src/__generated__/questions/algo/array-balanced-brackets/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/array-balanced-brackets/locales/zh-CN.json new file mode 100644 index 000000000..a943bbedd --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/array-balanced-brackets/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var u=Object.create;var d=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var j=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),_=(r,e)=>{for(var c in e)d(r,c,{get:e[c],enumerable:!0})},l=(r,e,c,i)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let t of m(e))!g.call(r,t)&&t!==c&&d(r,t,{get:()=>e[t],enumerable:!(i=x(e,t))||i.enumerable});return r};var T=(r,e,c)=>(c=r!=null?u(f(r)):{},l(e||!r||!r.__esModule?d(c,\"default\",{value:r,enumerable:!0}):c,r)),y=r=>l(d({},\"__esModule\",{value:!0}),r);var s=j((F,o)=>{o.exports=_jsx_runtime});var b={};_(b,{default:()=>X,frontmatter:()=>C});var n=T(s());var h=MDXTestExamples;var a=[{input:[[\"str\",\"[]\"]],output:!0,explanation:\"The string contains correctly paired and ordered parentheses.\"},{input:[[\"str\",\"([)]\"]],output:!1,explanation:\"The string contains correctly paired but incorrectly ordered parentheses.\"},{input:[[\"str\",\"([]){}\"]],output:!0,explanation:\"The string contains correctly paired and ordered parentheses.\"}];var C={title:\"\\u5E73\\u8861\\u62EC\\u53F7\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u786E\\u5B9A\\u4E00\\u4E2A\\u5B57\\u7B26\\u4E32\\u662F\\u5426\\u5305\\u542B\\u5E73\\u8861\\u7684\\u62EC\\u53F7\"};function p(r){let e=Object.assign({p:\"p\",code:\"code\",ul:\"ul\",li:\"li\",h3:\"h3\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u5B57\\u7B26\\u4E32 \",(0,n.jsx)(e.code,{children:\"str\"}),\"\\uFF0C\\u7531\\u8BF8\\u5982 \",(0,n.jsx)(e.code,{children:\"'(', ')', '{', '}', '[ \\u548C ']'\"}),\" \\u7B49\\u5B57\\u7B26\\u7EC4\\u6210\\uFF0C\\u786E\\u5B9A\\u8F93\\u5165\\u5B57\\u7B26\\u4E32\\u662F\\u5426\\u6B63\\u786E\\u5E73\\u8861\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u5982\\u679C\\u6EE1\\u8DB3\\u4EE5\\u4E0B\\u6761\\u4EF6\\uFF0C\\u5219\\u8BA4\\u4E3A\\u5B57\\u7B26\\u4E32\\u662F\\u5E73\\u8861\\u7684\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u6BCF\\u4E2A\\u5DE6\\u62EC\\u53F7\\u90FD\\u7531\\u76F8\\u540C\\u7C7B\\u578B\\u7684\\u53F3\\u62EC\\u53F7\\u95ED\\u5408\\uFF08\\u4F8B\\u5982\\uFF0C\",(0,n.jsx)(e.code,{children:\"(\"}),\" \\u5BF9\\u5E94 \",(0,n.jsx)(e.code,{children:\")\"}),\", \",(0,n.jsx)(e.code,{children:\"{\"}),\" \\u5BF9\\u5E94 \",(0,n.jsx)(e.code,{children:\"}\"}),\", \",(0,n.jsx)(e.code,{children:\"[\"}),\" \\u5BF9\\u5E94 \",(0,n.jsx)(e.code,{children:\"]\"}),\"\\uFF09\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u62EC\\u53F7\\u6309\\u6B63\\u786E\\u7684\\u987A\\u5E8F\\u95ED\\u5408\\uFF08\\u4F8B\\u5982\\uFF0C\",(0,n.jsx)(e.code,{children:\"([])\"}),\" \\u6709\\u6548\\uFF0C\\u4F46 \",(0,n.jsx)(e.code,{children:\"([)]\"}),\" \\u65E0\\u6548\\uFF09\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4EFB\\u4F55\\u5305\\u542B\\u5728\\u4E00\\u5BF9\\u5339\\u914D\\u62EC\\u53F7\\u5185\\u7684\\u62EC\\u53F7\\u5B50\\u96C6\\u4E5F\\u5FC5\\u987B\\u5F62\\u6210\\u4E00\\u4E2A\\u6709\\u6548\\u7684\\u5339\\u914D\\u5BF9\\uFF08\\u4F8B\\u5982\\uFF0C\",(0,n.jsx)(e.code,{children:\"{[(])}\"}),\" \\u4E0D\\u5E73\\u8861\\uFF0C\\u56E0\\u4E3A \",(0,n.jsx)(e.code,{children:\"{\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"}\"}),\" \\u5185\\u90E8\\u7684\\u5185\\u5BB9\\u4E0D\\u5E73\\u8861\\uFF09\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"str: string\"}),\": \\u5B57\\u7B26\\u4E32\"]}),`\n`]}),`\n`,(0,n.jsx)(h,{testCases:a}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"strs.length\"}),\" <= 1000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B57\\u7B26\\u4E32 \",(0,n.jsx)(e.code,{children:\"str\"}),\" \\u4EC5\\u5305\\u542B\\u5B57\\u7B26 \",(0,n.jsx)(e.code,{children:\"(\"}),\", \",(0,n.jsx)(e.code,{children:\")\"}),\", \",(0,n.jsx)(e.code,{children:\"{\"}),\", \",(0,n.jsx)(e.code,{children:\"}\"}),\", \",(0,n.jsx)(e.code,{children:\"[\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"]\"})]}),`\n`]})]})}function D(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(p,r)})):p(r)}var X=D;return y(b);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来确定一个字符串是否包含平衡的括号", + "title": "平衡括号" + }, + "solution": "var Component=(()=>{var g=Object.create;var c=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var x=(t,n)=>()=>(n||t((n={exports:{}}).exports,n),n.exports),O=(t,n)=>{for(var r in n)c(t,r,{get:n[r],enumerable:!0})},s=(t,n,r,l)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let i of f(n))!k.call(t,i)&&i!==r&&c(t,i,{get:()=>n[i],enumerable:!(l=u(n,i))||l.enumerable});return t};var j=(t,n,r)=>(r=t!=null?g(m(t)):{},s(n||!t||!t.__esModule?c(r,\"default\",{value:t,enumerable:!0}):r,t)),_=t=>s(c({},\"__esModule\",{value:!0}),t);var h=x((M,o)=>{o.exports=_jsx_runtime});var y={};O(y,{default:()=>I});var e=j(h());var a=MDXCodeBlock;var d=`export default function isBalancedBrackets(str: string): boolean {\n // Define a mapping from closing parentheses to their corresponding opening parentheses\n const mappings: { [key: string]: string } = {\n ')': '(',\n '}': '{',\n ']': '[',\n };\n\n // Initialize an empty stack to keep track of opening parentheses\n const stack: string[] = [];\n\n // Iterate through each character in the string\n for (let c of str) {\n // If the current character is a closing parenthesis\n if (mappings[c]) {\n // Pop the top element from the stack (or use '#' if the stack is empty)\n const topElement = stack.length ? stack.pop() : '#';\n\n // If the popped element does not match the corresponding opening parenthesis, return false\n if (topElement !== mappings[c]) {\n return false;\n }\n } else {\n // If the current character is an opening parenthesis, push it onto the stack\n stack.push(c);\n }\n }\n\n // After processing all characters, the stack should be empty for the string to be valid\n return stack.length === 0;\n}\n`;function p(t){let n=Object.assign({h2:\"h2\",p:\"p\",ol:\"ol\",li:\"li\",h3:\"h3\",code:\"code\",ul:\"ul\",strong:\"strong\"},t.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"1. \\u4F7F\\u7528\\u5806\\u6808\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5E73\\u8861\\u62EC\\u53F7\\u95EE\\u9898\\u6D89\\u53CA\\u786E\\u5B9A\\u5305\\u542B\\u62EC\\u53F7\\u7684\\u5B57\\u7B26\\u4E32\\u662F\\u5426\\u6709\\u6548\\u3002\\u5982\\u679C\\u6EE1\\u8DB3\\u4EE5\\u4E0B\\u6761\\u4EF6\\uFF0C\\u5219\\u5B57\\u7B26\\u4E32\\u6709\\u6548\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u6BCF\\u4E2A\\u5F00\\u62EC\\u53F7\\u90FD\\u6709\\u4E00\\u4E2A\\u5BF9\\u5E94\\u7684\\u3001\\u6B63\\u786E\\u6392\\u5E8F\\u7684\\u95ED\\u62EC\\u53F7\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u62EC\\u53F7\\u5D4C\\u5957\\u6B63\\u786E\\u3002\"}),`\n`]}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5806\\u6808\\u6570\\u636E\\u7ED3\\u6784\\u975E\\u5E38\\u9002\\u5408\\u89E3\\u51B3\\u8FD9\\u4E2A\\u95EE\\u9898\\uFF0C\\u56E0\\u4E3A\\u5B83\\u5177\\u6709 LIFO\\uFF08\\u540E\\u8FDB\\u5148\\u51FA\\uFF09\\u7684\\u7279\\u6027\\u3002\\u5F53\\u904D\\u5386\\u5B57\\u7B26\\u4E32\\u65F6\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5F00\\u62EC\\u53F7\\u88AB\\u538B\\u5165\\u5806\\u6808\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u95ED\\u62EC\\u53F7\\u4E0E\\u5806\\u6808\\u7684\\u9876\\u90E8\\u5143\\u7D20\\u5339\\u914D\\uFF0C\\u5982\\u679C\\u5339\\u914D\\uFF0C\\u5219\\u5F39\\u51FA\\u9876\\u90E8\\u5143\\u7D20\\u3002\"}),`\n`]}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u6734\\u7D20\\u65B9\\u6CD5\\u4E2D\\u7684\\u74F6\\u9888\\u53EF\\u80FD\\u6D89\\u53CA\\u53CD\\u590D\\u626B\\u63CF\\u6574\\u4E2A\\u5B57\\u7B26\\u4E32\\u4EE5\\u67E5\\u627E\\u5339\\u914D\\u7684\\u62EC\\u53F7\\uFF0C\\u4ECE\\u800C\\u5BFC\\u81F4 O(n\",(0,e.jsx)(\"sup\",{children:\"2\"}),\") \\u7684\\u590D\\u6742\\u5EA6\\u3002\\u57FA\\u4E8E\\u5806\\u6808\\u7684\\u65B9\\u6CD5\\u901A\\u8FC7\\u7EF4\\u62A4\\u5355\\u4E2A\\u904D\\u5386\\u5E76\\u4F7F\\u7528\\u7528\\u4E8E push \\u548C pop \\u7684\\u6052\\u5B9A\\u65F6\\u95F4\\u64CD\\u4F5C\\u6765\\u6D88\\u9664\\u4E0D\\u5FC5\\u8981\\u7684\\u5DE5\\u4F5C\\u3002\"]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u6620\\u5C04\\u5BF9\\u8C61 \",(0,e.jsx)(n.code,{children:\"mappings\"}),\"\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u95ED\\u62EC\\u53F7\\u6620\\u5C04\\u5230\\u5176\\u5BF9\\u5E94\\u7684\\u5F00\\u62EC\\u53F7\\u3002\"]}),`\n`,(0,e.jsx)(n.li,{children:\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u7A7A\\u5806\\u6808\\uFF0C\\u7528\\u4E8E\\u5728\\u904D\\u5386\\u671F\\u95F4\\u5B58\\u50A8\\u5F00\\u62EC\\u53F7\\u3002\"}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u904D\\u5386\\u8F93\\u5165\\u5B57\\u7B26\\u4E32\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5B57\\u7B26\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5982\\u679C\\u8BE5\\u5B57\\u7B26\\u662F\\u95ED\\u62EC\\u53F7\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u4ECE\\u5806\\u6808\\u4E2D\\u5F39\\u51FA\\u9876\\u90E8\\u5143\\u7D20\\uFF08\\u5982\\u679C\\u5806\\u6808\\u4E3A\\u7A7A\\uFF0C\\u5219\\u4F7F\\u7528\\u5360\\u4F4D\\u7B26\\uFF09\\u3002\"}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u68C0\\u67E5\\u5F39\\u51FA\\u7684\\u5143\\u7D20\\u662F\\u5426\\u4E0E\\u5F53\\u524D\\u95ED\\u62EC\\u53F7\\u5BF9\\u5E94\\u7684\\u5F00\\u62EC\\u53F7\\u5339\\u914D\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5982\\u679C\\u4E0D\\u5339\\u914D\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,e.jsx)(n.code,{children:\"false\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5982\\u679C\\u8BE5\\u5B57\\u7B26\\u662F\\u5F00\\u62EC\\u53F7\\uFF0C\\u5219\\u5C06\\u5176\\u538B\\u5165\\u5806\\u6808\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5904\\u7406\\u5B8C\\u6240\\u6709\\u5B57\\u7B26\\u540E\\uFF0C\\u68C0\\u67E5\\u5806\\u6808\\u662F\\u5426\\u4E3A\\u7A7A\\u3002\\u5982\\u679C\\u5806\\u6808\\u4E0D\\u4E3A\\u7A7A\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,e.jsx)(n.code,{children:\"false\"}),\"\\uFF1B\\u5426\\u5219\\uFF0C\\u8FD4\\u56DE \",(0,e.jsx)(n.code,{children:\"true\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(a,{children:d}),`\n`,(0,e.jsx)(n.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u4EC5\\u5904\\u7406\\u8F93\\u5165\\u5B57\\u7B26\\u4E32\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5B57\\u7B26\\u4E00\\u6B21\\uFF0C\\u5176\\u4E2D \",(0,e.jsx)(n.code,{children:\"n\"}),\" \\u662F\\u5B57\\u7B26\\u4E32\\u7684\\u957F\\u5EA6\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u5728\\u6700\\u574F\\u7684\\u60C5\\u51B5\\u4E0B\\uFF0C\\u6240\\u6709\\u5F00\\u62EC\\u53F7\\u90FD\\u5B58\\u50A8\\u5728\\u5806\\u6808\\u4E2D\\uFF0C\\u5BFC\\u81F4 O(n) \\u7684\\u7A7A\\u95F4\\u4F7F\\u7528\\u3002\"]}),`\n`]})]})}function B(t={}){let{wrapper:n}=t.components||{};return n?(0,e.jsx)(n,Object.assign({},t,{children:(0,e.jsx)(p,t)})):p(t)}var I=B;return _(y);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/array-find-duplicate/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/array-find-duplicate/locales/zh-CN.json new file mode 100644 index 000000000..d46d23571 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/array-find-duplicate/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var d=Object.create;var o=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var j=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),_=(n,e)=>{for(var r in e)o(n,r,{get:e[r],enumerable:!0})},l=(n,e,r,i)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let s of x(e))!f.call(n,s)&&s!==r&&o(n,s,{get:()=>e[s],enumerable:!(i=h(e,s))||i.enumerable});return n};var g=(n,e,r)=>(r=n!=null?d(b(n)):{},l(e||!n||!n.__esModule?o(r,\"default\",{value:n,enumerable:!0}):r,n)),M=n=>l(o({},\"__esModule\",{value:!0}),n);var c=j((F,a)=>{a.exports=_jsx_runtime});var y={};_(y,{default:()=>T,frontmatter:()=>D});var t=g(c());var u=MDXTestExamples;var m=[{input:[[\"numbers\",[5,7,1,3]]],output:!1,explanation:\"All elements in the array are unique.\"},{input:[[\"numbers\",[10,7,0,0,9]]],output:!0,explanation:\"0 appears more than once.\"},{input:[[\"numbers\",[3,2,6,5,0,3,10,3,10,5]]],output:!0,explanation:\"3,5, and 10 appears more than once.\"}];var D={title:\"\\u67E5\\u627E\\u6570\\u7EC4\\u4E2D\\u7684\\u91CD\\u590D\\u9879\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u68C0\\u67E5\\u6570\\u7EC4\\u4E2D\\u662F\\u5426\\u6709\\u4EFB\\u4F55\\u91CD\\u590D\\u7684\\u6570\\u5B57\"};function p(n){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},n.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4 \",(0,t.jsx)(e.code,{children:\"numbers\"}),\"\\uFF0C\\u786E\\u5B9A\\u8BE5\\u6570\\u7EC4\\u662F\\u5426\\u5305\\u542B\\u4EFB\\u4F55\\u91CD\\u590D\\u503C\\u3002\\u91CD\\u590D\\u5B9A\\u4E49\\u4E3A\\u6570\\u7EC4\\u4E2D\\u51FA\\u73B0\\u591A\\u6B21\\u7684\\u4EFB\\u4F55\\u6570\\u5B57\\u3002\"]}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.code,{children:\"numbers: number[]\"}),\": \\u6574\\u6570\\u6570\\u7EC4\"]}),`\n`]}),`\n`,(0,t.jsx)(u,{testCases:m}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[\"1 <= \",(0,t.jsx)(e.code,{children:\"numbers.length\"}),\" <= 10,000\"]}),`\n`,(0,t.jsxs)(e.li,{children:[\"-1,000,000 <= \",(0,t.jsx)(e.code,{children:\"numbers[i]\"}),\" <= 1,000,000\"]}),`\n`]})]})}function X(n={}){let{wrapper:e}=n.components||{};return e?(0,t.jsx)(e,Object.assign({},n,{children:(0,t.jsx)(p,n)})):p(n)}var T=X;return M(y);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来检查数组中是否有任何重复的数字", + "title": "查找数组中的重复项" + }, + "solution": "var Component=(()=>{var p=Object.create;var t=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var O=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var j=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),D=(r,e)=>{for(var i in e)t(r,i,{get:e[i],enumerable:!0})},h=(r,e,i,d)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let l of g(e))!x.call(r,l)&&l!==i&&t(r,l,{get:()=>e[l],enumerable:!(d=b(e,l))||d.enumerable});return r};var S=(r,e,i)=>(i=r!=null?p(O(r)):{},h(e||!r||!r.__esModule?t(i,\"default\",{value:r,enumerable:!0}):i,r)),y=r=>h(t({},\"__esModule\",{value:!0}),r);var u=j((X,o)=>{o.exports=_jsx_runtime});var M={};D(M,{default:()=>w});var n=S(u());var c=MDXCodeBlock;var s=`export default function findDuplicates(numbers: number[]): boolean {\n // Create a set to store unique elements seen so far\n const seen: Set = new Set();\n\n // Get the size of the input array for loop iteration\n const n: number = numbers.length;\n\n // Iterate through each element in the nums array\n for (let i = 0; i < n; i++) {\n // Try inserting the current element into the set\n // If insertion fails, it means the element already exists (duplicate)\n if (seen.has(numbers[i])) {\n return true; // Duplicate found, return true\n }\n seen.add(numbers[i]);\n }\n\n // If we reach here, no duplicates were found, return false\n return false;\n}\n`;var a=`export default function findDuplicates(numbers: number[]): boolean {\n // Sort the array in ascending order\n numbers.sort((a, b) => a - b);\n\n // Iterate through the sorted array\n for (let i = 0; i < numbers.length - 1; i++) {\n // Check if the current element is equal to the next element\n if (numbers[i] === numbers[i + 1]) {\n return true; // If a duplicate is found, return true\n }\n }\n\n // If no duplicates are found, return false\n return false;\n}\n`;var f=`export default function findDuplicates(numbers: number[]): boolean {\n // Get the size of the input array for loop iteration\n const n: number = numbers.length;\n\n // Iterate through each pair of elements in the array\n for (let i = 0; i < n; i++) {\n for (let j = i + 1; j < n; j++) {\n // Check if the elements at index i and j are the same\n if (numbers[i] === numbers[j]) {\n return true; // Duplicate found, return true\n }\n }\n }\n\n //No duplicates were found, return false\n return false;\n}\n`;function m(r){let e=Object.assign({h2:\"h2\",p:\"p\",h3:\"h3\",ol:\"ol\",li:\"li\",code:\"code\",ul:\"ul\",strong:\"strong\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u66B4\\u529B\\u89E3\\u6CD5\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8BE5\\u95EE\\u9898\\u6D89\\u53CA\\u67E5\\u627E\\u6570\\u7EC4\\u4E2D\\u662F\\u5426\\u5B58\\u5728\\u91CD\\u590D\\u5143\\u7D20\\u3002\\u66B4\\u529B\\u65B9\\u6CD5\\u68C0\\u67E5\\u6570\\u7EC4\\u4E2D\\u6BCF\\u5BF9\\u53EF\\u80FD\\u7684\\u5143\\u7D20\\uFF0C\\u4EE5\\u786E\\u5B9A\\u5B83\\u4EEC\\u662F\\u5426\\u76F8\\u7B49\\u3002\\u8FD9\\u662F\\u901A\\u8FC7\\u4E24\\u4E2A\\u5D4C\\u5957\\u5FAA\\u73AF\\u5B9E\\u73B0\\u7684\\uFF0C\\u5176\\u4E2D\\u6BD4\\u8F83\\u6BCF\\u4E00\\u5BF9\\u3002\\u867D\\u7136\\u8FD9\\u79CD\\u65B9\\u6CD5\\u5F88\\u7B80\\u5355\\uFF0C\\u4F46\\u7531\\u4E8E\\u5176 O(n\",(0,n.jsx)(\"sup\",{children:\"2\"}),\") \\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF0C\\u5BF9\\u4E8E\\u5927\\u578B\\u6570\\u7EC4\\u6765\\u8BF4\\u6548\\u7387\\u4F4E\\u4E0B\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u786E\\u5B9A\\u8F93\\u5165\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"numbers\"}),\" \\u7684\\u957F\\u5EA6\\uFF0C\\u5E76\\u5C06\\u5176\\u5B58\\u50A8\\u5728\\u53D8\\u91CF \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u4E2D\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"i\"}),\" \\u7684\\u5FAA\\u73AF\\u904D\\u5386\\u6570\\u7EC4\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5143\\u7D20\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A \",(0,n.jsx)(e.code,{children:\"i\"}),\"\\uFF0C\\u4F7F\\u7528\\u53E6\\u4E00\\u4E2A\\u4ECE \",(0,n.jsx)(e.code,{children:\"i + 1\"}),\" \\u5F00\\u59CB\\u7684\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"j\"}),\" \\u7684\\u5FAA\\u73AF\\u6765\\u68C0\\u67E5\\u6570\\u7EC4\\u4E2D\\u7684\\u6BCF\\u4E2A\\u540E\\u7EED\\u5143\\u7D20\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u6BD4\\u8F83\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"i\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"j\"}),\" \\u5904\\u7684\\u5143\\u7D20\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5B83\\u4EEC\\u76F8\\u7B49\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\" \\u4EE5\\u6307\\u793A\\u627E\\u5230\\u91CD\\u590D\\u9879\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5728\\u68C0\\u67E5\\u6240\\u6709\\u5BF9\\u540E\\u672A\\u627E\\u5230\\u91CD\\u590D\\u9879\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(c,{children:f}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,n.jsx)(\"sup\",{children:\"2\"}),\")\"]}),\"\\u3002\\u5916\\u5C42\\u5FAA\\u73AF\\u8FED\\u4EE3 \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u6B21\\uFF0C\\u5185\\u5C42\\u5FAA\\u73AF\\u6700\\u591A\\u8FED\\u4EE3 \",(0,n.jsx)(e.code,{children:\"n - i - 1\"}),\" \\u6B21\\uFF0C\\u5BFC\\u81F4\\u4E8C\\u6B21\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u4F7F\\u7528\\u6052\\u5B9A\\u91CF\\u7684\\u989D\\u5916\\u7A7A\\u95F4\\uFF0C\\u56E0\\u4E3A\\u5B83\\u4E0D\\u4F9D\\u8D56\\u4E8E\\u4EFB\\u4F55\\u8F85\\u52A9\\u6570\\u636E\\u7ED3\\u6784\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u6392\\u5E8F\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u4E4B\\u524D\\u7684\\u66B4\\u529B\\u89E3\\u6CD5\\u6709\\u4E0D\\u5FC5\\u8981\\u7684\\u68C0\\u67E5\\u6240\\u6709\\u5BF9\\u7684\\u5DE5\\u4F5C\\u3002\\u4E3A\\u4E86\\u6D88\\u9664\\u5197\\u4F59\\u7684\\u6BD4\\u8F83\\uFF0C\\u8FD9\\u4E2A\\u4F18\\u5316\\u7684\\u89E3\\u51B3\\u65B9\\u6848\\u5C06\\u6570\\u7EC4\\u6309\\u5347\\u5E8F\\u6392\\u5E8F\\uFF0C\\u8FD9\\u786E\\u4FDD\\u4E86\\u91CD\\u590D\\u7684\\u5143\\u7D20\\u8FDE\\u7EED\\u51FA\\u73B0\\u3002\\u4E00\\u65E6\\u6570\\u7EC4\\u6392\\u5E8F\\u5B8C\\u6210\\uFF0C\\u53EA\\u9700\\u4E00\\u6B21\\u904D\\u5386\\u5373\\u53EF\\u68C0\\u67E5\\u662F\\u5426\\u6709\\u4EFB\\u4F55\\u4E24\\u4E2A\\u8FDE\\u7EED\\u7684\\u5143\\u7D20\\u76F8\\u7B49\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u5185\\u7F6E\\u7684 \",(0,n.jsx)(e.code,{children:\"sort\"}),\" \\u51FD\\u6570\\u6309\\u5347\\u5E8F\\u5BF9\\u8F93\\u5165\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"numbers\"}),\" \\u8FDB\\u884C\\u6392\\u5E8F\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u5FAA\\u73AF\\u4ECE\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"0\"}),\" \\u5230 \",(0,n.jsx)(e.code,{children:\"numbers.length - 1\"}),\" \\u904D\\u5386\\u6392\\u5E8F\\u540E\\u7684\\u6570\\u7EC4\\u3002\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u5143\\u7D20\\uFF0C\\u5C06\\u5176\\u4E0E\\u6570\\u7EC4\\u4E2D\\u7684\\u4E0B\\u4E00\\u4E2A\\u5143\\u7D20\\u8FDB\\u884C\\u6BD4\\u8F83\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u8FD9\\u4E24\\u4E2A\\u5143\\u7D20\\u76F8\\u7B49\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\" \\u4EE5\\u6307\\u793A\\u5DF2\\u627E\\u5230\\u91CD\\u590D\\u9879\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5728\\u5FAA\\u73AF\\u5B8C\\u6210\\u4E4B\\u540E\\u672A\\u627E\\u5230\\u91CD\\u590D\\u9879\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(c,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n log n)\"}),\"\\u3002\\u6392\\u5E8F\\u64CD\\u4F5C\\u4EE5 O(n log n) \\u5360\\u636E\\u4E86\\u8FD0\\u884C\\u65F6\\u7684\\u5927\\u90E8\\u5206\\u3002\\u968F\\u540E\\u5BF9\\u6392\\u5E8F\\u6570\\u7EC4\\u7684\\u7EBF\\u6027\\u904D\\u5386\\u7684\\u590D\\u6742\\u5EA6\\u4E3A O(n)\\uFF0C\\u4E0E\\u6392\\u5E8F\\u6B65\\u9AA4\\u76F8\\u6BD4\\uFF0C\\u53EF\\u4EE5\\u5FFD\\u7565\\u4E0D\\u8BA1\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u6392\\u5E8F\\u662F\\u5C31\\u5730\\u6267\\u884C\\u7684\\uFF0C\\u5E76\\u4E14\\u8BE5\\u7B97\\u6CD5\\u4E0D\\u4F7F\\u7528\\u4EFB\\u4F55\\u5176\\u4ED6\\u6570\\u636E\\u7ED3\\u6784\\uFF0C\\u4ECE\\u800C\\u5BFC\\u81F4\\u6052\\u5B9A\\u7684\\u7A7A\\u95F4\\u4F7F\\u7528\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"3. \\u4F7F\\u7528 Set\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u4E4B\\u524D\\u7684\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u6392\\u5E8F\\uFF0C\\u7531\\u4E8E\\u6392\\u5E8F\\u6B65\\u9AA4\\uFF08O(n log n)\\uFF09\\uFF0C\\u5176\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u5B58\\u5728\\u74F6\\u9888\\u3002\\u6392\\u5E8F\\u786E\\u4FDD\\u91CD\\u590D\\u9879\\u8FDE\\u7EED\\u51FA\\u73B0\\uFF0C\\u4F46\\u5BF9\\u4E8E\\u8F83\\u5927\\u7684\\u8F93\\u5165\\u6570\\u7EC4\\u9700\\u8981\\u5927\\u91CF\\u65F6\\u95F4\\u3002\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5F53\\u524D\\u7684\\u89E3\\u51B3\\u65B9\\u6848\\u901A\\u8FC7\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"Set\"}),\" \\u6765\\u8DDF\\u8E2A\\u5230\\u76EE\\u524D\\u4E3A\\u6B62\\u770B\\u5230\\u7684\\u5143\\u7D20\\u6765\\u6539\\u8FDB\\u8FD9\\u4E00\\u70B9\\u3002\",(0,n.jsx)(e.code,{children:\"Set\"}),\" \\u5141\\u8BB8\\u4EE5\\u6052\\u5B9A\\u65F6\\u95F4\\u8FDB\\u884C\\u64CD\\u4F5C\\uFF0C\\u4EE5\\u68C0\\u67E5\\u5B58\\u5728\\u6027\\u548C\\u6DFB\\u52A0\\u5143\\u7D20\\u3002\\u8FD9\\u6D88\\u9664\\u4E86\\u5BF9\\u6392\\u5E8F\\u7684\\u9700\\u6C42\\uFF0C\\u5C06\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u964D\\u4F4E\\u5230\\u7EBF\\u6027 O(n)\\u3002\\u5B83\\u8FD8\\u4FDD\\u7559\\u4E86\\u539F\\u59CB\\u6570\\u7EC4\\uFF0C\\u56E0\\u4E3A\\u6CA1\\u6709\\u8FDB\\u884C\\u5C31\\u5730\\u66F4\\u6539\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521B\\u5EFA\\u4E00\\u4E2A\\u7A7A\\u7684 \",(0,n.jsx)(e.code,{children:\"Set\"}),\" \\u6765\\u5B58\\u50A8\\u552F\\u4E00\\u5143\\u7D20\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u8F93\\u5165\\u6570\\u7EC4\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5143\\u7D20\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u5F53\\u524D\\u5143\\u7D20\\u662F\\u5426\\u5B58\\u5728\\u4E8E \",(0,n.jsx)(e.code,{children:\"Set\"}),\" \\u4E2D\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u8BE5\\u5143\\u7D20\\u5B58\\u5728\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\uFF0C\\u8868\\u793A\\u5DF2\\u627E\\u5230\\u91CD\\u590D\\u9879\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5426\\u5219\\uFF0C\\u5C06\\u5F53\\u524D\\u5143\\u7D20\\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"Set\"}),\" \\u4E2D\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5728\\u672A\\u627E\\u5230\\u91CD\\u590D\\u9879\\u7684\\u60C5\\u51B5\\u4E0B\\u5B8C\\u6210\\u8FED\\u4EE3\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(c,{children:s}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u904D\\u5386\\u6570\\u7EC4\\u4E00\\u6B21\\uFF0C\\u5BF9 \",(0,n.jsx)(e.code,{children:\"Set\"}),\" \\u4E2D\\u7684\\u6DFB\\u52A0\\u548C\\u68C0\\u67E5\\u5143\\u7D20\\u6267\\u884C\\u6052\\u5B9A\\u65F6\\u95F4\\u7684\\u64CD\\u4F5C\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u5728\\u6240\\u6709\\u5143\\u7D20\\u90FD\\u552F\\u4E00\\u7684\\u6700\\u574F\\u60C5\\u51B5\\u4E0B\\uFF0C\",(0,n.jsx)(e.code,{children:\"Set\"}),\" \\u9700\\u8981\\u989D\\u5916\\u7684\\u7A7A\\u95F4\\u6765\\u5B58\\u50A8\\u591A\\u8FBE \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u4E2A\\u5143\\u7D20\\u3002\"]}),`\n`]})]})}function B(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(m,r)})):m(r)}var w=B;return y(M);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/array-find-missing-number-in-sequence/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/array-find-missing-number-in-sequence/locales/zh-CN.json new file mode 100644 index 000000000..07a171d4b --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/array-find-missing-number-in-sequence/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var u=Object.create;var o=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var g=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),j=(r,e)=>{for(var t in e)o(r,t,{get:e[t],enumerable:!0})},a=(r,e,t,s)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of f(e))!b.call(r,i)&&i!==t&&o(r,i,{get:()=>e[i],enumerable:!(s=p(e,i))||s.enumerable});return r};var y=(r,e,t)=>(t=r!=null?u(x(r)):{},a(e||!r||!r.__esModule?o(t,\"default\",{value:r,enumerable:!0}):t,r)),_=r=>a(o({},\"__esModule\",{value:!0}),r);var h=g((z,c)=>{c.exports=_jsx_runtime});var D={};j(D,{default:()=>C,frontmatter:()=>M});var n=y(h());var l=MDXTestExamples;var d=[{input:[[\"numbers\",[1,3,0]]],output:2,explanation:\"The array has a size of 3, and within the range from 0 to 3, the number 2 is missing from the array\"},{input:[[\"numbers\",[1]]],output:0,explanation:\"The array has a size of 1, and within the range from 0 to 1, the number 0 is missing from the array\"},{input:[[\"numbers\",[3,0,4,2,1]]],output:5,explanation:\"The array has a size of 5, and within the range from 0 to 5, the number 5 is missing from the array\"}];var M={title:\"\\u67E5\\u627E\\u5E8F\\u5217\\u4E2D\\u7F3A\\u5931\\u7684\\u6570\\u5B57\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u67E5\\u627E\\u5DF2\\u6392\\u5E8F\\u6570\\u7EC4\\u4E2D\\u7F3A\\u5931\\u7684\\u5143\\u7D20\"};function m(r){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u5927\\u5C0F\\u4E3A \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u7684\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"numbers\"}),\"\\uFF0C\\u7528\\u4E8E\\u5B58\\u50A8 \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u4E2A\\u4E0D\\u540C\\u7684\\u6574\\u6570\\uFF0C\\u8FD9\\u4E9B\\u6574\\u6570\\u7684\\u8303\\u56F4\\u5728 \",(0,n.jsx)(e.code,{children:\"[0, n]\"}),\" \\u4E4B\\u95F4\\uFF0C\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u8BC6\\u522B\\u6570\\u7EC4\\u4E2D\\u7F3A\\u5931\\u7684\\u5143\\u7D20\\u3002\\u9664\\u4E86\\u4E00\\u4E2A\\u6570\\u5B57\\u5916\\uFF0C\\u6240\\u6709\\u6570\\u5B57\\u90FD\\u5B58\\u5728\\u4E8E\\u6570\\u7EC4\\u4E2D\\u3002\\u627E\\u5230\\u7F3A\\u5931\\u7684\\u6570\\u5B57\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"numbers: number[]\"}),\": \\u6574\\u6570\\u6570\\u7EC4\"]}),`\n`]}),`\n`,(0,n.jsx)(l,{testCases:d}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"n\"}),\" <= 10,000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"0 <= \",(0,n.jsx)(e.code,{children:\"numbers[i]\"}),\" <= \",(0,n.jsx)(e.code,{children:\"n\"})]}),`\n`]})]})}function w(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(m,r)})):m(r)}var C=w;return _(D);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来查找已排序数组中缺失的元素", + "title": "查找序列中缺失的数字" + }, + "solution": "var Component=(()=>{var b=Object.create;var c=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var O=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports),j=(r,n)=>{for(var i in n)c(r,i,{get:n[i],enumerable:!0})},d=(r,n,i,u)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let l of p(n))!S.call(r,l)&&l!==i&&c(r,l,{get:()=>n[l],enumerable:!(u=g(n,l))||u.enumerable});return r};var M=(r,n,i)=>(i=r!=null?b(x(r)):{},d(n||!r||!r.__esModule?c(i,\"default\",{value:r,enumerable:!0}):i,r)),C=r=>d(c({},\"__esModule\",{value:!0}),r);var o=O((D,h)=>{h.exports=_jsx_runtime});var B={};j(B,{default:()=>k});var e=M(o());var t=MDXCodeBlock;var s=`export default function findMissingNumberInSequence(numbers: number[]): number {\n let expectedSum = 0;\n const n = numbers.length;\n\n // Calculate the expected sum of all numbers from 0 to n\n for (let i = 0; i <= n; i++) {\n expectedSum += i;\n }\n\n // Calculate the actual sum of elements in the array\n let actualSum = 0;\n for (const num of numbers) {\n actualSum += num;\n }\n\n // Return the missing number (expected sum - actual sum)\n return expectedSum - actualSum;\n}\n`;var m=`export default function findMissingNumberInSequence(numbers: number[]): number {\n numbers.sort((a, b) => a - b);\n\n // Check if the last number is equal to the array length\n if (numbers[numbers.length - 1] !== numbers.length) {\n return numbers.length;\n }\n // Check if the first number is 0\n else if (numbers[0] !== 0) {\n return 0;\n }\n\n // Iterate through the sorted array to find the missing number\n for (let i = 1; i < numbers.length; i++) {\n const expectedNum = numbers[i - 1] + 1;\n if (numbers[i] !== expectedNum) {\n return expectedNum;\n }\n }\n\n // Return -1 if no numbers are missing (should not happen in valid input)\n return -1;\n}\n`;var a=`export default function findMissingNumberInSequence(numbers: number[]): number {\n const n: number = numbers.length;\n\n // Iterate through the expected range of numbers from 0 to n\n for (let i = 0; i <= n; i++) {\n // Check if the current number \\`i\\` exists in the array\n let found = false;\n for (let j = 0; j < n; j++) {\n if (numbers[j] === i) {\n found = true;\n break; // Stop searching once the number is found\n }\n }\n\n // If the current number \\`i\\` is not found, it's the missing number\n if (!found) {\n return i;\n }\n }\n\n // Return -1 if no missing number is found (should not happen in valid input)\n return -1;\n}\n`;function f(r){let n=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},r.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"1. \\u66B4\\u529B\\u89E3\\u6CD5\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u8BE5\\u95EE\\u9898\\u9700\\u8981\\u4ECE 0 \\u5230 \",(0,e.jsx)(n.code,{children:\"n\"}),\" \\u7684\\u5E8F\\u5217\\u4E2D\\u8BC6\\u522B\\u7F3A\\u5931\\u7684\\u6570\\u5B57\\u3002\\u66B4\\u529B\\u89E3\\u6CD5\\u904D\\u5386\\u671F\\u671B\\u7684\\u6570\\u5B57\\u8303\\u56F4\\uFF0C\\u5E76\\u68C0\\u67E5\\u6570\\u7EC4\\u4E2D\\u662F\\u5426\\u5B58\\u5728\\u6BCF\\u4E2A\\u6570\\u5B57\\u3002\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u6570\\u5B57\\uFF0C\\u5C06\\u5BF9\\u6570\\u7EC4\\u8FDB\\u884C\\u53E6\\u4E00\\u6B21\\u8FED\\u4EE3\\u4EE5\\u68C0\\u67E5\\u5176\\u662F\\u5426\\u5B58\\u5728\\u3002\\u8FD9\\u79CD\\u65B9\\u6CD5\\u6D89\\u53CA\\u5D4C\\u5957\\u5FAA\\u73AF\\uFF0C\\u5BFC\\u81F4\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(n\",(0,e.jsx)(\"sup\",{children:\"2\"}),\")\\u3002\\u8FD9\\u79CD\\u65B9\\u6CD5\\u867D\\u7136\\u7B80\\u5355\\uFF0C\\u4F46\\u7531\\u4E8E\\u91CD\\u590D\\u68C0\\u67E5\\uFF0C\\u5BF9\\u4E8E\\u8F83\\u5927\\u7684\\u6570\\u7EC4\\u6548\\u7387\\u4F4E\\u4E0B\\u3002\"]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u8BA1\\u7B97\\u671F\\u671B\\u7684\\u8303\\u56F4\\u6570 \",(0,e.jsx)(n.code,{children:\"n\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u904D\\u5386\\u4ECE 0 \\u5230 \",(0,e.jsx)(n.code,{children:\"n\"}),\" \\u7684\\u6570\\u5B57\\u8303\\u56F4\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u6570\\u5B57\\uFF0C\\u904D\\u5386\\u6570\\u7EC4\\u4EE5\\u68C0\\u67E5\\u5F53\\u524D\\u6570\\u5B57\\u662F\\u5426\\u5B58\\u5728\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5982\\u679C\\u627E\\u5230\\u8BE5\\u6570\\u5B57\\uFF0C\\u505C\\u6B62\\u641C\\u7D22\\u5E76\\u79FB\\u81F3\\u4E0B\\u4E00\\u4E2A\\u6570\\u5B57\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5982\\u679C\\u672A\\u627E\\u5230\\u8BE5\\u6570\\u5B57\\uFF0C\\u5219\\u5C06\\u5176\\u4F5C\\u4E3A\\u7F3A\\u5931\\u6570\\u5B57\\u8FD4\\u56DE\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5982\\u679C\\u672A\\u627E\\u5230\\u7F3A\\u5931\\u6570\\u5B57\\uFF0C\\u5219\\u8FD4\\u56DE -1\\u3002\"}),`\n`]}),`\n`,(0,e.jsx)(t,{children:a}),`\n`,(0,e.jsx)(n.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsxs)(n.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,e.jsx)(\"sup\",{children:\"2\"}),\")\"]}),\"\\u3002\\u5BF9\\u4E8E\\u8303\\u56F4 0 \\u5230 \",(0,e.jsx)(n.code,{children:\"n\"}),\" \\u4E2D\\u7684\\u6BCF\\u4E2A\\u6570\\u5B57\\uFF0C\\u90FD\\u4F1A\\u5BF9\\u6570\\u7EC4\\u8FDB\\u884C\\u5B8C\\u5168\\u904D\\u5386\\u4EE5\\u68C0\\u67E5\\u5176\\u662F\\u5426\\u5B58\\u5728\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u9664\\u4E86\\u7528\\u4E8E\\u5B58\\u50A8\\u4E2D\\u95F4\\u7ED3\\u679C\\u7684\\u51E0\\u4E2A\\u53D8\\u91CF\\u5916\\uFF0C\\u6CA1\\u6709\\u4F7F\\u7528\\u989D\\u5916\\u7684\\u7A7A\\u95F4\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"2. \\u4F7F\\u7528\\u6392\\u5E8F\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u4E3A\\u4E86\\u6D88\\u9664\\u66B4\\u529B\\u89E3\\u6CD5\\u4E2D\\u7684\\u5197\\u4F59\\u68C0\\u67E5\\uFF0C\\u8FD9\\u79CD\\u4F18\\u5316\\u65B9\\u6CD5\\u5BF9\\u8F93\\u5165\\u6570\\u7EC4\\u8FDB\\u884C\\u6392\\u5E8F\\uFF0C\\u901A\\u8FC7\\u786E\\u4FDD\\u6570\\u5B57\\u6309\\u5347\\u5E8F\\u6392\\u5217\\uFF0C\\u4ECE\\u800C\\u66F4\\u5BB9\\u6613\\u8BC6\\u522B\\u5E8F\\u5217\\u4E2D\\u7F3A\\u5931\\u7684\\u6570\\u5B57\\u3002\\u6392\\u5E8F\\u540E\\uFF0C\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u68C0\\u67E5\\u8FB9\\u754C\\u60C5\\u51B5\\uFF08\\u5E8F\\u5217\\u4E2D\\u7B2C\\u4E00\\u4E2A\\u6216\\u6700\\u540E\\u4E00\\u4E2A\\u6570\\u5B57\\u662F\\u5426\\u7F3A\\u5931\\uFF09\\u3002\\u5982\\u679C\\u672A\\u68C0\\u6D4B\\u5230\\u8FB9\\u754C\\u60C5\\u51B5\\uFF0C\\u5219\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u904D\\u5386\\u6392\\u5E8F\\u540E\\u7684\\u6570\\u7EC4\\u4EE5\\u68C0\\u67E5\\u6BCF\\u4E2A\\u7D22\\u5F15\\u5904\\u662F\\u5426\\u5B58\\u5728\\u671F\\u671B\\u503C\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u6309\\u5347\\u5E8F\\u5BF9\\u8F93\\u5165\\u6570\\u7EC4\\u8FDB\\u884C\\u6392\\u5E8F\\u3002\"}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u68C0\\u67E5\\u6700\\u540E\\u4E00\\u4E2A\\u6570\\u5B57\\u662F\\u5426\\u7B49\\u4E8E\\u6570\\u7EC4\\u957F\\u5EA6\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5982\\u679C\\u4E0D\\u662F\\uFF0C\\u5219\\u8FD4\\u56DE\\u6570\\u7EC4\\u957F\\u5EA6\\u4F5C\\u4E3A\\u7F3A\\u5931\\u6570\\u5B57\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u68C0\\u67E5\\u7B2C\\u4E00\\u4E2A\\u6570\\u5B57\\u662F\\u5426\\u4E3A 0\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5982\\u679C\\u4E0D\\u662F\\uFF0C\\u5219\\u8FD4\\u56DE 0 \\u4F5C\\u4E3A\\u7F3A\\u5931\\u6570\\u5B57\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u904D\\u5386\\u6392\\u5E8F\\u540E\\u7684\\u6570\\u7EC4\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u6570\\u5B57\\uFF0C\\u5C06\\u671F\\u671B\\u7684\\u4E0B\\u4E00\\u4E2A\\u6570\\u5B57\\u8BA1\\u7B97\\u4E3A\\u5F53\\u524D\\u6570\\u5B57\\u52A0\\u4E00\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5982\\u679C\\u4E0B\\u4E00\\u4E2A\\u6570\\u5B57\\u4E0E\\u671F\\u671B\\u503C\\u4E0D\\u5339\\u914D\\uFF0C\\u5219\\u8FD4\\u56DE\\u671F\\u671B\\u503C\\u4F5C\\u4E3A\\u7F3A\\u5931\\u6570\\u5B57\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5982\\u679C\\u672A\\u627E\\u5230\\u7F3A\\u5931\\u6570\\u5B57\\uFF0C\\u5219\\u8FD4\\u56DE -1\\uFF0C\\u8FD9\\u5728\\u4F7F\\u7528\\u6709\\u6548\\u8F93\\u5165\\u65F6\\u4E0D\\u4F1A\\u53D1\\u751F\\u3002\"}),`\n`]}),`\n`,(0,e.jsx)(t,{children:m}),`\n`,(0,e.jsx)(n.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n log n)\"}),\"\\u3002\\u5BF9\\u6570\\u7EC4\\u8FDB\\u884C\\u6392\\u5E8F\\u5360\\u636E\\u4E86\\u8FD0\\u884C\\u65F6\\u7684\\u5927\\u90E8\\u5206\\u65F6\\u95F4\\uFF0C\\u9700\\u8981 O(n log n) \\u65F6\\u95F4\\u3002\\u968F\\u540E\\u5BF9\\u6570\\u7EC4\\u7684\\u8FED\\u4EE3\\u662F O(n)\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u6392\\u5E8F\\u662F\\u5C31\\u5730\\u6267\\u884C\\u7684\\uFF0C\\u9664\\u4E86\\u51E0\\u4E2A\\u53D8\\u91CF\\u5916\\uFF0C\\u6CA1\\u6709\\u4F7F\\u7528\\u989D\\u5916\\u7684\\u7A7A\\u95F4\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"3. \\u4F7F\\u7528\\u6570\\u5B66\\u6027\\u8D28\\u8BA1\\u7B97\\u4ECE 0 \\u5230 n \\u7684\\u6570\\u5B57\\u4E4B\\u548C\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u6392\\u5E8F\\u53EF\\u80FD\\u662F\\u4E0D\\u5FC5\\u8981\\u7684\\uFF0C\\u56E0\\u4E3A\\u53EF\\u4EE5\\u901A\\u8FC7\\u4F7F\\u7528\\u4ECE 0 \\u5230 \",(0,e.jsx)(n.code,{children:\"n\"}),\" \\u7684\\u6574\\u6570\\u4E4B\\u548C\\u7684\\u6570\\u5B66\\u6027\\u8D28\\u6765\\u786E\\u5B9A\\u7F3A\\u5931\\u7684\\u6570\\u5B57\\u3002\\u6570\\u5B66\\u6027\\u8D28\\u6D88\\u9664\\u4E86\\u8FED\\u4EE3\\u548C\\u6BD4\\u8F83\\u5143\\u7D20\\u7684\\u9700\\u8981\\u3002\\u76F8\\u53CD\\uFF0C\\u5B83\\u8BA1\\u7B97\\u603B\\u7684\\u671F\\u671B\\u548C\\uFF0C\\u5E76\\u51CF\\u53BB\\u5B9E\\u9645\\u548C\\u4EE5\\u627E\\u5230\\u7F3A\\u5931\\u7684\\u6570\\u5B57\\u3002\\u8FD9\\u79CD\\u4F18\\u5316\\u6D88\\u9664\\u4E86\\u6392\\u5E8F\\u7684\\u74F6\\u9888\\uFF0C\\u5E76\\u5C06\\u603B\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u964D\\u4F4E\\u5230 O(n)\\u3002\"]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5C06 \",(0,e.jsx)(n.code,{children:\"expectedSum\"}),\" \\u521D\\u59CB\\u5316\\u4E3A 0\\u3002\\u8FD9\\u5C06\\u4FDD\\u5B58\\u4ECE 0 \\u5230 \",(0,e.jsx)(n.code,{children:\"n\"}),\" \\u7684\\u6240\\u6709\\u6574\\u6570\\u7684\\u548C\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528\\u5FAA\\u73AF\\u8BA1\\u7B97\\u4ECE 0 \\u5230 \",(0,e.jsx)(n.code,{children:\"n\"}),\" \\u7684\\u6574\\u6570\\u7684\\u603B\\u671F\\u671B\\u548C\\uFF0C\\u5E76\\u5C06\\u7ED3\\u679C\\u5B58\\u50A8\\u5728 \",(0,e.jsx)(n.code,{children:\"expectedSum\"}),\" \\u4E2D\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5C06 \",(0,e.jsx)(n.code,{children:\"actualSum\"}),\" \\u521D\\u59CB\\u5316\\u4E3A 0\\u3002\\u8FD9\\u5C06\\u4FDD\\u5B58\\u7ED9\\u5B9A\\u6570\\u7EC4\\u4E2D\\u5143\\u7D20\\u7684\\u603B\\u548C\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u904D\\u5386\\u6570\\u7EC4\\u5E76\\u8BA1\\u7B97\\u6240\\u6709\\u5143\\u7D20\\u7684\\u603B\\u548C\\uFF0C\\u5C06\\u5176\\u5B58\\u50A8\\u5728 \",(0,e.jsx)(n.code,{children:\"actualSum\"}),\" \\u4E2D\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4ECE \",(0,e.jsx)(n.code,{children:\"expectedSum\"}),\" \\u4E2D\\u51CF\\u53BB \",(0,e.jsx)(n.code,{children:\"actualSum\"}),\" \\u4EE5\\u786E\\u5B9A\\u7F3A\\u5931\\u7684\\u6570\\u5B57\\u3002\"]}),`\n`,(0,e.jsx)(n.li,{children:\"\\u8FD4\\u56DE\\u7ED3\\u679C\\u3002\"}),`\n`]}),`\n`,(0,e.jsx)(t,{children:s}),`\n`,(0,e.jsx)(n.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u8BA1\\u7B97\\u671F\\u671B\\u548C\\u5E76\\u904D\\u5386\\u6570\\u7EC4\\u90FD\\u9700\\u8981 O(n) \\u65F6\\u95F4\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u5E38\\u91CF\\u6570\\u91CF\\u7684\\u53D8\\u91CF\\u7A7A\\u95F4\\u3002\"]}),`\n`]})]})}function _(r={}){let{wrapper:n}=r.components||{};return n?(0,e.jsx)(n,Object.assign({},r,{children:(0,e.jsx)(f,r)})):f(r)}var k=_;return C(B);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/array-maximum-product-contiguous/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/array-maximum-product-contiguous/locales/zh-CN.json new file mode 100644 index 000000000..82dcc531b --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/array-maximum-product-contiguous/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var m=Object.create;var l=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var f=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),j=(r,e)=>{for(var t in e)l(r,t,{get:e[t],enumerable:!0})},s=(r,e,t,c)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of x(e))!g.call(r,i)&&i!==t&&l(r,i,{get:()=>e[i],enumerable:!(c=p(e,i))||c.enumerable});return r};var _=(r,e,t)=>(t=r!=null?m(b(r)):{},s(e||!r||!r.__esModule?l(t,\"default\",{value:r,enumerable:!0}):t,r)),T=r=>s(l({},\"__esModule\",{value:!0}),r);var d=f((F,o)=>{o.exports=_jsx_runtime});var X={};j(X,{default:()=>D,frontmatter:()=>y});var n=_(d());var h=MDXTestExamples;var u=[{input:[[\"numbers\",[1,2,-3,5,1]]],output:5,explanation:\"The subarray [5, 1] has the largest product i.e 5.\"},{input:[[\"numbers\",[9]]],output:9,explanation:\"The single-element subarray [9] has the largest product i.e 9.\"},{input:[[\"numbers\",[1,2,0,-1,8,-4]]],output:32,explanation:\"The subarray [-1, 8, -4] has the largest product i.e 32.\"}];var y={title:\"\\u8FDE\\u7EED\\u6570\\u7EC4\\u4E2D\\u7684\\u6700\\u5927\\u4E58\\u79EF\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u67E5\\u627E\\u5177\\u6709\\u6700\\u5927\\u4E58\\u79EF\\u7684\\u5B50\\u6570\\u7EC4\"};function a(r){let e=Object.assign({p:\"p\",code:\"code\",strong:\"strong\",h3:\"h3\",ul:\"ul\",li:\"li\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"numbers\"}),\"\\uFF0C\\u786E\\u5B9A\\u5177\\u6709\\u6700\\u9AD8\\u4E58\\u79EF\\u7684\\u5B50\\u6570\\u7EC4\\u5E76\\u8FD4\\u56DE\\u8BE5\\u4E58\\u79EF\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A\",(0,n.jsx)(e.strong,{children:\"\\u5B50\\u6570\\u7EC4\"}),\"\\u662F\\u6570\\u7EC4\\u7684\\u8FDE\\u7EED\\u6BB5\\uFF0C\\u5176\\u4E2D\\u6240\\u6709\\u5143\\u7D20\\u90FD\\u53D6\\u81EA\\u8FDE\\u7EED\\u7684\\u7D22\\u5F15\\uFF0C\\u5E76\\u4FDD\\u7559\\u5176\\u987A\\u5E8F\\uFF0C\\u4F8B\\u5982 \",(0,n.jsx)(e.code,{children:\"[2, 3]\"}),\" \\u5728 \",(0,n.jsx)(e.code,{children:\"[1, 2, 3, 4]\"}),\" \\u4E2D\\uFF0C\\u800C\\u975E\\u8FDE\\u7EED\\u7684\\u9009\\u62E9\\uFF08\\u5982 \",(0,n.jsx)(e.code,{children:\"[1, 3]\"}),\"\\uFF09\\u4E0D\\u662F\\u6709\\u6548\\u7684\\u5B50\\u6570\\u7EC4\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"numbers: number[]\"}),\": \\u6574\\u6570\\u6570\\u7EC4\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u6CE8\\u610F\\u4E8B\\u9879\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u6D4B\\u8BD5\\u7528\\u4F8B\\u7684\\u8BBE\\u8BA1\\u4F7F\\u5F97\\u7ED3\\u679C\\u5C06\\u9002\\u5408 32 \\u4F4D\\u6574\\u6570\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4FDD\\u8BC1 \",(0,n.jsx)(e.code,{children:\"numbers\"}),\" \\u7684\\u4EFB\\u4F55\\u524D\\u7F00\\u6216\\u540E\\u7F00\\u7684\\u4E58\\u79EF\\u90FD\\u9002\\u5408 32 \\u4F4D\\u6574\\u6570\"]}),`\n`]}),`\n`,(0,n.jsx)(h,{testCases:u}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"numbers.length\"}),\" <= 1000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"-10 <= \",(0,n.jsx)(e.code,{children:\"numbers[i]\"}),\" <= 10\"]}),`\n`]})]})}function C(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(a,r)})):a(r)}var D=C;return T(X);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来查找具有最大乘积的子数组", + "title": "连续数组中的最大乘积" + }, + "solution": "var Component=(()=>{var p=Object.create;var d=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var y=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),F=(n,e)=>{for(var c in e)d(n,c,{get:e[c],enumerable:!0})},o=(n,e,c,l)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of b(e))!S.call(n,i)&&i!==c&&d(n,i,{get:()=>e[i],enumerable:!(l=x(e,i))||l.enumerable});return n};var P=(n,e,c)=>(c=n!=null?p(g(n)):{},o(e||!n||!n.__esModule?d(c,\"default\",{value:n,enumerable:!0}):c,n)),j=n=>o(d({},\"__esModule\",{value:!0}),n);var h=y((B,u)=>{u.exports=_jsx_runtime});var v={};F(v,{default:()=>_});var r=P(h());var t=MDXCodeBlock;var a=`export default function maxProductSubArray(numbers: number[]): number {\n // Get the size of the input array\n const n = numbers.length;\n\n // Initialize variables to store prefix product, suffix product, and maximum product\n let pre = 1; // Stores the product of all elements up to the current element (inclusive)\n let suff = 1; // Stores the product of all elements from the end up to the current element (inclusive)\n let maxProduct = Number.NEGATIVE_INFINITY; // Tracks the maximum product of any subarray found so far\n\n // Iterate through the array\n for (let i = 0; i < n; i++) {\n // Handle the case where the previous product was 0 (requires reset to 1)\n pre = pre === 0 ? numbers[i] : pre * numbers[i];\n\n // Handle the case where the previous product was 0 (requires reset to 1)\n suff = suff === 0 ? numbers[n - i - 1] : suff * numbers[n - i - 1];\n\n // Update the maximum product considering both prefix and suffix products\n maxProduct = Math.max(maxProduct, Math.max(pre, suff));\n }\n\n // Return the maximum product of any subarray found\n return maxProduct;\n}\n`;var m=`export default function maxProductSubArray(numbers: number[]): number {\n // Edge case: if the array is empty, return 0\n if (numbers.length === 0) return 0;\n\n // Initialize variables to track the maximum and minimum products so far\n let maxSoFar: number = numbers[0];\n let minSoFar: number = numbers[0];\n let result: number = maxSoFar;\n\n // Iterate through the array starting from the second element\n for (let i = 1; i < numbers.length; i++) {\n let curr: number = numbers[i];\n\n // Calculate the temporary maximum product\n let tempMax: number = Math.max(curr, maxSoFar * curr, minSoFar * curr);\n\n // Update the minimum product\n minSoFar = Math.min(curr, maxSoFar * curr, minSoFar * curr);\n\n // Update the maximum product with the temporary value\n maxSoFar = tempMax;\n\n // Update the result with the maximum product found so far\n result = Math.max(maxSoFar, result);\n }\n\n // Return the maximum product of any subarray\n return result;\n}\n`;var s=`export default function maxProductSubArray(numbers: number[]): number {\n // Edge case: if the array is empty, return 0\n if (numbers.length === 0) return 0;\n\n // Initialize the result with the first element\n let result = numbers[0];\n\n // Iterate through each element as the starting point\n for (let i = 0; i < numbers.length; i++) {\n // Initialize accumulator for the product of subarrays\n let accu = 1;\n\n // Iterate through subarrays starting from index i\n for (let j = i; j < numbers.length; j++) {\n // Multiply the current element\n accu *= numbers[j];\n\n // Update the result if the current product is larger\n result = Math.max(result, accu);\n }\n }\n\n // Return the maximum product found\n return result;\n}\n`;function f(n){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},n.components);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e.h2,{children:\"1. \\u66B4\\u529B\\u65B9\\u6CD5\"}),`\n`,(0,r.jsxs)(e.p,{children:[\"\\u6734\\u7D20\\u7684\\u65B9\\u6CD5\\u662F\\u8003\\u8651\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u8FDE\\u7EED\\u5B50\\u6570\\u7EC4\\u4EE5\\u786E\\u5B9A\\u6700\\u5927\\u4E58\\u79EF\\u3002\\u8BE5\\u8FC7\\u7A0B\\u6D89\\u53CA\\u9009\\u62E9\\u8D77\\u59CB\\u7D22\\u5F15 \",(0,r.jsx)(e.code,{children:\"i\"}),\"\\uFF0C\\u7136\\u540E\\u904D\\u5386\\u8BE5\\u5B50\\u6570\\u7EC4\\u7684\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u7ED3\\u675F\\u7D22\\u5F15 \",(0,r.jsx)(e.code,{children:\"j\"}),\"\\u3002\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u5B50\\u6570\\u7EC4\\uFF0C\\u8BA1\\u7B97\\u7D2F\\u79EF\\u4E58\\u79EF\\u5E76\\u5C06\\u5176\\u4E0E\\u5B58\\u50A8\\u5728 \",(0,r.jsx)(e.code,{children:\"result\"}),\" \\u4E2D\\u7684\\u5F53\\u524D\\u6700\\u5927\\u503C\\u8FDB\\u884C\\u6BD4\\u8F83\\u3002\\u7531\\u4E8E\\u68C0\\u67E5\\u4E86\\u6BCF\\u4E2A\\u5B50\\u6570\\u7EC4\\uFF0C\\u56E0\\u6B64\\u8BE5\\u65B9\\u6CD5\\u4FDD\\u8BC1\\u627E\\u5230\\u6700\\u5927\\u4E58\\u79EF\\u3002\"]}),`\n`,(0,r.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,r.jsxs)(e.ol,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u8F93\\u5165\\u6570\\u7EC4 \",(0,r.jsx)(e.code,{children:\"numbers\"}),\" \\u662F\\u5426\\u4E3A\\u7A7A\\uFF0C\\u5982\\u679C\\u4E3A\\u7A7A\\u5219\\u8FD4\\u56DE \",(0,r.jsx)(e.code,{children:\"0\"}),\"\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5C06 \",(0,r.jsx)(e.code,{children:\"result\"}),\" \\u521D\\u59CB\\u5316\\u4E3A \",(0,r.jsx)(e.code,{children:\"numbers\"}),\" \\u7684\\u7B2C\\u4E00\\u4E2A\\u5143\\u7D20\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u7D22\\u5F15 \",(0,r.jsx)(e.code,{children:\"i\"}),\" \\u904D\\u5386 \",(0,r.jsx)(e.code,{children:\"numbers\"}),\" \\u4E2D\\u7684\\u6BCF\\u4E2A\\u5143\\u7D20\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u4E3A\\u5F53\\u524D\\u5B50\\u6570\\u7EC4\\u4E58\\u79EF\\u5C06\\u7D2F\\u52A0\\u5668 \",(0,r.jsx)(e.code,{children:\"accu\"}),\" \\u521D\\u59CB\\u5316\\u4E3A \",(0,r.jsx)(e.code,{children:\"1\"}),\"\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A \",(0,r.jsx)(e.code,{children:\"i\"}),\"\\uFF0C\\u4F7F\\u7528\\u7D22\\u5F15 \",(0,r.jsx)(e.code,{children:\"j\"}),\" \\u904D\\u5386\\u4ECE \",(0,r.jsx)(e.code,{children:\"i\"}),\" \\u5230 \",(0,r.jsx)(e.code,{children:\"numbers\"}),\" \\u7ED3\\u5C3E\\u7684\\u5143\\u7D20\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u5C06 \",(0,r.jsx)(e.code,{children:\"accu\"}),\" \\u4E58\\u4EE5 \",(0,r.jsx)(e.code,{children:\"numbers[j]\"}),\" \\u6765\\u66F4\\u65B0 \",(0,r.jsx)(e.code,{children:\"accu\"}),\"\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5C06 \",(0,r.jsx)(e.code,{children:\"accu\"}),\" \\u4E0E \",(0,r.jsx)(e.code,{children:\"result\"}),\" \\u8FDB\\u884C\\u6BD4\\u8F83\\uFF0C\\u5982\\u679C \",(0,r.jsx)(e.code,{children:\"accu\"}),\" \\u5927\\u4E8E \",(0,r.jsx)(e.code,{children:\"result\"}),\"\\uFF0C\\u5219\\u66F4\\u65B0 \",(0,r.jsx)(e.code,{children:\"result\"}),\"\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u8003\\u8651\\u6240\\u6709\\u5B50\\u6570\\u7EC4\\u540E\\uFF0C\\u8FD4\\u56DE \",(0,r.jsx)(e.code,{children:\"result\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,r.jsx)(t,{children:s}),`\n`,(0,r.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsxs)(e.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,r.jsx)(\"sup\",{children:\"2\"}),\")\"]}),\"\\u3002\\u8003\\u8651\\u6BCF\\u4E2A\\u5B50\\u6570\\u7EC4\\uFF0C\\u5BFC\\u81F4\\u5BF9\\u6570\\u7EC4\\u8FDB\\u884C\\u5D4C\\u5957\\u8FED\\u4EE3\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u4EC5\\u4F7F\\u7528\\u51E0\\u4E2A\\u53D8\\u91CF \",(0,r.jsx)(e.code,{children:\"result\"}),\" \\u548C \",(0,r.jsx)(e.code,{children:\"accu\"}),\"\\uFF0C\\u9700\\u8981\\u6052\\u5B9A\\u7684\\u989D\\u5916\\u7A7A\\u95F4\\u3002\"]}),`\n`]}),`\n`,(0,r.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u52A8\\u6001\\u89C4\\u5212\"}),`\n`,(0,r.jsxs)(e.p,{children:[\"\\u4E00\\u79CD\\u66B4\\u529B\\u65B9\\u6CD5\\u8003\\u8651\\u4E86\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u5B50\\u6570\\u7EC4\\u5E76\\u8BA1\\u7B97\\u4E58\\u79EF\\uFF0C\\u8FD9\\u4F1A\\u5BFC\\u81F4\\u91CD\\u590D\\u4E58\\u6CD5\\u548C\\u5197\\u4F59\\u68C0\\u67E5\\u3002\\u8BE5\\u65B9\\u6CD5\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(n\",(0,r.jsx)(\"sup\",{children:\"2\"}),\")\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u5143\\u7D20\\u90FD\\u7528\\u4F5C\\u8D77\\u59CB\\u70B9\\uFF0C\\u6240\\u6709\\u540E\\u7EED\\u5143\\u7D20\\u6784\\u6210\\u8981\\u8003\\u8651\\u7684\\u5B50\\u6570\\u7EC4\\u3002\\u74F6\\u9888\\u5728\\u4E8E\\u591A\\u6B21\\u91CD\\u65B0\\u8BA1\\u7B97\\u5927\\u91CF\\u5B50\\u6570\\u7EC4\\u3002\"]}),`\n`,(0,r.jsx)(e.p,{children:\"\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u52A8\\u6001\\u89C4\\u5212\\u65B9\\u6CD5\\u5728 O(n) \\u65F6\\u95F4\\u5185\\u89E3\\u51B3\\u95EE\\u9898\\u3002\\u8BE5\\u65B9\\u6CD5\\u8DDF\\u8E2A\\u6BCF\\u4E2A\\u4F4D\\u7F6E\\u4EE5\\u8BE5\\u4F4D\\u7F6E\\u7ED3\\u5C3E\\u7684\\u6700\\u5927\\u548C\\u6700\\u5C0F\\u5B50\\u6570\\u7EC4\\u4E58\\u79EF\\u3002\\u8D1F\\u6570\\u4F1A\\u5F71\\u54CD\\u4E58\\u79EF\\u7B26\\u53F7\\uFF0C\\u5E76\\u53EF\\u4EE5\\u5C06\\u6700\\u5C0F\\u4E58\\u79EF\\u7FFB\\u8F6C\\u4E3A\\u6700\\u5927\\u4E58\\u79EF\\u3002\\u901A\\u8FC7\\u7EF4\\u62A4\\u5230\\u76EE\\u524D\\u4E3A\\u6B62\\u6700\\u5927\\u548C\\u6700\\u5C0F\\u4E58\\u79EF\\u7684\\u8FD0\\u884C\\u503C\\uFF0C\\u8BA1\\u7B97\\u907F\\u514D\\u4E86\\u91CD\\u65B0\\u8BA1\\u7B97\\u6240\\u6709\\u5B50\\u6570\\u7EC4\\u7684\\u4E58\\u79EF\\u3002\"}),`\n`,(0,r.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,r.jsxs)(e.ol,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u68C0\\u67E5 \",(0,r.jsx)(e.code,{children:\"numbers\"}),\" \\u662F\\u5426\\u4E3A\\u7A7A\\uFF0C\\u5982\\u679C\\u4E3A\\u771F\\u5219\\u8FD4\\u56DE \",(0,r.jsx)(e.code,{children:\"0\"}),\"\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5C06 \",(0,r.jsx)(e.code,{children:\"maxSoFar\"}),\"\\u3001\",(0,r.jsx)(e.code,{children:\"minSoFar\"}),\" \\u548C \",(0,r.jsx)(e.code,{children:\"result\"}),\" \\u521D\\u59CB\\u5316\\u4E3A \",(0,r.jsx)(e.code,{children:\"numbers\"}),\" \\u7684\\u7B2C\\u4E00\\u4E2A\\u5143\\u7D20\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u4ECE \",(0,r.jsx)(e.code,{children:\"numbers\"}),\" \\u7684\\u7B2C\\u4E8C\\u4E2A\\u5143\\u7D20\\u8FED\\u4EE3\\u5230\\u7ED3\\u5C3E\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u5143\\u7D20 \",(0,r.jsx)(e.code,{children:\"curr\"}),\"\\uFF0C\\u8BA1\\u7B97\\u4E34\\u65F6\\u6700\\u5927\\u4E58\\u79EF\\uFF0C\\u5373 \",(0,r.jsx)(e.code,{children:\"curr\"}),\"\\u3001\",(0,r.jsx)(e.code,{children:\"maxSoFar * curr\"}),\" \\u548C \",(0,r.jsx)(e.code,{children:\"minSoFar * curr\"}),\" \\u7684\\u6700\\u5927\\u503C\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5C06 \",(0,r.jsx)(e.code,{children:\"minSoFar\"}),\" \\u66F4\\u65B0\\u4E3A \",(0,r.jsx)(e.code,{children:\"curr\"}),\"\\u3001\",(0,r.jsx)(e.code,{children:\"maxSoFar * curr\"}),\" \\u548C \",(0,r.jsx)(e.code,{children:\"minSoFar * curr\"}),\" \\u7684\\u6700\\u5C0F\\u503C\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u4E34\\u65F6\\u6700\\u5927\\u503C\\u66F4\\u65B0 \",(0,r.jsx)(e.code,{children:\"maxSoFar\"}),\"\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,r.jsx)(e.code,{children:\"maxSoFar\"}),\" \\u5927\\u4E8E \",(0,r.jsx)(e.code,{children:\"result\"}),\"\\uFF0C\\u5219\\u66F4\\u65B0 \",(0,r.jsx)(e.code,{children:\"result\"}),\"\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE \",(0,r.jsx)(e.code,{children:\"result\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,r.jsx)(t,{children:m}),`\n`,(0,r.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u6BCF\\u4E2A\\u5143\\u7D20\\u53EA\\u5904\\u7406\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u6CA1\\u6709\\u4F7F\\u7528\\u989D\\u5916\\u7684\\u6570\\u636E\\u7ED3\\u6784\\uFF0C\\u56E0\\u6B64\\u4F7F\\u7528\\u4E86\\u6052\\u5B9A\\u7A7A\\u95F4\\u3002\"]}),`\n`]}),`\n`,(0,r.jsx)(e.h2,{children:\"3. \\u4F7F\\u7528\\u524D\\u7F00\\u548C\\u540E\\u7F00\\u4E58\\u79EF\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u53E6\\u4E00\\u79CD\\u4F18\\u5316\\u65B9\\u6CD5\\u4F7F\\u7528\\u524D\\u7F00\\u548C\\u540E\\u7F00\\u4E58\\u79EF\\u6765\\u8DDF\\u8E2A\\u4E24\\u7AEF\\u7684\\u8FD0\\u884C\\u4E58\\u79EF\\u3002\\u901A\\u8FC7\\u8FD9\\u6837\\u505A\\uFF0C\\u53EF\\u4EE5\\u66F4\\u5BB9\\u6613\\u5730\\u5904\\u7406\\u96F6\\u548C\\u8D1F\\u503C\\u3002\\u5F53\\u9047\\u5230\\u96F6\\u65F6\\uFF0C\\u53EF\\u4EE5\\u91CD\\u7F6E\\u8FD0\\u884C\\u4E58\\u79EF\\uFF0C\\u800C\\u4E0D\\u662F\\u518D\\u6B21\\u91CD\\u65B0\\u8BA1\\u7B97\\u6240\\u6709\\u5B50\\u6570\\u7EC4\\u3002\\u8FD9\\u79CD\\u65B9\\u6CD5\\u907F\\u514D\\u4E86\\u5197\\u4F59\\u5DE5\\u4F5C\\u5E76\\u5B9E\\u73B0\\u4E86\\u7EBF\\u6027\\u8FD0\\u884C\\u65F6\\u3002\"}),`\n`,(0,r.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,r.jsxs)(e.ol,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E09\\u4E2A\\u53D8\\u91CF\\uFF1A\",(0,r.jsx)(e.code,{children:\"pre\"}),\" \\u7528\\u4E8E\\u524D\\u7F00\\u4E58\\u79EF\\uFF0C\",(0,r.jsx)(e.code,{children:\"suff\"}),\" \\u7528\\u4E8E\\u540E\\u7F00\\u4E58\\u79EF\\uFF0C\",(0,r.jsx)(e.code,{children:\"maxProduct\"}),\" \\u7528\\u4E8E\\u8DDF\\u8E2A\\u627E\\u5230\\u7684\\u6700\\u5927\\u4E58\\u79EF\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u7D22\\u5F15 \",(0,r.jsx)(e.code,{children:\"i\"}),\" \\u4ECE 0 \\u5230 \",(0,r.jsx)(e.code,{children:\"n-1\"}),\" \\u904D\\u5386\\u6570\\u7EC4\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u68C0\\u67E5 \",(0,r.jsx)(e.code,{children:\"pre\"}),\" \\u662F\\u5426\\u4E3A\\u96F6\\u6765\\u66F4\\u65B0 \",(0,r.jsx)(e.code,{children:\"pre\"}),\"\\uFF0C\\u7136\\u540E\\u5C06 \",(0,r.jsx)(e.code,{children:\"pre\"}),\" \\u8BBE\\u7F6E\\u4E3A\\u5F53\\u524D\\u5143\\u7D20\\uFF0C\\u5426\\u5219\\u5C06 \",(0,r.jsx)(e.code,{children:\"pre\"}),\" \\u4E58\\u4EE5\\u5F53\\u524D\\u5143\\u7D20\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u7C7B\\u4F3C\\u5730\\uFF0C\\u901A\\u8FC7\\u68C0\\u67E5 \",(0,r.jsx)(e.code,{children:\"suff\"}),\" \\u662F\\u5426\\u4E3A\\u96F6\\u6765\\u66F4\\u65B0 \",(0,r.jsx)(e.code,{children:\"suff\"}),\"\\uFF0C\\u7136\\u540E\\u5C06 \",(0,r.jsx)(e.code,{children:\"suff\"}),\" \\u8BBE\\u7F6E\\u4E3A\\u7D22\\u5F15 \",(0,r.jsx)(e.code,{children:\"n - i - 1\"}),\" \\u5904\\u7684\\u7ED3\\u5C3E\\u5143\\u7D20\\uFF0C\\u5426\\u5219\\u5C06 \",(0,r.jsx)(e.code,{children:\"suff\"}),\" \\u4E58\\u4EE5\\u8BE5\\u5143\\u7D20\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u5C06 \",(0,r.jsx)(e.code,{children:\"maxProduct\"}),\" \\u4E0E \",(0,r.jsx)(e.code,{children:\"pre\"}),\" \\u548C \",(0,r.jsx)(e.code,{children:\"suff\"}),\" \\u8FDB\\u884C\\u6BD4\\u8F83\\u5E76\\u5B58\\u50A8\\u627E\\u5230\\u7684\\u6700\\u5927\\u503C\\u6765\\u66F4\\u65B0 \",(0,r.jsx)(e.code,{children:\"maxProduct\"}),\"\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5728\\u5B8C\\u6210\\u8FED\\u4EE3\\u540E\\u8FD4\\u56DE \",(0,r.jsx)(e.code,{children:\"maxProduct\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,r.jsx)(t,{children:a}),`\n`,(0,r.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u6BCF\\u4E2A\\u5143\\u7D20\\u53EA\\u5904\\u7406\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u53EA\\u9700\\u8981\\u6052\\u5B9A\\u7684\\u989D\\u5916\\u7A7A\\u95F4\\u3002\"]}),`\n`]})]})}function w(n={}){let{wrapper:e}=n.components||{};return e?(0,r.jsx)(e,Object.assign({},n,{children:(0,r.jsx)(f,n)})):f(n)}var _=w;return j(v);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/array-maximum-sum-contiguous/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/array-maximum-sum-contiguous/locales/zh-CN.json new file mode 100644 index 000000000..6e649fa95 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/array-maximum-sum-contiguous/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var m=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var f=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),j=(t,e)=>{for(var r in e)i(t,r,{get:e[r],enumerable:!0})},c=(t,e,r,l)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let s of x(e))!g.call(t,s)&&s!==r&&i(t,s,{get:()=>e[s],enumerable:!(l=p(e,s))||l.enumerable});return t};var _=(t,e,r)=>(r=t!=null?m(b(t)):{},c(e||!t||!t.__esModule?i(r,\"default\",{value:t,enumerable:!0}):r,t)),T=t=>c(i({},\"__esModule\",{value:!0}),t);var u=f((F,o)=>{o.exports=_jsx_runtime});var X={};j(X,{default:()=>D,frontmatter:()=>y});var n=_(u());var a=MDXTestExamples;var h=[{input:[[\"numbers\",[-1,5,-3,9,-11]]],output:11,explanation:\"The subarray [5, -3, 9] has the largest sum i.e 11.\"},{input:[[\"numbers\",[9]]],output:9,explanation:\"The single-element subarray [9] has the largest sum i.e 9.\"},{input:[[\"numbers\",[1,2,3,4]]],output:10,explanation:\"The subarray [1,2,3,4] has the largest sum i.e 10.\"}];var y={title:\"\\u8FDE\\u7EED\\u6570\\u7EC4\\u4E2D\\u7684\\u6700\\u5927\\u548C\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u67E5\\u627E\\u5177\\u6709\\u6700\\u5927\\u548C\\u7684\\u5B50\\u6570\\u7EC4\"};function d(t){let e=Object.assign({p:\"p\",code:\"code\",strong:\"strong\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"numbers\"}),\"\\uFF0C\\u786E\\u5B9A\\u603B\\u548C\\u6700\\u9AD8\\u7684\\u5B50\\u6570\\u7EC4\\u5E76\\u8FD4\\u56DE\\u8BE5\\u603B\\u548C\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A\",(0,n.jsx)(e.strong,{children:\"\\u5B50\\u6570\\u7EC4\"}),\"\\u662F\\u6570\\u7EC4\\u7684\\u8FDE\\u7EED\\u6BB5\\uFF0C\\u5176\\u4E2D\\u6240\\u6709\\u5143\\u7D20\\u90FD\\u53D6\\u81EA\\u8FDE\\u7EED\\u7684\\u7D22\\u5F15\\uFF0C\\u4FDD\\u7559\\u5176\\u987A\\u5E8F\\uFF0C\\u4F8B\\u5982 \",(0,n.jsx)(e.code,{children:\"[2, 3]\"}),\" \\u5728 \",(0,n.jsx)(e.code,{children:\"[1, 2, 3, 4]\"}),\" \\u4E2D\\uFF0C\\u800C\\u975E\\u8FDE\\u7EED\\u7684\\u9009\\u62E9\\uFF08\\u5982 \",(0,n.jsx)(e.code,{children:\"[1, 3]\"}),\"\\uFF09\\u4E0D\\u662F\\u6709\\u6548\\u7684\\u5B50\\u6570\\u7EC4\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"numbers: number[]\"}),\": \\u6574\\u6570\\u6570\\u7EC4\"]}),`\n`]}),`\n`,(0,n.jsx)(a,{testCases:h}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"numbers.length\"}),\" <= 10,000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"-10,000 <= \",(0,n.jsx)(e.code,{children:\"numbers[i]\"}),\" <= 10,000\"]}),`\n`]})]})}function C(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(d,t)})):d(t)}var D=C;return T(X);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来查找具有最大和的子数组", + "title": "连续数组中的最大和" + }, + "solution": "var Component=(()=>{var b=Object.create;var u=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var g=(n,r)=>()=>(r||n((r={exports:{}}).exports,r),r.exports),p=(n,r)=>{for(var i in r)u(n,i,{get:r[i],enumerable:!0})},l=(n,r,i,t)=>{if(r&&typeof r==\"object\"||typeof r==\"function\")for(let c of S(r))!f.call(n,c)&&c!==i&&u(n,c,{get:()=>r[c],enumerable:!(t=x(r,c))||t.enumerable});return n};var I=(n,r,i)=>(i=n!=null?b(y(n)):{},l(r||!n||!n.__esModule?u(i,\"default\",{value:n,enumerable:!0}):i,n)),j=n=>l(u({},\"__esModule\",{value:!0}),n);var m=g((F,d)=>{d.exports=_jsx_runtime});var A={};p(A,{default:()=>N});var e=I(m());var a=MDXCodeBlock;var h=`export default function maxSumSubArray(numbers: number[]): number {\n let currentSum = 0;\n let maxSum = -Infinity; // Use -Infinity to represent the smallest possible number\n\n for (let num of numbers) {\n // Update current sum, considering starting a new subarray if necessary\n currentSum = Math.max(num, currentSum + num);\n // Update max sum if current sum is larger\n maxSum = Math.max(maxSum, currentSum);\n }\n\n return maxSum;\n}\n`;var o=`export default function maxSumSubArray(numbers: number[]): number {\n // Initialize the maximum subarray sum to negative infinity\n let maxSubarray = Number.NEGATIVE_INFINITY;\n\n // Iterate through each element in the array\n for (let i = 0; i < numbers.length; i++) {\n // Initialize current subarray sum to zero\n let currentSubarray = 0;\n\n // Iterate through the subarray starting from index i\n for (let j = i; j < numbers.length; j++) {\n // Add the current element to the current subarray sum\n currentSubarray += numbers[j];\n\n // Update the maximum subarray sum if the current subarray sum is larger\n maxSubarray = Math.max(maxSubarray, currentSubarray);\n }\n }\n\n // Return the maximum subarray sum found\n return maxSubarray;\n}\n`;function s(n){let r=Object.assign({h2:\"h2\",p:\"p\",h3:\"h3\",ol:\"ol\",li:\"li\",code:\"code\",ul:\"ul\",strong:\"strong\"},n.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(r.h2,{children:\"1. \\u66B4\\u529B\\u7834\\u89E3\\u65B9\\u6CD5\"}),`\n`,(0,e.jsx)(r.p,{children:\"\\u66B4\\u529B\\u7834\\u89E3\\u65B9\\u6CD5\\u7528\\u4E8E\\u67E5\\u627E\\u6700\\u5927\\u548C\\u8FDE\\u7EED\\u5B50\\u6570\\u7EC4\\uFF0C\\u5B83\\u4F1A\\u68C0\\u67E5\\u6BCF\\u4E2A\\u53EF\\u80FD\\u7684\\u5B50\\u6570\\u7EC4\\u3002\\u8FD9\\u5305\\u62EC\\u5C06\\u6BCF\\u4E2A\\u5143\\u7D20\\u4F5C\\u4E3A\\u8D77\\u59CB\\u70B9\\u8FDB\\u884C\\u8FED\\u4EE3\\uFF0C\\u7136\\u540E\\u901A\\u8FC7\\u9010\\u4E2A\\u5305\\u542B\\u540E\\u7EED\\u5143\\u7D20\\u6765\\u6269\\u5C55\\u5B50\\u6570\\u7EC4\\u3002\\u5F53\\u5F62\\u6210\\u6BCF\\u4E2A\\u5B50\\u6570\\u7EC4\\u65F6\\uFF0C\\u8BA1\\u7B97\\u5176\\u603B\\u548C\\uFF0C\\u5E76\\u66F4\\u65B0\\u5230\\u76EE\\u524D\\u4E3A\\u6B62\\u627E\\u5230\\u7684\\u6700\\u5927\\u603B\\u548C\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\\u6BCF\\u4E2A\\u5B50\\u6570\\u7EC4\\u7684\\u603B\\u548C\\u90FD\\u88AB\\u8BC4\\u4F30\\u548C\\u6BD4\\u8F83\\u3002\"}),`\n`,(0,e.jsx)(r.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(r.ol,{children:[`\n`,(0,e.jsxs)(r.li,{children:[\"\\u5C06\\u53D8\\u91CF \",(0,e.jsx)(r.code,{children:\"maxSubarray\"}),\" \\u521D\\u59CB\\u5316\\u4E3A \",(0,e.jsx)(r.code,{children:\"Number.NEGATIVE_INFINITY\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(r.li,{children:[\"\\u4F7F\\u7528\\u5FAA\\u73AF\\u7D22\\u5F15 \",(0,e.jsx)(r.code,{children:\"i\"}),\" \\u4ECE\\u6570\\u7EC4\\u7684\\u5F00\\u5934\\u5F00\\u59CB\\u8FED\\u4EE3\\u3002\"]}),`\n`,(0,e.jsxs)(r.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A \",(0,e.jsx)(r.code,{children:\"i\"}),\"\\uFF0C\\u5C06 \",(0,e.jsx)(r.code,{children:\"currentSubarray\"}),\" \\u521D\\u59CB\\u5316\\u4E3A 0\\u3002\"]}),`\n`,(0,e.jsxs)(r.li,{children:[\"\\u4F7F\\u7528\\u53E6\\u4E00\\u4E2A\\u5FAA\\u73AF\\u7D22\\u5F15 \",(0,e.jsx)(r.code,{children:\"j\"}),\" \\u4ECE \",(0,e.jsx)(r.code,{children:\"i\"}),\" \\u8FED\\u4EE3\\u5230\\u6570\\u7EC4\\u7684\\u672B\\u5C3E\\u3002\"]}),`\n`,(0,e.jsxs)(r.li,{children:[\"\\u5C06 \",(0,e.jsx)(r.code,{children:\"numbers[j]\"}),\" \\u6DFB\\u52A0\\u5230 \",(0,e.jsx)(r.code,{children:\"currentSubarray\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(r.li,{children:[\"\\u4F7F\\u7528 \",(0,e.jsx)(r.code,{children:\"maxSubarray\"}),\" \\u548C \",(0,e.jsx)(r.code,{children:\"currentSubarray\"}),\" \\u4E4B\\u95F4\\u7684\\u6700\\u5927\\u503C\\u66F4\\u65B0 \",(0,e.jsx)(r.code,{children:\"maxSubarray\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(r.li,{children:[\"\\u5728\\u4E24\\u4E2A\\u5FAA\\u73AF\\u5B8C\\u6210\\u540E\\uFF0C\\u8FD4\\u56DE \",(0,e.jsx)(r.code,{children:\"maxSubarray\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(a,{children:o}),`\n`,(0,e.jsx)(r.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsxs)(r.ul,{children:[`\n`,(0,e.jsxs)(r.li,{children:[(0,e.jsx)(r.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\\xB2)\"}),\"\\u3002\\u4F7F\\u7528\\u4E24\\u4E2A\\u5D4C\\u5957\\u5FAA\\u73AF\\u6765\\u8003\\u8651\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u5B50\\u6570\\u7EC4\\u3002\"]}),`\n`,(0,e.jsxs)(r.li,{children:[(0,e.jsx)(r.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u4EC5\\u4F7F\\u7528\\u5E38\\u91CF\\u6570\\u91CF\\u7684\\u989D\\u5916\\u7A7A\\u95F4\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(r.h2,{children:\"2. \\u4F7F\\u7528 Kadane \\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(r.p,{children:[\"\\u4E4B\\u524D\\u7684\\u66B4\\u529B\\u7834\\u89E3\\u65B9\\u6CD5\\u679A\\u4E3E\\u4E86\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u5B50\\u6570\\u7EC4\\u5E76\\u8BA1\\u7B97\\u4E86\\u5B83\\u4EEC\\u7684\\u603B\\u548C\\u3002\\u8FD9\\u4E2A\\u8FC7\\u7A0B\\u6D89\\u53CA\\u91CD\\u590D\\u5BF9\\u91CD\\u53E0\\u5B50\\u6570\\u7EC4\\u6C42\\u548C\\uFF0C\\u8FD9\\u4F1A\\u4EA7\\u751F\\u4E0D\\u5FC5\\u8981\\u7684\\u5DE5\\u4F5C\\uFF0C\\u5BFC\\u81F4 O(n\\xB2) \\u7684\\u590D\\u6742\\u5EA6\\u3002Kadane \\u7B97\\u6CD5\\u901A\\u8FC7\\u7EF4\\u62A4\\u4E00\\u4E2A\\u8FD0\\u884C\\u7684 \",(0,e.jsx)(r.code,{children:\"currentSum\"}),\" \\u5E76\\u5728\\u6BCF\\u4E00\\u6B65\\u66F4\\u65B0\\u5B83\\u6765\\u89E3\\u51B3\\u8FD9\\u4E2A\\u95EE\\u9898\\u3002\\u8BE5\\u7B97\\u6CD5\\u6CA1\\u6709\\u91CD\\u65B0\\u8BA1\\u7B97\\u6574\\u4E2A\\u5B50\\u6570\\u7EC4\\u7684\\u603B\\u548C\\uFF0C\\u800C\\u662F\\u51B3\\u5B9A\\u662F\\u6269\\u5C55\\u73B0\\u6709\\u7684\\u5B50\\u6570\\u7EC4\\u8FD8\\u662F\\u4ECE\\u5F53\\u524D\\u5143\\u7D20\\u5F00\\u59CB\\u4E00\\u4E2A\\u65B0\\u7684\\u5B50\\u6570\\u7EC4\\u3002\\u5168\\u5C40 \",(0,e.jsx)(r.code,{children:\"maxSum\"}),\" \\u4F1A\\u4E0D\\u65AD\\u66F4\\u65B0\\uFF0C\\u786E\\u4FDD\\u8DDF\\u8E2A\\u9047\\u5230\\u7684\\u6700\\u5927\\u603B\\u548C\\uFF0C\\u800C\\u65E0\\u9700\\u679A\\u4E3E\\u6BCF\\u4E2A\\u53EF\\u80FD\\u7684\\u5B50\\u6570\\u7EC4\\u3002\\u8FD9\\u6D88\\u9664\\u4E86\\u4E0D\\u5FC5\\u8981\\u7684\\u91CD\\u590D\\u5DE5\\u4F5C\\uFF0C\\u5E76\\u5C06\\u590D\\u6742\\u5EA6\\u964D\\u4F4E\\u5230 O(n)\\u3002\"]}),`\n`,(0,e.jsx)(r.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(r.ol,{children:[`\n`,(0,e.jsxs)(r.li,{children:[\"\\u5C06 \",(0,e.jsx)(r.code,{children:\"currentSum\"}),\" \\u521D\\u59CB\\u5316\\u4E3A \",(0,e.jsx)(r.code,{children:\"0\"}),\"\\uFF0C\\u5C06 \",(0,e.jsx)(r.code,{children:\"maxSum\"}),\" \\u521D\\u59CB\\u5316\\u4E3A \",(0,e.jsx)(r.code,{children:\"-Infinity\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(r.li,{children:[\"\\u904D\\u5386\\u6570\\u7EC4\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5143\\u7D20 \",(0,e.jsx)(r.code,{children:\"num\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(r.li,{children:[\"\\u5C06 \",(0,e.jsx)(r.code,{children:\"currentSum\"}),\" \\u66F4\\u65B0\\u4E3A \",(0,e.jsx)(r.code,{children:\"Math.max(num, currentSum + num)\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(r.li,{children:[\"\\u5C06 \",(0,e.jsx)(r.code,{children:\"maxSum\"}),\" \\u66F4\\u65B0\\u4E3A \",(0,e.jsx)(r.code,{children:\"Math.max(maxSum, currentSum)\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(r.li,{children:[\"\\u8FD4\\u56DE \",(0,e.jsx)(r.code,{children:\"maxSum\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(a,{children:h}),`\n`,(0,e.jsx)(r.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsxs)(r.ul,{children:[`\n`,(0,e.jsxs)(r.li,{children:[(0,e.jsx)(r.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u6BCF\\u4E2A\\u5143\\u7D20\\u53EA\\u8BBF\\u95EE\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,e.jsxs)(r.li,{children:[(0,e.jsx)(r.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u9664\\u4E86\\u51E0\\u4E2A\\u53D8\\u91CF\\u5916\\uFF0C\\u4E0D\\u9700\\u8981\\u989D\\u5916\\u7684\\u7A7A\\u95F4\\u3002\"]}),`\n`]})]})}function _(n={}){let{wrapper:r}=n.components||{};return r?(0,e.jsx)(r,Object.assign({},n,{children:(0,e.jsx)(s,n)})):s(n)}var N=_;return j(A);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/array-most-common-elements/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/array-most-common-elements/locales/zh-CN.json new file mode 100644 index 000000000..d3c73d443 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/array-most-common-elements/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var m=Object.create;var c=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var k=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),j=(t,e)=>{for(var r in e)c(t,r,{get:e[r],enumerable:!0})},l=(t,e,r,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of x(e))!f.call(t,i)&&i!==r&&c(t,i,{get:()=>e[i],enumerable:!(o=p(e,i))||o.enumerable});return t};var _=(t,e,r)=>(r=t!=null?m(b(t)):{},l(e||!t||!t.__esModule?c(r,\"default\",{value:t,enumerable:!0}):r,t)),g=t=>l(c({},\"__esModule\",{value:!0}),t);var d=k((X,s)=>{s.exports=_jsx_runtime});var C={};j(C,{default:()=>y,frontmatter:()=>T});var n=_(d());var u=MDXTestExamples;var h=[{input:[[\"numbers\",[4,4,4,6,6,5,5,5]],[\"k\",2]],output:[4,5],explanation:\"The two most frequent numbers are 4 and 5, as they appear the most often in the array.\"},{input:[[\"numbers\",[7,7,7,8,8,9,9,9]],[\"k\",3]],output:[7,9,8],explanation:\"The three most frequent numbers are 7, 9, and 8.\"},{input:[[\"numbers\",[10,10,10,10,10]],[\"k\",1]],output:[10],explanation:\"Since there is only one unique number, 10, it is the most frequent.\"}];var T={title:\"\\u6700\\u5E38\\u89C1\\u7684\\u5143\\u7D20\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u786E\\u5B9A\\u6574\\u6570\\u6570\\u7EC4\\u4E2D\\u6700\\u5E38\\u89C1\\u7684\\u5143\\u7D20\"};function a(t){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"numbers\"}),\" \\u548C\\u4E00\\u4E2A\\u6570\\u5B57 \",(0,n.jsx)(e.code,{children:\"k\"}),\"\\uFF0C\\u627E\\u5230\\u6570\\u7EC4\\u4E2D\\u51FA\\u73B0\\u9891\\u7387\\u6700\\u9AD8\\u7684 \",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u4E2A\\u6570\\u5B57\\u3002\\u8FD9\\u91CC\\uFF0C\",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u8868\\u793A\\u5E94\\u8BE5\\u8FD4\\u56DE\\u7684\\u5143\\u7D20\\u6570\\u91CF\\uFF0C\\u8FD9\\u4E9B\\u5143\\u7D20\\u662F\\u51FA\\u73B0\\u9891\\u7387\\u6700\\u9AD8\\u7684\\u5143\\u7D20\\u3002\\u7ED3\\u679C\\u7684\\u987A\\u5E8F\\u65E0\\u5173\\u7D27\\u8981\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"numbers: number[]\"}),\": \\u6574\\u6570\\u6570\\u7EC4\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"k\"}),\": \\u4E00\\u4E2A\\u6574\\u6570\"]}),`\n`]}),`\n`,(0,n.jsx)(u,{testCases:h}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"numbers.length\"}),\" <= 1000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"-10,000 <= \",(0,n.jsx)(e.code,{children:\"numbers[i]\"}),\" <= 10,000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"k\"}),\" <= \",(0,n.jsx)(e.code,{children:\"numbers\"}),\" \\u4E2D\\u552F\\u4E00\\u5143\\u7D20\\u7684\\u6570\\u91CF\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u4FDD\\u8BC1\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u5177\\u6709\\u552F\\u4E00\\u7ED3\\u679C\"}),`\n`]})]})}function q(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(a,t)})):a(t)}var y=q;return g(C);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来确定整数数组中最常见的元素", + "title": "最常见的元素" + }, + "solution": "var Component=(()=>{var p=Object.create;var l=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var q=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),M=(r,e)=>{for(var c in e)l(r,c,{get:e[c],enumerable:!0})},u=(r,e,c,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let t of k(e))!g.call(r,t)&&t!==c&&l(r,t,{get:()=>e[t],enumerable:!(o=b(e,t))||o.enumerable});return r};var O=(r,e,c)=>(c=r!=null?p(y(r)):{},u(e||!r||!r.__esModule?l(c,\"default\",{value:r,enumerable:!0}):c,r)),x=r=>u(l({},\"__esModule\",{value:!0}),r);var d=q((B,h)=>{h.exports=_jsx_runtime});var v={};M(v,{default:()=>_});var n=O(d());var i=MDXCodeBlock;var s=`export default function mostCommonElements(\n numbers: number[],\n k: number,\n): number[] {\n // If k equals the size of numbers, return numbers as the result since all elements are required\n if (k === numbers.length) {\n return numbers;\n }\n\n // Step 1: Create a hash map to count the frequency of each element in numbers\n const countMap = new Map();\n numbers.forEach((k) => {\n countMap.set(k, (countMap.get(k) || 0) + 1);\n });\n\n // Step 2: Initialize a min-heap with a custom comparator to keep the most frequent elements\n const heap: number[] = [];\n const comp = (n1: number, n2: number) =>\n (countMap.get(n1) || 0) - (countMap.get(n2) || 0);\n\n // Step 3: Insert elements into the heap and maintain the size of the heap to k\n countMap.forEach((_, key) => {\n heap.push(key);\n heap.sort(comp); // Maintain heap order after insertion\n if (heap.length > k) heap.shift(); // Remove the least frequent element if heap exceeds size k\n });\n\n // Step 4: The heap now contains the k most frequent elements; return them as the result\n return heap;\n}\n`;var m=`export default function mostCommonElements(\n numbers: number[],\n k: number,\n): number[] {\n const frequencyMap: { [key: number]: number } = {};\n\n // Count the frequency of each number in the array\n for (let i = 0; i < numbers.length; i++) {\n frequencyMap[numbers[i]] = (frequencyMap[numbers[i]] || 0) + 1;\n }\n\n // Create an array of buckets where the index represents the frequency\n const buckets: number[][] = Array(numbers.length + 1)\n .fill(null)\n .map(() => []);\n\n // Place numbers into the corresponding bucket based on their frequency\n for (const num in frequencyMap) {\n const frequency = frequencyMap[num];\n buckets[frequency].push(Number(num));\n }\n\n const result: number[] = [];\n\n // Iterate from the highest frequency bucket to the lowest\n for (let i = buckets.length - 1; i >= 0 && k > 0; i--) {\n if (buckets[i].length > 0) {\n for (const num of buckets[i]) {\n result.push(num);\n k--;\n if (k === 0) break;\n }\n }\n }\n\n return result;\n}\n`;var a=`export default function mostCommonElements(\n numbers: number[],\n k: number,\n): number[] {\n const frequency: { value: number; count: number }[] = [];\n\n // Step 1: Calculate frequencies manually using nested loops\n for (let i = 0; i < numbers.length; i++) {\n let found = false;\n for (let j = 0; j < frequency.length; j++) {\n if (frequency[j].value === numbers[i]) {\n frequency[j].count++;\n found = true;\n break;\n }\n }\n if (!found) {\n frequency.push({ value: numbers[i], count: 1 });\n }\n }\n\n // Step 2: Sort the frequencies array by count in descending order\n frequency.sort((a, b) => b.count - a.count);\n\n // Step 3: Extract the \\`k\\` most common elements\n const result: number[] = [];\n for (let i = 0; i < k && i < frequency.length; i++) {\n result.push(frequency[i].value);\n }\n\n return result;\n}\n`;function f(r){let e=Object.assign({h2:\"h2\",p:\"p\",h3:\"h3\",ol:\"ol\",li:\"li\",code:\"code\",ul:\"ul\",strong:\"strong\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u66B4\\u529B\\u89E3\\u6CD5\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u4E00\\u79CD\\u6734\\u7D20\\u7684\\u65B9\\u6CD5\\u662F\\u4F7F\\u7528\\u5D4C\\u5957\\u5FAA\\u73AF\\u8BA1\\u7B97\\u6BCF\\u4E2A\\u5143\\u7D20\\u7684\\u9891\\u7387\\u3002\\u9891\\u7387\\u5B58\\u50A8\\u5728\\u4E00\\u4E2A\\u5355\\u72EC\\u7684\\u6570\\u7EC4\\u4E2D\\uFF0C\\u7136\\u540E\\u5BF9\\u8BE5\\u6570\\u7EC4\\u8FDB\\u884C\\u6392\\u5E8F\\u4EE5\\u627E\\u5230\\u6700\\u5E38\\u89C1\\u7684\\u5143\\u7D20\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u7A7A\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"frequency\"}),\"\\uFF0C\\u7528\\u4E8E\\u5B58\\u50A8\\u5177\\u6709 \",(0,n.jsx)(e.code,{children:\"value\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"count\"}),\" \\u5C5E\\u6027\\u7684\\u5BF9\\u8C61\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u8F93\\u5165\\u6570\\u7EC4\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u6570\\u5B57\\uFF0C\\u68C0\\u67E5\\u5B83\\u662F\\u5426\\u5DF2\\u5B58\\u5728\\u4E8E \",(0,n.jsx)(e.code,{children:\"frequency\"}),\" \\u6570\\u7EC4\\u4E2D\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5B58\\u5728\\uFF0C\\u5219\\u9012\\u589E\\u5176 \",(0,n.jsx)(e.code,{children:\"count\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u4E0D\\u5B58\\u5728\\uFF0C\\u5219\\u5C06\\u5176\\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"frequency\"}),\" \\u6570\\u7EC4\\u4E2D\\uFF0C\\u521D\\u59CB \",(0,n.jsx)(e.code,{children:\"count\"}),\" \\u4E3A 1\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u6309 \",(0,n.jsx)(e.code,{children:\"count\"}),\" \\u964D\\u5E8F\\u5BF9 \",(0,n.jsx)(e.code,{children:\"frequency\"}),\" \\u6570\\u7EC4\\u8FDB\\u884C\\u6392\\u5E8F\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u6392\\u5E8F\\u540E\\u7684 \",(0,n.jsx)(e.code,{children:\"frequency\"}),\" \\u6570\\u7EC4\\u4E2D\\u63D0\\u53D6\\u524D \",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u4E2A\\u5143\\u7D20\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE\\u4E00\\u4E2A\\u5305\\u542B\\u524D \",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u4E2A\\u5143\\u7D20\\u7684 \",(0,n.jsx)(e.code,{children:\"value\"}),\" \\u7684\\u6570\\u7EC4\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(i,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,n.jsx)(\"sup\",{children:\"2\"}),\")\"]}),\"\\u3002\\u8FD9\\u662F\\u7531\\u4E8E\\u7528\\u4E8E\\u9891\\u7387\\u8BA1\\u7B97\\u7684\\u5D4C\\u5957\\u5FAA\\u73AF\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u5982\\u679C\\u6570\\u5B57\\u4E2D\\u7684\\u6240\\u6709 \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u4E2A\\u5143\\u7D20\\u90FD\\u662F\\u552F\\u4E00\\u7684\\uFF0C\\u5219\\u9891\\u7387\\u6570\\u7EC4\\u7684\\u5927\\u5C0F\\u5C06\\u4E3A O(n)\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u5806\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u66B4\\u529B\\u89E3\\u6CD5\\u7684\\u4E3B\\u8981\\u74F6\\u9888\\u5728\\u4E8E\\u5176\\u7528\\u4E8E\\u8BA1\\u7B97\\u9891\\u7387\\u548C\\u5BF9\\u6574\\u4E2A\\u9891\\u7387\\u6570\\u7EC4\\u8FDB\\u884C\\u6392\\u5E8F\\u7684\\u5D4C\\u5957\\u5FAA\\u73AF\\u3002\\u8FD9\\u5BFC\\u81F4\\u4E86\\u5197\\u4F59\\u7684\\u6BD4\\u8F83\\u548C\\u9AD8\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u3002\\u4F18\\u5316\\u7684\\u65B9\\u6CD5\\u4F7F\\u7528\\u54C8\\u5E0C\\u6620\\u5C04\\u8FDB\\u884C\\u9891\\u7387\\u8BA1\\u6570\\uFF0C\\u8FD9\\u907F\\u514D\\u4E86\\u91CD\\u590D\\u8BA1\\u7B97\\uFF0C\\u5E76\\u4F7F\\u7528\\u6700\\u5C0F\\u5806\\u6765\\u6709\\u6548\\u5730\\u7EF4\\u62A4\\u524D \",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u4E2A\\u9891\\u7E41\\u5143\\u7D20\\u3002\\u8FD9\\u5927\\u5927\\u51CF\\u5C11\\u4E86\\u4E0D\\u5FC5\\u8981\\u7684\\u6392\\u5E8F\\u548C\\u6BD4\\u8F83\\uFF0C\\u4EC5\\u5173\\u6CE8\\u6240\\u9700\\u7684\\u5143\\u7D20\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5 \",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u662F\\u5426\\u7B49\\u4E8E\\u8F93\\u5165\\u6570\\u7EC4\\u7684\\u5927\\u5C0F\\u3002\\u5982\\u679C\\u4E3A\\u771F\\uFF0C\\u5219\\u8FD4\\u56DE\\u6570\\u7EC4\\uFF0C\\u56E0\\u4E3A\\u9700\\u8981\\u6240\\u6709\\u5143\\u7D20\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521B\\u5EFA\\u4E00\\u4E2A\\u54C8\\u5E0C\\u6620\\u5C04\\u6765\\u8BA1\\u7B97\\u6570\\u7EC4\\u4E2D\\u6BCF\\u4E2A\\u5143\\u7D20\\u7684\\u9891\\u7387\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u904D\\u5386\\u6570\\u7EC4\\uFF0C\\u66F4\\u65B0\\u54C8\\u5E0C\\u6620\\u5C04\\u4E2D\\u6BCF\\u4E2A\\u5143\\u7D20\\u7684\\u9891\\u7387\\u8BA1\\u6570\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u4F7F\\u7528\\u81EA\\u5B9A\\u4E49\\u6BD4\\u8F83\\u5668\\u521D\\u59CB\\u5316\\u6700\\u5C0F\\u5806\\u4EE5\\u6309\\u9891\\u7387\\u5BF9\\u5143\\u7D20\\u8FDB\\u884C\\u6392\\u5E8F\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u54C8\\u5E0C\\u6620\\u5C04\\u4E2D\\u7684\\u5143\\u7D20\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u6BCF\\u4E2A\\u5143\\u7D20\\u63D2\\u5165\\u5806\\u4E2D\\uFF0C\\u540C\\u65F6\\u5C06\\u5806\\u7684\\u5927\\u5C0F\\u4FDD\\u6301\\u4E3A \",(0,n.jsx)(e.code,{children:\"k\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u6BCF\\u6B21\\u63D2\\u5165\\u540E\\uFF0C\\u4F7F\\u7528\\u6BD4\\u8F83\\u5668\\u5BF9\\u5806\\u8FDB\\u884C\\u6392\\u5E8F\\uFF0C\\u5982\\u679C\\u5806\\u5927\\u5C0F\\u8D85\\u8FC7 \",(0,n.jsx)(e.code,{children:\"k\"}),\"\\uFF0C\\u5219\\u5220\\u9664\\u9891\\u7387\\u6700\\u4F4E\\u7684\\u5143\\u7D20\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE\\u5806\\u4E2D\\u7684\\u5143\\u7D20\\uFF0C\\u8FD9\\u4E9B\\u5143\\u7D20\\u662F \",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u4E2A\\u6700\\u9891\\u7E41\\u7684\\u5143\\u7D20\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(i,{children:s}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n log k)\"}),\"\\u3002\\u7EF4\\u62A4\\u5806\\u9700\\u8981\\u5BF9\\u6BCF\\u4E2A n \\u4E2A\\u552F\\u4E00\\u5143\\u7D20\\u6700\\u591A k \\u4E2A\\u5143\\u7D20\\u8FDB\\u884C\\u6392\\u5E8F\\uFF0C\\u603B\\u5171\\u9700\\u8981 O(n log k)\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n + k)\"}),\"\\u3002\\u54C8\\u5E0C\\u6620\\u5C04\\u9700\\u8981 O(n) \\u7A7A\\u95F4\\u6765\\u5B58\\u50A8\\u4E0D\\u8D85\\u8FC7 \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u4E2A\\u552F\\u4E00\\u5143\\u7D20\\uFF0C\\u5806\\u9700\\u8981 O(k) \\u7A7A\\u95F4\\u6765\\u5B58\\u50A8\\u524D \",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u4E2A\\u5143\\u7D20\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"3. \\u4F7F\\u7528 Map\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u53E6\\u4E00\\u79CD\\u65B9\\u6CD5\\u4F7F\\u7528\\u9891\\u7387\\u6620\\u5C04\\u6765\\u8BA1\\u7B97\\u6BCF\\u4E2A\\u6570\\u5B57\\u7684\\u51FA\\u73B0\\u6B21\\u6570\\u3002\\u7136\\u540E\\u6784\\u5EFA\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"buckets\"}),\" \\u6570\\u7EC4\\uFF0C\\u7528\\u4E8E\\u6309\\u9891\\u7387\\u5BF9\\u5143\\u7D20\\u8FDB\\u884C\\u5206\\u7EC4\\uFF0C\\u5176\\u4E2D\\u7D22\\u5F15\\u5BF9\\u5E94\\u4E8E\\u9891\\u7387\\u3002\\u4ECE\\u6700\\u9AD8\\u9891\\u7387\\u5230\\u6700\\u4F4E\\u9891\\u7387\\u904D\\u5386 \",(0,n.jsx)(e.code,{children:\"buckets\"}),\" \\u6570\\u7EC4\\u53EF\\u4EE5\\u6709\\u6548\\u5730\\u6536\\u96C6\\u524D \",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u4E2A\\u9891\\u7E41\\u5143\\u7D20\\uFF0C\\u800C\\u65E0\\u9700\\u6267\\u884C O(n log n) \\u6392\\u5E8F\\u6B65\\u9AA4\\u3002\\u8FD9\\u79CD\\u65B9\\u6CD5\\u5C06\\u603B\\u590D\\u6742\\u5EA6\\u964D\\u4F4E\\u5230 O(n)\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u6784\\u5EFA\\u4E00\\u4E2A\\u9891\\u7387\\u6620\\u5C04 \",(0,n.jsx)(e.code,{children:\"frequencyMap\"}),\"\\uFF0C\\u5C06\\u6BCF\\u4E2A\\u6570\\u5B57\\u6620\\u5C04\\u5230\\u5176\\u9891\\u7387\\u8BA1\\u6570\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u6784\\u5EFA\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"buckets\"}),\" \\u6570\\u7EC4\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u7D22\\u5F15\\u5BF9\\u5E94\\u4E00\\u4E2A\\u9891\\u7387\\uFF0C\\u5E76\\u5B58\\u50A8\\u5177\\u6709\\u8BE5\\u9891\\u7387\\u7684\\u6570\\u5B57\\u6570\\u7EC4\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u6700\\u9AD8\\u9891\\u7387\\u6876\\u5230\\u6700\\u4F4E\\u9891\\u7387\\u6876\\u904D\\u5386 \",(0,n.jsx)(e.code,{children:\"buckets\"}),\"\\uFF0C\\u5E76\\u9009\\u62E9\\u6570\\u5B57\\uFF0C\\u76F4\\u5230\\u8FBE\\u5230 \",(0,n.jsx)(e.code,{children:\"k\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(i,{children:m}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u8BA1\\u7B97\\u9891\\u7387\\uFF0C\\u7136\\u540E\\u586B\\u5145\\u6876\\uFF0C\\u4E24\\u8005\\u90FD\\u4EE5 O(n) \\u8FD0\\u884C\\uFF0C\\u7136\\u540E\\u8FDB\\u884C\\u6700\\u540E\\u4E00\\u6B21\\u4F20\\u9012\\uFF0C\\u9009\\u62E9\\u6700\\u591A \",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u4E2A\\u5143\\u7D20\\uFF0C\\u4ECD\\u7136\\u662F O(n)\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\",(0,n.jsx)(e.code,{children:\"frequencyMap\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"buckets\"}),\" \\u6570\\u7EC4\\u90FD\\u5360\\u7528\\u6700\\u591A O(n) \\u7A7A\\u95F4\\u3002\"]}),`\n`]})]})}function S(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(f,r)})):f(r)}var _=S;return x(v);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/array-product-excluding-current/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/array-product-excluding-current/locales/zh-CN.json new file mode 100644 index 000000000..e5fc027e9 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/array-product-excluding-current/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var r=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var j=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),_=(t,e)=>{for(var l in e)r(t,l,{get:e[l],enumerable:!0})},s=(t,e,l,c)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of x(e))!b.call(t,i)&&i!==l&&r(t,i,{get:()=>e[i],enumerable:!(c=a(e,i))||c.enumerable});return t};var g=(t,e,l)=>(l=t!=null?p(f(t)):{},s(e||!t||!t.__esModule?r(l,\"default\",{value:t,enumerable:!0}):l,t)),M=t=>s(r({},\"__esModule\",{value:!0}),t);var u=j((F,o)=>{o.exports=_jsx_runtime});var T={};_(T,{default:()=>X,frontmatter:()=>C});var n=g(u());var d=MDXTestExamples;var h=[{input:[[\"numbers\",[1,2,3]]],output:[6,3,2],explanation:\"Output is multiplication of all other elements except self, i.e 2*3, 1*3, 1*2\"},{input:[[\"numbers\",[2,0,3]]],output:[0,6,0],explanation:\"Output is multiplication of all other elements except self, i.e 0*3, 2*3, 2*0\"},{input:[[\"numbers\",[0,0,-1,1]]],output:[0,0,0,0],explanation:\"Output is multiplication of all other elements except self, i.e 0*-1*1, 0*-1*1, 0*0*1, 0*0*-1\"}];var C={title:\"\\u6570\\u7EC4\\u7684\\u4E58\\u79EF\\uFF0C\\u4E0D\\u5305\\u542B\\u5F53\\u524D\\u5143\\u7D20\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u627E\\u5230\\u6570\\u7EC4\\u4E2D\\u9664\\u5F53\\u524D\\u5143\\u7D20\\u4E4B\\u5916\\u7684\\u6240\\u6709\\u5143\\u7D20\\u7684\\u4E58\\u79EF\\u3002\"};function m(t){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"numbers\"}),\"\\uFF0C\\u8FD4\\u56DE\\u4E00\\u4E2A\\u65B0\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"result\"}),\"\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u5143\\u7D20 \",(0,n.jsx)(e.code,{children:\"result[i]\"}),\" \\u4EE3\\u8868 \",(0,n.jsx)(e.code,{children:\"numbers\"}),\" \\u4E2D\\u9664 \",(0,n.jsx)(e.code,{children:\"numbers[i]\"}),\" \\u4E4B\\u5916\\u7684\\u6240\\u6709\\u5143\\u7D20\\u7684\\u4E58\\u79EF\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"numbers: number[]\"}),\": \\u6574\\u6570\\u6570\\u7EC4\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u6CE8\\u610F\\u4E8B\\u9879\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u786E\\u4FDD \",(0,n.jsx)(e.code,{children:\"numbers\"}),\" \\u6570\\u7EC4\\u7684\\u4EFB\\u4F55\\u524D\\u7F00\\u6216\\u540E\\u7F00\\u7684\\u4E58\\u79EF\\u90FD\\u9002\\u5408 32 \\u4F4D\\u6574\\u6570\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u7981\\u6B62\\u4F7F\\u7528\\u9664\\u6CD5\\u8FD0\\u7B97\\u7B26\"}),`\n`]}),`\n`,(0,n.jsx)(d,{testCases:h}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"2 <= \",(0,n.jsx)(e.code,{children:\"numbers.length\"}),\" <= 1000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"-10 <= \",(0,n.jsx)(e.code,{children:\"numbers[i]\"}),\" <= 10\"]}),`\n`]})]})}function D(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(m,t)})):m(t)}var X=D;return M(T);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,找到数组中除当前元素之外的所有元素的乘积。", + "title": "数组的乘积,不包含当前元素" + }, + "solution": "var Component=(()=>{var x=Object.create;var c=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var y=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),C=(i,e)=>{for(var r in e)c(i,r,{get:e[r],enumerable:!0})},h=(i,e,r,t)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let l of p(e))!b.call(i,l)&&l!==r&&c(i,l,{get:()=>e[l],enumerable:!(t=m(e,l))||t.enumerable});return i};var P=(i,e,r)=>(r=i!=null?x(g(i)):{},h(e||!i||!i.__esModule?c(r,\"default\",{value:i,enumerable:!0}):r,i)),O=i=>h(c({},\"__esModule\",{value:!0}),i);var u=y((S,o)=>{o.exports=_jsx_runtime});var E={};C(E,{default:()=>M});var n=P(u());var d=MDXCodeBlock;var s=`export default function arrayProductExcludingCurrent(\n numbers: number[],\n): number[] {\n const n = numbers.length;\n\n // Create prefix and suffix arrays\n const prefix: number[] = new Array(n).fill(1);\n const suffix: number[] = new Array(n).fill(1);\n const result: number[] = new Array(n).fill(1);\n\n // Step 1: Fill prefix array\n prefix[0] = 1; // First element has no elements to its left\n for (let i = 1; i < n; i++) {\n prefix[i] = prefix[i - 1] * numbers[i - 1];\n }\n\n // Step 2: Fill suffix array\n suffix[n - 1] = 1; // Last element has no elements to its right\n for (let i = n - 2; i >= 0; i--) {\n suffix[i] = suffix[i + 1] * numbers[i + 1];\n }\n\n // Step 3: Calculate result array by combining prefix and suffix\n for (let i = 0; i < n; i++) {\n result[i] = prefix[i] * suffix[i];\n }\n\n // Step 4: Convert -0 to 0 if needed\n for (let i = 0; i < n; i++) {\n if (result[i] === -0) {\n result[i] = 0;\n }\n }\n\n return result;\n}\n`;var f=`export default function arrayProductExcludingCurrent(\n numbers: number[],\n): number[] {\n // Get the length of the input array\n const length = numbers.length;\n\n // Initialize the result array\n const result: number[] = new Array(length).fill(1);\n\n // Calculate products of all elements to the left of each index\n for (let i = 1; i < length; i++) {\n // result[i] contains the product of all elements to the left of index 'i'\n result[i] = numbers[i - 1] * result[i - 1];\n }\n\n // Variable to hold the product of all elements to the right\n let rightProduct = 1;\n for (let i = length - 1; i >= 0; i--) {\n // Multiply the right product with the current result\n result[i] *= rightProduct;\n // Update rightProduct with the current element\n rightProduct *= numbers[i];\n }\n\n // Convert -0 or +0 to normal 0\n for (let i = 0; i < length; i++) {\n if (result[i] === -0) {\n result[i] = 0;\n }\n }\n\n return result;\n}\n`;function a(i){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},i.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u524D\\u7F00\\u548C\\u540E\\u7F00\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8BE5\\u4EFB\\u52A1\\u662F\\u8BA1\\u7B97\\u4E00\\u4E2A\\u6570\\u7EC4\\uFF0C\\u5176\\u4E2D\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"i\"}),\" \\u5904\\u7684\\u6BCF\\u4E2A\\u5143\\u7D20\\u662F\\u8F93\\u5165\\u6570\\u7EC4\\u4E2D\\u9664 \",(0,n.jsx)(e.code,{children:\"i\"}),\" \\u5904\\u5143\\u7D20\\u4E4B\\u5916\\u7684\\u6240\\u6709\\u5143\\u7D20\\u7684\\u4E58\\u79EF\\u3002\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u5355\\u72EC\\u7684\\u524D\\u7F00\\u548C\\u540E\\u7F00\\u6570\\u7EC4\\u6765\\u5B58\\u50A8\\u4E2D\\u95F4\\u8BA1\\u7B97\\u7ED3\\u679C\\uFF0C\\u4ECE\\u800C\\u53EF\\u4EE5\\u9AD8\\u6548\\u5730\\u8BA1\\u7B97\\u7ED3\\u679C\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u79CD\\u86EE\\u529B\\u65B9\\u6CD5\\u5C06\\u6D89\\u53CA\\u904D\\u5386\\u6570\\u7EC4\\u5E76\\u8BA1\\u7B97\\u6BCF\\u4E2A\\u7D22\\u5F15\\u7684\\u6240\\u6709\\u5143\\u7D20\\u7684\\u4E58\\u79EF\\uFF0C\\u9664\\u4E86\\u5F53\\u524D\\u7D22\\u5F15\\u3002\\u7531\\u4E8E\\u6BCF\\u4E2A\\u7D22\\u5F15\\u7684\\u91CD\\u590D\\u4E58\\u6CD5\\uFF0C\\u8FD9\\u5BFC\\u81F4\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(n\",(0,n.jsx)(\"sup\",{children:\"2\"}),\")\\u3002\\u4F18\\u5316\\u7684\\u524D\\u7F00-\\u540E\\u7F00\\u65B9\\u6CD5\\u901A\\u8FC7\\u9884\\u5148\\u8BA1\\u7B97\\u6BCF\\u4E2A\\u5143\\u7D20\\u5DE6\\u4FA7\\u548C\\u53F3\\u4FA7\\u7684\\u4E58\\u79EF\\u6765\\u6D88\\u9664\\u8FD9\\u79CD\\u5197\\u4F59\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u524D\\u7F00\\u6570\\u7EC4\\u5B58\\u50A8\\u4ECE\\u5F00\\u59CB\\u5230\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"i - 1\"}),\" \\u7684\\u5143\\u7D20\\u7684\\u7D2F\\u79EF\\u4E58\\u79EF\\uFF0C\\u540E\\u7F00\\u6570\\u7EC4\\u5B58\\u50A8\\u4ECE\\u672B\\u5C3E\\u5230\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"i + 1\"}),\" \\u7684\\u5143\\u7D20\\u7684\\u7D2F\\u79EF\\u4E58\\u79EF\\u3002\\u8FD9\\u4E9B\\u6570\\u7EC4\\u88AB\\u7EC4\\u5408\\u8D77\\u6765\\u8BA1\\u7B97\\u6700\\u7EC8\\u7ED3\\u679C\\u6570\\u7EC4\\uFF0C\\u6BCF\\u4E2A\\u5143\\u7D20\\u662F\\u76F8\\u5E94\\u7684\\u524D\\u7F00\\u548C\\u540E\\u7F00\\u503C\\u7684\\u4E58\\u79EF\\u3002\\u8D1F\\u96F6\\u7684\\u5904\\u7406\\u786E\\u4FDD\\u4E86\\u4E00\\u81F4\\u7684\\u8F93\\u51FA\\u683C\\u5F0F\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521B\\u5EFA\\u4E09\\u4E2A\\u6570\\u7EC4\\uFF1A\",(0,n.jsx)(e.code,{children:\"prefix\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"suffix\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"result\"}),\"\\uFF0C\\u6BCF\\u4E2A\\u6570\\u7EC4\\u7684\\u5927\\u5C0F\\u4E3A \",(0,n.jsx)(e.code,{children:\"n\"}),\"\\uFF0C\\u5E76\\u521D\\u59CB\\u5316\\u4E3A \",(0,n.jsx)(e.code,{children:\"1\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8BA1\\u7B97\\u524D\\u7F00\\u6570\\u7EC4\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8BBE\\u7F6E \",(0,n.jsx)(e.code,{children:\"prefix[0] = 1\"}),\"\\uFF0C\\u56E0\\u4E3A\\u7B2C\\u4E00\\u4E2A\\u5143\\u7D20\\u7684\\u5DE6\\u8FB9\\u6CA1\\u6709\\u5143\\u7D20\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"1\"}),\" \\u8FED\\u4EE3\\u5230 \",(0,n.jsx)(e.code,{children:\"n - 1\"}),\"\\uFF0C\\u5C06 \",(0,n.jsx)(e.code,{children:\"prefix[i]\"}),\" \\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"prefix[i - 1] * numbers[i - 1]\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8BA1\\u7B97\\u540E\\u7F00\\u6570\\u7EC4\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8BBE\\u7F6E \",(0,n.jsx)(e.code,{children:\"suffix[n - 1] = 1\"}),\"\\uFF0C\\u56E0\\u4E3A\\u6700\\u540E\\u4E00\\u4E2A\\u5143\\u7D20\\u7684\\u53F3\\u8FB9\\u6CA1\\u6709\\u5143\\u7D20\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"n - 2\"}),\" \\u8FED\\u4EE3\\u5230 \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u5C06 \",(0,n.jsx)(e.code,{children:\"suffix[i]\"}),\" \\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"suffix[i + 1] * numbers[i + 1]\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8BA1\\u7B97\\u7ED3\\u679C\\u6570\\u7EC4\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u6570\\u7EC4\\u5E76\\u5C06 \",(0,n.jsx)(e.code,{children:\"result[i]\"}),\" \\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"prefix[i] * suffix[i]\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5904\\u7406\\u7279\\u6B8A\\u60C5\\u51B5\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386 \",(0,n.jsx)(e.code,{children:\"result\"}),\" \\u6570\\u7EC4\\uFF0C\\u5E76\\u5C06 \",(0,n.jsx)(e.code,{children:\"-0\"}),\" \\u7684\\u4EFB\\u4F55\\u51FA\\u73B0\\u66FF\\u6362\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u4EE5\\u83B7\\u5F97\\u4E00\\u81F4\\u7684\\u8F93\\u51FA\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"result\"}),\" \\u6570\\u7EC4\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(d,{children:s}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u6D89\\u53CA\\u4E09\\u4E2A\\u7EBF\\u6027\\u904D\\u5386\\uFF1A\\u4E00\\u4E2A\\u7528\\u4E8E\\u8BA1\\u7B97\\u524D\\u7F00\\u6570\\u7EC4\\uFF0C\\u4E00\\u4E2A\\u7528\\u4E8E\\u8BA1\\u7B97\\u540E\\u7F00\\u6570\\u7EC4\\uFF0C\\u4E00\\u4E2A\\u7528\\u4E8E\\u8BA1\\u7B97\\u7ED3\\u679C\\u6570\\u7EC4\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u9664\\u4E86 \",(0,n.jsx)(e.code,{children:\"result\"}),\" \\u6570\\u7EC4\\u5916\\uFF0C\\u8FD8\\u4F7F\\u7528\\u4E86\\u4E24\\u4E2A\\u5927\\u5C0F\\u4E3A \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u7684\\u8F85\\u52A9\\u6570\\u7EC4 (\",(0,n.jsx)(e.code,{children:\"prefix\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"suffix\"}),\")\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4E0A\\u8FF0\\u65B9\\u6CD5\\u7684\\u7A7A\\u95F4\\u4F18\\u5316\\u7248\\u672C\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u901A\\u8FC7\\u5728\\u7B2C\\u4E00\\u904D\\u4E2D\\u8BA1\\u7B97\\u6BCF\\u4E2A\\u7D22\\u5F15\\u5DE6\\u4FA7\\u7684\\u6240\\u6709\\u5143\\u7D20\\u7684\\u4E58\\u79EF\\u5E76\\u5C06\\u8FD9\\u4E9B\\u503C\\u5B58\\u50A8\\u5728 \",(0,n.jsx)(e.code,{children:\"result\"}),\" \\u6570\\u7EC4\\u4E2D\\uFF0C\\u4ECE\\u800C\\u8FDB\\u4E00\\u6B65\\u63D0\\u9AD8\\u4E86\\u7A7A\\u95F4\\u4F7F\\u7528\\u7387\\u3002\\u5728\\u7B2C\\u4E8C\\u904D\\u4E2D\\uFF0C\\u5B83\\u8BA1\\u7B97\\u6BCF\\u4E2A\\u7D22\\u5F15\\u53F3\\u4FA7\\u7684\\u6240\\u6709\\u5143\\u7D20\\u7684\\u4E58\\u79EF\\uFF0C\\u5E76\\u5C06\\u8FD9\\u4E9B\\u503C\\u4E0E\\u5DF2\\u5B58\\u50A8\\u5728 \",(0,n.jsx)(e.code,{children:\"result\"}),\" \\u6570\\u7EC4\\u4E2D\\u7684\\u76F8\\u5E94\\u503C\\u76F8\\u4E58\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u4E0E\\u8F93\\u5165\\u6570\\u7EC4\\u957F\\u5EA6\\u76F8\\u540C\\u7684 \",(0,n.jsx)(e.code,{children:\"result\"}),\" \\u6570\\u7EC4\\uFF0C\\u5E76\\u5C06\\u6240\\u6709\\u5143\\u7D20\\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"1\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8BA1\\u7B97\\u5DE6\\u4FA7\\u4E58\\u79EF\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u5DE6\\u5230\\u53F3\\u904D\\u5386\\u6570\\u7EC4\\uFF0C\\u4ECE\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"1\"}),\" \\u5F00\\u59CB\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"i\"}),\"\\uFF0C\\u901A\\u8FC7\\u5C06 \",(0,n.jsx)(e.code,{children:\"numbers[i - 1]\"}),\" \\u4E0E \",(0,n.jsx)(e.code,{children:\"result[i - 1]\"}),\" \\u76F8\\u4E58\\u6765\\u8BA1\\u7B97\\u5DE6\\u4FA7\\u6240\\u6709\\u5143\\u7D20\\u7684\\u4E58\\u79EF\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u7ED3\\u679C\\u5B58\\u50A8\\u5728 \",(0,n.jsx)(e.code,{children:\"result[i]\"}),\" \\u4E2D\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8BA1\\u7B97\\u53F3\\u4FA7\\u4E58\\u79EF\\u5E76\\u4E0E\\u5DE6\\u4FA7\\u4E58\\u79EF\\u5408\\u5E76\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u53D8\\u91CF \",(0,n.jsx)(e.code,{children:\"rightProduct\"}),\" \\u521D\\u59CB\\u5316\\u4E3A \",(0,n.jsx)(e.code,{children:\"1\"}),\"\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u4ECE\\u53F3\\u5230\\u5DE6\\u904D\\u5386\\u6570\\u7EC4\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"i\"}),\"\\uFF0C\\u5C06 \",(0,n.jsx)(e.code,{children:\"result[i]\"}),\" \\u4E2D\\u7684\\u503C\\u4E0E \",(0,n.jsx)(e.code,{children:\"rightProduct\"}),\" \\u76F8\\u4E58\\uFF0C\\u4EE5\\u5305\\u542B\\u53F3\\u4FA7\\u6240\\u6709\\u5143\\u7D20\\u7684\\u4E58\\u79EF\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u5C06 \",(0,n.jsx)(e.code,{children:\"rightProduct\"}),\" \\u4E0E \",(0,n.jsx)(e.code,{children:\"numbers[i]\"}),\" \\u76F8\\u4E58\\u6765\\u66F4\\u65B0\\u5B83\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5904\\u7406\\u7279\\u6B8A\\u60C5\\u51B5\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"result\"}),\" \\u4E2D \",(0,n.jsx)(e.code,{children:\"-0\"}),\" \\u7684\\u4EFB\\u4F55\\u51FA\\u73B0\\u66FF\\u6362\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u4EE5\\u83B7\\u5F97\\u4E00\\u81F4\\u7684\\u8F93\\u51FA\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"result\"}),\" \\u6570\\u7EC4\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(d,{children:f}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u6D89\\u53CA\\u5BF9\\u6570\\u7EC4\\u8FDB\\u884C\\u4E24\\u6B21\\u7EBF\\u6027\\u904D\\u5386\\uFF0C\\u7528\\u4E8E\\u8BA1\\u7B97\\u5DE6\\u53F3\\u4E58\\u79EF\\uFF0C\\u4EE5\\u53CA\\u4E00\\u6B21\\u989D\\u5916\\u7684\\u904D\\u5386\\u7528\\u4E8E\\u5F52\\u4E00\\u5316\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u6052\\u5B9A\\u7684\\u989D\\u5916\\u7A7A\\u95F4\\uFF0C\\u56E0\\u4E3A\\u8BA1\\u7B97\\u76F4\\u63A5\\u5728 \",(0,n.jsx)(e.code,{children:\"result\"}),\" \\u6570\\u7EC4\\u4E2D\\u6267\\u884C\\u3002\"]}),`\n`]})]})}function _(i={}){let{wrapper:e}=i.components||{};return e?(0,n.jsx)(e,Object.assign({},i,{children:(0,n.jsx)(a,i)})):a(i)}var M=_;return O(E);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/array-reachable-end/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/array-reachable-end/locales/zh-CN.json new file mode 100644 index 000000000..20dbe74e8 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/array-reachable-end/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var h=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var g=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),v=(t,e)=>{for(var o in e)i(t,o,{get:e[o],enumerable:!0})},l=(t,e,o,s)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of x(e))!b.call(t,r)&&r!==o&&i(t,r,{get:()=>e[r],enumerable:!(s=p(e,r))||s.enumerable});return t};var j=(t,e,o)=>(o=t!=null?h(f(t)):{},l(e||!t||!t.__esModule?i(o,\"default\",{value:t,enumerable:!0}):o,t)),M=t=>l(i({},\"__esModule\",{value:!0}),t);var c=g((T,d)=>{d.exports=_jsx_runtime});var X={};v(X,{default:()=>D,frontmatter:()=>C});var n=j(c());var u=MDXTestExamples;var a=[{input:[[\"numbers\",[4,1,0,0,2,3]]],output:!0,explanation:\"Move from index 0 to 4, then move 1 position to the last index.\"},{input:[[\"numbers\",[1,0,0,0]]],output:!1,explanation:\"Can only move from index 0 to index 1 and no further movements thereafter, so it impossible to reach the last index.\"},{input:[[\"numbers\",[2,3,1,1,4]]],output:!0,explanation:\"Move 1 position forward from index 0 to index 1 (it is allowed to move up to 2 positions, but going to index 1 first allows us to move further). From index 1, move 3 positions to reach the last index.\"}];var C={title:\"\\u6570\\u7EC4\\u672B\\u7AEF\\u53EF\\u8FBE\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u786E\\u5B9A\\u6570\\u7EC4\\u7684\\u672B\\u7AEF\\u662F\\u5426\\u53EF\\u8FBE\"};function m(t){let e=Object.assign({p:\"p\",code:\"code\",strong:\"strong\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4\",(0,n.jsx)(e.code,{children:\"numbers\"}),\"\\uFF0C\\u5176\\u4E2D\\u6570\\u7EC4\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5143\\u7D20\\u8868\\u793A\\u53EF\\u4EE5\\u4ECE\\u8BE5\\u7D22\\u5F15\\u5411\\u524D\\u79FB\\u52A8\\u7684\",(0,n.jsx)(e.strong,{children:\"\\u6700\\u5927\"}),\"\\u4F4D\\u7F6E\\u6570\\uFF1B\\u53EF\\u4EE5\\u79FB\\u52A8\\u8F83\\u5C11\\u7684\\u4F4D\\u7F6E\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u786E\\u5B9A\\u662F\\u5426\\u53EF\\u4EE5\\u901A\\u8FC7\\u4ECE\\u7B2C\\u4E00\\u4E2A\\u7D22\\u5F15\\u5F00\\u59CB\\u5230\\u8FBE\\u6570\\u7EC4\\u7684\\u6700\\u540E\\u4E00\\u4E2A\\u7D22\\u5F15\\u3002\\u5982\\u679C\\u53EF\\u4EE5\\u5230\\u8FBE\\uFF0C\\u5219\\u8FD4\\u56DE\",(0,n.jsx)(e.code,{children:\"true\"}),\"\\uFF0C\\u5426\\u5219\\u8FD4\\u56DE\",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"numbers: number[]\"}),\": \\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4\\uFF0C\\u6BCF\\u4E2A\\u7D22\\u5F15\\u7684\\u503C\\u662F\\u4ECE\\u8BE5\\u7D22\\u5F15\\u53EF\\u5230\\u8FBE\\u7684\\u6700\\u5927\\u4F4D\\u7F6E\\u6570\"]}),`\n`]}),`\n`,(0,n.jsx)(u,{testCases:a}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"numbers.length\"}),\" <= 10,000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"0 <= \",(0,n.jsx)(e.code,{children:\"numbers[i]\"}),\" <= 100,000\"]}),`\n`]})]})}function w(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(m,t)})):m(t)}var D=w;return M(X);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来确定数组的末端是否可达", + "title": "数组末端可达" + }, + "solution": "var Component=(()=>{var p=Object.create;var o=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var D=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),g=(r,e)=>{for(var i in e)o(r,i,{get:e[i],enumerable:!0})},l=(r,e,i,h)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let t of O(e))!y.call(r,t)&&t!==i&&o(r,t,{get:()=>e[t],enumerable:!(h=b(e,t))||h.enumerable});return r};var N=(r,e,i)=>(i=r!=null?p(x(r)):{},l(e||!r||!r.__esModule?o(i,\"default\",{value:r,enumerable:!0}):i,r)),G=r=>l(o({},\"__esModule\",{value:!0}),r);var d=D((U,a)=>{a.exports=_jsx_runtime});var k={};g(k,{default:()=>B});var n=N(d());var c=MDXCodeBlock;var s=`export default function arrayReachableEnd(numbers: number[]): boolean {\n // Initialize a variable to track the farthest reachable position (last element initially)\n let farthestReachable = numbers.length - 1;\n\n // Iterate backwards through the array (from the end)\n for (\n let currentPosition = numbers.length - 1;\n currentPosition >= 0;\n currentPosition--\n ) {\n // Check if the current position can reach the farthest reachable position\n if (currentPosition + numbers[currentPosition] >= farthestReachable) {\n // Update the farthest reachable position if the current position can reach it\n farthestReachable = currentPosition;\n }\n }\n\n // Return true if the farthest reachable position is the\n // first element (meaning you can reach the end)\n return farthestReachable === 0;\n}\n`;var m=`// Memoization array to store the state of each position\nlet memo: string[];\n\n/**\n * Helper function to determine if you can reach to the last position from the current position.\n *\n * @param {number} position - The current position in the array.\n * @param {number[]} numbers - An array of numbers representing maximum movement lengths at each index.\n * @returns {boolean} - True if you can reach the last element from the current position, false otherwise.\n */\nconst canReachLastPosition = (position: number, numbers: number[]): boolean => {\n // Check the memoization array to see if the result is already computed\n if (memo[position] !== 'UNKNOWN') {\n return memo[position] === 'GOOD';\n }\n\n // If current position is a stuck position, directly return false\n if (numbers[position] === 0) {\n memo[position] = 'BAD';\n return false;\n }\n\n // Calculate the furthest position that can be reached from the current position\n const furthestPosition = Math.min(\n position + numbers[position],\n numbers.length - 1,\n );\n\n // Iterate through all positions that can be reached from the current position\n // Iterate backward for better efficiency (reduce redundant calls)\n for (\n let nextPosition = furthestPosition;\n nextPosition > position;\n nextPosition--\n ) {\n if (canReachLastPosition(nextPosition, numbers)) {\n memo[position] = 'GOOD';\n return true;\n }\n }\n\n // If none of the next positions can reach the last position, mark the current position as \"BAD\"\n memo[position] = 'BAD';\n return false;\n};\n\n/**\n * Determines if you can reach the last element in an array, where each element represents\n * the maximum positions you can reach from that index.\n *\n * @param {number[]} numbers - An array of numbers representing maximum positions reachable from that index.\n * @returns {boolean} - True if you can reach the last index, false otherwise.\n */\nexport default function arrayReachableEnd(numbers: number[]): boolean {\n // Initialize the memoization array with \"UNKNOWN\"\n memo = new Array(numbers.length).fill('UNKNOWN');\n\n // The last position is always \"GOOD\" because we are already there\n memo[memo.length - 1] = 'GOOD';\n\n // Start the recursion from the first position\n return canReachLastPosition(0, numbers);\n}\n`;var u=`// Enum to represent the state of each index in the array\nenum Index {\n GOOD, // Represents a position from which you can reach the last position\n BAD, // Represents a position from which you cannot reach the last position\n UNKNOWN, // Represents an unknown state\n}\n\n/**\n * Determines if you can reach the last element in an array, where each element represents\n * the maximum positions you can reach from that index.\n *\n * @param {number[]} numbers - An array of numbers representing maximum positions reachable from that index.\n * @returns {boolean} - True if you can reach the last index, false otherwise.\n */\nexport default function arrayReachableEnd(numbers: number[]): boolean {\n // Initialize the memoization array with \"UNKNOWN\"\n let memo: Index[] = Array(numbers.length).fill(Index.UNKNOWN);\n\n // The last position is always \"GOOD\" because we are already there\n memo[memo.length - 1] = Index.GOOD;\n\n // Iterate from the second last position to the first position\n for (let i = numbers.length - 2; i >= 0; i--) {\n // Calculate the furthest position that can be reached from the current position\n let furthestPosition: number = Math.min(i + numbers[i], numbers.length - 1);\n\n // Check if any reachable position from the current position is \"GOOD\"\n for (let j = i + 1; j <= furthestPosition; j++) {\n if (memo[j] === Index.GOOD) {\n // Mark the current position as \"GOOD\" if a reachable position is \"GOOD\"\n memo[i] = Index.GOOD;\n break;\n }\n }\n }\n\n // Return true if the first position is \"GOOD\", meaning you can reach the last element\n return memo[0] === Index.GOOD;\n}\n`;function f(r){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u81EA\\u5E95\\u5411\\u4E0A\\u52A8\\u6001\\u89C4\\u5212\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u4E00\\u4E2A\\u6734\\u7D20\\u7684\\u89E3\\u51B3\\u65B9\\u6848\\u5C06\\u6D89\\u53CA\\u9012\\u5F52\\u5730\\u63A2\\u7D22\\u4ECE\\u7B2C\\u4E00\\u4E2A\\u4F4D\\u7F6E\\u5F00\\u59CB\\u7684\\u6240\\u6709\\u53EF\\u80FD\\u8DEF\\u5F84\\uFF0C\\u4EE5\\u68C0\\u67E5\\u662F\\u5426\\u53EF\\u4EE5\\u5230\\u8FBE\\u6700\\u540E\\u4E00\\u4E2A\\u4F4D\\u7F6E\\u3002\\u8FD9\\u79CD\\u65B9\\u6CD5\\u5B58\\u5728\\u5197\\u4F59\\u8BA1\\u7B97\\u548C\\u6307\\u6570\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u7684\\u7F3A\\u70B9\\uFF0C\\u56E0\\u4E3A\\u5B83\\u591A\\u6B21\\u63A2\\u7D22\\u91CD\\u53E0\\u7684\\u5B50\\u95EE\\u9898\\u3002\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u81EA\\u5E95\\u5411\\u4E0A\\u52A8\\u6001\\u89C4\\u5212\\u65B9\\u6CD5\\u901A\\u8FC7\\u4ECE\\u5012\\u6570\\u7B2C\\u4E8C\\u4E2A\\u4F4D\\u7F6E\\u8FED\\u4EE3\\u5230\\u7B2C\\u4E00\\u4E2A\\u4F4D\\u7F6E\\u6765\\u4F18\\u5316\\u8FD9\\u4E00\\u70B9\\uFF0C\\u540C\\u65F6\\u7EF4\\u62A4\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"memo\"}),\" \\u6570\\u7EC4\\uFF0C\\u8BE5\\u6570\\u7EC4\\u8BB0\\u5F55\\u6BCF\\u4E2A\\u4F4D\\u7F6E\\u662F \",(0,n.jsx)(e.code,{children:\"GOOD\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"BAD\"}),\" \\u8FD8\\u662F \",(0,n.jsx)(e.code,{children:\"UNKNOWN\"}),\"\\u3002\\u5982\\u679C\\u4E00\\u4E2A\\u4F4D\\u7F6E\\u53EF\\u4EE5\\u5230\\u8FBE\\u6700\\u540E\\u4E00\\u4E2A\\u4F4D\\u7F6E\\u6216\\u5DF2\\u7ECF\\u6807\\u8BB0\\u4E3A \",(0,n.jsx)(e.code,{children:\"GOOD\"}),\" \\u7684\\u4F4D\\u7F6E\\uFF0C\\u5219\\u8BE5\\u4F4D\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"GOOD\"}),\"\\u3002\\u4F18\\u5316\\u901A\\u8FC7\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"memo\"}),\" \\u6570\\u7EC4\\u4E2D\\u5148\\u524D\\u8BA1\\u7B97\\u7684\\u7ED3\\u679C\\u6765\\u6D88\\u9664\\u5197\\u4F59\\u68C0\\u67E5\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u679A\\u4E3E \",(0,n.jsx)(e.code,{children:\"Index\"}),\"\\uFF0C\\u5176\\u72B6\\u6001\\u4E3A \",(0,n.jsx)(e.code,{children:\"GOOD\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"BAD\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"UNKNOWN\"}),\"\\uFF0C\\u4EE5\\u8868\\u793A\\u6BCF\\u4E2A\\u7D22\\u5F15\\u7684\\u72B6\\u6001\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u4E0E\\u8F93\\u5165\\u6570\\u7EC4\\u957F\\u5EA6\\u76F8\\u540C\\u7684 \",(0,n.jsx)(e.code,{children:\"memo\"}),\" \\u6570\\u7EC4\\uFF0C\\u6240\\u6709\\u503C\\u90FD\\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"Index.UNKNOWN\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"memo\"}),\" \\u6570\\u7EC4\\u4E2D\\u7684\\u6700\\u540E\\u4E00\\u4E2A\\u4F4D\\u7F6E\\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"Index.GOOD\"}),\"\\uFF0C\\u56E0\\u4E3A\\u6700\\u540E\\u4E00\\u4E2A\\u4F4D\\u7F6E\\u53EF\\u4EE5\\u5F88\\u5BB9\\u6613\\u5730\\u5230\\u8FBE\\u5B83\\u81EA\\u5DF1\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u5012\\u6570\\u7B2C\\u4E8C\\u4E2A\\u4F4D\\u7F6E\\u5230\\u7B2C\\u4E00\\u4E2A\\u4F4D\\u7F6E\\u5411\\u540E\\u904D\\u5386\\u8F93\\u5165\\u6570\\u7EC4\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"i + numbers[i]\"}),\" \\u548C\\u6700\\u540E\\u4E00\\u4E2A\\u7D22\\u5F15\\u7684\\u6700\\u5C0F\\u503C\\u6765\\u8BA1\\u7B97\\u4ECE\\u5F53\\u524D\\u7D22\\u5F15\\u53EF\\u4EE5\\u5230\\u8FBE\\u7684\\u6700\\u8FDC\\u4F4D\\u7F6E\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u5F53\\u524D\\u7D22\\u5F15\\u548C\\u6700\\u8FDC\\u53EF\\u5230\\u8FBE\\u4F4D\\u7F6E\\u4E4B\\u95F4\\u7684\\u6240\\u6709\\u4F4D\\u7F6E\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u8FD9\\u4E9B\\u4F4D\\u7F6E\\u4E2D\\u7684\\u4EFB\\u4F55\\u4E00\\u4E2A\\u5728 \",(0,n.jsx)(e.code,{children:\"memo\"}),\" \\u4E2D\\u88AB\\u6807\\u8BB0\\u4E3A \",(0,n.jsx)(e.code,{children:\"Index.GOOD\"}),\"\\uFF0C\\u5219\\u5C06\\u5F53\\u524D\\u4F4D\\u7F6E\\u6807\\u8BB0\\u4E3A \",(0,n.jsx)(e.code,{children:\"Index.GOOD\"}),\" \\u5E76\\u4E2D\\u65AD\\u5185\\u5FAA\\u73AF\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u7B2C\\u4E00\\u4E2A\\u4F4D\\u7F6E\\u5728 \",(0,n.jsx)(e.code,{children:\"memo\"}),\" \\u4E2D\\u88AB\\u6807\\u8BB0\\u4E3A \",(0,n.jsx)(e.code,{children:\"Index.GOOD\"}),\"\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\uFF0C\\u8868\\u793A\\u53EF\\u4EE5\\u5230\\u8FBE\\u6700\\u540E\\u4E00\\u4E2A\\u4F4D\\u7F6E\\u3002\\u5426\\u5219\\uFF0C\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(c,{children:u}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,n.jsx)(\"sup\",{children:\"2\"}),\")\"]}),\"\\u3002\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u4F4D\\u7F6E\\uFF0C\\u5185\\u5FAA\\u73AF\\u68C0\\u67E5\\u6700\\u591A \",(0,n.jsx)(e.code,{children:\"numbers[i]\"}),\" \\u4E2A\\u4F4D\\u7F6E\\uFF0C\\u5BFC\\u81F4\\u6700\\u574F\\u60C5\\u51B5\\u4E0B\\u7684\\u4E8C\\u6B21\\u65B9\\u590D\\u6742\\u5EA6\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u5927\\u5C0F\\u4E3A \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u7684 \",(0,n.jsx)(e.code,{children:\"memo\"}),\" \\u6570\\u7EC4\\u7528\\u4E8E\\u52A8\\u6001\\u89C4\\u5212\\u5B58\\u50A8\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u81EA\\u9876\\u5411\\u4E0B\\u52A8\\u6001\\u89C4\\u5212\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8FD8\\u6709\\u53E6\\u4E00\\u79CD\\u81EA\\u9876\\u5411\\u4E0B\\u7684\\u52A8\\u6001\\u89C4\\u5212\\u65B9\\u6CD5\\uFF0C\\u8BE5\\u65B9\\u6CD5\\u4ECE\\u7B2C\\u4E00\\u4E2A\\u4F4D\\u7F6E\\u5F00\\u59CB\\uFF0C\\u5E76\\u4F7F\\u7528\\u9012\\u5F52\\u6765\\u786E\\u5B9A\\u540E\\u7EED\\u53EF\\u5230\\u8FBE\\u7684\\u4F4D\\u7F6E\\u662F\\u5426\\u53EF\\u4EE5\\u5230\\u8FBE\\u6700\\u540E\\u4E00\\u4E2A\\u4F4D\\u7F6E\\u3002\\u5907\\u5FD8\\u5F55\\u6570\\u7EC4\\u786E\\u4FDD\\u91CD\\u7528\\u5148\\u524D\\u8BA1\\u7B97\\u7684\\u7ED3\\u679C\\uFF0C\\u907F\\u514D\\u4E86\\u5197\\u4F59\\u8BA1\\u7B97\\u5E76\\u63D0\\u9AD8\\u4E86\\u6548\\u7387\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u4E0E\\u8F93\\u5165\\u6570\\u7EC4\\u957F\\u5EA6\\u76F8\\u540C\\u7684 \",(0,n.jsx)(e.code,{children:\"memo\"}),\" \\u6570\\u7EC4\\uFF0C\\u6240\\u6709\\u503C\\u90FD\\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"'UNKNOWN'\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"memo\"}),\" \\u6570\\u7EC4\\u4E2D\\u7684\\u6700\\u540E\\u4E00\\u4E2A\\u4F4D\\u7F6E\\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"'GOOD'\"}),\"\\uFF0C\\u56E0\\u4E3A\\u5B83\\u672C\\u8EAB\\u53EF\\u4EE5\\u8F7B\\u677E\\u5230\\u8FBE\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u8F85\\u52A9\\u51FD\\u6570 \",(0,n.jsx)(e.code,{children:\"canReachLastPosition\"}),\"\\uFF0C\\u5B83\\u5C06\\u5F53\\u524D\\u4F4D\\u7F6E\\u548C\\u8F93\\u5165\\u6570\\u7EC4\\u4F5C\\u4E3A\\u53C2\\u6570\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5F53\\u524D\\u4F4D\\u7F6E\\u5DF2\\u7ECF\\u5728 \",(0,n.jsx)(e.code,{children:\"memo\"}),\" \\u4E2D\\u6807\\u8BB0\\uFF0C\\u5219\\u8FD4\\u56DE\\u76F8\\u5E94\\u7684\\u7ED3\\u679C\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5F53\\u524D\\u4F4D\\u7F6E\\u7684\\u503C\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u5219\\u5C06\\u5176\\u6807\\u8BB0\\u4E3A \",(0,n.jsx)(e.code,{children:\"'BAD'\"}),\" \\u5E76\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\uFF0C\\u56E0\\u4E3A\\u5B83\\u65E0\\u6CD5\\u7EE7\\u7EED\\u524D\\u8FDB\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8BA1\\u7B97\\u4ECE\\u5F53\\u524D\\u4F4D\\u7F6E\\u53EF\\u4EE5\\u5230\\u8FBE\\u7684\\u6700\\u8FDC\\u4F4D\\u7F6E\\uFF0C\\u5373 \",(0,n.jsx)(e.code,{children:\"position + numbers[position]\"}),\" \\u548C\\u6700\\u540E\\u4E00\\u4E2A\\u7D22\\u5F15\\u7684\\u6700\\u5C0F\\u503C\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u5F53\\u524D\\u4F4D\\u7F6E\\u5411\\u540E\\u904D\\u5386\\u6240\\u6709\\u53EF\\u5230\\u8FBE\\u7684\\u4F4D\\u7F6E\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u4EFB\\u4F55\\u53EF\\u5230\\u8FBE\\u7684\\u4F4D\\u7F6E\\u662F \",(0,n.jsx)(e.code,{children:\"'GOOD'\"}),\"\\uFF0C\\u5219\\u5C06\\u5F53\\u524D\\u4F4D\\u7F6E\\u6807\\u8BB0\\u4E3A \",(0,n.jsx)(e.code,{children:\"'GOOD'\"}),\" \\u5E76\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u6CA1\\u6709\\u4EFB\\u4F55\\u53EF\\u5230\\u8FBE\\u7684\\u4F4D\\u7F6E\\u662F \",(0,n.jsx)(e.code,{children:\"'GOOD'\"}),\"\\uFF0C\\u5219\\u5C06\\u5F53\\u524D\\u4F4D\\u7F6E\\u6807\\u8BB0\\u4E3A \",(0,n.jsx)(e.code,{children:\"'BAD'\"}),\" \\u5E76\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u4F7F\\u7528\\u8F85\\u52A9\\u51FD\\u6570\\u4ECE\\u7B2C\\u4E00\\u4E2A\\u4F4D\\u7F6E\\u5F00\\u59CB\\u9012\\u5F52\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u7B2C\\u4E00\\u4E2A\\u4F4D\\u7F6E\\u662F \",(0,n.jsx)(e.code,{children:\"'GOOD'\"}),\"\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\uFF0C\\u8868\\u793A\\u53EF\\u4EE5\\u5230\\u8FBE\\u6700\\u540E\\u4E00\\u4E2A\\u4F4D\\u7F6E\\u3002\\u5426\\u5219\\uFF0C\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(c,{children:m}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,n.jsx)(\"sup\",{children:\"2\"}),\")\"]}),\"\\u3002\\u6700\\u574F\\u7684\\u60C5\\u51B5\\u6D89\\u53CA\\u68C0\\u67E5\\u6BCF\\u4E2A\\u7D22\\u5F15\\u7684\\u6240\\u6709\\u53EF\\u5230\\u8FBE\\u4F4D\\u7F6E\\uFF0C\\u5BFC\\u81F4\\u4E8C\\u6B21\\u65B9\\u590D\\u6742\\u5EA6\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u5927\\u5C0F\\u4E3A \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u7684 \",(0,n.jsx)(e.code,{children:\"memo\"}),\" \\u6570\\u7EC4\\u7528\\u4E8E\\u5B58\\u50A8\\u4E2D\\u95F4\\u7ED3\\u679C\\uFF0C\\u5E76\\u4E14\\u9012\\u5F52\\u5806\\u6808\\u53EF\\u80FD\\u8FBE\\u5230 \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u6B21\\u8C03\\u7528\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"3. \\u8D2A\\u5FC3\\u7B97\\u6CD5\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u5728\\u8D2A\\u5FC3\\u7B97\\u6CD5\\u4E2D\\uFF0C\\u7B97\\u6CD5\\u4ECE\\u6700\\u540E\\u4E00\\u4E2A\\u4F4D\\u7F6E\\u5F00\\u59CB\\u5E76\\u5411\\u540E\\u8FED\\u4EE3\\u3002\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u4F4D\\u7F6E\\uFF0C\\u5B83\\u68C0\\u67E5\\u5F53\\u524D\\u4F4D\\u7F6E\\u662F\\u5426\\u53EF\\u4EE5\\u5230\\u8FBE\\u6700\\u8FDC\\u7684\\u53EF\\u5230\\u8FBE\\u4F4D\\u7F6E\\u3002\\u5982\\u679C\\u53EF\\u4EE5\\uFF0C\\u5219\\u5C06\\u6700\\u8FDC\\u7684\\u53EF\\u5230\\u8FBE\\u4F4D\\u7F6E\\u66F4\\u65B0\\u4E3A\\u5F53\\u524D\\u4F4D\\u7F6E\\u3002\\u5982\\u679C\\u5728\\u5904\\u7406\\u5B8C\\u6574\\u4E2A\\u6570\\u7EC4\\u540E\\uFF0C\\u6700\\u8FDC\\u7684\\u53EF\\u5230\\u8FBE\\u4F4D\\u7F6E\\u53D8\\u4E3A\\u7B2C\\u4E00\\u4E2A\\u7D22\\u5F15\\uFF0C\\u5219\\u8868\\u793A\\u53EF\\u4EE5\\u5230\\u8FBE\\u6700\\u540E\\u4E00\\u4E2A\\u4F4D\\u7F6E\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u53D8\\u91CF \",(0,n.jsx)(e.code,{children:\"farthestReachable\"}),\" \\u521D\\u59CB\\u5316\\u4E3A\\u6570\\u7EC4\\u7684\\u6700\\u540E\\u4E00\\u4E2A\\u7D22\\u5F15 (\",(0,n.jsx)(e.code,{children:\"numbers.length - 1\"}),\")\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u6700\\u540E\\u4E00\\u4E2A\\u7D22\\u5F15\\u5F00\\u59CB\\u5411\\u540E\\u904D\\u5386\\u6570\\u7EC4\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u4F4D\\u7F6E\\uFF0C\\u68C0\\u67E5 \",(0,n.jsx)(e.code,{children:\"currentPosition + numbers[currentPosition]\"}),\" \\u662F\\u5426\\u5927\\u4E8E\\u6216\\u7B49\\u4E8E \",(0,n.jsx)(e.code,{children:\"farthestReachable\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u4E3A\\u771F\\uFF0C\\u5219\\u5C06 \",(0,n.jsx)(e.code,{children:\"farthestReachable\"}),\" \\u66F4\\u65B0\\u4E3A \",(0,n.jsx)(e.code,{children:\"currentPosition\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FED\\u4EE3\\u540E\\uFF0C\\u68C0\\u67E5 \",(0,n.jsx)(e.code,{children:\"farthestReachable\"}),\" \\u662F\\u5426\\u7B49\\u4E8E \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"farthestReachable\"}),\" \\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\uFF0C\\u8868\\u793A\\u53EF\\u4EE5\\u4ECE\\u7B2C\\u4E00\\u4E2A\\u4F4D\\u7F6E\\u5230\\u8FBE\\u6700\\u540E\\u4E00\\u4E2A\\u4F4D\\u7F6E\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5426\\u5219\\uFF0C\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(c,{children:s}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u4EE5\\u76F8\\u53CD\\u7684\\u987A\\u5E8F\\u904D\\u5386\\u6570\\u7EC4\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u9664\\u4E86\\u5E38\\u91CF\\u6570\\u91CF\\u7684\\u53D8\\u91CF\\u5916\\uFF0C\\u6CA1\\u6709\\u4F7F\\u7528\\u989D\\u5916\\u7684\\u7A7A\\u95F4\\u3002\"]}),`\n`]})]})}function w(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(f,r)})):f(r)}var B=w;return G(k);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/array-rotated-find/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/array-rotated-find/locales/zh-CN.json new file mode 100644 index 000000000..b195ad101 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/array-rotated-find/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var m=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var f=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),j=(r,e)=>{for(var t in e)i(r,t,{get:e[t],enumerable:!0})},d=(r,e,t,c)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let a of g(e))!b.call(r,a)&&a!==t&&i(r,a,{get:()=>e[a],enumerable:!(c=p(e,a))||c.enumerable});return r};var y=(r,e,t)=>(t=r!=null?m(x(r)):{},d(e||!r||!r.__esModule?i(t,\"default\",{value:r,enumerable:!0}):t,r)),_=r=>d(i({},\"__esModule\",{value:!0}),r);var o=f((v,l)=>{l.exports=_jsx_runtime});var D={};j(D,{default:()=>C,frontmatter:()=>M});var n=y(o());var s=MDXTestExamples;var h=[{input:[[\"numbers\",[0,1,2,3,4]],[\"target\",2]],output:2,explanation:\"The original array [0,1,2,3,4] was rotated 0 times and 2 is present at 2nd index in given array\"},{input:[[\"numbers\",[2,3,4,0,1]],[\"target\",0]],output:3,explanation:\"The original array [0,1,2,3,4] was rotated 3 times and became [2,3,4,0,1]. 0 is present at 3rd index in given array\"},{input:[[\"numbers\",[4]],[\"target\",2]],output:-1,explanation:\"The original array [4] was rotated 0 times and became [4]. 2 is not present in the given array\"}];var M={title:\"\\u5728\\u65CB\\u8F6C\\u6570\\u7EC4\\u4E2D\\u67E5\\u627E\\u5143\\u7D20\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u5728\\u65CB\\u8F6C\\u6392\\u5E8F\\u6570\\u7EC4\\u4E2D\\u67E5\\u627E\\u4E00\\u4E2A\\u6574\\u6570\"};function u(r){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u5305\\u542B\\u552F\\u4E00\\u5143\\u7D20\\u7684\\u5DF2\\u6392\\u5E8F\\u548C\\u65CB\\u8F6C\\u7684\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"numbers\"}),\" \\u548C\\u4E00\\u4E2A\\u6574\\u6570 \",(0,n.jsx)(e.code,{children:\"target\"}),\"\\uFF0C\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"target\"}),\" \\u5728 \",(0,n.jsx)(e.code,{children:\"numbers\"}),\" \\u4E2D\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"target\"}),\" \\u7684\\u7D22\\u5F15\\uFF0C\\u5982\\u679C\\u4E0D\\u5728\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"-1\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5C06\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"[a[0], a[1], a[2], ..., a[n-1]]\"}),\" \\u65CB\\u8F6C\\u4E00\\u6B21\\u4F1A\\u5F97\\u5230 \",(0,n.jsx)(e.code,{children:\"[a[n-1], a[0], a[1], a[2], ..., a[n-2]]\"}),\"\\u3002\\u5C06\\u5176\\u65CB\\u8F6C\\u7B2C\\u4E8C\\u6B21\\u4F1A\\u5F97\\u5230 \",(0,n.jsx)(e.code,{children:\"[a[n-2], a[n-1], a[0], a[1], ..., a[n-3]]\"}),\"\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u5F00\\u53D1\\u4E00\\u4E2A\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(log n) \\u7684\\u7B97\\u6CD5\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"numbers: number[]\"}),\": \\u6574\\u6570\\u6570\\u7EC4\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"target: number\"}),\": \\u6574\\u6570\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u6CE8\\u610F\\u4E8B\\u9879\"}),`\n`,(0,n.jsx)(s,{testCases:h}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"numbers.length\"}),\" <= 1000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"-10,000 <= \",(0,n.jsx)(e.code,{children:\"numbers[i]\"}),\" <= 10,000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"-10,000 <= \",(0,n.jsx)(e.code,{children:\"target\"}),\" <= 10,000\"]}),`\n`]})]})}function w(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(u,r)})):u(r)}var C=w;return _(D);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,在旋转排序数组中查找一个整数", + "title": "在旋转数组中查找元素" + }, + "solution": "var Component=(()=>{var g=Object.create;var h=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty;var x=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),v=(i,e)=>{for(var r in e)h(i,r,{get:e[r],enumerable:!0})},c=(i,e,r,t)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let l of b(e))!p.call(i,l)&&l!==r&&h(i,l,{get:()=>e[l],enumerable:!(t=f(e,l))||t.enumerable});return i};var y=(i,e,r)=>(r=i!=null?g(w(i)):{},c(e||!i||!i.__esModule?h(r,\"default\",{value:i,enumerable:!0}):r,i)),I=i=>c(h({},\"__esModule\",{value:!0}),i);var m=x((_,o)=>{o.exports=_jsx_runtime});var P={};v(P,{default:()=>C});var n=y(m());var d=MDXCodeBlock;var a=`export default function findInRotatedArray(\n numbers: number[],\n target: number,\n): number {\n let low: number = 0;\n let high: number = numbers.length - 1;\n\n while (low <= high) {\n let mid: number = Math.floor((low + high) / 2);\n\n // Check if the middle element is the target value\n if (numbers[mid] === target) {\n return mid;\n }\n\n // Determine if the left half of the array is sorted\n if (numbers[low] <= numbers[mid]) {\n // Check if the target is within the sorted left half\n if (numbers[low] <= target && target <= numbers[mid]) {\n // If target is in the left half, adjust the search range to exclude the right half\n high = mid - 1;\n } else {\n // If target is not in the left half, adjust to search in the right half\n low = mid + 1;\n }\n } else {\n // The right half must be sorted\n // Check if the target is within the sorted right half\n if (target <= numbers[high] && target >= numbers[mid]) {\n // If target is in the right half, adjust the search range to exclude the left half\n low = mid + 1;\n } else {\n // If target is not in the right half, adjust to search in the left half\n high = mid - 1;\n }\n }\n }\n\n // If we exit the loop, it means the target was not found in the array\n // Return -1 to indicate that the target is not present\n return -1;\n}\n`;var s=`export default function findInRotatedArray(\n numbers: number[],\n target: number,\n): number {\n // Helper function to find the pivot index\n function findPivotIndex(nums: number[]): number {\n let low = 0;\n let high = nums.length - 1;\n\n while (low < high) {\n let mid = Math.floor((low + high) / 2);\n\n // Pivot point is where the rotation happens; find the smallest element\n if (nums[mid] > nums[high]) {\n low = mid + 1;\n } else {\n high = mid;\n }\n }\n return low; // Pivot index where the smallest element is located\n }\n\n // Helper function to perform binary search\n function binarySearch(\n nums: number[],\n target: number,\n low: number,\n high: number,\n ): number {\n while (low <= high) {\n let mid = Math.floor((low + high) / 2);\n\n if (nums[mid] === target) {\n return mid;\n } else if (nums[mid] < target) {\n low = mid + 1;\n } else {\n high = mid - 1;\n }\n }\n return -1; // Target not found\n }\n\n const n = numbers.length;\n if (n === 0) return -1;\n\n const pivot = findPivotIndex(numbers);\n\n // Decide which part of the array to search\n if (numbers[pivot] <= target && target <= numbers[n - 1]) {\n // Search in the right (rotated) half\n return binarySearch(numbers, target, pivot, n - 1);\n } else {\n // Search in the left (non-rotated) half\n return binarySearch(numbers, target, 0, pivot - 1);\n }\n}\n`;function u(i){let e=Object.assign({h2:\"h2\",p:\"p\",h3:\"h3\",ol:\"ol\",li:\"li\",code:\"code\",ul:\"ul\",strong:\"strong\"},i.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u67A2\\u8F74\\u7D22\\u5F15\\u548C\\u4E8C\\u5206\\u67E5\\u627E\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u901A\\u8FC7\\u7ED3\\u5408\\u4E24\\u79CD\\u6709\\u6548\\u6280\\u672F\\u6765\\u89E3\\u51B3\\u5728\\u65CB\\u8F6C\\u6392\\u5E8F\\u6570\\u7EC4\\u4E2D\\u67E5\\u627E\\u76EE\\u6807\\u7684\\u95EE\\u9898\\uFF1A\\u8BC6\\u522B\\u67A2\\u8F74\\u7D22\\u5F15\\u548C\\u6267\\u884C\\u4E8C\\u5206\\u67E5\\u627E\\u3002 \\u5728\\u6734\\u7D20\\u65B9\\u6CD5\\u4E2D\\uFF0C\\u7EBF\\u6027\\u626B\\u63CF\\u6574\\u4E2A\\u6570\\u7EC4\\u662F\\u4E3B\\u8981\\u7684\\u74F6\\u9888\\uFF0C\\u56E0\\u4E3A\\u5B83\\u5BFC\\u81F4\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(n)\\u3002 \\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u901A\\u8FC7\\u4F7F\\u7528\\u6570\\u7EC4\\u5DF2\\u6392\\u5E8F\\u4F46\\u5DF2\\u65CB\\u8F6C\\u7684\\u4E8B\\u5B9E\\u6765\\u6D88\\u9664\\u4E0D\\u5FC5\\u8981\\u7684\\u5DE5\\u4F5C\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u7B2C\\u4E00\\u6B65\\u662F\\u627E\\u5230\\u67A2\\u8F74\\u7D22\\u5F15\\uFF0C\\u5B83\\u662F\\u6570\\u7EC4\\u4E2D\\u6700\\u5C0F\\u7684\\u5143\\u7D20\\u3002 \\u8BE5\\u7D22\\u5F15\\u4E5F\\u8868\\u793A\\u6392\\u5E8F\\u6570\\u7EC4\\u88AB\\u5206\\u6210\\u4E24\\u4E2A\\u5B50\\u6570\\u7EC4\\u7684\\u65CB\\u8F6C\\u70B9\\u3002 \\u77E5\\u9053\\u8FD9\\u4E2A\\u67A2\\u8F74\\u7D22\\u5F15\\u6709\\u52A9\\u4E8E\\u786E\\u5B9A\\u8981\\u641C\\u7D22\\u76EE\\u6807\\u7684\\u6570\\u7EC4\\u90E8\\u5206\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u786E\\u5B9A\\u67A2\\u8F74\\u7D22\\u5F15\\u540E\\uFF0C\\u4F7F\\u7528\\u4E8C\\u5206\\u67E5\\u627E\\u6765\\u6709\\u6548\\u5730\\u641C\\u7D22\\u76EE\\u6807\\u3002 \\u641C\\u7D22\\u7A7A\\u95F4\\u6839\\u636E\\u76EE\\u6807\\u76F8\\u5BF9\\u4E8E\\u67A2\\u8F74\\u7684\\u503C\\u8FDB\\u884C\\u5212\\u5206\\u3002 \\u8FD9\\u5141\\u8BB8\\u4EC5\\u5173\\u6CE8\\u6570\\u7EC4\\u7684\\u76F8\\u5173\\u4E00\\u534A\\u3002 \\u4F7F\\u7528\\u4E8C\\u5206\\u67E5\\u627E\\u5C06\\u603B\\u8FD0\\u884C\\u65F6\\u95F4\\u4ECE O(n) \\u51CF\\u5C11\\u5230 O(log n)\\uFF0C\\u4F7F\\u89E3\\u51B3\\u65B9\\u6848\\u8FBE\\u5230\\u6700\\u4F73\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u8F85\\u52A9\\u51FD\\u6570 \",(0,n.jsx)(e.code,{children:\"findPivotIndex\"}),\" \\u6765\\u5B9A\\u4F4D\\u6570\\u7EC4\\u65CB\\u8F6C\\u7684\\u67A2\\u8F74\\u70B9\\u3002\"]}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5206\\u522B\\u5728\\u6570\\u7EC4\\u7684\\u5F00\\u5934\\u548C\\u7ED3\\u5C3E\\u521D\\u59CB\\u5316\\u4E24\\u4E2A\\u6307\\u9488 \",(0,n.jsx)(e.code,{children:\"low\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"high\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u5FAA\\u73AF\\u8C03\\u6574\\u6307\\u9488\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8BA1\\u7B97\\u4E2D\\u95F4\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"mid\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"numbers[mid]\"}),\" \\u5927\\u4E8E \",(0,n.jsx)(e.code,{children:\"numbers[high]\"}),\"\\uFF0C\\u5219\\u67A2\\u8F74\\u5728\\u53F3\\u4FA7\\u3002 \\u5C06 \",(0,n.jsx)(e.code,{children:\"low\"}),\" \\u66F4\\u65B0\\u4E3A \",(0,n.jsx)(e.code,{children:\"mid + 1\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5426\\u5219\\uFF0C\\u67A2\\u8F74\\u5728\\u5DE6\\u4FA7\\u6216\\u5728 \",(0,n.jsx)(e.code,{children:\"mid\"}),\" \\u5904\\u3002 \\u5C06 \",(0,n.jsx)(e.code,{children:\"high\"}),\" \\u66F4\\u65B0\\u4E3A \",(0,n.jsx)(e.code,{children:\"mid\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5F53\\u5FAA\\u73AF\\u7ED3\\u675F\\u65F6\\uFF0C\",(0,n.jsx)(e.code,{children:\"low\"}),\" \\u6307\\u5411\\u67A2\\u8F74\\u7D22\\u5F15\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u8F85\\u52A9\\u51FD\\u6570 \",(0,n.jsx)(e.code,{children:\"binarySearch\"}),\" \\u4EE5\\u5728\\u6392\\u5E8F\\u7684\\u5B50\\u6570\\u7EC4\\u4E2D\\u641C\\u7D22\\u76EE\\u6807\\u3002\"]}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"low\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"high\"}),\" \\u6307\\u9488\\u521D\\u59CB\\u5316\\u4E3A\\u5B50\\u6570\\u7EC4\\u7684\\u5F00\\u5934\\u548C\\u7ED3\\u5C3E\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u5FAA\\u73AF\\u6267\\u884C\\u4E8C\\u5206\\u67E5\\u627E\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8BA1\\u7B97\\u4E2D\\u95F4\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"mid\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"numbers[mid]\"}),\" \\u4E0E\\u76EE\\u6807\\u5339\\u914D\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"mid\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"numbers[mid]\"}),\" \\u5C0F\\u4E8E\\u76EE\\u6807\\uFF0C\\u5219\\u5C06 \",(0,n.jsx)(e.code,{children:\"low\"}),\" \\u8C03\\u6574\\u4E3A \",(0,n.jsx)(e.code,{children:\"mid + 1\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5426\\u5219\\uFF0C\\u5C06 \",(0,n.jsx)(e.code,{children:\"high\"}),\" \\u8C03\\u6574\\u4E3A \",(0,n.jsx)(e.code,{children:\"mid - 1\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5FAA\\u73AF\\u7ED3\\u675F\\u65F6\\u672A\\u627E\\u5230\\u76EE\\u6807\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"-1\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"findPivotIndex\"}),\" \\u627E\\u5230\\u67A2\\u8F74\\u7D22\\u5F15\\u3002\"]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[`\n`,(0,n.jsx)(e.p,{children:\"\\u6839\\u636E\\u76EE\\u6807\\u51B3\\u5B9A\\u641C\\u7D22\\u6570\\u7EC4\\u7684\\u54EA\\u4E00\\u90E8\\u5206\\u3002\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u76EE\\u6807\\u4F4D\\u4E8E\\u65CB\\u8F6C\\u90E8\\u5206\\u7684\\u8303\\u56F4\\u5185\\uFF08\\u4ECE \",(0,n.jsx)(e.code,{children:\"pivot\"}),\" \\u5230\\u6570\\u7EC4\\u7684\\u672B\\u5C3E\\uFF09\\uFF0C\\u5219\\u5BF9\\u8BE5\\u90E8\\u5206\\u6267\\u884C\\u4E8C\\u5206\\u67E5\\u627E\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5426\\u5219\\uFF0C\\u5BF9\\u975E\\u65CB\\u8F6C\\u90E8\\u5206\\uFF08\\u4ECE\\u6570\\u7EC4\\u7684\\u5F00\\u5934\\u5230 \",(0,n.jsx)(e.code,{children:\"pivot - 1\"}),\"\\uFF09\\u6267\\u884C\\u4E8C\\u5206\\u67E5\\u627E\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[`\n`,(0,n.jsx)(e.p,{children:\"\\u8FD4\\u56DE\\u4E8C\\u5206\\u67E5\\u627E\\u7684\\u7ED3\\u679C\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(d,{children:s}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(log n)\"}),\"\\u3002 \\u67A2\\u8F74\\u67E5\\u627E\\u64CD\\u4F5C\\u548C\\u4E8C\\u5206\\u67E5\\u627E\\u90FD\\u82B1\\u8D39 O(log n) \\u65F6\\u95F4\\uFF0C\\u5BFC\\u81F4\\u603B\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(log n)\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002 \\u8BE5\\u7B97\\u6CD5\\u5728\\u6052\\u5B9A\\u7A7A\\u95F4\\u4E2D\\u8FD0\\u884C\\uFF0C\\u4EC5\\u4F7F\\u7528\\u51E0\\u4E2A\\u53D8\\u91CF\\u8FDB\\u884C\\u6307\\u9488\\u64CD\\u4F5C\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u4FEE\\u6539\\u540E\\u7684\\u4E8C\\u5206\\u67E5\\u627E\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u7ED9\\u5B9A\\u7684\\u89E3\\u51B3\\u65B9\\u6848\\u901A\\u8FC7\\u6D88\\u9664\\u663E\\u5F0F\\u7684\\u67A2\\u8F74\\u7D22\\u5F15\\u8BA1\\u7B97\\u6765\\u6539\\u8FDB\\u4E4B\\u524D\\u7684\\u65B9\\u6848\\u3002 \\u8BE5\\u65B9\\u6CD5\\u6CA1\\u6709\\u5C06\\u6570\\u7EC4\\u5206\\u6210\\u4E24\\u90E8\\u5206\\u5E76\\u6267\\u884C\\u4E24\\u4E2A\\u5355\\u72EC\\u7684\\u4E8C\\u5206\\u67E5\\u627E\\uFF0C\\u800C\\u662F\\u4F7F\\u7528\\u4E00\\u4E2A\\u4E8C\\u5206\\u67E5\\u627E\\uFF0C\\u5E76\\u6DFB\\u52A0\\u4E86\\u989D\\u5916\\u7684\\u903B\\u8F91\\u6765\\u5904\\u7406\\u65CB\\u8F6C\\u6392\\u5E8F\\u6570\\u7EC4\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u5173\\u952E\\u7684\\u89C1\\u89E3\\u662F\\uFF0C\\u5728\\u65CB\\u8F6C\\u6392\\u5E8F\\u6570\\u7EC4\\u4E2D\\uFF0C\\u6570\\u7EC4\\u7684\\u81F3\\u5C11\\u4E00\\u534A\\uFF08\\u5DE6\\u4FA7\\u6216\\u53F3\\u4FA7\\uFF09\\u59CB\\u7EC8\\u5DF2\\u6392\\u5E8F\\u3002 \\u901A\\u8FC7\\u5728\\u6BCF\\u4E00\\u6B65\\u68C0\\u67E5\\u54EA\\u4E00\\u534A\\u5DF2\\u6392\\u5E8F\\uFF0C\\u8BE5\\u7B97\\u6CD5\\u786E\\u5B9A\\u76EE\\u6807\\u662F\\u5426\\u4F4D\\u4E8E\\u5DF2\\u6392\\u5E8F\\u7684\\u8303\\u56F4\\u5185\\u3002 \\u5982\\u679C\\u662F\\uFF0C\\u5219\\u8C03\\u6574\\u641C\\u7D22\\u8303\\u56F4\\u4EE5\\u6392\\u9664\\u672A\\u6392\\u5E8F\\u7684\\u4E00\\u534A\\u3002 \\u5426\\u5219\\uFF0C\\u641C\\u7D22\\u5C06\\u7EE7\\u7EED\\u5728\\u672A\\u6392\\u5E8F\\u7684\\u4E00\\u534A\\u4E2D\\u8FDB\\u884C\\u3002 \\u8FD9\\u79CD\\u65B9\\u6CD5\\u907F\\u514D\\u4E86\\u663E\\u5F0F\\u67E5\\u627E\\u67A2\\u8F74\\u7D22\\u5F15\\u7684\\u5F00\\u9500\\uFF0C\\u76F4\\u63A5\\u7F29\\u5C0F\\u4E86\\u641C\\u7D22\\u7A7A\\u95F4\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5206\\u522B\\u5C06\\u4E24\\u4E2A\\u6307\\u9488 \",(0,n.jsx)(e.code,{children:\"low\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"high\"}),\" \\u521D\\u59CB\\u5316\\u4E3A\\u6570\\u7EC4\\u7684\\u5F00\\u5934\\u548C\\u7ED3\\u5C3E\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u5FAA\\u73AF\\u6267\\u884C\\u4E8C\\u5206\\u67E5\\u627E\\uFF0C\\u5F53 \",(0,n.jsx)(e.code,{children:\"low\"}),\" \\u5C0F\\u4E8E\\u6216\\u7B49\\u4E8E \",(0,n.jsx)(e.code,{children:\"high\"}),\" \\u65F6\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u4E2D\\u95F4\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"mid\"}),\" \\u8BA1\\u7B97\\u4E3A \",(0,n.jsx)(e.code,{children:\"low\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"high\"}),\" \\u7684\\u5E73\\u5747\\u503C\\u7684\\u4E0B\\u9650\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"numbers[mid]\"}),\" \\u7B49\\u4E8E\\u76EE\\u6807\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"mid\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u6BD4\\u8F83 \",(0,n.jsx)(e.code,{children:\"numbers[low]\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"numbers[mid]\"}),\" \\u6765\\u786E\\u5B9A\\u6570\\u7EC4\\u7684\\u5DE6\\u534A\\u90E8\\u5206\\u662F\\u5426\\u5DF2\\u6392\\u5E8F\\u3002\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5DE6\\u534A\\u90E8\\u5206\\u5DF2\\u6392\\u5E8F\\uFF0C\\u8BF7\\u68C0\\u67E5\\u76EE\\u6807\\u662F\\u5426\\u4F4D\\u4E8E\\u6B64\\u8303\\u56F4\\u5185\\u3002 \\u5982\\u679C\\u662F\\uFF0C\\u5219\\u5C06 \",(0,n.jsx)(e.code,{children:\"high\"}),\" \\u8C03\\u6574\\u4E3A \",(0,n.jsx)(e.code,{children:\"mid - 1\"}),\"\\u3002 \\u5426\\u5219\\uFF0C\\u5C06 \",(0,n.jsx)(e.code,{children:\"low\"}),\" \\u8C03\\u6574\\u4E3A \",(0,n.jsx)(e.code,{children:\"mid + 1\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5DE6\\u534A\\u90E8\\u5206\\u672A\\u6392\\u5E8F\\uFF0C\\u5219\\u53F3\\u534A\\u90E8\\u5206\\u5FC5\\u987B\\u5DF2\\u6392\\u5E8F\\u3002 \\u68C0\\u67E5\\u76EE\\u6807\\u662F\\u5426\\u4F4D\\u4E8E\\u6B64\\u8303\\u56F4\\u5185\\u3002 \\u5982\\u679C\\u662F\\uFF0C\\u5219\\u5C06 \",(0,n.jsx)(e.code,{children:\"low\"}),\" \\u8C03\\u6574\\u4E3A \",(0,n.jsx)(e.code,{children:\"mid + 1\"}),\"\\u3002 \\u5426\\u5219\\uFF0C\\u5C06 \",(0,n.jsx)(e.code,{children:\"high\"}),\" \\u8C03\\u6574\\u4E3A \",(0,n.jsx)(e.code,{children:\"mid - 1\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5FAA\\u73AF\\u7ED3\\u675F\\u65F6\\u672A\\u627E\\u5230\\u76EE\\u6807\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"-1\"}),\" \\u4EE5\\u6307\\u793A\\u76EE\\u6807\\u4E0D\\u5B58\\u5728\\u4E8E\\u6570\\u7EC4\\u4E2D\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(d,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(log n)\"}),\"\\u3002 \\u4E8C\\u5206\\u67E5\\u627E\\u5728\\u6BCF\\u4E00\\u6B65\\u5C06\\u641C\\u7D22\\u7A7A\\u95F4\\u51CF\\u534A\\uFF0C\\u4ECE\\u800C\\u4EA7\\u751F\\u5BF9\\u6570\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002 \\u8BE5\\u7B97\\u6CD5\\u4F7F\\u7528\\u6052\\u5B9A\\u91CF\\u7684\\u989D\\u5916\\u7A7A\\u95F4\\u7528\\u4E8E\\u53D8\\u91CF\\uFF0C\\u56E0\\u4E3A\\u5B83\\u76F4\\u63A5\\u5BF9\\u8F93\\u5165\\u6570\\u7EC4\\u8FDB\\u884C\\u64CD\\u4F5C\\u3002\"]}),`\n`]})]})}function M(i={}){let{wrapper:e}=i.components||{};return e?(0,n.jsx)(e,Object.assign({},i,{children:(0,n.jsx)(u,i)})):u(i)}var C=M;return I(P);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/array-smallest-in-rotated/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/array-smallest-in-rotated/locales/zh-CN.json new file mode 100644 index 000000000..fdd354e5e --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/array-smallest-in-rotated/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var m=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var f=(t,n)=>()=>(n||t((n={exports:{}}).exports,n),n.exports),j=(t,n)=>{for(var r in n)i(t,r,{get:n[r],enumerable:!0})},l=(t,n,r,o)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let a of x(n))!g.call(t,a)&&a!==r&&i(t,a,{get:()=>n[a],enumerable:!(o=p(n,a))||o.enumerable});return t};var _=(t,n,r)=>(r=t!=null?m(b(t)):{},l(n||!t||!t.__esModule?i(r,\"default\",{value:t,enumerable:!0}):r,t)),T=t=>l(i({},\"__esModule\",{value:!0}),t);var c=f((O,s)=>{s.exports=_jsx_runtime});var D={};j(D,{default:()=>C,frontmatter:()=>w});var e=_(c());var d=MDXTestExamples;var u=[{input:[[\"numbers\",[1,2,3,4]]],output:1,explanation:\"The original array [1,2,3,4] was rotated 0 times\"},{input:[[\"numbers\",[3,4,1,2]]],output:1,explanation:\"The original array [1,2,3,4] was rotated 2 times\"},{input:[[\"numbers\",[6,7,8,-5,-4,2]]],output:-5,explanation:\"The original array [-5,-4,2,6,7,8] was rotated 3 times.\"}];var w={title:\"\\u65CB\\u8F6C\\u6392\\u5E8F\\u6570\\u7EC4\\u4E2D\\u7684\\u6700\\u5C0F\\u5143\\u7D20\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u627E\\u5230\\u65CB\\u8F6C\\u6392\\u5E8F\\u6570\\u7EC4\\u4E2D\\u7684\\u6700\\u5C0F\\u5143\\u7D20\"};function h(t){let n=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)(n.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u5305\\u542B\\u552F\\u4E00\\u5143\\u7D20\\u7684\\u5DF2\\u6392\\u5E8F\\u548C\\u65CB\\u8F6C\\u7684\\u6570\\u7EC4 \",(0,e.jsx)(n.code,{children:\"numbers\"}),\"\\uFF0C\\u627E\\u5230\\u5E76\\u8FD4\\u56DE\\u8BE5\\u6570\\u7EC4\\u4E2D\\u7684\\u6700\\u5C0F\\u5143\\u7D20\\u3002\"]}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u65CB\\u8F6C\\u6570\\u7EC4 \",(0,e.jsx)(n.code,{children:\"[a[0], a[1], a[2], ..., a[n-1]]\"}),\" \\u4E00\\u6B21\\u4F1A\\u5F97\\u5230 \",(0,e.jsx)(n.code,{children:\"[a[n-1], a[0], a[1], a[2], ..., a[n-2]]\"}),\"\\u3002\\u518D\\u6B21\\u65CB\\u8F6C\\u4F1A\\u5F97\\u5230 \",(0,e.jsx)(n.code,{children:\"[a[n-2], a[n-1], a[0], a[1], ..., a[n-3]]\"}),\"\\u3002\"]}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5F00\\u53D1\\u4E00\\u4E2A\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(log n) \\u7684\\u7B97\\u6CD5\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"numbers: number[]\"}),\": \\u6574\\u6570\\u6570\\u7EC4\"]}),`\n`]}),`\n`,(0,e.jsx)(d,{testCases:u}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"1 <= \",(0,e.jsx)(n.code,{children:\"numbers.length\"}),\" <= 1000\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"-10,000 <= \",(0,e.jsx)(n.code,{children:\"numbers[i]\"}),\" <= 10,000\"]}),`\n`]})]})}function y(t={}){let{wrapper:n}=t.components||{};return n?(0,e.jsx)(n,Object.assign({},t,{children:(0,e.jsx)(h,t)})):h(t)}var C=y;return T(D);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,找到旋转排序数组中的最小元素", + "title": "旋转排序数组中的最小元素" + }, + "solution": "var Component=(()=>{var u=Object.create;var t=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var w=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),x=(i,e)=>{for(var l in e)t(i,l,{get:e[l],enumerable:!0})},h=(i,e,l,d)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of g(e))!b.call(i,r)&&r!==l&&t(i,r,{get:()=>e[r],enumerable:!(d=f(e,r))||d.enumerable});return i};var _=(i,e,l)=>(l=i!=null?u(p(i)):{},h(e||!i||!i.__esModule?t(l,\"default\",{value:i,enumerable:!0}):l,i)),M=i=>h(t({},\"__esModule\",{value:!0}),i);var c=w((C,o)=>{o.exports=_jsx_runtime});var E={};x(E,{default:()=>A});var n=_(c());var s=MDXCodeBlock;var m=`export default function smallestInRotatedArray(numbers: number[]): number {\n // Initialize variables to store starting and ending indices for searching\n let low = 0;\n let high = numbers.length - 1;\n\n // Initialize a variable to store the minimum element found so far\n let ans = Number.MAX_SAFE_INTEGER;\n\n // Iterate while the search space (low <= high) exists\n while (low <= high) {\n // Calculate the middle index (avoiding potential overflow)\n const mid = Math.floor((low + high) / 2);\n\n // Check if the left part of the array is sorted (nums[low] <= nums[mid])\n if (numbers[low] <= numbers[mid]) {\n // If left part is sorted, the minimum element could be there\n ans = Math.min(ans, numbers[low]); // Update minimum if a smaller element is found\n\n // Since the left part is sorted, eliminate it from the search space\n low = mid + 1;\n } else {\n // If the left part is not sorted, the right part must be sorted\n // The minimum element must be in the right half of the array\n ans = Math.min(ans, numbers[mid]); // Update minimum if a smaller element is found\n\n // Eliminate the right half from the search space\n high = mid - 1;\n }\n }\n\n // After the loop, the minimum element is stored in 'ans'\n return ans;\n}\n`;function a(i){let e=Object.assign({h2:\"h2\",p:\"p\",h3:\"h3\",ol:\"ol\",li:\"li\",code:\"code\",ul:\"ul\",strong:\"strong\"},i.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u4FEE\\u6539\\u540E\\u7684\\u4E8C\\u5206\\u67E5\\u627E\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u95EE\\u9898\\u662F\\u5728\\u65CB\\u8F6C\\u6392\\u5E8F\\u6570\\u7EC4\\u4E2D\\u4F7F\\u7528\\u4FEE\\u6539\\u540E\\u7684\\u4E8C\\u5206\\u67E5\\u627E\\u65B9\\u6CD5\\u627E\\u5230\\u6700\\u5C0F\\u7684\\u5143\\u7D20\\u3002\\u66B4\\u529B\\u89E3\\u6CD5\\u5C06\\u904D\\u5386\\u6570\\u7EC4\\u4EE5\\u5728 O(n) \\u65F6\\u95F4\\u5185\\u627E\\u5230\\u6700\\u5C0F\\u5143\\u7D20\\u3002\\u4F46\\u662F\\uFF0C\\u53EF\\u4EE5\\u5229\\u7528\\u6570\\u7EC4\\u7684\\u6392\\u5E8F\\u6027\\u8D28\\uFF0C\\u4F7F\\u7528\\u4E8C\\u5206\\u67E5\\u627E\\u5C06\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u964D\\u4F4E\\u5230 O(log n)\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u5173\\u952E\\u7684\\u89C1\\u89E3\\u662F\\uFF0C\\u5728\\u65CB\\u8F6C\\u6392\\u5E8F\\u6570\\u7EC4\\u4E2D\\uFF0C\\u6570\\u7EC4\\u7684\\u4E00\\u90E8\\u5206\\u59CB\\u7EC8\\u662F\\u6709\\u5E8F\\u7684\\u3002\\u901A\\u8FC7\\u68C0\\u67E5\\u54EA\\u4E00\\u90E8\\u5206\\u662F\\u6709\\u5E8F\\u7684\\uFF0C\\u53EF\\u4EE5\\u6709\\u6548\\u5730\\u7F29\\u5C0F\\u641C\\u7D22\\u7A7A\\u95F4\\u3002\\u8BE5\\u7B97\\u6CD5\\u8FED\\u4EE3\\u5730\\u51CF\\u5C11\\u641C\\u7D22\\u7A7A\\u95F4\\uFF0C\\u540C\\u65F6\\u8DDF\\u8E2A\\u5230\\u76EE\\u524D\\u4E3A\\u6B62\\u9047\\u5230\\u7684\\u6700\\u5C0F\\u5143\\u7D20\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u901A\\u8FC7\\u4EC5\\u5173\\u6CE8\\u53EF\\u80FD\\u5305\\u542B\\u6700\\u5C0F\\u5143\\u7D20\\u7684\\u90E8\\u5206\\u6570\\u7EC4\\u6765\\u6D88\\u9664\\u4E0D\\u5FC5\\u8981\\u7684\\u8FED\\u4EE3\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"low\"}),\" \\u521D\\u59CB\\u5316\\u4E3A 0\\uFF0C\\u5C06 \",(0,n.jsx)(e.code,{children:\"high\"}),\" \\u521D\\u59CB\\u5316\\u4E3A \",(0,n.jsx)(e.code,{children:\"numbers.length - 1\"}),\"\\uFF0C\\u4EE5\\u8868\\u793A\\u641C\\u7D22\\u7A7A\\u95F4\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"ans\"}),\" \\u521D\\u59CB\\u5316\\u4E3A \",(0,n.jsx)(e.code,{children:\"Number.MAX_SAFE_INTEGER\"}),\"\\uFF0C\\u4EE5\\u5B58\\u50A8\\u5230\\u76EE\\u524D\\u4E3A\\u6B62\\u627E\\u5230\\u7684\\u6700\\u5C0F\\u5143\\u7D20\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u5FAA\\u73AF \",(0,n.jsx)(e.code,{children:\"while low <= high\"}),\":\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"mid\"}),\" \\u8BA1\\u7B97\\u4E3A \",(0,n.jsx)(e.code,{children:\"(low + high) / 2\"}),\" \\u7684\\u5411\\u4E0B\\u53D6\\u6574\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u6BD4\\u8F83 \",(0,n.jsx)(e.code,{children:\"numbers[low]\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"numbers[mid]\"}),\" \\u6765\\u68C0\\u67E5\\u6570\\u7EC4\\u7684\\u5DE6\\u534A\\u90E8\\u5206\\u662F\\u5426\\u5DF2\\u6392\\u5E8F\\u3002\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5DE6\\u534A\\u90E8\\u5206\\u5DF2\\u6392\\u5E8F:\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"ans\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"numbers[low]\"}),\" \\u4E2D\\u8F83\\u5C0F\\u7684\\u503C\\u66F4\\u65B0 \",(0,n.jsx)(e.code,{children:\"ans\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u5C06 \",(0,n.jsx)(e.code,{children:\"low\"}),\" \\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"mid + 1\"}),\" \\u6765\\u6D88\\u9664\\u5DE6\\u534A\\u90E8\\u5206\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5426\\u5219\\uFF0C\\u53F3\\u534A\\u90E8\\u5206\\u5FC5\\u987B\\u5DF2\\u6392\\u5E8F:\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"ans\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"numbers[mid]\"}),\" \\u4E2D\\u8F83\\u5C0F\\u7684\\u503C\\u66F4\\u65B0 \",(0,n.jsx)(e.code,{children:\"ans\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u5C06 \",(0,n.jsx)(e.code,{children:\"high\"}),\" \\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"mid - 1\"}),\" \\u6765\\u6D88\\u9664\\u53F3\\u534A\\u90E8\\u5206\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5FAA\\u73AF\\u7ED3\\u675F\\u540E\\uFF0C\\u5C06 \",(0,n.jsx)(e.code,{children:\"ans\"}),\" \\u4F5C\\u4E3A\\u6570\\u7EC4\\u4E2D\\u7684\\u6700\\u5C0F\\u5143\\u7D20\\u8FD4\\u56DE\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(s,{children:m}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(log n)\"}),\"\\u3002\\u4E8C\\u5206\\u67E5\\u627E\\u5728\\u6BCF\\u4E00\\u6B65\\u90FD\\u5C06\\u641C\\u7D22\\u7A7A\\u95F4\\u51CF\\u534A\\uFF0C\\u4ECE\\u800C\\u4EA7\\u751F\\u5BF9\\u6570\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u4F7F\\u7528\\u5E38\\u91CF\\u7A7A\\u95F4\\u7528\\u4E8E\\u53D8\\u91CF\\uFF0C\\u56E0\\u4E3A\\u5B83\\u76F4\\u63A5\\u5BF9\\u8F93\\u5165\\u6570\\u7EC4\\u8FDB\\u884C\\u64CD\\u4F5C\\u3002\"]}),`\n`]})]})}function j(i={}){let{wrapper:e}=i.components||{};return e?(0,n.jsx)(e,Object.assign({},i,{children:(0,n.jsx)(a,i)})):a(i)}var A=j;return M(E);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/binary-search-tree-kth-smallest/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/binary-search-tree-kth-smallest/locales/zh-CN.json new file mode 100644 index 000000000..3072e8bd5 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/binary-search-tree-kth-smallest/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var i=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var g=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),k=(t,e)=>{for(var r in e)i(t,r,{get:e[r],enumerable:!0})},c=(t,e,r,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let l of T(e))!x.call(t,l)&&l!==r&&i(t,l,{get:()=>e[l],enumerable:!(o=m(e,l))||o.enumerable});return t};var N=(t,e,r)=>(r=t!=null?p(f(t)):{},c(e||!t||!t.__esModule?i(r,\"default\",{value:t,enumerable:!0}):r,t)),_=t=>c(i({},\"__esModule\",{value:!0}),t);var s=g((C,d)=>{d.exports=_jsx_runtime});var M={};k(M,{default:()=>v,frontmatter:()=>B});var n=N(s());var h=MDXTestExamples;var a=[{input:[[\"root\",[7,3,10,1,5,8,12]],[\"k\",2]],output:3,explanation:\"In this BST, the second smallest value is 3.\"},{input:[[\"root\",[1,null,2,null,3,null,4,null,5]],[\"k\",4]],output:4,explanation:\"In this right-skewed BST, the fourth smallest value is 4.\"},{input:[[\"root\",[8,6,10,5,7,9,12]],[\"k\",5]],output:9,explanation:\"In this BST, the fifth smallest value is 9.\"}];var B={title:\"\\u4E8C\\u53C9\\u641C\\u7D22\\u6811\\u7B2C K \\u5C0F\\u7684\\u5143\\u7D20\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u7528\\u4E8E\\u67E5\\u627E BST \\u4E2D\\u7B2C k \\u4E2A\\u6700\\u5C0F\\u7684\\u8282\\u70B9\"};function u(t){let e=Object.assign({p:\"p\",code:\"code\",pre:\"pre\",h3:\"h3\",ul:\"ul\",li:\"li\",a:\"a\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u4E8C\\u53C9\\u641C\\u7D22\\u6811 (BST) \\u7684 \",(0,n.jsx)(e.code,{children:\"root\"}),\" \\u8282\\u70B9\\u548C\\u4E00\\u4E2A\\u6574\\u6570 \",(0,n.jsx)(e.code,{children:\"k\"}),\"\\uFF0C\\u7F16\\u5199\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u67E5\\u627E\\u5E76\\u8FD4\\u56DE BST \\u4E2D\\u7684\\u7B2C \",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u4E2A\\u6700\\u5C0F\\u503C\\u3002\\u6811\\u4E2D\\u7684\\u6700\\u5C0F\\u503C\\u662F 1\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E8C\\u53C9\\u6811\\u7531 \",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\" \\u7684\\u96C6\\u5408\\u8868\\u793A\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u8282\\u70B9\\u90FD\\u6709\\u53EF\\u9009\\u7684 \",(0,n.jsx)(e.code,{children:\"left\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"right\"}),\" \\u5B50\\u8282\\u70B9\\uFF0C\\u5B83\\u4EEC\\u4E5F\\u662F \",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\" \\u5177\\u6709\\u4EE5\\u4E0B\\u63A5\\u53E3\\uFF1A\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-ts\",children:`interface TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n}\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"root: TreeNode\"}),\": \\u6811\\u7684\\u6839\\u8282\\u70B9\\u3002\\u793A\\u4F8B\\u663E\\u793A\\u6811\\u7684 \",(0,n.jsx)(e.a,{href:\"https://en.wikipedia.org/wiki/Breadth-first_search\",children:\"\\u5E7F\\u5EA6\\u4F18\\u5148\\u904D\\u5386\"})]}),`\n`]}),`\n`,(0,n.jsx)(h,{testCases:a}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"k\"}),\" <= \\u8282\\u70B9\\u6570 <= 1000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"TreeNode.val\"}),\" <= 1,000,000\"]}),`\n`]})]})}function S(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(u,t)})):u(t)}var v=S;return _(M);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,用于查找 BST 中第 k 个最小的节点", + "title": "二叉搜索树第 K 小的元素" + }, + "solution": "var Component=(()=>{var f=Object.create;var t=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var v=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty;var g=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),B=(n,e)=>{for(var l in e)t(n,l,{get:e[l],enumerable:!0})},c=(n,e,l,i)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let o of T(e))!p.call(n,o)&&o!==l&&t(n,o,{get:()=>e[o],enumerable:!(i=k(e,o))||i.enumerable});return n};var b=(n,e,l)=>(l=n!=null?f(v(n)):{},c(e||!n||!n.__esModule?t(l,\"default\",{value:n,enumerable:!0}):l,n)),x=n=>c(t({},\"__esModule\",{value:!0}),n);var a=g((y,h)=>{h.exports=_jsx_runtime});var M={};B(M,{default:()=>j});var r=b(a());var d=MDXCodeBlock;var s=`interface TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n}\n\nfunction inorderTraversal(root: TreeNode | null, arr: number[]): number[] {\n if (root === null) {\n return arr; // Base case: if the node is null, return the current array\n }\n\n inorderTraversal(root.left, arr); // Recursively traverse the left subtree\n arr.push(root.val); // Add the current node's value to the array\n inorderTraversal(root.right, arr); // Recursively traverse the right subtree\n\n return arr; // Return the array with collected values\n}\n\nexport default function kthSmallestElementInABst(\n root: TreeNode | null,\n k: number,\n): number {\n // Perform in-order traversal to get a sorted list of node values\n const nums = inorderTraversal(root, []);\n\n // Return the k-th smallest element (k-1 index due to 0-based indexing)\n return nums[k - 1];\n}\n`;var u=`interface TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n}\n\nexport default function kthSmallestElementInABst(\n root: TreeNode | null,\n k: number,\n): number {\n // Stack to hold nodes during the in-order traversal\n const stack: TreeNode[] = [];\n\n while (true) {\n // Traverse to the leftmost node\n while (root !== null) {\n stack.push(root); // Push the current node onto the stack\n root = root.left; // Move to the left child\n }\n\n // Process the node at the top of the stack\n root = stack.pop()!; // Pop the node from the stack\n if (--k === 0) {\n return root.val; // If k is 0, return the value of the current node\n }\n\n // Move to the right subtree\n root = root.right;\n }\n}\n`;function m(n){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},n.components);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u9012\\u5F52\"}),`\n`,(0,r.jsxs)(e.p,{children:[\"\\u5728\\u4E8C\\u53C9\\u641C\\u7D22\\u6811 (BST) \\u4E2D\\u67E5\\u627E\\u7B2C \",(0,r.jsx)(e.code,{children:\"k\"}),\" \\u4E2A\\u6700\\u5C0F\\u5143\\u7D20\\u7684\\u8FD9\\u4E2A\\u95EE\\u9898\\u4F7F\\u7528\\u4E86\\u4E2D\\u5E8F\\u904D\\u5386\\u7684\\u5C5E\\u6027\\u3002BST \\u7684\\u4E2D\\u5E8F\\u904D\\u5386\\u6309\\u7167\\u8282\\u70B9\\u503C\\u7684\\u5347\\u5E8F\\u8BBF\\u95EE\\u8282\\u70B9\\u3002\\u5229\\u7528\\u6B64\\u5C5E\\u6027\\uFF0C\\u8BE5\\u7B97\\u6CD5\\u6309\\u6392\\u5E8F\\u987A\\u5E8F\\u6536\\u96C6\\u8282\\u70B9\\u503C\\u5E76\\u76F4\\u63A5\\u68C0\\u7D22\\u7B2C \",(0,r.jsx)(e.code,{children:\"k\"}),\" \\u4E2A\\u6700\\u5C0F\\u503C\\u3002\"]}),`\n`,(0,r.jsx)(e.p,{children:\"\\u4E2D\\u5E8F\\u904D\\u5386\\u786E\\u4FDD BST \\u7684\\u503C\\u6309\\u5347\\u5E8F\\u8BBF\\u95EE\\u3002\\u901A\\u8FC7\\u904D\\u5386\\u5DE6\\u5B50\\u6811\\uFF0C\\u7136\\u540E\\u662F\\u5F53\\u524D\\u8282\\u70B9\\uFF0C\\u6700\\u540E\\u662F\\u53F3\\u5B50\\u6811\\uFF0C\\u8BE5\\u7B97\\u6CD5\\u7CFB\\u7EDF\\u5730\\u6536\\u96C6\\u6392\\u5E8F\\u540E\\u7684\\u503C\\u3002\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u8BE5\\u7B97\\u6CD5\\u9012\\u5F52\\u5730\\u904D\\u5386 BST\\uFF0C\\u5728\\u6B64\\u8FC7\\u7A0B\\u4E2D\\u5C06\\u8282\\u70B9\\u503C\\u9644\\u52A0\\u5230\\u6570\\u7EC4\\u4E2D\\u3002\\u6B64\\u6570\\u7EC4\\u5305\\u542B\\u6240\\u6709\\u6309\\u5347\\u5E8F\\u6392\\u5217\\u7684\\u8282\\u70B9\\u503C\\u3002\"}),`\n`,(0,r.jsxs)(e.p,{children:[\"\\u7531\\u4E8E\\u6570\\u7EC4\\u5DF2\\u6392\\u5E8F\\uFF0C\\u7B2C \",(0,r.jsx)(e.code,{children:\"k\"}),\" \\u4E2A\\u6700\\u5C0F\\u5143\\u7D20\\u5BF9\\u5E94\\u4E8E\\u7D22\\u5F15 \",(0,r.jsx)(e.code,{children:\"k-1\"}),\" \\u5904\\u7684\\u5143\\u7D20\\uFF0C\\u56E0\\u4E3A\\u7D22\\u5F15\\u662F\\u4ECE\\u96F6\\u5F00\\u59CB\\u7684\\u3002\\u8FD9\\u4F7F\\u5F97\\u68C0\\u7D22\\u6548\\u7387\\u5F88\\u9AD8\\u3002\"]}),`\n`,(0,r.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,r.jsxs)(e.ol,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u8F85\\u52A9\\u51FD\\u6570 \",(0,r.jsx)(e.code,{children:\"inorderTraversal\"}),\"\\uFF0C\\u8BE5\\u51FD\\u6570\\uFF1A\",`\n`,(0,r.jsxs)(e.ol,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u63A5\\u53D7\\u4E00\\u4E2A\\u8282\\u70B9 \",(0,r.jsx)(e.code,{children:\"root\"}),\" \\u548C\\u4E00\\u4E2A\\u6570\\u7EC4 \",(0,r.jsx)(e.code,{children:\"arr\"}),\" \\u4F5C\\u4E3A\\u8F93\\u5165\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u5F53\\u524D\\u8282\\u70B9\\u662F\\u5426\\u4E3A \",(0,r.jsx)(e.code,{children:\"null\"}),\"\\u3002\\u5982\\u679C\\u4E3A\\u771F\\uFF0C\\u5219\\u8FD4\\u56DE\\u6570\\u7EC4\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u5728 \",(0,r.jsx)(e.code,{children:\"root.left\"}),\" \\u4E0A\\u8C03\\u7528 \",(0,r.jsx)(e.code,{children:\"inorderTraversal\"}),\" \\u6765\\u9012\\u5F52\\u904D\\u5386\\u5DE6\\u5B50\\u6811\\u3002\"]}),`\n`,(0,r.jsx)(e.li,{children:\"\\u5C06\\u5F53\\u524D\\u8282\\u70B9\\u7684\\u503C\\u9644\\u52A0\\u5230\\u6570\\u7EC4\\u4E2D\\u3002\"}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u5728 \",(0,r.jsx)(e.code,{children:\"root.right\"}),\" \\u4E0A\\u8C03\\u7528 \",(0,r.jsx)(e.code,{children:\"inorderTraversal\"}),\" \\u6765\\u9012\\u5F52\\u904D\\u5386\\u53F3\\u5B50\\u6811\\u3002\"]}),`\n`,(0,r.jsx)(e.li,{children:\"\\u8FD4\\u56DE\\u6309\\u6392\\u5E8F\\u987A\\u5E8F\\u6536\\u96C6\\u7684\\u503C\\u7684\\u6570\\u7EC4\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5728 BST \\u7684\\u6839\\u8282\\u70B9\\u4E0A\\u8C03\\u7528 \",(0,r.jsx)(e.code,{children:\"inorderTraversal\"}),\"\\uFF0C\\u5E76\\u4F7F\\u7528\\u4E00\\u4E2A\\u7A7A\\u6570\\u7EC4\\u6765\\u83B7\\u53D6\\u6240\\u6709\\u6309\\u6392\\u5E8F\\u987A\\u5E8F\\u6392\\u5217\\u7684\\u8282\\u70B9\\u503C\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u8BBF\\u95EE\\u6392\\u5E8F\\u6570\\u7EC4\\u7684 \",(0,r.jsx)(e.code,{children:\"(k-1)\"}),\"-th \\u7D22\\u5F15\\u6765\\u68C0\\u7D22\\u7B2C \",(0,r.jsx)(e.code,{children:\"k\"}),\" \\u4E2A\\u6700\\u5C0F\\u5143\\u7D20\\u3002\"]}),`\n`,(0,r.jsx)(e.li,{children:\"\\u5C06\\u6B64\\u503C\\u4F5C\\u4E3A\\u7ED3\\u679C\\u8FD4\\u56DE\\u3002\"}),`\n`]}),`\n`,(0,r.jsx)(d,{children:s}),`\n`,(0,r.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u4E2D\\u5E8F\\u904D\\u5386\\u6B63\\u597D\\u8BBF\\u95EE\\u6BCF\\u4E2A\\u8282\\u70B9\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u6570\\u7EC4\\u5B58\\u50A8\\u6240\\u6709\\u8282\\u70B9\\u503C\\uFF0C\\u9012\\u5F52\\u5806\\u6808\\u4E5F\\u53EF\\u80FD\\u4F7F\\u7528\\u9AD8\\u8FBE O(h) \\u7684\\u7A7A\\u95F4\\uFF0C\\u5176\\u4E2D \",(0,r.jsx)(e.code,{children:\"h\"}),\" \\u662F BST \\u7684\\u9AD8\\u5EA6\\u3002\"]}),`\n`]}),`\n`,(0,r.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u8FED\\u4EE3\"}),`\n`,(0,r.jsxs)(e.p,{children:[\"\\u7528\\u4E8E\\u5728\\u4E8C\\u53C9\\u641C\\u7D22\\u6811 (BST) \\u4E2D\\u67E5\\u627E\\u7B2C \",(0,r.jsx)(e.code,{children:\"k\"}),\" \\u4E2A\\u6700\\u5C0F\\u5143\\u7D20\\u7684\\u8FED\\u4EE3\\u65B9\\u6CD5\\u4F7F\\u7528\\u4E2D\\u5E8F\\u904D\\u5386\\uFF0C\\u8BE5\\u904D\\u5386\\u6309\\u5347\\u5E8F\\u8BBF\\u95EE\\u8282\\u70B9\\u3002\\u4E0E\\u9012\\u5F52\\u65B9\\u6CD5\\u4E0D\\u540C\\uFF0C\\u6B64\\u65B9\\u6CD5\\u4F7F\\u7528\\u5806\\u6808\\u6765\\u7BA1\\u7406\\u904D\\u5386\\uFF0C\\u907F\\u514D\\u9012\\u5F52\\u5E76\\u51CF\\u5C11\\u8C03\\u7528\\u5806\\u6808\\u7684\\u4F7F\\u7528\\u3002\"]}),`\n`,(0,r.jsx)(e.p,{children:\"\\u4E2D\\u5E8F\\u904D\\u5386\\u6309\\u5347\\u5E8F\\u5904\\u7406 BST \\u7684\\u8282\\u70B9\\u3002\\u901A\\u8FC7\\u904D\\u5386\\u5DE6\\u5B50\\u6811\\uFF0C\\u8BBF\\u95EE\\u6839\\u8282\\u70B9\\uFF0C\\u7136\\u540E\\u904D\\u5386\\u53F3\\u5B50\\u6811\\uFF0C\\u8282\\u70B9\\u6309\\u6392\\u5E8F\\u987A\\u5E8F\\u4F9D\\u6B21\\u8BBF\\u95EE\\u3002\"}),`\n`,(0,r.jsxs)(e.p,{children:[\"\\u8BE5\\u7B97\\u6CD5\\u6CA1\\u6709\\u904D\\u5386\\u6574\\u4E2A\\u6811\\uFF0C\\u800C\\u662F\\u8DDF\\u8E2A\\u5DF2\\u8BBF\\u95EE\\u7684\\u8282\\u70B9\\u6570 (\",(0,r.jsx)(e.code,{children:\"k\"}),\")\\uFF0C\\u5E76\\u5728\\u627E\\u5230\\u7B2C \",(0,r.jsx)(e.code,{children:\"k\"}),\" \\u4E2A\\u6700\\u5C0F\\u8282\\u70B9\\u540E\\u505C\\u6B62\\u3002\\u8FD9\\u79CD\\u4F18\\u5316\\u786E\\u4FDD\\u4E86\\u6548\\u7387\\u3002\"]}),`\n`,(0,r.jsx)(e.p,{children:\"\\u8FED\\u4EE3\\u65B9\\u6CD5\\u907F\\u514D\\u4E86\\u9012\\u5F52\\u7684\\u5F00\\u9500\\uFF0C\\u5E76\\u4F7F\\u7528\\u5806\\u6808\\u6765\\u7BA1\\u7406\\u904D\\u5386\\uFF0C\\u5806\\u6808\\u5927\\u5C0F\\u4E0E\\u6811\\u7684\\u9AD8\\u5EA6\\u6210\\u6B63\\u6BD4\\u3002\"}),`\n`,(0,r.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,r.jsxs)(e.ol,{children:[`\n`,(0,r.jsx)(e.li,{children:\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u7A7A\\u5806\\u6808\\u4EE5\\u5728\\u904D\\u5386\\u671F\\u95F4\\u5B58\\u50A8\\u8282\\u70B9\\u3002\"}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5F53 \",(0,r.jsx)(e.code,{children:\"true\"}),\"\\uFF08\\u65E0\\u9650\\u5FAA\\u73AF\\uFF09\\u65F6\\uFF1A\",`\n`,(0,r.jsxs)(e.ol,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u5230\\u6700\\u5DE6\\u8FB9\\u7684\\u8282\\u70B9\\uFF1A\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5C06\\u5F53\\u524D \",(0,r.jsx)(e.code,{children:\"root\"}),\" \\u8282\\u70B9\\u63A8\\u5165\\u5806\\u6808\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u79FB\\u52A8\\u5230\\u5DE6\\u5B50\\u8282\\u70B9 (\",(0,r.jsx)(e.code,{children:\"root = root.left\"}),\")\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5F39\\u51FA\\u5806\\u6808\\u9876\\u90E8\\u7684\\u8282\\u70B9\\uFF1A\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5C06\\u5F39\\u51FA\\u7684\\u8282\\u70B9\\u5206\\u914D\\u7ED9 \",(0,r.jsx)(e.code,{children:\"root\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u9012\\u51CF \",(0,r.jsx)(e.code,{children:\"k\"}),\"\\u3002\\u5982\\u679C \",(0,r.jsx)(e.code,{children:\"k\"}),\" \\u53D8\\u4E3A \",(0,r.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u5219\\u8FD4\\u56DE\\u5F53\\u524D\\u8282\\u70B9\\u7684\\u503C (\",(0,r.jsx)(e.code,{children:\"root.val\"}),\")\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u79FB\\u52A8\\u5230\\u53F3\\u5B50\\u6811 (\",(0,r.jsx)(e.code,{children:\"root = root.right\"}),\")\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,r.jsx)(d,{children:u}),`\n`,(0,r.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(h + k)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u6700\\u591A\\u8BBF\\u95EE \",(0,r.jsx)(e.code,{children:\"k\"}),\" \\u4E2A\\u8282\\u70B9\\uFF0C\\u5E76\\u5728\\u6700\\u5DE6\\u8FB9\\u7684\\u904D\\u5386\\u4E2D\\u63A2\\u7D22\\u6700\\u5927\\u6DF1\\u5EA6 \",(0,r.jsx)(e.code,{children:\"h\"}),\"\\uFF08\\u6811\\u7684\\u9AD8\\u5EA6\\uFF09\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(h)\"}),\"\\u3002\\u5806\\u6808\\u5B58\\u50A8\\u6CBF\\u901A\\u5F80\\u6700\\u5DE6\\u8FB9\\u8282\\u70B9\\u7684\\u8DEF\\u5F84\\u7684\\u8282\\u70B9\\uFF0C\\u8FD9\\u4E0E\\u6811\\u7684\\u9AD8\\u5EA6\\u6210\\u6B63\\u6BD4\\u3002\"]}),`\n`]})]})}function O(n={}){let{wrapper:e}=n.components||{};return e?(0,r.jsx)(e,Object.assign({},n,{children:(0,r.jsx)(m,n)})):m(n)}var j=O;return x(M);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/binary-search-tree-lowest-common-ancestor/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/binary-search-tree-lowest-common-ancestor/locales/zh-CN.json new file mode 100644 index 000000000..b4886212c --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/binary-search-tree-lowest-common-ancestor/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var u=Object.create;var i=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var N=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),C=(r,e)=>{for(var o in e)i(r,o,{get:e[o],enumerable:!0})},t=(r,e,o,c)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let d of f(e))!x.call(r,d)&&d!==o&&i(r,d,{get:()=>e[d],enumerable:!(c=T(e,d))||c.enumerable});return r};var b=(r,e,o)=>(o=r!=null?u(m(r)):{},t(e||!r||!r.__esModule?i(o,\"default\",{value:r,enumerable:!0}):o,r)),g=r=>t(i({},\"__esModule\",{value:!0}),r);var h=N((D,l)=>{l.exports=_jsx_runtime});var w={};C(w,{default:()=>j,frontmatter:()=>A});var n=b(h());var a=MDXTestExamples;var s=[{input:[[\"root\",[3,1,7,null,2,6,10]],[\"a\",7],[\"b\",6]],output:7,explanation:\"The LCA of nodes 7 and 6 is 7 because 7 is the ancestor of 6.\"},{input:[[\"root\",[5,3,8,2,4,7,9]],[\"a\",3],[\"b\",9]],output:5,explanation:\"The LCA of nodes 3 and 9 is 5, which is the root of the tree.\"},{input:[[\"root\",[7,3,10,2,5,8,12]],[\"a\",8],[\"b\",12]],output:10,explanation:\"The LCA of nodes 8 and 12 is 10, which is the parent of both nodes.\"}];var A={title:\"\\u4E8C\\u53C9\\u641C\\u7D22\\u6811\\u7684\\u6700\\u4F4E\\u516C\\u5171\\u7956\\u5148\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u4EE5\\u627E\\u5230\\u4E8C\\u53C9\\u641C\\u7D22\\u6811\\u4E2D\\u7684 LCA\"};function p(r){let e=Object.assign({p:\"p\",code:\"code\",pre:\"pre\",h3:\"h3\",ul:\"ul\",li:\"li\",a:\"a\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E8C\\u53C9\\u641C\\u7D22\\u6811 (BST) \\u7684 \",(0,n.jsx)(e.code,{children:\"root\"}),\"\\uFF0C\\u786E\\u5B9A\\u6811\\u4E2D\\u4E24\\u4E2A\\u6307\\u5B9A\\u8282\\u70B9\\u7684\\u6700\\u4F4E\\u516C\\u5171\\u7956\\u5148 (LCA)\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"LCA \\u662F\\u6811\\u4E2D\\u540C\\u65F6\\u62E5\\u6709\\u7ED9\\u5B9A\\u4E24\\u4E2A\\u8282\\u70B9\\u4F5C\\u4E3A\\u540E\\u4EE3\\u7684\\u6700\\u4F4E\\u8282\\u70B9\\u3002\\u6839\\u636E LCA \\u7684\\u6807\\u51C6\\u5B9A\\u4E49\\uFF0C\\u4E00\\u4E2A\\u8282\\u70B9\\u53EF\\u4EE5\\u88AB\\u8BA4\\u4E3A\\u662F\\u5176\\u81EA\\u8EAB\\u7684\\u540E\\u4EE3\\u3002\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E8C\\u53C9\\u6811\\u7531 \",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\" \\u7684\\u96C6\\u5408\\u8868\\u793A\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u8282\\u70B9\\u90FD\\u6709\\u53EF\\u9009\\u7684 \",(0,n.jsx)(e.code,{children:\"left\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"right\"}),\" \\u5B50\\u8282\\u70B9\\uFF0C\\u5B83\\u4EEC\\u4E5F\\u662F \",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\" \\u5177\\u6709\\u4EE5\\u4E0B\\u63A5\\u53E3\\uFF1A\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-ts\",children:`interface TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n}\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"root: TreeNode\"}),\": \\u6811\\u7684\\u6839\\u8282\\u70B9\\u3002\\u793A\\u4F8B\\u663E\\u793A\\u6811\\u7684 \",(0,n.jsx)(e.a,{href:\"https://en.wikipedia.org/wiki/Breadth-first_search\",children:\"\\u5C42\\u5E8F\\u904D\\u5386\"})]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"a: TreeNode\"}),\": \\u7B2C\\u4E00\\u4E2A\\u6811\\u8282\\u70B9\\u3002\\u793A\\u4F8B\\u663E\\u793A\\u8282\\u70B9\\u7684\\u503C\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"b: TreeNode\"}),\": \\u7B2C\\u4E8C\\u4E2A\\u6811\\u8282\\u70B9\\u3002\\u793A\\u4F8B\\u663E\\u793A\\u8282\\u70B9\\u7684\\u503C\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u51FA\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\" \\u5BF9\\u8C61\\uFF0C\\u5B83\\u662F \",(0,n.jsx)(e.code,{children:\"a\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"b\"}),\" \\u7684 LCA\"]}),`\n`]}),`\n`,(0,n.jsx)(a,{testCases:s}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"1 <= \\u8282\\u70B9\\u6570 <= 1000\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"TreeNode.val\"}),\" <= 1,000,000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4FDD\\u8BC1 \",(0,n.jsx)(e.code,{children:\"a\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"b\"}),\" \\u5B58\\u5728\\u4E8E BST \\u4E2D\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u6240\\u6709 \",(0,n.jsx)(e.code,{children:\"TreeNode.val\"}),\" \\u5728\\u6811\\u4E2D\\u90FD\\u662F\\u552F\\u4E00\\u7684\"]}),`\n`]})]})}function _(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(p,r)})):p(r)}var j=_;return g(w);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,以找到二叉搜索树中的 LCA", + "title": "二叉搜索树的最低公共祖先" + }, + "solution": "var Component=(()=>{var V=Object.create;var d=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty;var C=(l,e)=>()=>(e||l((e={exports:{}}).exports,e),e.exports),A=(l,e)=>{for(var r in e)d(l,r,{get:e[r],enumerable:!0})},t=(l,e,r,i)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let o of b(e))!T.call(l,o)&&o!==r&&d(l,o,{get:()=>e[o],enumerable:!(i=f(e,o))||i.enumerable});return l};var g=(l,e,r)=>(r=l!=null?V(m(l)):{},t(e||!l||!l.__esModule?d(r,\"default\",{value:l,enumerable:!0}):r,l)),B=l=>t(d({},\"__esModule\",{value:!0}),l);var a=C((w,h)=>{h.exports=_jsx_runtime});var O={};A(O,{default:()=>N});var n=g(a());var c=MDXCodeBlock;var s=`interface TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n}\n\nexport default function BSTLowestCommonAncestor(\n root: TreeNode | null,\n a: TreeNode | null,\n b: TreeNode | null,\n): TreeNode | null {\n if (root === null) {\n return null; // Base case: if the root is null, there's no ancestor\n }\n\n // Value of the current node (parent node)\n const parentVal = root.val;\n\n // Value of node a\n const aVal = a!.val;\n\n // Value of node b\n const bVal = b!.val;\n\n // If both a and b are bigger than parent, explore the right subtree\n if (aVal > parentVal && bVal > parentVal) {\n return BSTLowestCommonAncestor(root.right, a, b);\n }\n\n // If both a and b are smaller than parent, explore the left subtree\n if (aVal < parentVal && bVal < parentVal) {\n return BSTLowestCommonAncestor(root.left, a, b);\n }\n\n // If one of a or b is on one side and the other is on the opposite side,\n // the current node is the lowest common ancestor.\n return root;\n}\n`;var u=`interface TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n}\n\nexport default function BSTLowestCommonAncestor(\n root: TreeNode | null,\n a: TreeNode,\n b: TreeNode,\n): TreeNode | null {\n // Value of a\n const aVal = a.val;\n\n // Value of b\n const bVal = b.val;\n\n // Start from the root node of the tree\n let node = root;\n\n // Traverse the tree\n while (node !== null) {\n // Value of the current ancestor/parent node\n const parentVal = node.val;\n\n if (aVal > parentVal && bVal > parentVal) {\n // If both a and b are greater than the parent, move to the right subtree\n node = node.right;\n } else if (aVal < parentVal && bVal < parentVal) {\n // If both a and b are lesser than the parent, move to the left subtree\n node = node.left;\n } else {\n // We have found the split point, i.e., the lowest common ancestor (LCA)\n return node;\n }\n }\n\n // If the LCA is not found, return null (this case is generally not expected in a BST)\n return null;\n}\n`;function p(l){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",ul:\"ul\",li:\"li\",h3:\"h3\",ol:\"ol\",strong:\"strong\"},l.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u9012\\u5F52\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5728\\u4E8C\\u53C9\\u641C\\u7D22\\u6811 (BST) \\u4E2D\\u5BFB\\u627E\\u6700\\u8FD1\\u516C\\u5171\\u7956\\u5148 (LCA) \\u7684\\u95EE\\u9898\\u5229\\u7528\\u4E86 BST \\u7684\\u6709\\u5E8F\\u5C5E\\u6027\\u3002 LCA \\u662F\\u4E00\\u4E2A\\u8282\\u70B9\\uFF0C\\u5176\\u4E2D\\u4E00\\u4E2A\\u8282\\u70B9 (\",(0,n.jsx)(e.code,{children:\"a\"}),\") \\u4F4D\\u4E8E\\u5F53\\u524D\\u8282\\u70B9\\u7684\\u4E00\\u4FA7\\uFF0C\\u800C\\u53E6\\u4E00\\u4E2A\\u8282\\u70B9 (\",(0,n.jsx)(e.code,{children:\"b\"}),\") \\u4F4D\\u4E8E\\u53E6\\u4E00\\u4FA7\\uFF0C\\u6216\\u8005\\u5F53\\u524D\\u8282\\u70B9\\u672C\\u8EAB\\u662F\\u8981\\u641C\\u7D22\\u7684\\u8282\\u70B9\\u4E4B\\u4E00\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u5BF9\\u4E8E BST \\u4E2D\\u7684\\u4EFB\\u4F55\\u8282\\u70B9\\uFF0C\\u5DE6\\u5B50\\u6811\\u4E2D\\u7684\\u6240\\u6709\\u503C\\u90FD\\u8F83\\u5C0F\\uFF0C\\u53F3\\u5B50\\u6811\\u4E2D\\u7684\\u6240\\u6709\\u503C\\u90FD\\u8F83\\u5927\\u3002 \\u6B64\\u5C5E\\u6027\\u7B80\\u5316\\u4E86\\u67E5\\u627E LCA \\u7684\\u8FC7\\u7A0B\\u3002\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8BE5\\u7B97\\u6CD5\\u68C0\\u67E5 \",(0,n.jsx)(e.code,{children:\"a\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"b\"}),\" \\u7684\\u503C\\u76F8\\u5BF9\\u4E8E\\u5F53\\u524D\\u8282\\u70B9 (\",(0,n.jsx)(e.code,{children:\"root\"}),\") \\u7684\\u503C\\u3002\"]}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u4E24\\u4E2A\\u503C\\u90FD\\u5927\\u4E8E\\u5F53\\u524D\\u8282\\u70B9\\u7684\\u503C\\uFF0C\\u5219 LCA \\u5FC5\\u987B\\u4F4D\\u4E8E\\u53F3\\u5B50\\u6811\\u4E2D\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u4E24\\u4E2A\\u503C\\u90FD\\u8F83\\u5C0F\\uFF0C\\u5219 LCA \\u5FC5\\u987B\\u4F4D\\u4E8E\\u5DE6\\u5B50\\u6811\\u4E2D\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u4E00\\u4E2A\\u503C\\u5728\\u5DE6\\u4FA7\\uFF0C\\u53E6\\u4E00\\u4E2A\\u503C\\u5728\\u53F3\\u4FA7\\uFF08\\u6216\\u8005\\u5176\\u4E2D\\u4E00\\u4E2A\\u8282\\u70B9\\u4E0E\\u5F53\\u524D\\u8282\\u70B9\\u5339\\u914D\\uFF09\\uFF0C\\u5219\\u5F53\\u524D\\u8282\\u70B9\\u662F LCA\\u3002\"}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8BE5\\u7B97\\u6CD5\\u6839\\u636E \",(0,n.jsx)(e.code,{children:\"a\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"b\"}),\" \\u7684\\u76F8\\u5BF9\\u503C\\u9012\\u5F52\\u904D\\u5386\\u6811\\uFF0C\\u76F4\\u5230\\u627E\\u5230 LCA\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u57FA\\u672C\\u60C5\\u51B5\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"root\"}),\" \\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u56E0\\u4E3A\\u6CA1\\u6709\\u7956\\u5148\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u7D22\\u5F53\\u524D\\u8282\\u70B9 (\",(0,n.jsx)(e.code,{children:\"parentVal\"}),\")\\u3001\",(0,n.jsx)(e.code,{children:\"a\"}),\" (\",(0,n.jsx)(e.code,{children:\"aVal\"}),\") \\u548C \",(0,n.jsx)(e.code,{children:\"b\"}),\" (\",(0,n.jsx)(e.code,{children:\"bVal\"}),\") \\u7684\\u503C\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"aVal\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"bVal\"}),\" \\u4E0E \",(0,n.jsx)(e.code,{children:\"parentVal\"}),\" \\u8FDB\\u884C\\u6BD4\\u8F83\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"aVal\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"bVal\"}),\" \\u90FD\\u5927\\u4E8E \",(0,n.jsx)(e.code,{children:\"parentVal\"}),\"\\uFF0C\\u5219\\u4F7F\\u7528\\u53F3\\u5B50\\u6811 (\",(0,n.jsx)(e.code,{children:\"root.right\"}),\") \\u4F5C\\u4E3A\\u65B0\\u6839\\u9012\\u5F52\\u8C03\\u7528\\u8BE5\\u51FD\\u6570\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"aVal\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"bVal\"}),\" \\u90FD\\u5C0F\\u4E8E \",(0,n.jsx)(e.code,{children:\"parentVal\"}),\"\\uFF0C\\u5219\\u4F7F\\u7528\\u5DE6\\u5B50\\u6811 (\",(0,n.jsx)(e.code,{children:\"root.left\"}),\") \\u4F5C\\u4E3A\\u65B0\\u6839\\u9012\\u5F52\\u8C03\\u7528\\u8BE5\\u51FD\\u6570\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u4E00\\u4E2A\\u503C\\u5728\\u5DE6\\u4FA7\\uFF0C\\u53E6\\u4E00\\u4E2A\\u503C\\u5728\\u53F3\\u4FA7\\uFF0C\\u6216\\u8005\\u4E00\\u4E2A\\u503C\\u4E0E \",(0,n.jsx)(e.code,{children:\"parentVal\"}),\" \\u5339\\u914D\\uFF0C\\u5219\\u8FD4\\u56DE\\u5F53\\u524D\\u8282\\u70B9 (\",(0,n.jsx)(e.code,{children:\"root\"}),\") \\u4F5C\\u4E3A LCA\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(c,{children:s}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(h)\"}),\"\\u3002 \\u8BE5\\u7B97\\u6CD5\\u904D\\u5386\\u6811\\u7684\\u9AD8\\u5EA6\\uFF0C\\u5176\\u4E2D \",(0,n.jsx)(e.code,{children:\"h\"}),\" \\u662F BST \\u7684\\u9AD8\\u5EA6\\u3002 \\u5728\\u5E73\\u8861\\u7684 BST \\u4E2D\\uFF0C\\u8FD9\\u662F O(log n)\\uFF0C\\u5728\\u6700\\u574F\\u7684\\u60C5\\u51B5\\u4E0B\\uFF08\\u4E0D\\u5E73\\u8861\\u6811\\uFF09\\uFF0C\\u8FD9\\u662F O(n)\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(h)\"}),\"\\u3002 \\u9012\\u5F52\\u5806\\u6808\\u9700\\u8981\\u4E0E\\u6811\\u7684\\u9AD8\\u5EA6\\u6210\\u6BD4\\u4F8B\\u7684\\u7A7A\\u95F4\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u8FED\\u4EE3\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5728\\u4E8C\\u53C9\\u641C\\u7D22\\u6811 (BST) \\u4E2D\\u5BFB\\u627E\\u6700\\u8FD1\\u516C\\u5171\\u7956\\u5148 (LCA) \\u7684\\u8FED\\u4EE3\\u65B9\\u6CD5\\u4F7F\\u7528 BST \\u7684\\u5C5E\\u6027\\uFF0C\\u65E0\\u9700\\u9012\\u5F52\\u5373\\u53EF\\u4ECE\\u6839\\u8282\\u70B9\\u5BFC\\u822A\\u5230 LCA\\u3002 LCA \\u88AB\\u6807\\u8BC6\\u4E3A\\u4E24\\u4E2A\\u8282\\u70B9 (\",(0,n.jsx)(e.code,{children:\"a\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"b\"}),\") \\u7684\\u8DEF\\u5F84\\u53D1\\u6563\\u6216\\u5176\\u4E2D\\u4E00\\u4E2A\\u8282\\u70B9\\u4E0E\\u5F53\\u524D\\u8282\\u70B9\\u5339\\u914D\\u7684\\u8282\\u70B9\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u5728 BST \\u4E2D\\uFF0C\\u5DE6\\u5B50\\u6811\\u4E2D\\u7684\\u6240\\u6709\\u503C\\u90FD\\u5C0F\\u4E8E\\u6839\\uFF0C\\u53F3\\u5B50\\u6811\\u4E2D\\u7684\\u6240\\u6709\\u503C\\u90FD\\u5927\\u4E8E\\u6839\\u3002 \\u6B64\\u5C5E\\u6027\\u6709\\u52A9\\u4E8E\\u786E\\u5B9A\\u904D\\u5386\\u65B9\\u5411\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"a\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"b\"}),\" \\u90FD\\u5C0F\\u4E8E\\u5F53\\u524D\\u8282\\u70B9\\uFF0C\\u5219 LCA \\u4F4D\\u4E8E\\u5DE6\\u5B50\\u6811\\u4E2D\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"a\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"b\"}),\" \\u90FD\\u5927\\u4E8E\\u5F53\\u524D\\u8282\\u70B9\\uFF0C\\u5219 LCA \\u4F4D\\u4E8E\\u53F3\\u5B50\\u6811\\u4E2D\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u4E00\\u4E2A\\u8282\\u70B9\\u5728\\u5DE6\\u4FA7\\uFF0C\\u53E6\\u4E00\\u4E2A\\u8282\\u70B9\\u5728\\u53F3\\u4FA7\\uFF0C\\u6216\\u8005\\u4E00\\u4E2A\\u8282\\u70B9\\u4E0E\\u5F53\\u524D\\u8282\\u70B9\\u5339\\u914D\\uFF0C\\u5219\\u5F53\\u524D\\u8282\\u70B9\\u662F LCA\\u3002\"}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8BE5\\u7B97\\u6CD5\\u901A\\u8FC7\\u57FA\\u4E8E\\u6BD4\\u8F83\\u8FED\\u4EE3\\u79FB\\u52A8\\u6307\\u9488 (\",(0,n.jsx)(e.code,{children:\"node\"}),\") \\u6765\\u6D88\\u9664\\u9012\\u5F52\\uFF0C\\u4ECE\\u800C\\u4FDD\\u6301\\u6548\\u7387\\u548C\\u7B80\\u5355\\u6027\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u627E\\u5230 LCA \\u540E\\uFF0C\\u904D\\u5386\\u7ACB\\u5373\\u505C\\u6B62\\uFF0C\\u907F\\u514D\\u4E86\\u4E0D\\u5FC5\\u8981\\u7684\\u64CD\\u4F5C\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u7D22 \",(0,n.jsx)(e.code,{children:\"a\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"b\"}),\" \\u7684\\u503C (\",(0,n.jsx)(e.code,{children:\"aVal\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"bVal\"}),\")\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u6307\\u9488 \",(0,n.jsx)(e.code,{children:\"node\"}),\" \\u521D\\u59CB\\u5316\\u4E3A BST \\u7684\\u6839\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"while\"}),\" \\u5FAA\\u73AF\\u904D\\u5386 BST\\uFF0C\\u76F4\\u5230 \",(0,n.jsx)(e.code,{children:\"node\"}),\" \\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u7D22\\u5F53\\u524D\\u8282\\u70B9\\u7684\\u503C (\",(0,n.jsx)(e.code,{children:\"parentVal\"}),\")\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"aVal\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"bVal\"}),\" \\u4E0E \",(0,n.jsx)(e.code,{children:\"parentVal\"}),\" \\u8FDB\\u884C\\u6BD4\\u8F83\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u4E24\\u8005\\u90FD\\u5927\\u4E8E \",(0,n.jsx)(e.code,{children:\"parentVal\"}),\"\\uFF0C\\u5219\\u5C06 \",(0,n.jsx)(e.code,{children:\"node\"}),\" \\u79FB\\u52A8\\u5230\\u53F3\\u5B50\\u8282\\u70B9 (\",(0,n.jsx)(e.code,{children:\"node = node.right\"}),\")\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u4E24\\u8005\\u90FD\\u5C0F\\u4E8E \",(0,n.jsx)(e.code,{children:\"parentVal\"}),\"\\uFF0C\\u5219\\u5C06 \",(0,n.jsx)(e.code,{children:\"node\"}),\" \\u79FB\\u52A8\\u5230\\u5DE6\\u5B50\\u8282\\u70B9 (\",(0,n.jsx)(e.code,{children:\"node = node.left\"}),\")\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5426\\u5219\\uFF0C\\u5F53\\u524D\\u8282\\u70B9\\u662F LCA\\uFF1B\\u8FD4\\u56DE\\u5B83\\u3002\"}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u672A\\u627E\\u5230 LCA\\uFF08\\u8FB9\\u7F18\\u60C5\\u51B5\\uFF09\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsxs)(c,{children:[\" \",u,\" \"]}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(h)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u904D\\u5386\\u6811\\u7684\\u9AD8\\u5EA6\\uFF0C\\u5176\\u4E2D \",(0,n.jsx)(e.code,{children:\"h\"}),\" \\u662F BST \\u7684\\u9AD8\\u5EA6\\u3002\\u5728\\u5E73\\u8861 BST \\u4E2D\\uFF0C\\u8FD9\\u662F O(log n)\\uFF0C\\u5728\\u6700\\u574F\\u60C5\\u51B5\\u4E0B\\uFF08\\u4E0D\\u5E73\\u8861\\u6811\\uFF09\\uFF0C\\u8FD9\\u662F O(n)\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u4F7F\\u7528\\u6052\\u5B9A\\u7684\\u7A7A\\u95F4\\u91CF\\uFF0C\\u56E0\\u4E3A\\u6CA1\\u6709\\u9012\\u5F52\\u6216\\u8F85\\u52A9\\u6570\\u636E\\u7ED3\\u6784\\u3002\"]}),`\n`]})]})}function x(l={}){let{wrapper:e}=l.components||{};return e?(0,n.jsx)(e,Object.assign({},l,{children:(0,n.jsx)(p,l)})):p(l)}var N=x;return B(O);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/binary-search-tree-validate/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/binary-search-tree-validate/locales/zh-CN.json new file mode 100644 index 000000000..f2c4d4c3d --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/binary-search-tree-validate/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var i=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var g=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),B=(t,e)=>{for(var r in e)i(t,r,{get:e[r],enumerable:!0})},d=(t,e,r,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let l of f(e))!x.call(t,l)&&l!==r&&i(t,l,{get:()=>e[l],enumerable:!(o=T(e,l))||o.enumerable});return t};var N=(t,e,r)=>(r=t!=null?p(m(t)):{},d(e||!t||!t.__esModule?i(r,\"default\",{value:t,enumerable:!0}):r,t)),S=t=>d(i({},\"__esModule\",{value:!0}),t);var h=g((C,c)=>{c.exports=_jsx_runtime});var j={};B(j,{default:()=>b,frontmatter:()=>w});var n=N(h());var a=MDXTestExamples;var s=[{input:[[\"root\",[10,5,15,1,8,12,20]]],output:!0,explanation:\"The tree is a valid BST because all nodes follow the BST properties.\"},{input:[[\"root\",[5,1,4,null,null,null,3]]],output:!1,explanation:\"The tree is not a valid BST because the node with value 3 is in the right subtree of the node with value 4, which violates the BST property.\"},{input:[[\"root\",[3,2,4,1,null,null,5]]],output:!0,explanation:\"The tree is a valid BST because all nodes follow the BST properties.\"}];var w={title:\"\\u9A8C\\u8BC1\\u4E8C\\u53C9\\u641C\\u7D22\\u6811\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u9A8C\\u8BC1\\u4E8C\\u53C9\\u6811\\u662F\\u5426\\u4E3A\\u6709\\u6548\\u7684\\u4E8C\\u53C9\\u641C\\u7D22\\u6811\"};function u(t){let e=Object.assign({p:\"p\",code:\"code\",ul:\"ul\",li:\"li\",pre:\"pre\",h3:\"h3\",a:\"a\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u4E8C\\u53C9\\u6811\\u7684\",(0,n.jsx)(e.code,{children:\"root\"}),\"\\uFF0C\\u786E\\u5B9A\\u5B83\\u662F\\u5426\\u662F\\u4E00\\u4E2A\\u6709\\u6548\\u7684\\u4E8C\\u53C9\\u641C\\u7D22\\u6811(BST)\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u4E3A\\u4E86\\u4F7F\\u6811\\u7B26\\u5408\\u6709\\u6548\\u7684BST\\u7684\\u6761\\u4EF6\\uFF0C\\u5B83\\u5FC5\\u987B\\u6EE1\\u8DB3\\u4EE5\\u4E0B\\u6761\\u4EF6\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u8282\\u70B9\\u7684\\u5DE6\\u5B50\\u6811\\u53EA\\u5305\\u542B\\u503C\\u5C0F\\u4E8E\\u8BE5\\u8282\\u70B9\\u503C\\u7684\\u8282\\u70B9\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8282\\u70B9\\u7684\\u53F3\\u5B50\\u6811\\u53EA\\u5305\\u542B\\u503C\\u5927\\u4E8E\\u8BE5\\u8282\\u70B9\\u503C\\u7684\\u8282\\u70B9\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5DE6\\u5B50\\u6811\\u548C\\u53F3\\u5B50\\u6811\\u4E5F\\u90FD\\u662F\\u6709\\u6548\\u7684BST\"}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E8C\\u53C9\\u6811\\u7531\",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\"\\u7684\\u96C6\\u5408\\u8868\\u793A\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u8282\\u70B9\\u90FD\\u6709\\u53EF\\u9009\\u7684\",(0,n.jsx)(e.code,{children:\"left\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"right\"}),\"\\u5B50\\u8282\\u70B9\\uFF0C\\u5B83\\u4EEC\\u4E5F\\u662F\",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A\",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\"\\u6709\\u4EE5\\u4E0B\\u63A5\\u53E3\\uFF1A\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-ts\",children:`interface TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n}\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"root: TreeNode\"}),\": \\u6811\\u7684\\u6839\\u8282\\u70B9\\u3002\\u793A\\u4F8B\\u663E\\u793A\\u6811\\u7684\",(0,n.jsx)(e.a,{href:\"https://en.wikipedia.org/wiki/Breadth-first_search\",children:\"\\u5C42\\u5E8F\\u904D\\u5386\"})]}),`\n`]}),`\n`,(0,n.jsx)(a,{testCases:s}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"1 <= \\u8282\\u70B9\\u6570 <= 1000\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"-1,000,000 <= \",(0,n.jsx)(e.code,{children:\"TreeNode.val\"}),\" <= 1,000,000\"]}),`\n`]})]})}function _(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(u,t)})):u(t)}var b=_;return S(j);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来验证二叉树是否为有效的二叉搜索树", + "title": "验证二叉搜索树" + }, + "solution": "var Component=(()=>{var f=Object.create;var r=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var T=(l,e)=>()=>(e||l((e={exports:{}}).exports,e),e.exports),b=(l,e)=>{for(var i in e)r(l,i,{get:e[i],enumerable:!0})},h=(l,e,i,c)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let d of g(e))!v.call(l,d)&&d!==i&&r(l,d,{get:()=>e[d],enumerable:!(c=p(e,d))||c.enumerable});return l};var k=(l,e,i)=>(i=l!=null?f(w(l)):{},h(e||!l||!l.__esModule?r(i,\"default\",{value:l,enumerable:!0}):i,l)),x=l=>h(r({},\"__esModule\",{value:!0}),l);var a=T((L,t)=>{t.exports=_jsx_runtime});var B={};b(B,{default:()=>S});var n=k(a());var o=MDXCodeBlock;var u=`interface TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n}\n\nexport default function binarySearchTreeValidate(\n root: TreeNode | null,\n): boolean {\n // Helper function to recursively check each node within the allowed range\n function checkNodeInRange(\n node: TreeNode | null,\n minAllowed: number,\n maxAllowed: number,\n ): boolean {\n // Base case: an empty node is a valid BST\n if (node == null) {\n return true;\n }\n\n // The current node's value must lie between minAllowed and maxAllowed\n if (node.val <= minAllowed || node.val >= maxAllowed) {\n return false;\n }\n\n // Recursively check the left and right subtrees with updated ranges\n const isLeftValid = checkNodeInRange(node.left, minAllowed, node.val);\n const isRightValid = checkNodeInRange(node.right, node.val, maxAllowed);\n\n // Both left and right subtrees must be valid\n return isLeftValid && isRightValid;\n }\n\n // Initial call with the entire range of valid values for a 32-bit signed integer\n return checkNodeInRange(root, -Infinity, Infinity);\n}\n`;var s=`interface TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n}\n\nexport default function binarySearchTreeValidate(\n root: TreeNode | null,\n): boolean {\n // Stack to hold nodes during iterative traversal\n const stack: (TreeNode | null | undefined)[] = [];\n // Stack to hold the lower limits for node values\n const lowerLimits: (number | null | undefined)[] = [];\n // Stack to hold the upper limits for node values\n const upperLimits: (number | null | undefined)[] = [];\n\n function update(\n node: TreeNode | null,\n low?: number | null,\n high?: number | null,\n ) {\n stack.push(node);\n lowerLimits.push(low);\n upperLimits.push(high);\n }\n\n // Initialize the stack with the root node and null limits\n update(root, null, null);\n\n // Iterate while there are nodes in the stack\n while (stack.length > 0) {\n // Pop the top node and its corresponding limits\n const node = stack.pop()!;\n const low = lowerLimits.pop();\n const high = upperLimits.pop();\n\n // If the node is null, continue to the next iteration\n if (node === null) {\n continue;\n }\n\n const val = node.val;\n\n // Ensure low and high are defined before comparison\n if (low != null && val <= low) {\n return false; // Invalid if value is less than or equal to the lower limit\n }\n if (high != null && val >= high) {\n return false; // Invalid if value is greater than or equal to the upper limit\n }\n\n // Push the right child with updated limits\n update(node.right, val, high);\n\n // Push the left child with updated limits\n update(node.left, low, val);\n }\n\n // If no violations are found, return true\n return true;\n}\n`;function m(l){let e=Object.assign({h2:\"h2\",p:\"p\",ul:\"ul\",li:\"li\",code:\"code\",h3:\"h3\",ol:\"ol\",strong:\"strong\"},l.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u9012\\u5F52\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u9A8C\\u8BC1\\u4E8C\\u53C9\\u641C\\u7D22\\u6811\\uFF08BST\\uFF09\\u7684\\u95EE\\u9898\\u786E\\u4FDD\\u4E86\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u8282\\u70B9\\uFF0C\\u5DE6\\u5B50\\u6811\\u4E2D\\u6240\\u6709\\u8282\\u70B9\\u7684\\u503C\\u90FD\\u8F83\\u5C0F\\uFF0C\\u800C\\u53F3\\u5B50\\u6811\\u4E2D\\u6240\\u6709\\u8282\\u70B9\\u7684\\u503C\\u90FD\\u8F83\\u5927\\u3002\\u8FD9\\u79CD\\u9012\\u5F52\\u65B9\\u6CD5\\u5229\\u7528\\u8303\\u56F4\\u68C0\\u67E5\\u6765\\u9A8C\\u8BC1 BST \\u5C5E\\u6027\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u8282\\u70B9\\uFF0C\\u90FD\\u4F1A\\u7EF4\\u62A4\\u4E00\\u4E2A\\u8303\\u56F4\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u8282\\u70B9\\u7684\\u503C\\u5FC5\\u987B\\u4F4D\\u4E8E\\u5176\\u7956\\u5148\\u5B9A\\u4E49\\u7684\\u8303\\u56F4\\u5185\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u5DE6\\u5B50\\u8282\\u70B9\\uFF0C\\u8303\\u56F4\\u66F4\\u65B0\\u4E3A \",(0,n.jsx)(e.code,{children:\"[minAllowed, node.val)\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u53F3\\u5B50\\u8282\\u70B9\\uFF0C\\u8303\\u56F4\\u66F4\\u65B0\\u4E3A \",(0,n.jsx)(e.code,{children:\"(node.val, maxAllowed]\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u7B97\\u6CD5\\u9012\\u5F52\\u5730\\u68C0\\u67E5\\u6BCF\\u4E2A\\u8282\\u70B9\\uFF0C\\u786E\\u4FDD\\u5B83\\u4F4D\\u4E8E\\u5176\\u5141\\u8BB8\\u7684\\u8303\\u56F4\\u5185\\u3002\\u5982\\u679C\\u4EFB\\u4F55\\u8282\\u70B9\\u8FDD\\u53CD\\u8303\\u56F4\\u7EA6\\u675F\\uFF0C\\u5219\\u8BE5\\u6811\\u4E0D\\u662F\\u6709\\u6548\\u7684 BST\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u7B97\\u6CD5\\u6B63\\u597D\\u904D\\u5386\\u6BCF\\u4E2A\\u8282\\u70B9\\u4E00\\u6B21\\uFF0C\\u5E76\\u901A\\u8FC7\\u9012\\u5F52\\u8C03\\u7528\\u4F20\\u64AD\\u8303\\u56F4\\u7EA6\\u675F\\u6765\\u786E\\u4FDD\\u6B63\\u786E\\u6027\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u8F85\\u52A9\\u51FD\\u6570 \",(0,n.jsx)(e.code,{children:\"checkNodeInRange\"}),\"\\uFF0C\\u5B83\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u63A5\\u53D7 \",(0,n.jsx)(e.code,{children:\"node\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"minAllowed\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"maxAllowed\"}),\" \\u4F5C\\u4E3A\\u53C2\\u6570\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u8282\\u70B9\\u53CA\\u5176\\u5B50\\u6811\\u6EE1\\u8DB3 BST \\u5C5E\\u6027\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u8282\\u70B9\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"node\"}),\" \\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\uFF08\\u9012\\u5F52\\u7684\\u57FA\\u672C\\u60C5\\u51B5\\uFF09\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5 \",(0,n.jsx)(e.code,{children:\"node.val\"}),\" \\u662F\\u5426\\u5728 \",(0,n.jsx)(e.code,{children:\"minAllowed\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"maxAllowed\"}),\" \\u5B9A\\u4E49\\u7684\\u8303\\u56F4\\u4E4B\\u5916\\u3002\\u5982\\u679C\\u4E3A\\u771F\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u9012\\u5F52\\u5730\\u4F7F\\u7528\\u8303\\u56F4 \",(0,n.jsx)(e.code,{children:\"[minAllowed, node.val)\"}),\" \\u9A8C\\u8BC1\\u5DE6\\u5B50\\u6811\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u9012\\u5F52\\u5730\\u4F7F\\u7528\\u8303\\u56F4 \",(0,n.jsx)(e.code,{children:\"(node.val, maxAllowed]\"}),\" \\u9A8C\\u8BC1\\u53F3\\u5B50\\u6811\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4EC5\\u5F53\\u5DE6\\u53F3\\u5B50\\u6811\\u90FD\\u6709\\u6548\\u65F6\\u624D\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u6839\\u8282\\u70B9\\u5F00\\u59CB\\u9A8C\\u8BC1\\uFF0C\\u8303\\u56F4\\u4E3A \",(0,n.jsx)(e.code,{children:\"[-Infinity, Infinity]\"}),\"\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8FD4\\u56DE\\u8F85\\u52A9\\u51FD\\u6570\\u7684\\u7ED3\\u679C\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(o,{children:u}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u6BCF\\u4E2A\\u8282\\u70B9\\u53EA\\u8BBF\\u95EE\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(h)\"}),\"\\u3002\\u9012\\u5F52\\u5806\\u6808\\u9700\\u8981\\u7684\\u7A7A\\u95F4\\u4E0E\\u6811\\u7684\\u9AD8\\u5EA6\\u6210\\u6B63\\u6BD4\\uFF0C\\u5176\\u4E2D \",(0,n.jsx)(e.code,{children:\"h\"}),\" \\u662F BST \\u7684\\u9AD8\\u5EA6\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u8FED\\u4EE3\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u7528\\u4E8E\\u9A8C\\u8BC1\\u4E8C\\u53C9\\u641C\\u7D22\\u6811\\uFF08BST\\uFF09\\u7684\\u8FED\\u4EE3\\u65B9\\u6CD5\\u786E\\u4FDD\\u6240\\u6709\\u8282\\u70B9\\u90FD\\u7B26\\u5408 BST \\u5C5E\\u6027\\uFF1A\\u5DE6\\u5B50\\u6811\\u4E2D\\u7684\\u6240\\u6709\\u503C\\u90FD\\u5C0F\\u4E8E\\u6839\\uFF0C\\u53F3\\u5B50\\u6811\\u4E2D\\u7684\\u6240\\u6709\\u503C\\u90FD\\u5927\\u4E8E\\u6839\\u3002\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u5806\\u6808\\u6765\\u7BA1\\u7406\\u8282\\u70B9\\u53CA\\u5176\\u5728\\u904D\\u5386\\u671F\\u95F4\\u5BF9\\u5E94\\u7684\\u6709\\u6548\\u503C\\u8303\\u56F4\\u3002\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u6BCF\\u4E2A\\u8282\\u70B9\\u90FD\\u4E0E\\u4E00\\u4E2A\\u8303\\u56F4\\uFF08\",(0,n.jsx)(e.code,{children:\"low\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"high\"}),\"\\uFF09\\u76F8\\u5173\\u8054\\uFF0C\\u8BE5\\u8303\\u56F4\\u8868\\u793A\\u57FA\\u4E8E\\u5176\\u7956\\u5148\\u7684\\u5141\\u8BB8\\u503C\\u3002\"]}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u5DE6\\u5B50\\u8282\\u70B9\\uFF0C\\u8303\\u56F4\\u66F4\\u65B0\\u4E3A \",(0,n.jsx)(e.code,{children:\"[low, node.val)\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u53F3\\u5B50\\u8282\\u70B9\\uFF0C\\u8303\\u56F4\\u66F4\\u65B0\\u4E3A \",(0,n.jsx)(e.code,{children:\"(node.val, high]\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u5806\\u6808\\u7528\\u4E8E\\u7EF4\\u62A4\\u5C1A\\u672A\\u9A8C\\u8BC1\\u7684\\u8282\\u70B9\\u53CA\\u5176\\u6709\\u6548\\u8303\\u56F4\\u3002\\u8FED\\u4EE3\\u8FC7\\u7A0B\\u907F\\u514D\\u4E86\\u9012\\u5F52\\uFF0C\\u5E76\\u786E\\u4FDD\\u6240\\u6709\\u8282\\u70B9\\u90FD\\u6309\\u7167 BST \\u89C4\\u5219\\u8FDB\\u884C\\u9A8C\\u8BC1\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u8282\\u70B9\\uFF0C\\u5C06\\u5176\\u503C\\u4E0E\\u5176\\u5206\\u914D\\u7684\\u8303\\u56F4\\u8FDB\\u884C\\u6BD4\\u8F83\\u3002\\u5982\\u679C\\u8BE5\\u503C\\u8FDD\\u53CD\\u4E86\\u8303\\u56F4\\u7EA6\\u675F\\uFF0C\\u5219\\u8BE5\\u6811\\u65E0\\u6548\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u7B97\\u6CD5\\u6B63\\u597D\\u5904\\u7406\\u6BCF\\u4E2A\\u8282\\u70B9\\u4E00\\u6B21\\uFF0C\\u5E76\\u4F7F\\u7528\\u5806\\u6808\\u6765\\u7BA1\\u7406\\u904D\\u5386\\uFF0C\\u4F7F\\u5176\\u5177\\u6709\\u65F6\\u95F4\\u548C\\u7A7A\\u95F4\\u6548\\u7387\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E09\\u4E2A\\u6808\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"stack\"}),\" \\u7528\\u4E8E\\u5B58\\u50A8\\u8282\\u70B9\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"lowerLimits\"}),\" \\u7528\\u4E8E\\u5B58\\u50A8\\u6BCF\\u4E2A\\u8282\\u70B9\\u7684\\u4E0B\\u9650\\u8303\\u56F4\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"upperLimits\"}),\" \\u7528\\u4E8E\\u5B58\\u50A8\\u6BCF\\u4E2A\\u8282\\u70B9\\u7684\\u4E0A\\u9650\\u8303\\u56F4\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u8F85\\u52A9\\u51FD\\u6570 \",(0,n.jsx)(e.code,{children:\"update\"}),\"\\uFF0C\\u8BE5\\u51FD\\u6570\\u5C06\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u4E00\\u4E2A\\u8282\\u70B9\\u53CA\\u5176\\u66F4\\u65B0\\u540E\\u7684\\u8303\\u56F4 (\",(0,n.jsx)(e.code,{children:\"low\"}),\", \",(0,n.jsx)(e.code,{children:\"high\"}),\") \\u63A8\\u5165\\u5404\\u81EA\\u7684\\u6808\\u4E2D\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u6839\\u8282\\u70B9\\u63A8\\u5165\\u6808\\u4E2D\\uFF0C\\u521D\\u59CB\\u9650\\u5236\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF08\\u65E0\\u7EA6\\u675F\\uFF09\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5F53 \",(0,n.jsx)(e.code,{children:\"stack\"}),\" \\u4E0D\\u4E3A\\u7A7A\\u65F6\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5F39\\u51FA\\u9876\\u90E8\\u8282\\u70B9\\u53CA\\u5176\\u5BF9\\u5E94\\u7684\\u8303\\u56F4 (\",(0,n.jsx)(e.code,{children:\"low\"}),\", \",(0,n.jsx)(e.code,{children:\"high\"}),\")\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u8282\\u70B9\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u5219\\u8DF3\\u8FC7\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u9A8C\\u8BC1\\u8282\\u70B9\\u7684\\u503C\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u8BE5\\u503C\\u662F\\u5426\\u5C0F\\u4E8E\\u6216\\u7B49\\u4E8E \",(0,n.jsx)(e.code,{children:\"low\"}),\" \\u6216\\u5927\\u4E8E\\u6216\\u7B49\\u4E8E \",(0,n.jsx)(e.code,{children:\"high\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u8FDD\\u53CD\\u4EFB\\u4F55\\u6761\\u4EF6\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u53F3\\u5B50\\u8282\\u70B9\\u63A8\\u5165\\u6808\\u4E2D\\uFF0C\\u66F4\\u65B0\\u9650\\u5236\\u4E3A \",(0,n.jsx)(e.code,{children:\"[node.val, high]\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u5DE6\\u5B50\\u8282\\u70B9\\u63A8\\u5165\\u6808\\u4E2D\\uFF0C\\u66F4\\u65B0\\u9650\\u5236\\u4E3A \",(0,n.jsx)(e.code,{children:\"[low, node.val]\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u672A\\u53D1\\u73B0\\u8FDD\\u89C4\\u884C\\u4E3A\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsxs)(o,{children:[\" \",s,\" \"]}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u6BCF\\u4E2A\\u8282\\u70B9\\u53EA\\u5904\\u7406\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(h)\"}),\"\\u3002\\u6808\\u6700\\u591A\\u540C\\u65F6\\u5BB9\\u7EB3 \",(0,n.jsx)(e.code,{children:\"h\"}),\" \\u4E2A\\u8282\\u70B9\\uFF0C\\u5176\\u4E2D \",(0,n.jsx)(e.code,{children:\"h\"}),\" \\u662F\\u6811\\u7684\\u9AD8\\u5EA6\\u3002\"]}),`\n`]})]})}function N(l={}){let{wrapper:e}=l.components||{};return e?(0,n.jsx)(e,Object.assign({},l,{children:(0,n.jsx)(m,l)})):m(l)}var S=N;return x(B);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/binary-search-tree/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/binary-search-tree/locales/zh-CN.json new file mode 100644 index 000000000..378a88086 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/binary-search-tree/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var h=Object.create;var l=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var b=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),g=(n,e)=>{for(var c in e)l(n,c,{get:e[c],enumerable:!0})},i=(n,e,c,s)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of m(e))!x.call(n,r)&&r!==c&&l(n,r,{get:()=>e[r],enumerable:!(s=u(e,r))||s.enumerable});return n};var B=(n,e,c)=>(c=n!=null?h(p(n)):{},i(e||!n||!n.__esModule?l(c,\"default\",{value:n,enumerable:!0}):c,n)),S=n=>i(l({},\"__esModule\",{value:!0}),n);var o=b((v,d)=>{d.exports=_jsx_runtime});var f={};g(f,{default:()=>O,frontmatter:()=>T});var t=B(o()),T={title:\"\\u4E8C\\u53C9\\u641C\\u7D22\\u6811\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u4E8C\\u53C9\\u641C\\u7D22\\u6811\\u6570\\u636E\\u7ED3\\u6784\\uFF0C\\u5305\\u62EC\\u57FA\\u672C\\u7684 BST \\u64CD\\u4F5C\"};function a(n){let e=Object.assign({p:\"p\",ul:\"ul\",li:\"li\",code:\"code\",h2:\"h2\",pre:\"pre\"},n.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(e.p,{children:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u652F\\u6301\\u4EE5\\u4E0B\\u64CD\\u4F5C\\u7684\\u4E8C\\u53C9\\u641C\\u7D22\\u6811 (BST) \\u6570\\u636E\\u7ED3\\u6784\\uFF1A\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.code,{children:\"new BST()\"}),\"\\uFF1A\\u521B\\u5EFA\\u4E00\\u4E2A BST \\u7C7B\\u7684\\u5B9E\\u4F8B\\u3002\\u5B83\\u5C06\\u6839\\u8282\\u70B9\\u521D\\u59CB\\u5316\\u4E3A \",(0,t.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u56E0\\u4E3A\\u6700\\u521D\\u6811\\u4E2D\\u6CA1\\u6709\\u8282\\u70B9\\u3002\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.code,{children:\"insert(value)\"}),\"\\uFF1A\\u5C06\\u4E00\\u4E2A\\u65B0\\u503C\\u6DFB\\u52A0\\u5230 BST \\u4E2D\\u3002\\u65B0\\u503C\\u88AB\\u63D2\\u5165\\u5230\\u6B63\\u786E\\u7684\\u4F4D\\u7F6E\\u4EE5\\u4FDD\\u6301\\u4E8C\\u53C9\\u641C\\u7D22\\u6811\\u7684\\u987A\\u5E8F\\u3002\\u5982\\u679C\\u6811\\u4E3A\\u7A7A\\uFF0C\\u5219\\u65B0\\u503C\\u6210\\u4E3A\\u6839\\u8282\\u70B9\\u3002\\u6240\\u9700\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1A\\u5E73\\u5747\\u4E3A O(log n)\\uFF0C\\u4F46\\u5728\\u6811\\u53D8\\u6210\\u7EBF\\u6027\\u94FE\\u7684\\u6700\\u574F\\u60C5\\u51B5\\u4E0B\\u53EF\\u80FD\\u4F1A\\u964D\\u4F4E\\u5230 O(n)\\u3002\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.code,{children:\"search(value)\"}),\"\\uFF1A\\u5728 BST \\u4E2D\\u641C\\u7D22\\u4E00\\u4E2A\\u503C\\u3002\\u5982\\u679C\\u8BE5\\u503C\\u5B58\\u5728\\u4E8E\\u6811\\u4E2D\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,t.jsx)(e.code,{children:\"true\"}),\"\\uFF1B\\u5426\\u5219\\uFF0C\\u8FD4\\u56DE \",(0,t.jsx)(e.code,{children:\"false\"}),\"\\u3002\\u6B64\\u64CD\\u4F5C\\u4E5F\\u9075\\u5FAA\\u5E73\\u5747\\u65F6\\u95F4\\u590D\\u6742\\u5EA6 O(log n)\\uFF0C\\u4F46\\u5728\\u6700\\u574F\\u60C5\\u51B5\\u4E0B\\u53EF\\u80FD\\u53D8\\u4E3A O(n)\\u3002\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.code,{children:\"delete(value)\"}),\"\\uFF1A\\u5982\\u679C\\u5B58\\u5728\\uFF0C\\u5219\\u4ECE BST \\u4E2D\\u5220\\u9664\\u4E00\\u4E2A\\u503C\\u3002\\u6B64\\u65B9\\u6CD5\\u9700\\u8981\\u5904\\u7406\\u4E09\\u79CD\\u60C5\\u51B5\\uFF1A\\u5220\\u9664\\u6CA1\\u6709\\u5B50\\u8282\\u70B9\\u7684\\u8282\\u70B9\\u3001\\u4E00\\u4E2A\\u5B50\\u8282\\u70B9\\u7684\\u8282\\u70B9\\u6216\\u4E24\\u4E2A\\u5B50\\u8282\\u70B9\\u7684\\u8282\\u70B9\\u3002\\u8BE5\\u51FD\\u6570\\u5728\\u5220\\u9664\\u540E\\u4FDD\\u6301 BST \\u7684\\u5C5E\\u6027\\u3002\\u6240\\u9700\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1A\\u5E73\\u5747\\u4E3A O(log n)\\uFF0C\\u4F46\\u5728\\u6700\\u574F\\u60C5\\u51B5\\u4E0B\\u53EF\\u80FD\\u4E3A O(n)\\u3002\"]}),`\n`]}),`\n`,(0,t.jsx)(e.h2,{children:\"\\u4F8B\\u5B50\"}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-js\",children:`const bst = new BST();\nbst.insert(15);\nbst.insert(10);\nbst.insert(20);\nbst.search(10); // true\nbst.delete(10);\nbst.search(10); // false\n`})})]})}function j(n={}){let{wrapper:e}=n.components||{};return e?(0,t.jsx)(e,Object.assign({},n,{children:(0,t.jsx)(a,n)})):a(n)}var O=j;return S(f);})();\n;return Component;", + "info": { + "excerpt": "实现一个二叉搜索树数据结构,包括基本的 BST 操作", + "title": "二叉搜索树" + }, + "solution": "var Component=(()=>{var f=Object.create;var o=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty;var m=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),w=(t,e)=>{for(var n in e)o(t,n,{get:e[n],enumerable:!0})},i=(t,e,n,u)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let l of p(e))!T.call(t,l)&&l!==n&&o(t,l,{get:()=>e[l],enumerable:!(u=v(e,l))||u.enumerable});return t};var S=(t,e,n)=>(n=t!=null?f(g(t)):{},i(e||!t||!t.__esModule?o(n,\"default\",{value:t,enumerable:!0}):n,t)),B=t=>i(o({},\"__esModule\",{value:!0}),t);var s=m((M,c)=>{c.exports=_jsx_runtime});var y={};w(y,{default:()=>O});var r=S(s());var d=MDXCodeBlock;var a=`class Node {\n constructor(value = null) {\n this.value = value;\n this.left = null;\n this.right = null;\n }\n}\n\nexport default class BinarySearchTree {\n constructor() {\n this.root = null;\n }\n\n /**\n * Inserts a new value into the BST while maintaining BST properties.\n * @param {*} value The value to be inserted into the BST.\n */\n insert(value) {\n const newNode = new Node(value);\n if (this.root === null) {\n this.root = newNode;\n return;\n }\n\n let currentNode = this.root;\n let parent = null;\n while (currentNode) {\n parent = currentNode;\n if (value < currentNode.value) {\n currentNode = currentNode.left;\n } else {\n currentNode = currentNode.right;\n }\n }\n\n if (value < parent.value) {\n parent.left = newNode;\n } else {\n parent.right = newNode;\n }\n }\n\n /**\n * Searches for a value in the BST. Returns true if the value exists, false otherwise.\n * @param {*} value The value to search for.\n * @return {boolean} True if the value is found, false otherwise.\n */\n search(value) {\n let currentNode = this.root;\n while (currentNode) {\n if (value === currentNode.value) {\n return true;\n }\n currentNode =\n value < currentNode.value ? currentNode.left : currentNode.right;\n }\n return false;\n }\n\n /**\n * Deletes a value from the BST, if it exists, while maintaining BST properties.\n * @param {*} value The value to be deleted from the BST.\n */\n delete(value) {\n let currentNode = this.root;\n let parent = null;\n\n // Find the node and its parent.\n while (currentNode && currentNode.value !== value) {\n parent = currentNode;\n if (value < currentNode.value) {\n currentNode = currentNode.left;\n } else {\n currentNode = currentNode.right;\n }\n }\n\n if (!currentNode) {\n return; // Node not found.\n }\n\n // Node has two children.\n if (currentNode.left && currentNode.right) {\n let successor = currentNode.right;\n let successorParent = currentNode;\n\n // Find the node with the smallest value in the right subtree and take note of its parent.\n while (successor.left) {\n successorParent = successor;\n successor = successor.left;\n }\n\n currentNode.value = successor.value; // Replace value.\n currentNode = successor; // Move pointer to successor, which will be deleted.\n parent = successorParent;\n }\n\n // Node has one or zero children.\n let child = currentNode.left ? currentNode.left : currentNode.right;\n\n // If the node to be deleted is the root node.\n if (!parent) {\n this.root = child;\n } else {\n if (parent.left === currentNode) {\n parent.left = child;\n } else {\n parent.right = child;\n }\n }\n }\n}\n`;var h=`class Node {\n value: number | null;\n left: Node | null;\n right: Node | null;\n\n constructor(value: number | null = null) {\n this.value = value;\n this.left = null;\n this.right = null;\n }\n}\n\nexport default class BinarySearchTree {\n root: Node | null;\n\n constructor() {\n this.root = null;\n }\n\n /**\n * Inserts a new value into the BST while maintaining BST properties.\n * @param value The value to be inserted into the BST.\n */\n insert(value: number): void {\n const newNode = new Node(value);\n if (this.root === null) {\n this.root = newNode;\n return;\n }\n\n let currentNode: Node | null = this.root;\n let parent: Node | null = null;\n while (currentNode) {\n parent = currentNode;\n if (value < currentNode.value!) {\n currentNode = currentNode.left;\n } else {\n currentNode = currentNode.right;\n }\n }\n\n if (parent && value < parent.value!) {\n parent.left = newNode;\n } else if (parent) {\n parent.right = newNode;\n }\n }\n\n /**\n * Searches for a value in the BST. Returns true if the value exists, false otherwise.\n * @param value The value to search for.\n * @return True if the value is found, false otherwise.\n */\n search(value: number): boolean {\n let currentNode = this.root;\n while (currentNode) {\n if (value === currentNode.value) {\n return true;\n }\n currentNode =\n value < currentNode.value! ? currentNode.left : currentNode.right;\n }\n return false;\n }\n\n /**\n * Deletes a value from the BST, if it exists, while maintaining BST properties.\n * @param value The value to be deleted from the BST.\n */\n delete(value: number): void {\n let currentNode = this.root;\n let parent: Node | null = null;\n\n // Find the node and its parent.\n while (currentNode && currentNode.value !== value) {\n parent = currentNode;\n if (value < currentNode.value!) {\n currentNode = currentNode.left;\n } else {\n currentNode = currentNode.right;\n }\n }\n\n if (!currentNode) {\n return; // Node not found.\n }\n\n // Node has two children.\n if (currentNode.left && currentNode.right) {\n let successor = currentNode.right;\n let successorParent = currentNode;\n\n // Find the node with the smallest value in the right subtree and take note of its parent.\n while (successor.left) {\n successorParent = successor;\n successor = successor.left;\n }\n\n currentNode.value = successor.value; // Replace value.\n currentNode = successor; // Move pointer to successor, which will be deleted.\n parent = successorParent;\n }\n\n // Node has one or zero children.\n let child = currentNode.left ? currentNode.left : currentNode.right;\n\n // If the node to be deleted is the root node.\n if (!parent) {\n this.root = child;\n } else {\n if (parent.left === currentNode) {\n parent.left = child;\n } else {\n parent.right = child;\n }\n }\n }\n}\n`;function N(t){let e=Object.assign({h2:\"h2\",p:\"p\",h3:\"h3\",ul:\"ul\",li:\"li\",code:\"code\",img:\"img\",strong:\"strong\"},t.components);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e.h2,{children:\"\\u89E3\\u51B3\\u65B9\\u6848\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u4E8C\\u53C9\\u641C\\u7D22\\u6811 (BST) \\u662F\\u8BA1\\u7B97\\u673A\\u79D1\\u5B66\\u4E2D\\u7684\\u4E00\\u79CD\\u57FA\\u672C\\u6570\\u636E\\u7ED3\\u6784\\uFF0C\\u4E3B\\u8981\\u7528\\u4E8E\\u4EE5\\u6392\\u5E8F\\u987A\\u5E8F\\u7EF4\\u62A4\\u52A8\\u6001\\u53D8\\u5316\\u7684\\u6570\\u636E\\u96C6\\u3002BST \\u4E2D\\u7684\\u6BCF\\u4E2A\\u8282\\u70B9\\u90FD\\u5305\\u542B\\u4E00\\u4E2A\\u952E\\u548C\\u6307\\u5411\\u5176\\u5DE6\\u5B50\\u8282\\u70B9\\u548C\\u53F3\\u5B50\\u8282\\u70B9\\u7684\\u6307\\u9488\\u3002\\u8BE5\\u6811\\u7684\\u7ED3\\u6784\\u4F7F\\u5F97\\u5BF9\\u4E8E\\u4EFB\\u4F55\\u7ED9\\u5B9A\\u7684\\u8282\\u70B9\\uFF0C\\u5176\\u5DE6\\u5B50\\u6811\\u4E2D\\u7684\\u6240\\u6709\\u8282\\u70B9\\u90FD\\u5177\\u6709\\u5C0F\\u4E8E\\u8BE5\\u8282\\u70B9\\u952E\\u7684\\u952E\\uFF0C\\u5E76\\u4E14\\u5176\\u53F3\\u5B50\\u6811\\u4E2D\\u7684\\u6240\\u6709\\u8282\\u70B9\\u90FD\\u5177\\u6709\\u5927\\u4E8E\\u8BE5\\u8282\\u70B9\\u952E\\u7684\\u952E\\u3002\\u6B64\\u5C5E\\u6027\\u652F\\u6301\\u9AD8\\u6548\\u7684\\u641C\\u7D22\\u3001\\u63D2\\u5165\\u548C\\u5220\\u9664\\u64CD\\u4F5C\\u3002\"}),`\n`,(0,r.jsx)(d,{languages:{jsx:a,tsx:h}}),`\n`,(0,r.jsx)(e.h3,{children:\"\\u64CD\\u4F5C\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"new BST()\"}),\"\\uFF1A\\u521D\\u59CB\\u5316 BST \\u7684\\u65B0\\u5B9E\\u4F8B\\u3002\\u6784\\u9020\\u51FD\\u6570\\u5C06\\u6811\\u7684\\u6839\\u8BBE\\u7F6E\\u4E3A null\\uFF0C\\u8868\\u793A\\u6811\\u6700\\u521D\\u4E3A\\u7A7A\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"insert(value)\"}),\"\\uFF1A\\u5C06\\u5177\\u6709\\u7ED9\\u5B9A\\u503C\\u7684\\u8282\\u70B9\\u6DFB\\u52A0\\u5230 BST\\u3002\\u5982\\u679C\\u6811\\u4E3A\\u7A7A\\uFF0C\\u5219\\u65B0\\u8282\\u70B9\\u5C06\\u6210\\u4E3A\\u6839\\u3002\\u5982\\u679C\\u4E0D\\u662F\\uFF0C\\u5219\\u4ECE\\u6839\\u5F00\\u59CB\\u904D\\u5386\\u6811\\uFF0C\\u4EE5\\u627E\\u5230\\u65B0\\u8282\\u70B9\\u4EE5\\u7EF4\\u62A4 BST \\u5C5E\\u6027\\u7684\\u6B63\\u786E\\u4F4D\\u7F6E\\u3002\\u6B64\\u64CD\\u4F5C\\u6D89\\u53CA\\u5C06\\u65B0\\u503C\\u4E0E\\u5F53\\u524D\\u8282\\u70B9\\u7684\\u503C\\u8FDB\\u884C\\u6BD4\\u8F83\\uFF0C\\u5E76\\u51B3\\u5B9A\\u5411\\u5DE6\\u6216\\u5411\\u53F3\\u79FB\\u52A8\\u3002\\u5E73\\u5747\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(log n)\\uFF0C\\u4F46\\u5982\\u679C\\u6309\\u5347\\u5E8F/\\u964D\\u5E8F\\u63D2\\u5165\\u503C\\uFF0C\\u5219\\u53EF\\u80FD\\u4F1A\\u964D\\u4F4E\\u5230 O(n)\\u3002\"]}),`\n`]}),`\n`,(0,r.jsx)(e.p,{children:(0,r.jsx)(e.img,{src:\"/img/questions/binary-search-tree/insert.png\",alt:\"Insert\"})}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"search(value)\"}),\"\\uFF1A\\u641C\\u7D22\\u5305\\u542B\\u6307\\u5B9A\\u503C\\u7684\\u8282\\u70B9\\u3002\\u4ECE\\u6839\\u5F00\\u59CB\\uFF0C\\u6839\\u636E\\u76EE\\u6807\\u503C\\u4E0E\\u5F53\\u524D\\u8282\\u70B9\\u7684\\u503C\\u7684\\u6BD4\\u8F83\\u7ED3\\u679C\\uFF0C\\u5411\\u5DE6\\u6216\\u5411\\u53F3\\u904D\\u5386\\u6811\\u3002\\u91CD\\u590D\\u6B64\\u8FC7\\u7A0B\\uFF0C\\u76F4\\u5230\\u627E\\u5230\\u8BE5\\u503C\\u6216\\u5230\\u8FBE\\u53F6\\u5B50\\u3002\\u4E0E \",(0,r.jsx)(e.code,{children:\"insert(value)\"}),\" \\u7C7B\\u4F3C\\uFF0C\\u5E73\\u5747\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(log n)\\uFF0C\\u6700\\u574F\\u60C5\\u51B5\\u4E3A O(n)\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"delete(value)\"}),\"\\uFF1A\\u4ECE BST \\u4E2D\\u5220\\u9664\\u5177\\u6709\\u6307\\u5B9A\\u503C\\u7684\\u8282\\u70B9\\u3002\\u6B64\\u64CD\\u4F5C\\u66F4\\u4E3A\\u590D\\u6742\\uFF0C\\u56E0\\u4E3A\\u5B83\\u9700\\u8981\\u5904\\u7406\\u4E09\\u79CD\\u60C5\\u51B5\\uFF1A\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"\\u53F6\\u8282\\u70B9\\uFF1A\\u76F4\\u63A5\\u5220\\u9664\\u8BE5\\u8282\\u70B9\\u3002\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u5177\\u6709\\u4E00\\u4E2A\\u5B50\\u8282\\u70B9\\u7684\\u8282\\u70B9\\uFF1A\\u5220\\u9664\\u8BE5\\u8282\\u70B9\\u5E76\\u5C06\\u5176\\u66FF\\u6362\\u4E3A\\u5176\\u5B50\\u8282\\u70B9\\u3002\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u5177\\u6709\\u4E24\\u4E2A\\u5B50\\u8282\\u70B9\\u7684\\u8282\\u70B9\\uFF1A\\u5C06\\u8282\\u70B9\\u7684\\u503C\\u66FF\\u6362\\u4E3A\\u53F3\\u5B50\\u6811\\u4E2D\\u7684\\u6700\\u5C0F\\u503C\\uFF0C\\u7136\\u540E\\u5220\\u9664\\u540E\\u7EE7\\u8282\\u70B9\\u3002\"}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,r.jsx)(e.p,{children:(0,r.jsx)(e.img,{src:\"/img/questions/binary-search-tree/delete.png\",alt:\"Delete\"})}),`\n`,(0,r.jsx)(e.p,{children:\"\\u5220\\u9664\\u8FC7\\u7A0B\\u786E\\u4FDD\\u5728\\u5220\\u9664\\u8282\\u70B9\\u540E\\u7EF4\\u62A4 BST \\u5C5E\\u6027\\u3002\\u4E0E\\u63D2\\u5165\\u7C7B\\u4F3C\\uFF0C\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u5E73\\u5747\\u4E3A O(log n)\\uFF0C\\u4F46\\u53EF\\u80FD\\u53D8\\u4E3A O(n)\\u3002\"}),`\n`,(0,r.jsx)(e.h2,{children:\"\\u8FB9\\u7F18\\u60C5\\u51B5\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"\\u63D2\\u5165\\u6811\\u4E2D\\u5DF2\\u5B58\\u5728\\u7684\\u503C\\u3002\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u4ECE\\u7A7A\\u6811\\u6216\\u4E0D\\u5B58\\u5728\\u7684\\u503C\\u4E2D\\u5220\\u9664\\u8282\\u70B9\\u3002\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u641C\\u7D22\\u6811\\u4E2D\\u4E0D\\u5B58\\u5728\\u7684\\u503C\\u3002\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u5220\\u9664\\u4E8C\\u53C9\\u641C\\u7D22\\u6811\\u4E2D\\u7684\\u91CD\\u590D\\u503C\\u3002\"}),`\n`]}),`\n`,(0,r.jsx)(e.h2,{children:\"\\u6280\\u672F\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u4E2D\\u5E8F\\u904D\\u5386\"}),\"\\uFF1A\\u5728\\u5220\\u9664\\u64CD\\u4F5C\\u671F\\u95F4\\u7528\\u4E8E\\u67E5\\u627E\\u540E\\u7EE7\\u8282\\u70B9\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u9762\\u5411\\u5BF9\\u8C61\\u8BBE\\u8BA1\"}),\"\\uFF1A\\u4F7F\\u7528 Node \\u7C7B\\u8868\\u793A\\u6BCF\\u4E2A\\u6811\\u8282\\u70B9\\uFF0C\\u5E76\\u4F7F\\u7528 BST \\u7C7B\\u8FDB\\u884C\\u6811\\u64CD\\u4F5C\\uFF0C\\u4ECE\\u800C\\u63D0\\u4F9B\\u6E05\\u6670\\u7684\\u7ED3\\u6784\\u548C\\u5C01\\u88C5\\u3002\"]}),`\n`]}),`\n`,(0,r.jsxs)(e.p,{children:[\"\\u6B64\\u4E8C\\u53C9\\u641C\\u7D22\\u6811\\u5B9E\\u73B0\\u4F7F\\u7528\\u8FED\\u4EE3\\u89E3\\u51B3\\u65B9\\u6848\\uFF0C\\u800C \",(0,r.jsx)(e.code,{children:\"delete(value)\"}),\" \\u7684\\u9012\\u5F52\\u89E3\\u51B3\\u65B9\\u6848\\u53EF\\u80FD\\u66F4\\u5BB9\\u6613\\u5B9E\\u73B0\\u3002\"]})]})}function j(t={}){let{wrapper:e}=t.components||{};return e?(0,r.jsx)(e,Object.assign({},t,{children:(0,r.jsx)(N,t)})):N(t)}var O=j;return B(y);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/binary-search/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/binary-search/locales/zh-CN.json new file mode 100644 index 000000000..fc44920b9 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/binary-search/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var d=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var u=(e,n)=>()=>(n||e((n={exports:{}}).exports,n),n.exports),_=(e,n)=>{for(var c in n)i(e,c,{get:n[c],enumerable:!0})},o=(e,n,c,l)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let t of m(n))!j.call(e,t)&&t!==c&&i(e,t,{get:()=>n[t],enumerable:!(l=p(n,t))||l.enumerable});return e};var g=(e,n,c)=>(c=e!=null?d(x(e)):{},o(n||!e||!e.__esModule?i(c,\"default\",{value:e,enumerable:!0}):c,e)),f=e=>o(i({},\"__esModule\",{value:!0}),e);var s=u((F,h)=>{h.exports=_jsx_runtime});var C={};_(C,{default:()=>M,frontmatter:()=>b});var r=g(s()),b={title:\"\\u4E8C\\u5206\\u67E5\\u627E\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u5BF9\\u6570\\u5B57\\u6570\\u7EC4\\u6267\\u884C\\u4E8C\\u5206\\u67E5\\u627E\\u7684\\u51FD\\u6570\"};function a(e){let n=Object.assign({p:\"p\",h2:\"h2\",pre:\"pre\",code:\"code\",ol:\"ol\",li:\"li\"},e.components);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.p,{children:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u5BF9\\u6570\\u5B57\\u6570\\u7EC4\\u6267\\u884C\\u4E8C\\u5206\\u67E5\\u627E\\u7684\\u51FD\\u6570\\u3002\\u8BE5\\u51FD\\u6570\\u5E94\\u63A5\\u6536\\u4E00\\u4E2A\\u5DF2\\u6392\\u5E8F\\u7684\\u6574\\u6570\\u6570\\u7EC4\\u548C\\u4E00\\u4E2A\\u8981\\u67E5\\u627E\\u7684\\u76EE\\u6807\\u6574\\u6570\\u3002\\u5982\\u679C\\u76EE\\u6807\\u5143\\u7D20\\u4E0D\\u5B58\\u5728\\u4E8E\\u6570\\u7EC4\\u4E2D\\uFF0C\\u5219\\u8FD4\\u56DE\\u76EE\\u6807\\u5143\\u7D20\\u7684\\u7D22\\u5F15\\u6216 -1\\u3002\"}),`\n`,(0,r.jsx)(n.h2,{children:\"\\u4F8B\\u5B50\"}),`\n`,(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:\"language-js\",children:`binarySearch([1, 2, 3, 6, 9, 11], 6); // 3\nbinarySearch([1, 2, 3, 12, 14, 16], 5); // -1\n`})}),`\n`,(0,r.jsx)(n.h2,{children:\"\\u56DE\\u987E\"}),`\n`,(0,r.jsx)(n.p,{children:\"\\u4E8C\\u5206\\u67E5\\u627E\\u662F\\u4E00\\u79CD\\u641C\\u7D22\\u7B97\\u6CD5\\uFF0C\\u53EF\\u4EE5\\u6709\\u6548\\u5730\\u786E\\u5B9A\\u5DF2\\u6392\\u5E8F\\u7684\\u6574\\u6570\\u6570\\u7EC4\\u662F\\u5426\\u5305\\u542B\\u7279\\u5B9A\\u6570\\u5B57\\u3002\\u8BE5\\u7B97\\u6CD5\\u5C06\\u8F93\\u5165\\u6570\\u7EC4\\u91CD\\u590D\\u5730\\u5206\\u6210\\u4E24\\u534A\\uFF0C\\u76F4\\u5230\\u627E\\u5230\\u76EE\\u6807\\u5143\\u7D20\\uFF0C\\u4ECE\\u800C\\u4F7F\\u641C\\u7D22\\u7A7A\\u95F4\\u6BCF\\u4E00\\u6B65\\u90FD\\u51CF\\u5C11\\u4E00\\u534A\\u3002\\u4E0E\\u7EBF\\u6027\\u641C\\u7D22\\u76F8\\u6BD4\\uFF0C\\u8FD9\\u662F\\u4E00\\u4E2A\\u663E\\u7740\\u7684\\u6539\\u8FDB\\u3002\"}),`\n`,(0,r.jsx)(n.p,{children:\"\\u4EE5\\u4E0B\\u662F\\u5173\\u4E8E\\u4E8C\\u5206\\u67E5\\u627E\\u5728\\u5DF2\\u6392\\u5E8F\\u6570\\u7EC4\\u4E0A\\u5982\\u4F55\\u5DE5\\u4F5C\\u7684\\u5FEB\\u901F\\u8BF4\\u660E\\uFF1A\"}),`\n`,(0,r.jsxs)(n.ol,{children:[`\n`,(0,r.jsx)(n.li,{children:\"\\u8BA1\\u7B97\\u6570\\u7EC4\\u7684\\u4E2D\\u95F4\\u7D22\\u5F15\\u5E76\\u68C0\\u7D22\\u4E2D\\u95F4\\u5143\\u7D20\\u3002\"}),`\n`,(0,r.jsx)(n.li,{children:\"\\u5982\\u679C\\u76EE\\u6807\\u5143\\u7D20\\u5927\\u4E8E\\u4E2D\\u95F4\\u5143\\u7D20\\uFF0C\\u5219\\u641C\\u7D22\\u6570\\u7EC4\\u7684\\u53F3\\u534A\\u90E8\\u5206\\uFF08\\u5FFD\\u7565\\u5DE6\\u534A\\u90E8\\u5206\\uFF09\\u3002\"}),`\n`,(0,r.jsx)(n.li,{children:\"\\u5982\\u679C\\u76EE\\u6807\\u5143\\u7D20\\u5C0F\\u4E8E\\u4E2D\\u95F4\\u5143\\u7D20\\uFF0C\\u5219\\u641C\\u7D22\\u6570\\u7EC4\\u7684\\u5DE6\\u534A\\u90E8\\u5206\\u3002\"}),`\n`,(0,r.jsx)(n.li,{children:\"\\u5982\\u679C\\u76EE\\u6807\\u5143\\u7D20\\u7B49\\u4E8E\\u4E2D\\u95F4\\u5143\\u7D20\\uFF0C\\u5219\\u8FD4\\u56DE\\u8BE5\\u5143\\u7D20\\u7684\\u7D22\\u5F15\\u3002\"}),`\n`,(0,r.jsx)(n.li,{children:\"\\u91CD\\u590D\\u4E0A\\u8FF0\\u6B65\\u9AA4\\uFF0C\\u76F4\\u5230\\u6211\\u4EEC\\u5B8C\\u6210\\u641C\\u7D22\\u3002\\u5982\\u679C\\u672A\\u627E\\u5230\\u76EE\\u6807\\uFF0C\\u5219\\u8FD4\\u56DE -1\\u3002\"}),`\n`]})]})}function y(e={}){let{wrapper:n}=e.components||{};return n?(0,r.jsx)(n,Object.assign({},e,{children:(0,r.jsx)(a,e)})):a(e)}var M=y;return f(C);})();\n;return Component;", + "info": { + "excerpt": "实现一个对数字数组执行二分查找的函数", + "title": "二分查找" + }, + "solution": "var Component=(()=>{var u=Object.create;var a=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var I=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),j=(r,e)=>{for(var n in e)a(r,n,{get:e[n],enumerable:!0})},d=(r,e,n,l)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of y(e))!b.call(r,i)&&i!==n&&a(r,i,{get:()=>e[i],enumerable:!(l=p(e,i))||l.enumerable});return r};var S=(r,e,n)=>(n=r!=null?u(x(r)):{},d(e||!r||!r.__esModule?a(n,\"default\",{value:r,enumerable:!0}):n,r)),O=r=>d(a({},\"__esModule\",{value:!0}),r);var m=I((D,o)=>{o.exports=_jsx_runtime});var w={};j(w,{default:()=>v});var t=S(m());var h=MDXCodeBlock;var s=`/**\n * @param {Array} arr The input integer array to be searched.\n * @param {number} target The target integer to search within the array.\n * @return {number} The index of target element in the array, or -1 if not found.\n */\nexport default function binarySearch(arr, target) {\n // Initialize the left and right indices of the array\n let left = 0;\n let right = arr.length - 1;\n\n // Keep searching until the left and right indices meet.\n while (left <= right) {\n // Calculate the mid index to retrieve the mid element later.\n const mid = Math.floor((left + right) / 2);\n\n if (target < arr[mid]) {\n // If the target element is less than the middle element,\n // search the left half of the array.\n // Adjust the right index so the next loop iteration\n // searches the left side.\n right = mid - 1;\n } else if (target > arr[mid]) {\n // If the target element is greater than the middle element,\n // search the right half of the array.\n // Adjust the left index so the next loop iteration\n // searches the left side.\n left = mid + 1;\n } else {\n // If the target element is equal to the middle element,\n // return the index of the middle element.\n return mid;\n }\n }\n\n // If the element is not found, return -1.\n return -1;\n}\n`;var c=`export default function binarySearch(\n arr: Array,\n target: number,\n): number {\n // Initialize the left and right indices of the array\n let left = 0;\n let right = arr.length - 1;\n\n // Keep searching until the left and right indices meet.\n while (left <= right) {\n // Calculate the mid index to retrieve the mid element later.\n const mid = Math.floor((left + right) / 2);\n\n if (target < arr[mid]) {\n // If the target element is less than the middle element,\n // search the left half of the array.\n // Adjust the right index so the next loop iteration\n // searches the left side.\n right = mid - 1;\n } else if (target > arr[mid]) {\n // If the target element is greater than the middle element,\n // search the right half of the array.\n // Adjust the left index so the next loop iteration\n // searches the left side.\n left = mid + 1;\n } else {\n // If the target element is equal to the middle element,\n // return the index of the middle element.\n return mid;\n }\n }\n\n // If the element is not found, return -1.\n return -1;\n}\n`;var f=`/**\n * @param {Array} arr The input integer array to be searched.\n * @param {number} target Target integer to search within the array\n * @return {number} Index of target element in the array, or -1 if not found\n */\nexport default function binarySearch(arr, target) {\n return binarySearchImpl(arr, target, 0, arr.length - 1);\n}\n\nfunction binarySearchImpl(arr, target, left, right) {\n // Return immediately if the range to search is empty,\n // since the target element hasn't been found / won't be found.\n if (left > right) {\n return -1;\n }\n\n // Calculate the mid index to retrieve the mid element later.\n const mid = Math.floor((left + right) / 2);\n\n if (target < arr[mid]) {\n // If the target element is less than the middle element,\n // search the left half of the array and adjust the input\n // array passed into the recursive call accordingly.\n return binarySearchImpl(arr, target, left, mid - 1);\n }\n\n if (target > arr[mid]) {\n // If the target element is greater than the middle element,\n // search the right half of the array and adjust the input\n // array passed into the recursive call accordingly.\n return binarySearchImpl(arr, target, mid + 1, right);\n }\n\n // If the target element is equal to the middle element,\n // return the index of the middle element\n return mid;\n}\n`;function g(r){let e=Object.assign({p:\"p\",h2:\"h2\",ul:\"ul\",li:\"li\",h3:\"h3\"},r.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(e.p,{children:\"\\u4E8C\\u5206\\u67E5\\u627E\\u662F\\u4E00\\u79CD\\u9AD8\\u6548\\u7684\\u641C\\u7D22\\u7B97\\u6CD5\\uFF0C\\u5B83\\u5728\\u6BCF\\u4E00\\u6B65\\u90FD\\u5C06\\u641C\\u7D22\\u7A7A\\u95F4\\u51CF\\u534A\\uFF0C\\u8FD9\\u610F\\u5473\\u7740\\u5B83\\u53EF\\u4EE5\\u5728 O(log(n)) \\u65F6\\u95F4\\u5185\\u627E\\u5230\\u76EE\\u6807\\u5143\\u7D20\\uFF0C\\u5176\\u4E2D n \\u662F\\u8F93\\u5165\\u6570\\u7EC4\\u7684\\u5927\\u5C0F\\u3002\\u8FD9\\u4F7F\\u5F97\\u5B83\\u6BD4\\u7EBF\\u6027\\u641C\\u7D22\\u5FEB\\u5F97\\u591A\\uFF0C\\u7EBF\\u6027\\u641C\\u7D22\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(n)\\u3002\"}),`\n`,(0,t.jsx)(e.h2,{children:\"\\u6F84\\u6E05\\u95EE\\u9898\"}),`\n`,(0,t.jsx)(e.p,{children:\"\\u5982\\u679C\\u672A\\u6307\\u5B9A\\uFF1A\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsx)(e.li,{children:\"\\u6392\\u5E8F\\u987A\\u5E8F\\uFF1A\\u662F\\u5347\\u5E8F\\u8FD8\\u662F\\u964D\\u5E8F\\uFF1F\"}),`\n`,(0,t.jsxs)(e.li,{children:[\"\\u6211\\u4EEC\\u9700\\u8981\\u5904\\u7406\\u4EC0\\u4E48\\u6837\\u7684\\u8F93\\u5165\\uFF1F\",`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsx)(e.li,{children:\"\\u5B83\\u53EA\\u662F\\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4\\uFF0C\\u8FD8\\u662F\\u6211\\u4EEC\\u5E94\\u8BE5\\u5904\\u7406\\u5176\\u4ED6\\u6570\\u636E\\u7C7B\\u578B\\uFF1F\"}),`\n`,(0,t.jsx)(e.li,{children:\"\\u662F\\u5426\\u6709\\u91CD\\u590D\\u7684\\u5143\\u7D20\\uFF1F\"}),`\n`,(0,t.jsx)(e.li,{children:\"\\u5E94\\u8BE5\\u5982\\u4F55\\u5904\\u7406\\u8D1F\\u6570\\uFF1F\"}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,t.jsx)(e.h2,{children:\"\\u89E3\\u51B3\\u65B9\\u6848\"}),`\n`,(0,t.jsx)(e.p,{children:\"\\u6CE8\\u610F\\uFF1A\\u8FD9\\u4E2A\\u95EE\\u9898\\u5904\\u7406\\u7684\\u662F\\u4E00\\u4E2A\\u6807\\u51C6\\u7684\\u4E8C\\u5206\\u67E5\\u627E\\uFF0C\\u5B83\\u4F7F\\u7528\\u8FED\\u4EE3\\u65B9\\u6CD5\\uFF0C\\u5E76\\u5047\\u8BBE\\u6570\\u7EC4\\u5DF2\\u7ECF\\u6392\\u5E8F\\u3002\\u6709\\u5173\\u5176\\u4ED6\\u66FF\\u4EE3\\u65B9\\u6848\\uFF0C\\u8BF7\\u53C2\\u9605\\u201C\\u6CE8\\u91CA\\u201D\\u90E8\\u5206\\u3002\"}),`\n`,(0,t.jsx)(h,{languages:{jsx:s,tsx:c}}),`\n`,(0,t.jsx)(e.p,{children:\"\\u5982\\u679C\\u9762\\u8BD5\\u5B98\\u8981\\u6C42\\u4F7F\\u7528\\u9012\\u5F52\\u65B9\\u6CD5\\uFF1A\"}),`\n`,(0,t.jsx)(h,{children:f}),`\n`,(0,t.jsx)(e.h2,{children:\"\\u8FB9\\u7F18\\u60C5\\u51B5\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsx)(e.li,{children:\"\\u975E\\u6574\\u6570\\u5143\\u7D20\\u8F93\\u5165\\uFF1A\\u5982\\u679C\\u8F93\\u5165\\u6570\\u7EC4\\u5305\\u542B\\u4E0D\\u540C\\u6570\\u636E\\u7C7B\\u578B\\u7684\\u5143\\u7D20\\uFF0C\\u60A8\\u53EF\\u80FD\\u9700\\u8981\\u8FD4\\u56DE\\u4E00\\u4E2A\\u9519\\u8BEF\\uFF0C\\u4EE5\\u5C3D\\u529B\\u800C\\u4E3A\\u7684\\u65B9\\u5F0F\\u8FDB\\u884C\\u6392\\u5E8F\\uFF0C\\u4F8B\\u5982\\uFF0C\\u4EC5\\u5BF9\\u8F93\\u5165\\u6570\\u636E\\u7684\\u5B50\\u96C6\\u8FDB\\u884C\\u6392\\u5E8F\\uFF0C\\u751A\\u81F3\\u4E3A\\u975E\\u6574\\u6570\\u5B9A\\u4E49\\u81EA\\u5B9A\\u4E49\\u6BD4\\u8F83\\u51FD\\u6570\\u3002\"}),`\n`]}),`\n`,(0,t.jsx)(e.h2,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,t.jsx)(e.p,{children:\"\\u8BA9\\u6211\\u4EEC\\u5206\\u6790\\u4E00\\u4E0B\\u7B97\\u6CD5\\u7684\\u65F6\\u95F4\\u548C\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u3002\"}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\"}),`\n`,(0,t.jsx)(e.p,{children:\"\\u4E8C\\u5206\\u67E5\\u627E\\u5728\\u5E73\\u5747\\u548C\\u6700\\u574F\\u60C5\\u51B5\\u4E0B\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(log(n))\\uFF0C\\u56E0\\u4E3A\\u5B83\\u6BCF\\u4E00\\u6B65\\u90FD\\u5C06\\u641C\\u7D22\\u7A7A\\u95F4\\u51CF\\u534A\\u3002\\u5373\\u4F7F\\u5728\\u76EE\\u6807\\u5143\\u7D20\\u4E0D\\u5728\\u6570\\u7EC4\\u4E2D\\u7684\\u6700\\u574F\\u60C5\\u51B5\\u4E0B\\uFF0C\\u5B83\\u4ECD\\u7136\\u5C06\\u641C\\u7D22\\u7A7A\\u95F4\\u51CF\\u534A\\uFF0C\\u56E0\\u6B64\\u5728\\u5BF9\\u6570\\u65F6\\u95F4\\u5185\\u5B8C\\u6210\\u641C\\u7D22\\u3002\"}),`\n`,(0,t.jsx)(e.p,{children:\"\\u5728\\u6700\\u4F73\\u60C5\\u51B5\\u4E0B\\uFF0C\\u4E8C\\u5206\\u67E5\\u627E\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(1)\\u3002\\u5F53\\u76EE\\u6807\\u5143\\u7D20\\u6070\\u597D\\u4F4D\\u4E8E\\u8F93\\u5165\\u6570\\u7EC4\\u7684\\u4E2D\\u95F4\\u7D22\\u5F15\\u65F6\\uFF0C\\u5C31\\u4F1A\\u53D1\\u751F\\u8FD9\\u79CD\\u60C5\\u51B5\\u3002\"}),`\n`,(0,t.jsx)(e.p,{children:\"\\u4F46\\u662F\\uFF0C\\u4E8C\\u5206\\u67E5\\u627E\\u5047\\u8BBE\\u8F93\\u5165\\u6570\\u7EC4\\u5DF2\\u6392\\u5E8F\\u3002\\u5982\\u679C\\u9700\\u8981\\u6392\\u5E8F\\uFF0C\\u5219\\u9700\\u8981\\u989D\\u5916\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF0C\\u5177\\u4F53\\u53D6\\u51B3\\u4E8E\\u6240\\u9009\\u7684\\u6392\\u5E8F\\u7B97\\u6CD5\\u3002\"}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\"}),`\n`,(0,t.jsx)(e.p,{children:\"\\u4E8C\\u5206\\u67E5\\u627E\\u5728\\u6240\\u6709\\u60C5\\u51B5\\u4E0B\\uFF0C\\u8FED\\u4EE3\\u65B9\\u6CD5\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(1)\\uFF0C\\u56E0\\u4E3A\\u5B83\\u4F7F\\u7528\\u6052\\u5B9A\\u7684\\u989D\\u5916\\u5185\\u5B58\\u6765\\u5B58\\u50A8\\u53D8\\u91CF\\u3002\\u9664\\u4E86\\u8F93\\u5165\\u4E4B\\u5916\\uFF0C\\u6211\\u4EEC\\u4E0D\\u4FDD\\u7559\\u989D\\u5916\\u7684\\u5185\\u5B58\\u3002\"}),`\n`,(0,t.jsx)(e.p,{children:\"\\u4F46\\u662F\\uFF0C\\u5982\\u679C\\u4F7F\\u7528\\u9012\\u5F52\\u65B9\\u6CD5\\uFF0C\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u53D6\\u51B3\\u4E8E\\u9012\\u5F52\\u8C03\\u7528\\u5806\\u6808\\u6240\\u9700\\u7684\\u7A7A\\u95F4\\u3002\\u7531\\u4E8E\\u9012\\u5F52\\u6811\\u7684\\u9AD8\\u5EA6\\u662F log(n) + 1\\uFF0C\\u5E76\\u4E14\\u5728\\u6BCF\\u4E00\\u5C42\\u53EA\\u6709\\u4E00\\u4E2A\\u9012\\u5F52\\u8C03\\u7528\\uFF0C\\u6211\\u4EEC\\u9884\\u8BA1\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(log(n))\\u3002\"})]})}function _(r={}){let{wrapper:e}=r.components||{};return e?(0,t.jsx)(e,Object.assign({},r,{children:(0,t.jsx)(g,r)})):g(r)}var v=_;return O(w);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/binary-tree-equal/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/binary-tree-equal/locales/zh-CN.json new file mode 100644 index 000000000..f837fcb7c --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/binary-tree-equal/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var i=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty;var g=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),N=(r,e)=>{for(var t in e)i(r,t,{get:e[t],enumerable:!0})},c=(r,e,t,d)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let l of m(e))!T.call(r,l)&&l!==t&&i(r,l,{get:()=>e[l],enumerable:!(d=f(e,l))||d.enumerable});return r};var _=(r,e,t)=>(t=r!=null?p(x(r)):{},c(e||!r||!r.__esModule?i(t,\"default\",{value:r,enumerable:!0}):t,r)),b=r=>c(i({},\"__esModule\",{value:!0}),r);var h=g((D,a)=>{a.exports=_jsx_runtime});var k={};N(k,{default:()=>M,frontmatter:()=>w});var n=_(h());var o=MDXTestExamples;var s=[{input:[[\"a\",[1,2]],[\"b\",[1,null,2]]],output:!1,explanation:\"The trees differ in the structure.\"},{input:[[\"a\",[3,null,7]],[\"b\",[3,5,7]]],output:!1,explanation:\"The first tree has a null left child, while the second tree has a left child with value 5.\"},{input:[[\"a\",[65,null,17]],[\"b\",[65,null,17]]],output:!0,explanation:\"Both trees have the same structure and node values.\"}];var w={title:\"\\u4E8C\\u53C9\\u6811\\u76F8\\u7B49\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u786E\\u5B9A\\u4E24\\u4E2A\\u4E8C\\u53C9\\u6811\\u662F\\u5426\\u76F8\\u7B49\"};function u(r){let e=Object.assign({p:\"p\",code:\"code\",pre:\"pre\",h3:\"h3\",ul:\"ul\",li:\"li\",a:\"a\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E24\\u68F5\\u4E8C\\u53C9\\u6811\\u7684\\u6839\\u8282\\u70B9\",(0,n.jsx)(e.code,{children:\"a\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"b\"}),\"\\uFF0C\\u786E\\u5B9A\\u8FD9\\u4E24\\u68F5\\u6811\\u662F\\u5426\\u76F8\\u7B49\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u5982\\u679C\\u4E24\\u68F5\\u4E8C\\u53C9\\u6811\\u5177\\u6709\\u76F8\\u540C\\u7684\\u7ED3\\u6784\\uFF0C\\u5E76\\u4E14\\u4E24\\u68F5\\u6811\\u4E2D\\u5BF9\\u5E94\\u7684\\u8282\\u70B9\\u5177\\u6709\\u76F8\\u540C\\u7684\\u503C\\uFF0C\\u5219\\u8BA4\\u4E3A\\u5B83\\u4EEC\\u76F8\\u7B49\\u3002\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E8C\\u53C9\\u6811\\u7531\",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\"\\u7684\\u96C6\\u5408\\u8868\\u793A\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u8282\\u70B9\\u90FD\\u6709\\u53EF\\u9009\\u7684\",(0,n.jsx)(e.code,{children:\"left\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"right\"}),\"\\u5B50\\u8282\\u70B9\\uFF0C\\u5B83\\u4EEC\\u4E5F\\u662F\",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A\",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\"\\u5177\\u6709\\u4EE5\\u4E0B\\u63A5\\u53E3\\uFF1A\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-ts\",children:`interface TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n}\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"a: TreeNode\"}),\": \\u7B2C\\u4E00\\u68F5\\u6811\\u7684\\u6839\\u8282\\u70B9\\u3002\\u793A\\u4F8B\\u663E\\u793A\\u6811\\u7684\",(0,n.jsx)(e.a,{href:\"https://en.wikipedia.org/wiki/Breadth-first_search\",children:\"\\u5C42\\u5E8F\\u904D\\u5386\"})]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"b: TreeNode\"}),\": \\u7B2C\\u4E8C\\u68F5\\u6811\\u7684\\u6839\\u8282\\u70B9\\u3002\\u793A\\u4F8B\\u663E\\u793A\\u6811\\u7684\",(0,n.jsx)(e.a,{href:\"https://en.wikipedia.org/wiki/Breadth-first_search\",children:\"\\u5C42\\u5E8F\\u904D\\u5386\"})]}),`\n`]}),`\n`,(0,n.jsx)(o,{testCases:s}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"0 <= \\u8282\\u70B9\\u6570 <= 100\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"-10,000 <= \",(0,n.jsx)(e.code,{children:\"TreeNode.val\"}),\" <= 10,000\"]}),`\n`]})]})}function v(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(u,r)})):u(r)}var M=v;return b(k);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来确定两个二叉树是否相等", + "title": "二叉树相等" + }, + "solution": "var Component=(()=>{var b=Object.create;var d=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty;var N=(l,e)=>()=>(e||l((e={exports:{}}).exports,e),e.exports),q=(l,e)=>{for(var r in e)d(l,r,{get:e[r],enumerable:!0})},t=(l,e,r,h)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of m(e))!p.call(l,i)&&i!==r&&d(l,i,{get:()=>e[i],enumerable:!(h=T(e,i))||h.enumerable});return l};var y=(l,e,r)=>(r=l!=null?b(g(l)):{},t(e||!l||!l.__esModule?d(r,\"default\",{value:l,enumerable:!0}):r,l)),v=l=>t(d({},\"__esModule\",{value:!0}),l);var u=N((_,o)=>{o.exports=_jsx_runtime});var O={};q(O,{default:()=>E});var n=y(u());var c=MDXCodeBlock;var a=`interface TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n}\n\nexport default function binaryTreeEqual(\n a: TreeNode | null,\n b: TreeNode | null,\n): boolean {\n // Check if both a and b are null\n if (a == null && b == null) {\n return true;\n }\n\n // If one of a or b is null (but not both), the trees are not the same\n if (b == null || a == null) {\n return false;\n }\n\n // If the values of the current nodes are different, the trees are not the same\n if (a.val != b.val) {\n return false;\n }\n\n // Recursively check if the right subtrees are the same and if the left subtrees are the same\n return binaryTreeEqual(a.right, b.right) && binaryTreeEqual(a.left, b.left);\n}\n`;var s=`interface TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n}\n\nexport default function binaryTreeEqual(\n a: TreeNode | null,\n b: TreeNode | null,\n): boolean {\n // Helper function to check if two nodes are the same\n function check(a: TreeNode | null, b: TreeNode | null) {\n // If both nodes are null, they are the same\n if (a === null && b === null) {\n return true;\n }\n // If one node is null and the other is not, they are different\n if (a === null || b === null) {\n return false;\n }\n // If the values of the nodes are different, they are different\n if (a.val !== b.val) {\n return false;\n }\n // If none of the above conditions are met, the nodes are the same\n return true;\n }\n\n // Initialize a queue with the pair of root nodes\n const queue: [TreeNode | null, TreeNode | null][] = [[a, b]];\n\n // Process the queue until it is empty\n while (queue.length) {\n // Dequeue the first pair of nodes\n [a, b] = queue.shift() as [TreeNode | null, TreeNode | null];\n\n // If the nodes are not the same, return false\n if (!check(a, b)) {\n return false;\n }\n\n // If the current node in a is not null, enqueue its left and right children along with b's corresponding children\n if (a) {\n queue.push([a.left, b?.left] as [TreeNode | null, TreeNode | null]);\n queue.push([a.right, b?.right] as [TreeNode | null, TreeNode | null]);\n }\n }\n\n // If all nodes are the same, return true\n return true;\n}\n`;function f(l){let e=Object.assign({h2:\"h2\",p:\"p\",h3:\"h3\",ol:\"ol\",li:\"li\",code:\"code\",ul:\"ul\",strong:\"strong\"},l.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u9012\\u5F52\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u68C0\\u67E5\\u4E24\\u4E2A\\u4E8C\\u53C9\\u6811\\u662F\\u5426\\u76F8\\u540C\\u7684\\u95EE\\u9898\\u6D89\\u53CA\\u9010\\u4E2A\\u6BD4\\u8F83\\u4E24\\u4E2A\\u6811\\u7684\\u7ED3\\u6784\\u548C\\u503C\\u3002\\u9012\\u5F52\\u65B9\\u6CD5\\u901A\\u8FC7\\u5C06\\u5176\\u5206\\u89E3\\u4E3A\\u5DE6\\u53F3\\u5B50\\u6811\\u7684\\u8F83\\u5C0F\\u5B50\\u95EE\\u9898\\u6765\\u7B80\\u5316\\u6B64\\u8FC7\\u7A0B\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u65B9\\u6CD5\\u9996\\u5148\\u68C0\\u67E5\\u57FA\\u672C\\u60C5\\u51B5\\uFF1A\\u5982\\u679C\\u4E24\\u4E2A\\u8282\\u70B9\\u90FD\\u4E3A null\\uFF0C\\u5219\\u6811\\u5728\\u8BE5\\u70B9\\u4E0A\\u76F8\\u540C\\uFF0C\\u4F46\\u5982\\u679C\\u4E00\\u4E2A\\u8282\\u70B9\\u4E3A null \\u800C\\u53E6\\u4E00\\u4E2A\\u8282\\u70B9\\u4E0D\\u4E3A null\\uFF0C\\u6216\\u8005\\u5B83\\u4EEC\\u7684\\u503C\\u4E0D\\u540C\\uFF0C\\u5219\\u6811\\u4E0D\\u76F8\\u540C\\u3002\\u7136\\u540E\\u5B83\\u6267\\u884C\\u9012\\u5F52\\u68C0\\u67E5\\uFF0C\\u6BD4\\u8F83\\u4E24\\u68F5\\u6811\\u7684\\u5DE6\\u5B50\\u6811\\u548C\\u4E24\\u68F5\\u6811\\u7684\\u53F3\\u5B50\\u6811\\u3002\\u4EC5\\u5F53\\u5DE6\\u53F3\\u5B50\\u6811\\u90FD\\u76F8\\u540C\\u65F6\\uFF0C\\u624D\\u8BA4\\u4E3A\\u6811\\u76F8\\u540C\\u3002\\u4E00\\u65E6\\u6240\\u6709\\u5BF9\\u5E94\\u7684\\u8282\\u70B9\\u90FD\\u5DF2\\u6BD4\\u8F83\\u6216\\u53D1\\u73B0\\u4E0D\\u5339\\u914D\\uFF0C\\u9012\\u5F52\\u5C31\\u4F1A\\u7EC8\\u6B62\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u786E\\u4FDD\\u68C0\\u67E5\\u6BCF\\u4E2A\\u8282\\u70B9\\u7684\\u7ED3\\u6784\\u548C\\u503C\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u57FA\\u672C\\u60C5\\u51B5\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"a\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"b\"}),\" \\u90FD\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\uFF0C\\u56E0\\u4E3A\\u6811\\u5728\\u8BE5\\u70B9\\u4E0A\\u76F8\\u540C\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"a\"}),\" \\u6216 \",(0,n.jsx)(e.code,{children:\"b\"}),\" \\u5176\\u4E2D\\u4E4B\\u4E00\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\uFF0C\\u56E0\\u4E3A\\u6811\\u7684\\u7ED3\\u6784\\u4E0D\\u540C\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"a\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"b\"}),\" \\u7684\\u503C\\u4E0D\\u76F8\\u7B49\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\uFF0C\\u56E0\\u4E3A\\u6811\\u7684\\u503C\\u4E0D\\u540C\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u9012\\u5F52\\u68C0\\u67E5\\u5DE6\\u53F3\\u5B50\\u6811\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9 \",(0,n.jsx)(e.code,{children:\"a\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"b\"}),\" \\u7684\\u53F3\\u5B50\\u6811\\u8C03\\u7528 \",(0,n.jsx)(e.code,{children:\"binaryTreeEqual\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9 \",(0,n.jsx)(e.code,{children:\"a\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"b\"}),\" \\u7684\\u5DE6\\u5B50\\u6811\\u8C03\\u7528 \",(0,n.jsx)(e.code,{children:\"binaryTreeEqual\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5DE6\\u53F3\\u5B50\\u6811\\u7684\\u6BD4\\u8F83\\u90FD\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(c,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002 \\u4E24\\u4E2A\\u6811\\u4E2D\\u7684\\u6BCF\\u4E2A\\u8282\\u70B9\\u90FD\\u4F1A\\u88AB\\u8BBF\\u95EE\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(h)\"}),\"\\u3002 \\u9012\\u5F52\\u5806\\u6808\\u9700\\u8981\\u4E0E\\u6811\\u7684\\u9AD8\\u5EA6\\u6210\\u6BD4\\u4F8B\\u7684\\u7A7A\\u95F4\\uFF0C\\u5176\\u4E2D \",(0,n.jsx)(e.code,{children:\"h\"}),\" \\u662F\\u4E24\\u68F5\\u6811\\u7684\\u6700\\u5927\\u9AD8\\u5EA6\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u8FED\\u4EE3\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u7528\\u4E8E\\u786E\\u5B9A\\u4E24\\u4E2A\\u4E8C\\u53C9\\u6811\\u662F\\u5426\\u76F8\\u540C\\u7684\\u8FED\\u4EE3\\u65B9\\u6CD5\\u4F7F\\u7528\\u5E7F\\u5EA6\\u4F18\\u5148\\u904D\\u5386\\u7B56\\u7565\\u3002 \\u8FD9\\u79CD\\u65B9\\u6CD5\\u4E0D\\u4F9D\\u8D56\\u4E8E\\u9012\\u5F52\\uFF0C\\u800C\\u662F\\u4F7F\\u7528\\u961F\\u5217\\u6765\\u7BA1\\u7406\\u6765\\u81EA\\u4E24\\u68F5\\u6811\\u7684\\u8282\\u70B9\\u5BF9\\uFF0C\\u4ECE\\u800C\\u786E\\u4FDD\\u7ED3\\u6784\\u548C\\u503C\\u7684\\u7B49\\u4EF7\\u6027\\u3002\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8BE5\\u7B97\\u6CD5\\u9996\\u5148\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u961F\\u5217\\uFF0C\\u5176\\u4E2D\\u5305\\u542B\\u4E24\\u68F5\\u6811\\u7684\\u6839\\u8282\\u70B9\\u4F5C\\u4E3A\\u4E00\\u5BF9\\u3002 \\u6BCF\\u4E00\\u5BF9\\u8282\\u70B9\\u90FD\\u4F1A\\u51FA\\u5217\\uFF0C\\u5E76\\u68C0\\u67E5\\u5B83\\u4EEC\\u7684\\u7B49\\u4EF7\\u6027\\u3002 \\u5982\\u679C\\u4E24\\u4E2A\\u8282\\u70B9\\u90FD\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u5219\\u8BE5\\u5BF9\\u5728\\u8BE5\\u70B9\\u4E0A\\u88AB\\u8BA4\\u4E3A\\u662F\\u76F8\\u540C\\u7684\\u3002 \\u5982\\u679C\\u4E00\\u4E2A\\u8282\\u70B9\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\" \\u800C\\u53E6\\u4E00\\u4E2A\\u8282\\u70B9\\u4E0D\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u6216\\u8005\\u5B83\\u4EEC\\u7684\\u503C\\u4E0D\\u540C\\uFF0C\\u5219\\u6811\\u4E0D\\u76F8\\u540C\\u3002 \\u5BF9\\u4E8E\\u975E \",(0,n.jsx)(e.code,{children:\"null\"}),\" \\u8282\\u70B9\\uFF0C\\u5C06\\u4E24\\u4E2A\\u8282\\u70B9\\u7684\\u5DE6\\u53F3\\u5B50\\u8282\\u70B9\\u4F5C\\u4E3A\\u65B0\\u5BF9\\u5165\\u961F\\u3002 \\u8BE5\\u8FC7\\u7A0B\\u4E00\\u76F4\\u6301\\u7EED\\u5230\\u961F\\u5217\\u4E3A\\u7A7A\\uFF0C\\u8FD9\\u8868\\u660E\\u4E24\\u68F5\\u6811\\u4E2D\\u6240\\u6709\\u5BF9\\u5E94\\u7684\\u8282\\u70B9\\u5728\\u7ED3\\u6784\\u548C\\u503C\\u4E0A\\u90FD\\u662F\\u76F8\\u540C\\u7684\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u8F85\\u52A9\\u51FD\\u6570 \",(0,n.jsx)(e.code,{children:\"check\"}),\"\\uFF0C\\u8BE5\\u51FD\\u6570\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u4E24\\u4E2A\\u8282\\u70B9\\u90FD\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u4E00\\u4E2A\\u8282\\u70B9\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\" \\u800C\\u53E6\\u4E00\\u4E2A\\u8282\\u70B9\\u4E0D\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u6BD4\\u8F83\\u4E24\\u4E2A\\u975E \",(0,n.jsx)(e.code,{children:\"null\"}),\" \\u8282\\u70B9\\u7684\\u503C\\uFF0C\\u5982\\u679C\\u5B83\\u4EEC\\u76F8\\u7B49\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u4F7F\\u7528\\u4E24\\u68F5\\u6811\\u7684\\u6839\\u8282\\u70B9\\u4F5C\\u4E3A\\u4E00\\u5BF9\\u6765\\u521D\\u59CB\\u5316\\u961F\\u5217\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5F53\\u961F\\u5217\\u4E0D\\u4E3A\\u7A7A\\u65F6\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u51FA\\u961F\\u7B2C\\u4E00\\u5BF9\\u8282\\u70B9\\uFF0C\\u5E76\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"check\"}),\" \\u51FD\\u6570\\u9A8C\\u8BC1\\u5B83\\u4EEC\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u8282\\u70B9\\u6709\\u6548\\uFF0C\\u5219\\u5C06\\u5B83\\u4EEC\\u7684\\u5DE6\\u53F3\\u5B50\\u8282\\u70B9\\u4F5C\\u4E3A\\u65B0\\u5BF9\\u5165\\u961F\\u4EE5\\u8FDB\\u884C\\u8FDB\\u4E00\\u6B65\\u6BD4\\u8F83\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5728\\u904D\\u5386\\u8FC7\\u7A0B\\u4E2D\\u672A\\u53D1\\u73B0\\u8FDD\\u89C4\\u884C\\u4E3A\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(c,{children:s}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002 \\u4E24\\u4E2A\\u6811\\u4E2D\\u7684\\u6BCF\\u4E2A\\u8282\\u70B9\\u90FD\\u4F1A\\u88AB\\u5904\\u7406\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002 \\u961F\\u5217\\u6700\\u591A\\u5B58\\u50A8 \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u5BF9\\u8282\\u70B9\\uFF0C\\u5177\\u4F53\\u53D6\\u51B3\\u4E8E\\u6811\\u7684\\u5927\\u5C0F\\u3002\"]}),`\n`]})]})}function k(l={}){let{wrapper:e}=l.components||{};return e?(0,n.jsx)(e,Object.assign({},l,{children:(0,n.jsx)(f,l)})):f(l)}var E=k;return v(O);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/binary-tree-flip/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/binary-tree-flip/locales/zh-CN.json new file mode 100644 index 000000000..cb3910245 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/binary-tree-flip/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var u=Object.create;var i=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty;var g=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),N=(r,e)=>{for(var t in e)i(r,t,{get:e[t],enumerable:!0})},d=(r,e,t,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let l of m(e))!T.call(r,l)&&l!==t&&i(r,l,{get:()=>e[l],enumerable:!(o=f(e,l))||o.enumerable});return r};var _=(r,e,t)=>(t=r!=null?u(x(r)):{},d(e||!r||!r.__esModule?i(t,\"default\",{value:r,enumerable:!0}):t,r)),j=r=>d(i({},\"__esModule\",{value:!0}),r);var h=g((X,c)=>{c.exports=_jsx_runtime});var C={};N(C,{default:()=>v,frontmatter:()=>b});var n=_(h());var a=MDXTestExamples;var s=[{input:[[\"root\",[2,1,3]]],output:[2,3,1],explanation:\"The left and right children are swapped.\"},{input:[[\"root\",[43,null,-55]]],output:[43,-55],explanation:\"The right child becomes the left child after inversion.\"},{input:[[\"root\",[12,8,18,6,null,null,20]]],output:[12,18,8,20,null,null,6],explanation:\"The tree is inverted, with left and right children of each node being swapped.\"}];var b={title:\"\\u7FFB\\u8F6C\\u4E8C\\u53C9\\u6811\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u7FFB\\u8F6C\\u4E8C\\u53C9\\u6811\\u4E2D\\u7684\\u8282\\u70B9\"};function p(r){let e=Object.assign({p:\"p\",code:\"code\",pre:\"pre\",h3:\"h3\",ul:\"ul\",li:\"li\",a:\"a\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u4E8C\\u53C9\\u6811\\u7684\",(0,n.jsx)(e.code,{children:\"root\"}),\"\\u8282\\u70B9\\uFF0C\\u901A\\u8FC7\\u4EA4\\u6362\\u6BCF\\u4E2A\\u8282\\u70B9\\u7684\\u5DE6\\u5B69\\u5B50\\u548C\\u53F3\\u5B69\\u5B50\\u6765\\u7FFB\\u8F6C\\u6811\\uFF0C\\u7136\\u540E\\u8FD4\\u56DE\\u7FFB\\u8F6C\\u540E\\u7684\\u6811\\u7684\\u6839\\u8282\\u70B9\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E8C\\u53C9\\u6811\\u7531\",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\"\\u7684\\u96C6\\u5408\\u8868\\u793A\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u8282\\u70B9\\u90FD\\u6709\\u53EF\\u9009\\u7684\",(0,n.jsx)(e.code,{children:\"left\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"right\"}),\"\\u5B50\\u8282\\u70B9\\uFF0C\\u5B83\\u4EEC\\u4E5F\\u662F\",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A\",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\"\\u5177\\u6709\\u4EE5\\u4E0B\\u63A5\\u53E3\\uFF1A\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-ts\",children:`interface TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n}\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"root: TreeNode\"}),\": \\u6811\\u7684\\u6839\\u8282\\u70B9\\u3002\\u793A\\u4F8B\\u663E\\u793A\\u6811\\u7684\",(0,n.jsx)(e.a,{href:\"https://en.wikipedia.org/wiki/Breadth-first_search\",children:\"\\u5C42\\u5E8F\\u904D\\u5386\"})]}),`\n`]}),`\n`,(0,n.jsx)(a,{testCases:s}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"1 <= \\u8282\\u70B9\\u6570 <= 100\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"-100 <= \",(0,n.jsx)(e.code,{children:\"TreeNode.val\"}),\" <= 100\"]}),`\n`]})]})}function M(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(p,r)})):p(r)}var v=M;return j(C);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来翻转二叉树中的节点", + "title": "翻转二叉树" + }, + "solution": "var Component=(()=>{var g=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var N=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),b=(r,e)=>{for(var l in e)i(r,l,{get:e[l],enumerable:!0})},c=(r,e,l,d)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let t of T(e))!x.call(r,t)&&t!==l&&i(r,t,{get:()=>e[t],enumerable:!(d=p(e,t))||d.enumerable});return r};var q=(r,e,l)=>(l=r!=null?g(m(r)):{},c(e||!r||!r.__esModule?i(l,\"default\",{value:r,enumerable:!0}):l,r)),y=r=>c(i({},\"__esModule\",{value:!0}),r);var u=N((w,h)=>{h.exports=_jsx_runtime});var v={};b(v,{default:()=>_});var n=q(u());var o=MDXCodeBlock;var s=`interface TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n}\n\nexport default function binaryTreeFlip(root: TreeNode | null): TreeNode | null {\n // Base case: if the node is null, return null\n if (root === null) {\n return null;\n }\n\n // Recursively invert the left and right subtrees\n const right: TreeNode | null = binaryTreeFlip(root.right);\n const left: TreeNode | null = binaryTreeFlip(root.left);\n\n // Swap the left and right children of the current node\n root.left = right;\n root.right = left;\n\n // Return the root of the inverted tree\n return root;\n}\n`;var a=`interface TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n}\n\nexport default function binaryTreeFlip(root: TreeNode | null): TreeNode | null {\n // Base case: if the root is null, return null\n if (root === null) {\n return null;\n }\n\n // Initialize a queue and add the root node\n const queue: (TreeNode | null)[] = [];\n queue.push(root);\n\n // Iterate while there are nodes in the queue\n while (queue.length > 0) {\n // Dequeue the current node\n const current = queue.shift();\n\n if (current !== undefined && current !== null) {\n // Swap the left and right children\n const temp = current.left;\n current.left = current.right;\n current.right = temp;\n\n // If the left child exists, add it to the queue\n if (current.left !== null) {\n queue.push(current.left);\n }\n\n // If the right child exists, add it to the queue\n if (current.right !== null) {\n queue.push(current.right);\n }\n }\n }\n\n // Return the root of the inverted tree\n return root;\n}\n`;function f(r){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u9012\\u5F52\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u7FFB\\u8F6C\\u4E8C\\u53C9\\u6811\\u6D89\\u53CA\\u4EA4\\u6362\\u6811\\u4E2D\\u6BCF\\u4E2A\\u8282\\u70B9\\u7684\\u5DE6\\u53F3\\u5B50\\u6811\\u3002\\u9012\\u5F52\\u65B9\\u6CD5\\u901A\\u8FC7\\u5C06\\u95EE\\u9898\\u5206\\u89E3\\u4E3A\\u6BCF\\u4E2A\\u5B50\\u6811\\u7684\\u8F83\\u5C0F\\u95EE\\u9898\\u6765\\u7B80\\u5316\\u6B64\\u64CD\\u4F5C\\u3002\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5B83\\u4ECE\\u4E00\\u4E2A\\u57FA\\u672C\\u60C5\\u51B5\\u5F00\\u59CB\\uFF1A\\u5982\\u679C\\u5F53\\u524D\\u8282\\u70B9\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u5219\\u65E0\\u9700\\u7FFB\\u8F6C\\uFF0C\\u56E0\\u6B64\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\u3002\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u975E \",(0,n.jsx)(e.code,{children:\"null\"}),\" \\u8282\\u70B9\\uFF0C\\u9012\\u5F52\\u7FFB\\u8F6C\\u5DE6\\u53F3\\u5B50\\u6811\\uFF0C\\u5E76\\u5C06\\u7ED3\\u679C\\u5B58\\u50A8\\u5728\\u4E34\\u65F6\\u53D8\\u91CF\\u4E2D\\u3002\\u9012\\u5F52\\u540E\\uFF0C\\u4EA4\\u6362\\u5F53\\u524D\\u8282\\u70B9\\u7684\\u5DE6\\u53F3\\u5B50\\u8282\\u70B9\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\\u6811\\u7684\\u6240\\u6709\\u5C42\\u90FD\\u88AB\\u6B63\\u786E\\u7FFB\\u8F6C\\uFF0C\\u5E76\\u4E14\\u7ED3\\u6784\\u5B8C\\u5168\\u98A0\\u5012\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u57FA\\u672C\\u60C5\\u51B5\\uFF1A\\u5982\\u679C\\u8282\\u70B9\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u9012\\u5F52\\u8C03\\u7528\\u53F3\\u5B50\\u6811\\u4E0A\\u7684\\u51FD\\u6570\\u5E76\\u5B58\\u50A8\\u7ED3\\u679C\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u9012\\u5F52\\u8C03\\u7528\\u5DE6\\u5B50\\u6811\\u4E0A\\u7684\\u51FD\\u6570\\u5E76\\u5B58\\u50A8\\u7ED3\\u679C\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u4EA4\\u6362\\u5F53\\u524D\\u8282\\u70B9\\u7684\\u5DE6\\u53F3\\u5B50\\u8282\\u70B9\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5C06\\u5F53\\u524D\\u8282\\u70B9\\u4F5C\\u4E3A\\u7FFB\\u8F6C\\u6811\\u7684\\u6839\\u8282\\u70B9\\u8FD4\\u56DE\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(o,{children:s}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u6BCF\\u4E2A\\u8282\\u70B9\\u53EA\\u8BBF\\u95EE\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(h)\"}),\"\\u3002\\u9012\\u5F52\\u5806\\u6808\\u4F7F\\u7528\\u7684\\u7A7A\\u95F4\\u4E0E\\u6811\\u7684\\u9AD8\\u5EA6\\u6210\\u6B63\\u6BD4\\uFF0C\\u5176\\u4E2D \",(0,n.jsx)(e.code,{children:\"h\"}),\" \\u662F\\u6811\\u7684\\u9AD8\\u5EA6\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u8FED\\u4EE3\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u7FFB\\u8F6C\\u4E8C\\u53C9\\u6811\\u6D89\\u53CA\\u4EA4\\u6362\\u6BCF\\u4E2A\\u8282\\u70B9\\u7684\\u5DE6\\u53F3\\u5B50\\u6811\\u3002\\u8FED\\u4EE3\\u65B9\\u6CD5\\u4F7F\\u7528\\u961F\\u5217\\u9010\\u5C42\\u904D\\u5386\\u6811\\uFF0C\\u786E\\u4FDD\\u5904\\u7406\\u6240\\u6709\\u8282\\u70B9\\u3002\\u6B64\\u65B9\\u6CD5\\u907F\\u514D\\u4E86\\u9012\\u5F52\\uFF0C\\u4F7F\\u5176\\u6210\\u4E3A\\u5904\\u7406\\u6DF1\\u5EA6\\u6811\\u4EE5\\u9632\\u6B62\\u5806\\u6808\\u6EA2\\u51FA\\u7684\\u4E00\\u4E2A\\u5F88\\u597D\\u7684\\u66FF\\u4EE3\\u65B9\\u6848\\u3002\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8FED\\u4EE3\\u65B9\\u6CD5\\u4ECE\\u4E00\\u4E2A\\u57FA\\u672C\\u60C5\\u51B5\\u5F00\\u59CB\\uFF0C\\u5176\\u4E2D\\u7A7A\\u6811\\uFF08\",(0,n.jsx)(e.code,{children:\"null\"}),\" \\u6839\\uFF09\\u76F4\\u63A5\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\u3002\\u4F7F\\u7528\\u6839\\u8282\\u70B9\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u961F\\u5217\\uFF0C\\u5E76\\u6267\\u884C\\u5E7F\\u5EA6\\u4F18\\u5148\\u904D\\u5386\\u3002\\u5728\\u6BCF\\u4E2A\\u6B65\\u9AA4\\u4E2D\\uFF0C\\u4EA4\\u6362\\u5F53\\u524D\\u8282\\u70B9\\u7684\\u5DE6\\u53F3\\u5B50\\u8282\\u70B9\\u3002\\u5982\\u679C\\u4EA4\\u6362\\u7684\\u5B50\\u8282\\u70B9\\u4E0D\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u5219\\u5C06\\u5B83\\u4EEC\\u6DFB\\u52A0\\u5230\\u961F\\u5217\\u4E2D\\u4EE5\\u8FDB\\u884C\\u540E\\u7EED\\u5904\\u7406\\u3002\\u8BE5\\u8FC7\\u7A0B\\u4E00\\u76F4\\u6301\\u7EED\\u5230\\u961F\\u5217\\u4E3A\\u7A7A\\uFF0C\\u786E\\u4FDD\\u6811\\u4E2D\\u7684\\u6240\\u6709\\u8282\\u70B9\\u90FD\\u88AB\\u7FFB\\u8F6C\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u5728\\u6839\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\" \\u65F6\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"null\"}),\" \\u6765\\u5904\\u7406\\u57FA\\u672C\\u60C5\\u51B5\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u961F\\u5217\\u5E76\\u6DFB\\u52A0\\u6839\\u8282\\u70B9\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5F53\\u961F\\u5217\\u4E0D\\u4E3A\\u7A7A\\u65F6\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u51FA\\u961F\\u4E00\\u4E2A\\u8282\\u70B9\\u5E76\\u4EA4\\u6362\\u5176\\u5DE6\\u53F3\\u5B50\\u8282\\u70B9\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u5DE6\\u5B50\\u8282\\u70B9\\u5B58\\u5728\\uFF0C\\u5219\\u5C06\\u5176\\u5165\\u961F\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u53F3\\u5B50\\u8282\\u70B9\\u5B58\\u5728\\uFF0C\\u5219\\u5C06\\u5176\\u5165\\u961F\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8FD4\\u56DE\\u53CD\\u8F6C\\u6811\\u7684\\u6839\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(o,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u6811\\u4E2D\\u7684\\u6BCF\\u4E2A\\u8282\\u70B9\\u53EA\\u5904\\u7406\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u5728\\u6700\\u574F\\u7684\\u60C5\\u51B5\\u4E0B\\uFF0C\\u961F\\u5217\\u6700\\u591A\\u53EF\\u4EE5\\u5B58\\u50A8 \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u4E2A\\u8282\\u70B9\\uFF0C\\u8FD9\\u4E0E\\u6811\\u5728\\u5176\\u6700\\u5BBD\\u5C42\\u4E0A\\u7684\\u5E7F\\u5EA6\\u6210\\u6B63\\u6BD4\\u3002\"]}),`\n`]})]})}function j(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(f,r)})):f(r)}var _=j;return y(v);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/binary-tree-level-order-traversal/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/binary-tree-level-order-traversal/locales/zh-CN.json new file mode 100644 index 000000000..051aaa284 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/binary-tree-level-order-traversal/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var o=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var T=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),g=(n,e)=>{for(var r in e)o(n,r,{get:e[r],enumerable:!0})},d=(n,e,r,i)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let l of f(e))!v.call(n,l)&&l!==r&&o(n,l,{get:()=>e[l],enumerable:!(i=m(e,l))||i.enumerable});return n};var N=(n,e,r)=>(r=n!=null?p(x(n)):{},d(e||!n||!n.__esModule?o(r,\"default\",{value:n,enumerable:!0}):r,n)),_=n=>d(o({},\"__esModule\",{value:!0}),n);var c=T((b,h)=>{h.exports=_jsx_runtime});var D={};g(D,{default:()=>C,frontmatter:()=>w});var t=N(c());var a=MDXTestExamples;var s=[{input:[[\"root\",[13,null,-55]]],output:[[13],[-55]],explanation:\"The root has two levels: the first level with the value 13, and the second level with the value -55.\"},{input:[[\"root\",[1,2,3,4,5,6,7]]],output:[[1],[2,3],[4,5,6,7]],explanation:\"The tree has three levels: [1] at the first level, [2, 3] at the second level, and [4, 5, 6, 7] at the third level.\"},{input:[[\"root\",[5,3,8,null,4,7,9]]],output:[[5],[3,8],[4,7,9]],explanation:\"The tree has three levels: [5] at the first level, [3, 8] at the second level, and [4, 7, 9] at the third level.\"}];var w={title:\"\\u4E8C\\u53C9\\u6811\\u5C42\\u5E8F\\u904D\\u5386\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u67E5\\u627E\\u4E8C\\u53C9\\u6811\\u7684\\u5C42\\u5E8F\\u904D\\u5386\"};function u(n){let e=Object.assign({p:\"p\",code:\"code\",pre:\"pre\",h3:\"h3\",ul:\"ul\",li:\"li\",a:\"a\"},n.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E8C\\u53C9\\u6811\\u7684\",(0,t.jsx)(e.code,{children:\"root\"}),\"\\u8282\\u70B9\\uFF0C\\u8FD4\\u56DE\\u4E00\\u4E2A\\u6570\\u7EC4\\u7684\\u6570\\u7EC4\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u5185\\u90E8\\u6570\\u7EC4\\u8868\\u793A\\u6811\\u4E2D\\u6BCF\\u4E00\\u5C42\\u7684\\u8282\\u70B9\\u7684\\u503C\\uFF0C\\u4ECE\\u5DE6\\u5230\\u53F3\\u904D\\u5386\\u3002\"]}),`\n`,(0,t.jsxs)(e.p,{children:[\"\\u4E8C\\u53C9\\u6811\\u7531\",(0,t.jsx)(e.code,{children:\"TreeNode\"}),\"\\u7684\\u96C6\\u5408\\u8868\\u793A\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u8282\\u70B9\\u90FD\\u6709\\u53EF\\u9009\\u7684\",(0,t.jsx)(e.code,{children:\"left\"}),\"\\u548C\",(0,t.jsx)(e.code,{children:\"right\"}),\"\\u5B50\\u8282\\u70B9\\uFF0C\\u5B83\\u4EEC\\u4E5F\\u662F\",(0,t.jsx)(e.code,{children:\"TreeNode\"}),\"\\u3002\"]}),`\n`,(0,t.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A\",(0,t.jsx)(e.code,{children:\"TreeNode\"}),\"\\u5177\\u6709\\u4EE5\\u4E0B\\u63A5\\u53E3\\uFF1A\"]}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-ts\",children:`interface TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n}\n`})}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.code,{children:\"root: TreeNode\"}),\": \\u6811\\u7684\\u6839\\u8282\\u70B9\\u3002\\u793A\\u4F8B\\u663E\\u793A\\u6811\\u7684\",(0,t.jsx)(e.a,{href:\"https://en.wikipedia.org/wiki/Breadth-first_search\",children:\"\\u5C42\\u5E8F\\u904D\\u5386\"})]}),`\n`]}),`\n`,(0,t.jsx)(a,{testCases:s}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsx)(e.li,{children:\"1 <= \\u8282\\u70B9\\u6570 <= 10,000\"}),`\n`,(0,t.jsxs)(e.li,{children:[\"-100 <= \",(0,t.jsx)(e.code,{children:\"TreeNode.val\"}),\" <= 100\"]}),`\n`]})]})}function M(n={}){let{wrapper:e}=n.components||{};return e?(0,t.jsx)(e,Object.assign({},n,{children:(0,t.jsx)(u,n)})):u(n)}var C=M;return _(D);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来查找二叉树的层序遍历", + "title": "二叉树层序遍历" + }, + "solution": "var Component=(()=>{var f=Object.create;var i=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var y=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),T=(n,e)=>{for(var r in e)i(n,r,{get:e[r],enumerable:!0})},d=(n,e,r,h)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let t of p(e))!b.call(n,t)&&t!==r&&i(n,t,{get:()=>e[t],enumerable:!(h=m(e,t))||h.enumerable});return n};var x=(n,e,r)=>(r=n!=null?f(g(n)):{},d(e||!n||!n.__esModule?i(r,\"default\",{value:n,enumerable:!0}):r,n)),N=n=>d(i({},\"__esModule\",{value:!0}),n);var a=y((C,u)=>{u.exports=_jsx_runtime});var _={};T(_,{default:()=>j});var l=x(a());var o=MDXCodeBlock;var s=`interface TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n}\n\nexport default function binaryTreeLevelOrderTraversal(\n root: TreeNode | null,\n): number[][] {\n // Initialize an array to hold the values at each level of the tree\n let levels: number[][] = [];\n\n // Helper function to traverse the tree\n function helper(node: TreeNode, level: number) {\n // If we're visiting a new level for the first time, add an empty array for that level\n if (levels.length === level) {\n levels.push([]);\n }\n\n // Add the current node's value to the corresponding level array\n levels[level].push(node.val);\n\n // Recursively traverse the left subtree, if it exists, and increment the level\n if (node.left !== null) {\n helper(node.left, level + 1);\n }\n\n // Recursively traverse the right subtree, if it exists, and increment the level\n if (node.right !== null) {\n helper(node.right, level + 1);\n }\n }\n\n // Start the traversal from the root node at level 0\n if (root !== null) {\n helper(root, 0);\n }\n\n // Return the array of levels, each containing the node values at that level\n return levels;\n}\n`;var c=`interface TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n}\n\nexport default function binaryTreeLevelOrderTraversal(\n root: TreeNode | null,\n): number[][] {\n // Initialize an array to store levels of the tree\n let levels: number[][] = [];\n\n // If the root is null, return the empty levels array\n if (!root) {\n return levels;\n }\n\n // Initialize a queue with the root node\n let queue: TreeNode[] = [root];\n\n // Initialize the level counter\n let level: number = 0;\n\n // Iterate while there are nodes in the queue\n while (queue.length) {\n // Start the current level by adding an empty array\n levels.push([]);\n\n // Number of nodes in the current level\n let levelCount: number = queue.length;\n\n // Process all nodes at the current level\n for (let i = 0; i < levelCount; i++) {\n // Dequeue the first node in the queue\n let node: TreeNode | undefined = queue.shift();\n\n // Add the node's value to the current level\n if (node) {\n levels[level].push(node.val);\n }\n\n // Add the node's children to the queue for the next level\n if (node?.left) {\n queue.push(node.left);\n }\n if (node?.right) {\n queue.push(node.right);\n }\n }\n\n // Move on to the next level\n level++;\n }\n\n // Return the array of levels\n return levels;\n}\n`;function v(n){let e=Object.assign({h2:\"h2\",p:\"p\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\",code:\"code\"},n.components);return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u9012\\u5F52\"}),`\n`,(0,l.jsx)(e.p,{children:\"\\u9012\\u5F52\\u65B9\\u6CD5\\u901A\\u8FC7\\u5176\\u6DF1\\u5EA6\\u7EA7\\u522B\\u5BF9\\u4E8C\\u53C9\\u6811\\u4E2D\\u7684\\u8282\\u70B9\\u8FDB\\u884C\\u5206\\u7EC4\\u3002\\u6BCF\\u4E2A\\u7EA7\\u522B\\u90FD\\u8868\\u793A\\u4E3A\\u4E00\\u4E2A\\u6570\\u7EC4\\uFF0C\\u5E76\\u4E14\\u5C06\\u540C\\u4E00\\u6DF1\\u5EA6\\u7684\\u6240\\u6709\\u8282\\u70B9\\u5B58\\u50A8\\u5728\\u4E00\\u8D77\\u3002\\u904D\\u5386\\u4ECE\\u6839\\u8282\\u70B9\\u5F00\\u59CB\\uFF0C\\u9010\\u7EA7\\u8FDB\\u884C\\uFF0C\\u786E\\u4FDD\\u4FDD\\u7559\\u6811\\u7684\\u5C42\\u6B21\\u7ED3\\u6784\\u3002\\u6BCF\\u5F53\\u5230\\u8FBE\\u4E00\\u4E2A\\u65B0\\u7EA7\\u522B\\u65F6\\uFF0C\\u90FD\\u4F1A\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u65B0\\u7EC4\\u4EE5\\u5BB9\\u7EB3\\u8BE5\\u6DF1\\u5EA6\\u5904\\u7684\\u8282\\u70B9\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\\u8282\\u70B9\\u88AB\\u6709\\u6548\\u5730\\u5206\\u7EC4\\uFF0C\\u4ECE\\u800C\\u4FDD\\u6301\\u4E86\\u6811\\u7684\\u7EA7\\u522B\\u4E4B\\u95F4\\u7684\\u6E05\\u6670\\u533A\\u5206\\u3002\"}),`\n`,(0,l.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,l.jsxs)(e.ol,{children:[`\n`,(0,l.jsx)(e.li,{children:\"\\u4ECE\\u6839\\u8282\\u70B9\\u5F00\\u59CB\\u904D\\u5386\\u6811\\uFF0C\\u8DDF\\u8E2A\\u5F53\\u524D\\u7684\\u6DF1\\u5EA6\\u7EA7\\u522B\\u3002\"}),`\n`,(0,l.jsx)(e.li,{children:\"\\u5BF9\\u4E8E\\u7B2C\\u4E00\\u6B21\\u9047\\u5230\\u7684\\u6BCF\\u4E2A\\u7EA7\\u522B\\uFF0C\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u65B0\\u7EC4\\u6765\\u5B58\\u50A8\\u8282\\u70B9\\u503C\\u3002\"}),`\n`,(0,l.jsx)(e.li,{children:\"\\u5C06\\u6BCF\\u4E2A\\u8282\\u70B9\\u7684\\u503C\\u6DFB\\u52A0\\u5230\\u5176\\u5BF9\\u5E94\\u7684\\u7EC4\\u4E2D\\uFF0C\\u5177\\u4F53\\u53D6\\u51B3\\u4E8E\\u5176\\u6DF1\\u5EA6\\u7EA7\\u522B\\u3002\"}),`\n`,(0,l.jsx)(e.li,{children:\"\\u9012\\u5F52\\u5904\\u7406\\u5DE6\\u5B50\\u8282\\u70B9\\u548C\\u53F3\\u5B50\\u8282\\u70B9\\uFF0C\\u5728\\u904D\\u5386\\u6DF1\\u5165\\u6811\\u65F6\\u589E\\u52A0\\u7EA7\\u522B\\u3002\"}),`\n`,(0,l.jsx)(e.li,{children:\"\\u7EE7\\u7EED\\uFF0C\\u76F4\\u5230\\u6240\\u6709\\u8282\\u70B9\\u90FD\\u88AB\\u5904\\u7406\\u5E76\\u6309\\u7EA7\\u522B\\u5206\\u7EC4\\u3002\"}),`\n`]}),`\n`,(0,l.jsx)(o,{children:s}),`\n`,(0,l.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,l.jsxs)(e.ul,{children:[`\n`,(0,l.jsxs)(e.li,{children:[(0,l.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u6811\\u4E2D\\u7684\\u6BCF\\u4E2A\\u8282\\u70B9\\u53EA\\u8BBF\\u95EE\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,l.jsxs)(e.li,{children:[(0,l.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(h)\"}),\"\\u3002\\u9012\\u5F52\\u5806\\u6808\\u4F7F\\u7528\\u7684\\u7A7A\\u95F4\\u4E0E\\u6811\\u7684\\u9AD8\\u5EA6 \",(0,l.jsx)(e.code,{children:\"h\"}),\" \\u6210\\u6B63\\u6BD4\\uFF0C\\u5E76\\u4E14\\u4F7F\\u7528\\u989D\\u5916\\u7684\\u7A7A\\u95F4\\u6765\\u5B58\\u50A8\\u7EA7\\u522B\\u7EC4\\u3002\"]}),`\n`]}),`\n`,(0,l.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u8FED\\u4EE3\"}),`\n`,(0,l.jsx)(e.p,{children:\"\\u8FED\\u4EE3\\u65B9\\u6CD5\\u4F7F\\u7528\\u961F\\u5217\\u901A\\u8FC7\\u5176\\u6DF1\\u5EA6\\u7EA7\\u522B\\u5BF9\\u4E8C\\u53C9\\u6811\\u4E2D\\u7684\\u8282\\u70B9\\u8FDB\\u884C\\u5206\\u7EC4\\u3002\\u904D\\u5386\\u4ECE\\u6839\\u8282\\u70B9\\u5F00\\u59CB\\uFF0C\\u5E76\\u5206\\u522B\\u5904\\u7406\\u6BCF\\u4E2A\\u7EA7\\u522B\\u3002\\u5728\\u6BCF\\u4E2A\\u7EA7\\u522B\\uFF0C\\u6240\\u6709\\u8282\\u70B9\\u90FD\\u4F1A\\u51FA\\u961F\\uFF0C\\u5B83\\u4EEC\\u7684\\u503C\\u5B58\\u50A8\\u5728\\u5BF9\\u5E94\\u4E8E\\u5F53\\u524D\\u7EA7\\u522B\\u7684\\u7EC4\\u4E2D\\uFF0C\\u5E76\\u4E14\\u5B83\\u4EEC\\u7684\\u5B50\\u8282\\u70B9\\u4F1A\\u6392\\u961F\\u7B49\\u5F85\\u4E0B\\u4E00\\u6B21\\u8FED\\u4EE3\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\\u5728\\u79FB\\u52A8\\u5230\\u4E0B\\u4E00\\u7EA7\\u522B\\u4E4B\\u524D\\uFF0C\\u540C\\u4E00\\u6DF1\\u5EA6\\u7684\\u6240\\u6709\\u8282\\u70B9\\u90FD\\u88AB\\u4E00\\u8D77\\u5904\\u7406\\u3002\\u8BE5\\u65B9\\u6CD5\\u4EE5\\u5E7F\\u5EA6\\u4F18\\u5148\\u7684\\u65B9\\u5F0F\\u6709\\u6548\\u5730\\u5904\\u7406\\u6240\\u6709\\u8282\\u70B9\\uFF0C\\u4ECE\\u800C\\u4FDD\\u6301\\u4E86\\u6811\\u7684\\u5C42\\u6B21\\u7ED3\\u6784\\u3002\"}),`\n`,(0,l.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,l.jsxs)(e.ol,{children:[`\n`,(0,l.jsx)(e.li,{children:\"\\u4F7F\\u7528\\u6839\\u8282\\u70B9\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u961F\\u5217\\u4EE5\\u8FED\\u4EE3\\u5904\\u7406\\u7EA7\\u522B\\u3002\"}),`\n`,(0,l.jsx)(e.li,{children:\"\\u4F7F\\u7528\\u5FAA\\u73AF\\u9010\\u7EA7\\u5904\\u7406\\u8282\\u70B9\\uFF0C\\u76F4\\u5230\\u961F\\u5217\\u4E3A\\u7A7A\\u3002\"}),`\n`,(0,l.jsx)(e.li,{children:\"\\u5728\\u6BCF\\u4E2A\\u7EA7\\u522B\\uFF0C\\u8DDF\\u8E2A\\u8981\\u5904\\u7406\\u7684\\u8282\\u70B9\\u6570\\uFF0C\\u5E76\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u65B0\\u7EC4\\u4EE5\\u5B58\\u50A8\\u5B83\\u4EEC\\u7684\\u503C\\u3002\"}),`\n`,(0,l.jsx)(e.li,{children:\"\\u79FB\\u9664\\u5F53\\u524D\\u7EA7\\u522B\\u7684\\u6BCF\\u4E2A\\u8282\\u70B9\\uFF0C\\u5C06\\u5176\\u503C\\u6DFB\\u52A0\\u5230\\u7EC4\\u4E2D\\uFF0C\\u5E76\\u5C06\\u5176\\u5DE6\\u5B50\\u8282\\u70B9\\u548C\\u53F3\\u5B50\\u8282\\u70B9\\u6392\\u961F\\uFF08\\u5982\\u679C\\u5B58\\u5728\\uFF09\\u3002\"}),`\n`,(0,l.jsx)(e.li,{children:\"\\u5C06\\u503C\\u7EC4\\u9644\\u52A0\\u5230\\u7ED3\\u679C\\u4E2D\\uFF0C\\u7136\\u540E\\u7EE7\\u7EED\\u5230\\u4E0B\\u4E00\\u7EA7\\u522B\\u3002\"}),`\n`,(0,l.jsx)(e.li,{children:\"\\u7EE7\\u7EED\\uFF0C\\u76F4\\u5230\\u6240\\u6709\\u8282\\u70B9\\u90FD\\u88AB\\u5904\\u7406\\u5E76\\u6309\\u6DF1\\u5EA6\\u5206\\u7EC4\\u3002\"}),`\n`]}),`\n`,(0,l.jsx)(o,{children:c}),`\n`,(0,l.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,l.jsxs)(e.ul,{children:[`\n`,(0,l.jsxs)(e.li,{children:[(0,l.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u6BCF\\u4E2A\\u8282\\u70B9\\u53EA\\u8BBF\\u95EE\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,l.jsxs)(e.li,{children:[(0,l.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m)\"}),\"\\u3002\\u961F\\u5217\\u4FDD\\u5B58\\u5F53\\u524D\\u7EA7\\u522B\\u7684\\u8282\\u70B9\\uFF0C\\u5176\\u4E2D \",(0,l.jsx)(e.code,{children:\"m\"}),\" \\u662F\\u4EFB\\u4F55\\u7EA7\\u522B\\u4E0A\\u7684\\u6700\\u5927\\u8282\\u70B9\\u6570\\uFF08\\u7B49\\u4E8E\\u6811\\u7684\\u5BBD\\u5EA6\\uFF09\\u3002\"]}),`\n`]})]})}function I(n={}){let{wrapper:e}=n.components||{};return e?(0,l.jsx)(e,Object.assign({},n,{children:(0,l.jsx)(v,n)})):v(n)}var j=I;return N(_);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/binary-tree-maximum-depth/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/binary-tree-maximum-depth/locales/zh-CN.json new file mode 100644 index 000000000..46587f4fe --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/binary-tree-maximum-depth/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var u=Object.create;var l=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty;var g=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),N=(t,e)=>{for(var o in e)l(t,o,{get:e[o],enumerable:!0})},a=(t,e,o,i)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of f(e))!T.call(t,r)&&r!==o&&l(t,r,{get:()=>e[r],enumerable:!(i=m(e,r))||i.enumerable});return t};var _=(t,e,o)=>(o=t!=null?u(x(t)):{},a(e||!t||!t.__esModule?l(o,\"default\",{value:t,enumerable:!0}):o,t)),j=t=>a(l({},\"__esModule\",{value:!0}),t);var d=g((w,h)=>{h.exports=_jsx_runtime});var X={};N(X,{default:()=>D,frontmatter:()=>v});var n=_(d());var c=MDXTestExamples;var s=[{input:[[\"root\",[1,2,3,4,5,6,7]]],output:3,explanation:\"The tree has a maximum depth of 3. The longest path from root (1) to leaves (4, 5, 6, or 7) is of length 3.\"},{input:[[\"root\",[1,null,2]]],output:2,explanation:\"The tree has a maximum depth of 2. The longest path from root (1) to leaf (2) is of length 2.\"},{input:[[\"root\",[10,5,15,null,null,12,20]]],output:3,explanation:\"The tree has a maximum depth of 3. The longest path from root (10) to leaves (12 or 20) is of length 3.\"}];var v={title:\"\\u4E8C\\u53C9\\u6811\\u7684\\u6700\\u5927\\u6DF1\\u5EA6\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u67E5\\u627E\\u4E8C\\u53C9\\u6811\\u7684\\u6700\\u5927\\u6DF1\\u5EA6\"};function p(t){let e=Object.assign({p:\"p\",code:\"code\",pre:\"pre\",h3:\"h3\",ul:\"ul\",li:\"li\",a:\"a\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u4E8C\\u53C9\\u6811\\u7684\",(0,n.jsx)(e.code,{children:\"root\"}),\"\\uFF0C\\u786E\\u5B9A\\u6811\\u7684\\u6DF1\\u5EA6\\uFF0C\\u5B83\\u88AB\\u5B9A\\u4E49\\u4E3A\\u4ECE\\u6839\\u5230\\u6700\\u8FDC\\u53F6\\u5B50\\u8282\\u70B9\\u7684\\u6700\\u957F\\u8DEF\\u5F84\\u4E0A\\u7684\\u8282\\u70B9\\u6570\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E8C\\u53C9\\u6811\\u7531\",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\"\\u7684\\u96C6\\u5408\\u8868\\u793A\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u8282\\u70B9\\u90FD\\u6709\\u53EF\\u9009\\u7684\",(0,n.jsx)(e.code,{children:\"left\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"right\"}),\"\\u5B50\\u8282\\u70B9\\uFF0C\\u5B83\\u4EEC\\u4E5F\\u662F\",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A\",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\"\\u5177\\u6709\\u4EE5\\u4E0B\\u63A5\\u53E3\\uFF1A\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-ts\",children:`interface TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n}\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"root: TreeNode\"}),\": \\u6811\\u7684\\u6839\\u8282\\u70B9\\u3002\\u793A\\u4F8B\\u663E\\u793A\\u6811\\u7684\",(0,n.jsx)(e.a,{href:\"https://en.wikipedia.org/wiki/Breadth-first_search\",children:\"\\u5E7F\\u5EA6\\u4F18\\u5148\\u904D\\u5386\"})]}),`\n`]}),`\n`,(0,n.jsx)(c,{testCases:s}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"1 <= \\u8282\\u70B9\\u6570 <= 10,000\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"-100 <= \",(0,n.jsx)(e.code,{children:\"TreeNode.val\"}),\" <= 100\"]}),`\n`]})]})}function C(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(p,t)})):p(t)}var D=C;return j(X);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来查找二叉树的最大深度", + "title": "二叉树的最大深度" + }, + "solution": "var Component=(()=>{var m=Object.create;var i=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty;var b=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),_=(n,e)=>{for(var r in e)i(n,r,{get:e[r],enumerable:!0})},d=(n,e,r,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let h of g(e))!T.call(n,h)&&h!==r&&i(n,h,{get:()=>e[h],enumerable:!(o=f(e,h))||o.enumerable});return n};var k=(n,e,r)=>(r=n!=null?m(x(n)):{},d(e||!n||!n.__esModule?i(r,\"default\",{value:n,enumerable:!0}):r,n)),M=n=>d(i({},\"__esModule\",{value:!0}),n);var u=b((w,c)=>{c.exports=_jsx_runtime});var j={};_(j,{default:()=>O});var t=k(u());var l=MDXCodeBlock;var a=`interface TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n}\n\nexport default function binaryTreeMaximumDepth(root: TreeNode | null): number {\n // Base case: if the root is null, the depth is 0\n if (root === null) {\n return 0;\n }\n\n // Recursively compute the depth of the left subtree\n const left_height = binaryTreeMaximumDepth(root.left);\n\n // Recursively compute the depth of the right subtree\n const right_height = binaryTreeMaximumDepth(root.right);\n\n // The depth of the current node is 1 (for the current node)\n // plus the maximum depth of the left and right subtrees\n return 1 + Math.max(left_height, right_height);\n}\n`;var s=`interface TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n}\n\nexport default function binaryTreeMaximumDepth(root: TreeNode | null): number {\n // If the root is null, the depth is 0\n if (root == null) {\n return 0;\n }\n\n // Initialize a stack for iterative traversal.\n // The stack holds tuples of (TreeNode, current_depth)\n let stack: [TreeNode | null, number][] = [];\n\n // Start with the root node at depth 1\n stack.push([root, 1]);\n\n // Variable to keep track of the maximum depth encountered\n let depth = 0;\n\n // Iterate while there are nodes in the stack\n while (stack.length !== 0) {\n // Pop a node and its associated depth from the stack\n let [node, current_depth] = stack.pop() as [TreeNode, number];\n\n // If the node is not null, process it\n if (node != null) {\n // Update the maximum depth if the current depth is greater\n depth = Math.max(depth, current_depth);\n\n // Push left child and right child into the stack with updated depth\n stack.push([node.left, current_depth + 1]);\n stack.push([node.right, current_depth + 1]);\n }\n }\n\n // Return the maximum depth found\n return depth;\n}\n`;function p(n){let e=Object.assign({h2:\"h2\",p:\"p\",h3:\"h3\",ol:\"ol\",li:\"li\",code:\"code\",ul:\"ul\",strong:\"strong\"},n.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u9012\\u5F52\"}),`\n`,(0,t.jsx)(e.p,{children:\"\\u4E8C\\u53C9\\u6811\\u7684\\u6700\\u5927\\u6DF1\\u5EA6\\u662F\\u901A\\u8FC7\\u627E\\u5230\\u4ECE\\u6839\\u8282\\u70B9\\u5230\\u53F6\\u8282\\u70B9\\u7684\\u6700\\u957F\\u8DEF\\u5F84\\u6765\\u786E\\u5B9A\\u7684\\u3002\\u9012\\u5F52\\u65B9\\u6CD5\\u975E\\u5E38\\u9002\\u5408\\u8FD9\\u4E2A\\u95EE\\u9898\\uFF0C\\u56E0\\u4E3A\\u8282\\u70B9\\u7684\\u6DF1\\u5EA6\\u662F\\u5176\\u5DE6\\u5B50\\u6811\\u548C\\u53F3\\u5B50\\u6811\\u7684\\u6700\\u5927\\u6DF1\\u5EA6\\u52A0 1\\u3002\\u4ECE\\u6839\\u8282\\u70B9\\u5F00\\u59CB\\uFF0C\\u7B97\\u6CD5\\u63A2\\u7D22\\u5DE6\\u5B50\\u6811\\u548C\\u53F3\\u5B50\\u6811\\uFF0C\\u8BA1\\u7B97\\u5B83\\u4EEC\\u7684\\u6DF1\\u5EA6\\uFF0C\\u5E76\\u9009\\u62E9\\u8F83\\u5927\\u7684\\u503C\\uFF0C\\u6709\\u6548\\u5730\\u4EE5\\u5206\\u6CBB\\u65B9\\u5F0F\\u904D\\u5386\\u6240\\u6709\\u8282\\u70B9\\u3002\"}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,t.jsxs)(e.ol,{children:[`\n`,(0,t.jsx)(e.li,{children:\"\\u4ECE\\u6839\\u8282\\u70B9\\u5F00\\u59CB\\u3002\"}),`\n`,(0,t.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5F53\\u524D\\u8282\\u70B9\\u4E3A \",(0,t.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u5219\\u8FD4\\u56DE\\u6DF1\\u5EA6 0\\uFF0C\\u56E0\\u4E3A\\u5176\\u4E0B\\u6CA1\\u6709\\u8282\\u70B9\\u3002\"]}),`\n`,(0,t.jsx)(e.li,{children:\"\\u9012\\u5F52\\u8BA1\\u7B97\\u5DE6\\u5B50\\u6811\\u7684\\u6DF1\\u5EA6\\u3002\"}),`\n`,(0,t.jsx)(e.li,{children:\"\\u9012\\u5F52\\u8BA1\\u7B97\\u53F3\\u5B50\\u6811\\u7684\\u6DF1\\u5EA6\\u3002\"}),`\n`,(0,t.jsx)(e.li,{children:\"\\u901A\\u8FC7\\u5C06 1\\uFF08\\u5BF9\\u4E8E\\u5F53\\u524D\\u8282\\u70B9\\u672C\\u8EAB\\uFF09\\u6DFB\\u52A0\\u5230\\u5176\\u5DE6\\u5B50\\u6811\\u548C\\u53F3\\u5B50\\u6811\\u7684\\u6DF1\\u5EA6\\u7684\\u6700\\u5927\\u503C\\u6765\\u8BA1\\u7B97\\u5F53\\u524D\\u8282\\u70B9\\u7684\\u6DF1\\u5EA6\\u3002\"}),`\n`,(0,t.jsx)(e.li,{children:\"\\u7EE7\\u7EED\\u6B64\\u8FC7\\u7A0B\\uFF0C\\u76F4\\u5230\\u6240\\u6709\\u8282\\u70B9\\u90FD\\u88AB\\u8BBF\\u95EE\\u3002\"}),`\n`]}),`\n`,(0,t.jsx)(l,{children:a}),`\n`,(0,t.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u6811\\u4E2D\\u7684\\u6BCF\\u4E2A\\u8282\\u70B9\\u53EA\\u8BBF\\u95EE\\u4E00\\u6B21\\u4EE5\\u8BA1\\u7B97\\u5176\\u6DF1\\u5EA6\\u3002\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(h)\"}),\"\\u3002\\u9012\\u5F52\\u5806\\u6808\\u5927\\u5C0F\\u53D6\\u51B3\\u4E8E\\u6811\\u7684\\u9AD8\\u5EA6\\uFF0C\\u5176\\u4E2D \",(0,t.jsx)(e.code,{children:\"h\"}),\" \\u662F\\u6811\\u7684\\u9AD8\\u5EA6\\u3002\"]}),`\n`]}),`\n`,(0,t.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u8FED\\u4EE3\"}),`\n`,(0,t.jsx)(e.p,{children:\"\\u8FED\\u4EE3\\u65B9\\u6CD5\\u67E5\\u627E\\u4E8C\\u53C9\\u6811\\u7684\\u6700\\u5927\\u6DF1\\u5EA6\\uFF0C\\u4F7F\\u7528\\u5806\\u6808\\u6765\\u6A21\\u62DF\\u6DF1\\u5EA6\\u4F18\\u5148\\u904D\\u5386\\u3002\\u6BCF\\u4E2A\\u5806\\u6808\\u6761\\u76EE\\u5305\\u542B\\u4E00\\u4E2A\\u8282\\u70B9\\u53CA\\u5176\\u5F53\\u524D\\u6DF1\\u5EA6\\u3002\\u8FD9\\u907F\\u514D\\u4E86\\u9012\\u5F52\\uFF0C\\u5E76\\u4F7F\\u7528\\u5806\\u6808\\u663E\\u5F0F\\u7BA1\\u7406\\u904D\\u5386\\u3002\\u4ECE\\u6DF1\\u5EA6\\u4E3A 1 \\u7684\\u6839\\u8282\\u70B9\\u5F00\\u59CB\\uFF0C\\u7B97\\u6CD5\\u904D\\u5386\\u6811\\u4E2D\\u7684\\u6240\\u6709\\u8282\\u70B9\\uFF0C\\u5728\\u5904\\u7406\\u6BCF\\u4E2A\\u8282\\u70B9\\u65F6\\u66F4\\u65B0\\u6700\\u5927\\u6DF1\\u5EA6\\u3002\\u8282\\u70B9\\u4EE5\\u5176\\u6DF1\\u5EA6\\u589E\\u52A0 1 \\u7684\\u65B9\\u5F0F\\u6DFB\\u52A0\\u5230\\u5806\\u6808\\u4E2D\\uFF0C\\u8868\\u793A\\u6811\\u7684\\u4E0B\\u4E00\\u5C42\\u3002\\u8FD9\\u79CD\\u65B9\\u6CD5\\u786E\\u4FDD\\u8003\\u8651\\u4ECE\\u6839\\u5230\\u53F6\\u7684\\u6BCF\\u6761\\u8DEF\\u5F84\\uFF0C\\u5E76\\u8BB0\\u5F55\\u6700\\u5927\\u6DF1\\u5EA6\\u3002\"}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,t.jsxs)(e.ol,{children:[`\n`,(0,t.jsx)(e.li,{children:\"\\u4F7F\\u7528\\u6839\\u8282\\u70B9\\u53CA\\u5176\\u521D\\u59CB\\u6DF1\\u5EA6\\u8BBE\\u7F6E\\u4E3A 1 \\u6765\\u521D\\u59CB\\u5316\\u5806\\u6808\\u3002\"}),`\n`,(0,t.jsx)(e.li,{children:\"\\u4F7F\\u7528\\u4E00\\u4E2A\\u53D8\\u91CF\\u6765\\u8DDF\\u8E2A\\u904D\\u5386\\u671F\\u95F4\\u9047\\u5230\\u7684\\u6700\\u5927\\u6DF1\\u5EA6\\u3002\"}),`\n`,(0,t.jsxs)(e.li,{children:[\"\\u5F53\\u5806\\u6808\\u4E0D\\u4E3A\\u7A7A\\u65F6\\uFF1A\",`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsx)(e.li,{children:\"\\u5F39\\u51FA\\u9876\\u90E8\\u8282\\u70B9\\u53CA\\u5176\\u5173\\u8054\\u7684\\u6DF1\\u5EA6\\u3002\"}),`\n`,(0,t.jsx)(e.li,{children:\"\\u5982\\u679C\\u5F53\\u524D\\u6DF1\\u5EA6\\u66F4\\u5927\\uFF0C\\u5219\\u66F4\\u65B0\\u6700\\u5927\\u6DF1\\u5EA6\\u3002\"}),`\n`,(0,t.jsx)(e.li,{children:\"\\u5C06\\u8282\\u70B9\\u7684\\u5DE6\\u5B50\\u8282\\u70B9\\u548C\\u53F3\\u5B50\\u8282\\u70B9\\u63A8\\u5165\\u5806\\u6808\\uFF0C\\u5176\\u6DF1\\u5EA6\\u589E\\u52A0 1\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,t.jsx)(e.li,{children:\"\\u7EE7\\u7EED\\uFF0C\\u76F4\\u5230\\u6240\\u6709\\u8282\\u70B9\\u90FD\\u88AB\\u5904\\u7406\\u3002\"}),`\n`]}),`\n`,(0,t.jsx)(l,{children:s}),`\n`,(0,t.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u6811\\u4E2D\\u7684\\u6BCF\\u4E2A\\u8282\\u70B9\\u5728\\u904D\\u5386\\u671F\\u95F4\\u53EA\\u8BBF\\u95EE\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(h)\"}),\"\\u3002\\u5806\\u6808\\u5927\\u5C0F\\u53D6\\u51B3\\u4E8E\\u6811\\u7684\\u9AD8\\u5EA6\\uFF0C\\u5176\\u4E2D \",(0,t.jsx)(e.code,{children:\"h\"}),\" \\u662F\\u6811\\u7684\\u9AD8\\u5EA6\\u3002\"]}),`\n`]})]})}function y(n={}){let{wrapper:e}=n.components||{};return e?(0,t.jsx)(e,Object.assign({},n,{children:(0,t.jsx)(p,n)})):p(n)}var O=y;return M(j);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/binary-tree-maximum-total-path/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/binary-tree-maximum-total-path/locales/zh-CN.json new file mode 100644 index 000000000..f97028b7c --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/binary-tree-maximum-total-path/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var u=Object.create;var i=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty;var g=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),N=(t,e)=>{for(var r in e)i(t,r,{get:e[r],enumerable:!0})},c=(t,e,r,l)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let o of x(e))!T.call(t,o)&&o!==r&&i(t,o,{get:()=>e[o],enumerable:!(l=m(e,o))||l.enumerable});return t};var _=(t,e,r)=>(r=t!=null?u(f(t)):{},c(e||!t||!t.__esModule?i(r,\"default\",{value:t,enumerable:!0}):r,t)),j=t=>c(i({},\"__esModule\",{value:!0}),t);var a=g((v,d)=>{d.exports=_jsx_runtime});var X={};N(X,{default:()=>D,frontmatter:()=>M});var n=_(a());var h=MDXTestExamples;var s=[{input:[[\"root\",[4,3,5]]],output:12,explanation:\"The optimal path is 3 -> 4 -> 5 with a sum of 12.\"},{input:[[\"root\",[-2,1]]],output:1,explanation:\"The optimal path is the single node with value 1.\"},{input:[[\"root\",[-30,8,22,null,null,17,8]]],output:47,explanation:\"The optimal path is 17 -> 22 -> 8 with a sum of 47.\"}];var M={title:\"\\u4E8C\\u53C9\\u6811\\u6700\\u5927\\u8DEF\\u5F84\\u548C\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u4EE5\\u627E\\u5230\\u4E8C\\u53C9\\u6811\\u8DEF\\u5F84\\u4E2D\\u8282\\u70B9\\u7684\\u6700\\u5927\\u603B\\u548C\"};function p(t){let e=Object.assign({p:\"p\",code:\"code\",pre:\"pre\",h3:\"h3\",ul:\"ul\",li:\"li\",a:\"a\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u4E8C\\u53C9\\u6811\\u7684\",(0,n.jsx)(e.code,{children:\"root\"}),\"\\uFF0C\\u786E\\u5B9A\\u6811\\u4E2D\\u4EFB\\u4F55\\u975E\\u7A7A\\u8DEF\\u5F84\\u7684\\u6700\\u5927\\u53EF\\u80FD\\u603B\\u548C\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u5728\\u4E8C\\u53C9\\u6811\\u4E2D\\uFF0C\\u8DEF\\u5F84\\u5B9A\\u4E49\\u4E3A\\u8282\\u70B9\\u7684\\u5E8F\\u5217\\uFF0C\\u5176\\u4E2D\\u5E8F\\u5217\\u4E2D\\u7684\\u6BCF\\u5BF9\\u8FDE\\u7EED\\u8282\\u70B9\\u90FD\\u7531\\u8FB9\\u76F4\\u63A5\\u8FDE\\u63A5\\u3002\\u4E00\\u4E2A\\u8282\\u70B9\\u53EA\\u80FD\\u5728\\u8DEF\\u5F84\\u5E8F\\u5217\\u4E2D\\u51FA\\u73B0\\u4E00\\u6B21\\uFF0C\\u5E76\\u4E14\\u8DEF\\u5F84\\u4E0D\\u4E00\\u5B9A\\u9700\\u8981\\u5305\\u542B\\u6839\\u8282\\u70B9\\u3002\\u8DEF\\u5F84\\u7684\\u603B\\u548C\\u901A\\u8FC7\\u5C06\\u8BE5\\u8DEF\\u5F84\\u4E2D\\u5B58\\u5728\\u7684\\u6240\\u6709\\u8282\\u70B9\\u7684\\u503C\\u76F8\\u52A0\\u6765\\u8BA1\\u7B97\\u3002\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E8C\\u53C9\\u6811\\u7531\",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\"\\u7684\\u96C6\\u5408\\u8868\\u793A\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u8282\\u70B9\\u90FD\\u6709\\u53EF\\u9009\\u7684\",(0,n.jsx)(e.code,{children:\"left\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"right\"}),\"\\u5B50\\u8282\\u70B9\\uFF0C\\u5B83\\u4EEC\\u4E5F\\u662F\",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A\",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\"\\u5177\\u6709\\u4EE5\\u4E0B\\u63A5\\u53E3\\uFF1A\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-ts\",children:`interface TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n}\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"root: TreeNode\"}),\": \\u6811\\u7684\\u6839\\u8282\\u70B9\\u3002\\u793A\\u4F8B\\u663E\\u793A\\u6811\\u7684\",(0,n.jsx)(e.a,{href:\"https://en.wikipedia.org/wiki/Breadth-first_search\",children:\"\\u5E7F\\u5EA6\\u4F18\\u5148\\u904D\\u5386\"})]}),`\n`]}),`\n`,(0,n.jsx)(h,{testCases:s}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"1 <= \\u8282\\u70B9\\u6570 <= 10,000\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"-100 <= \",(0,n.jsx)(e.code,{children:\"TreeNode.val\"}),\" <= 100\"]}),`\n`]})]})}function C(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(p,t)})):p(t)}var D=C;return j(X);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,以找到二叉树路径中节点的最大总和", + "title": "二叉树最大路径和" + }, + "solution": "var Component=(()=>{var s=Object.create;var a=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var p=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),S=(t,e)=>{for(var r in e)a(t,r,{get:e[r],enumerable:!0})},l=(t,e,r,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of f(e))!b.call(t,i)&&i!==r&&a(t,i,{get:()=>e[i],enumerable:!(o=g(e,i))||o.enumerable});return t};var F=(t,e,r)=>(r=t!=null?s(x(t)):{},l(e||!t||!t.__esModule?a(r,\"default\",{value:t,enumerable:!0}):r,t)),v=t=>l(a({},\"__esModule\",{value:!0}),t);var u=p((_,m)=>{m.exports=_jsx_runtime});var R={};S(R,{default:()=>j});var n=F(u());var h=MDXCodeBlock;var c=`interface TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n}\n\n// Main function to find the maximum path sum in a binary tree\nexport default function binaryTreeMaximumPathSum(\n root: TreeNode | null,\n): number {\n // Initialize maxSum as a very small value (negative infinity)\n let maxSum = -Infinity;\n\n // Helper function to perform a post-order traversal of the tree\n // and calculate the maximum gain from each subtree\n function gainFromSubtree(node: TreeNode | null): number {\n // Base case: If the node is null, return 0 (no gain)\n if (node === null) {\n return 0;\n }\n\n // Recursively calculate the maximum gain from the left subtree\n // If the gain is negative, consider it as 0 (ignore it)\n const gainFromLeft = Math.max(gainFromSubtree(node.left), 0);\n\n // Recursively calculate the maximum gain from the right subtree\n // If the gain is negative, consider it as 0 (ignore it)\n const gainFromRight = Math.max(gainFromSubtree(node.right), 0);\n\n // Calculate the maximum path sum including the current node\n // and update maxSum if this path has the highest sum so far\n maxSum = Math.max(maxSum, gainFromLeft + gainFromRight + node.val);\n\n // Return the maximum gain that can be obtained by including the current node\n // and either its left or right subtree (but not both, to keep the path continuous)\n return Math.max(gainFromLeft + node.val, gainFromRight + node.val);\n }\n\n // Start the traversal from the root node to calculate maxSum\n gainFromSubtree(root);\n\n // Return the maximum path sum found\n return maxSum;\n}\n`;function d(t){let e=Object.assign({h2:\"h2\",p:\"p\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\",code:\"code\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u540E\\u5E8F\\u904D\\u5386DFS\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u4E8C\\u53C9\\u6811\\u4E2D\\u7684\\u6700\\u5927\\u8DEF\\u5F84\\u548C\\u662F\\u4EFB\\u4F55\\u8DEF\\u5F84\\u4E2D\\u8282\\u70B9\\u503C\\u7684\\u6700\\u5927\\u603B\\u548C\\u3002\\u8DEF\\u5F84\\u53EF\\u4EE5\\u4ECE\\u6811\\u4E2D\\u7684\\u4EFB\\u4F55\\u8282\\u70B9\\u5F00\\u59CB\\u548C\\u7ED3\\u675F\\uFF0C\\u4F46\\u5B83\\u5FC5\\u987B\\u9075\\u5FAA\\u7236\\u5B50\\u8FDE\\u63A5\\u3002\\u8BE5\\u7B56\\u7565\\u4F7F\\u7528\\u540E\\u5E8F\\u6DF1\\u5EA6\\u4F18\\u5148\\u641C\\u7D22\\uFF08DFS\\uFF09\\u6765\\u63A2\\u7D22\\u6BCF\\u4E2A\\u5B50\\u6811\\uFF0C\\u5E76\\u8BA1\\u7B97\\u6BCF\\u4E2A\\u8282\\u70B9\\u5DE6\\u53F3\\u5B50\\u6811\\u7684\\u6700\\u5927\\u589E\\u76CA\\u3002\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u8282\\u70B9\\uFF0C\\u6F5C\\u5728\\u7684\\u6700\\u5927\\u8DEF\\u5F84\\u548C\\u8BA1\\u7B97\\u4E3A\\u5176\\u503C\\u4E0E\\u5DE6\\u53F3\\u5B50\\u6811\\u7684\\u6700\\u5927\\u589E\\u76CA\\u4E4B\\u548C\\u3002\\u5FFD\\u7565\\u6765\\u81EA\\u5B50\\u6811\\u7684\\u8D1F\\u589E\\u76CA\\uFF0C\\u4EE5\\u786E\\u4FDD\\u4EC5\\u5305\\u542B\\u5177\\u6709\\u6B63\\u8D21\\u732E\\u7684\\u8DEF\\u5F84\\u3002\\u901A\\u8FC7\\u904D\\u5386\\u6574\\u4E2A\\u6811\\uFF0C\\u786E\\u5B9A\\u5168\\u5C40\\u6700\\u5927\\u8DEF\\u5F84\\u548C\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u5BF9\\u6811\\u6267\\u884C\\u540E\\u5E8F\\u904D\\u5386\\uFF0C\\u4EC5\\u5728\\u5904\\u7406\\u5B8C\\u5176\\u5DE6\\u53F3\\u5B50\\u6811\\u540E\\u624D\\u5904\\u7406\\u6BCF\\u4E2A\\u8282\\u70B9\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u8282\\u70B9\\uFF0C\\u8BA1\\u7B97\\u5176\\u5DE6\\u53F3\\u5B50\\u6811\\u7684\\u6700\\u5927\\u589E\\u76CA\\u3002\\u5982\\u679C\\u5B50\\u6811\\u8D21\\u732E\\u8D1F\\u589E\\u76CA\\uFF0C\\u5219\\u5C06\\u5176\\u5FFD\\u7565\\uFF0C\\u89C6\\u4E3A 0\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8BA1\\u7B97\\u5F53\\u524D\\u8282\\u70B9\\u7684\\u8DEF\\u5F84\\u548C\\uFF0C\\u5373\\u5176\\u503C\\u4E0E\\u5176\\u5DE6\\u53F3\\u5B50\\u6811\\u7684\\u6700\\u5927\\u589E\\u76CA\\u4E4B\\u548C\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u5F53\\u524D\\u8282\\u70B9\\u7684\\u8BA1\\u7B97\\u8DEF\\u5F84\\u548C\\u66F4\\u5927\\uFF0C\\u5219\\u66F4\\u65B0\\u5168\\u5C40\\u6700\\u5927\\u8DEF\\u5F84\\u548C\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8FD4\\u56DE\\u53EF\\u4EE5\\u4F20\\u9012\\u7ED9\\u7236\\u8282\\u70B9\\u7684\\u6700\\u5927\\u589E\\u76CA\\uFF0C\\u5176\\u4E2D\\u5305\\u62EC\\u8282\\u70B9\\u7684\\u503C\\u4EE5\\u53CA\\u6765\\u81EA\\u5176\\u5DE6\\u5B50\\u6811\\u6216\\u53F3\\u5B50\\u6811\\u7684\\u8F83\\u5927\\u589E\\u76CA\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(h,{children:c}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u5728\\u904D\\u5386\\u671F\\u95F4\\uFF0C\\u6BCF\\u4E2A\\u8282\\u70B9\\u90FD\\u4F1A\\u88AB\\u8BBF\\u95EE\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(h)\"}),\"\\u3002\\u9012\\u5F52\\u5806\\u6808\\u6240\\u9700\\u7684\\u7A7A\\u95F4\\u4E0E\\u6811\\u7684\\u9AD8\\u5EA6\\u6210\\u6B63\\u6BD4\\uFF0C\\u5176\\u4E2D \",(0,n.jsx)(e.code,{children:\"h\"}),\" \\u662F\\u6811\\u7684\\u9AD8\\u5EA6\\u3002\"]}),`\n`]})]})}function y(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(d,t)})):d(t)}var j=y;return v(R);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/binary-tree-rebuilding-from-traversals/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/binary-tree-rebuilding-from-traversals/locales/zh-CN.json new file mode 100644 index 000000000..48ba71d93 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/binary-tree-rebuilding-from-traversals/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var i=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var g=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),j=(n,e)=>{for(var t in e)i(n,t,{get:e[t],enumerable:!0})},l=(n,e,t,d)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let o of x(e))!b.call(n,o)&&o!==t&&i(n,o,{get:()=>e[o],enumerable:!(d=m(e,o))||d.enumerable});return n};var T=(n,e,t)=>(t=n!=null?p(f(n)):{},l(e||!n||!n.__esModule?i(t,\"default\",{value:n,enumerable:!0}):t,n)),_=n=>l(i({},\"__esModule\",{value:!0}),n);var h=g((y,c)=>{c.exports=_jsx_runtime});var X={};j(X,{default:()=>D,frontmatter:()=>M});var r=T(h());var s=MDXTestExamples;var u=[{input:[[\"preorder\",[3,1,2,6,5,9]],[\"inorder\",[1,2,3,5,6,9]]],output:[3,1,6,null,2,5,9],explanation:\"The root is 3, with left subtree [1, 2] and right subtree [6, 5, 9].\"},{input:[[\"preorder\",[1,2,3]],[\"inorder\",[3,2,1]]],output:[1,2,null,3],explanation:\"The root is 1, with left subtree [2, 3] and no right subtree.\"},{input:[[\"preorder\",[7]],[\"inorder\",[7]]],output:[7],explanation:\"The tree consists of a single node with the value 7, which is both the root and the only node.\"}];var M={title:\"\\u901A\\u8FC7\\u5148\\u5E8F\\u548C\\u4E2D\\u5E8F\\u904D\\u5386\\u91CD\\u5EFA\\u4E8C\\u53C9\\u6811\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u4ECE\\u5148\\u5E8F\\u548C\\u4E2D\\u5E8F\\u904D\\u5386\\u6784\\u9020\\u4E8C\\u53C9\\u6811\\u7684\\u51FD\\u6570\"};function a(n){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},n.components);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E24\\u4E2A\\u6574\\u6570\\u6570\\u7EC4 \",(0,r.jsx)(e.code,{children:\"preorder\"}),\" \\u548C \",(0,r.jsx)(e.code,{children:\"inorder\"}),\"\\uFF0C\\u5176\\u4E2D \",(0,r.jsx)(e.code,{children:\"preorder\"}),\" \\u8868\\u793A\\u4E8C\\u53C9\\u6811\\u7684\\u5148\\u5E8F\\u904D\\u5386\\u503C\\uFF0C\",(0,r.jsx)(e.code,{children:\"inorder\"}),\" \\u8868\\u793A\\u540C\\u4E00\\u68F5\\u6811\\u7684\\u4E2D\\u5E8F\\u904D\\u5386\\u503C\\uFF0C\\u4ECE\\u8FD9\\u4E9B\\u904D\\u5386\\u6784\\u9020\\u5E76\\u8FD4\\u56DE\\u4E8C\\u53C9\\u6811\\u3002\"]}),`\n`,(0,r.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"preorder: number[]\"}),\": \\u6B63\\u6574\\u6570\\u6570\\u7EC4\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"inorder: number[]\"}),\": \\u6B63\\u6574\\u6570\\u6570\\u7EC4\"]}),`\n`]}),`\n`,(0,r.jsx)(s,{testCases:u}),`\n`,(0,r.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"1 <= \\u8282\\u70B9\\u6570 <= 1000\"}),`\n`,(0,r.jsxs)(e.li,{children:[\"1 <= \",(0,r.jsx)(e.code,{children:\"TreeNode.val\"}),\" <= 1,000,000\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"preorder\"}),\" \\u548C \",(0,r.jsx)(e.code,{children:\"inorder\"}),\" \\u5305\\u542B\\u552F\\u4E00\\u503C\"]}),`\n`]})]})}function C(n={}){let{wrapper:e}=n.components||{};return e?(0,r.jsx)(e,Object.assign({},n,{children:(0,r.jsx)(a,n)})):a(n)}var D=C;return _(X);})();\n;return Component;", + "info": { + "excerpt": "实现一个从先序和中序遍历构造二叉树的函数", + "title": "通过先序和中序遍历重建二叉树" + }, + "solution": "var Component=(()=>{var f=Object.create;var l=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty;var x=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),b=(n,e)=>{for(var t in e)l(n,t,{get:e[t],enumerable:!0})},d=(n,e,t,i)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let o of m(e))!T.call(n,o)&&o!==t&&l(n,o,{get:()=>e[o],enumerable:!(i=g(e,o))||i.enumerable});return n};var y=(n,e,t)=>(t=n!=null?f(p(n)):{},d(e||!n||!n.__esModule?l(t,\"default\",{value:n,enumerable:!0}):t,n)),M=n=>d(l({},\"__esModule\",{value:!0}),n);var a=x((B,h)=>{h.exports=_jsx_runtime});var O={};b(O,{default:()=>j});var r=y(a());var u=MDXCodeBlock;var c=`class TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n\n constructor(\n val: number,\n left: TreeNode | null = null,\n right: TreeNode | null = null,\n ) {\n this.val = val;\n this.left = left;\n this.right = right;\n }\n}\n\nexport default function binaryTreeRebuildingFromTraversals(\n preorder: number[],\n inorder: number[],\n): TreeNode | null {\n let preorderIndex = 0;\n\n // Create a map to store the index of each value in the inorder array for quick lookup\n let inorderIndexMap = new Map();\n for (let i = 0; i < inorder.length; i++) {\n inorderIndexMap.set(inorder[i], i);\n }\n\n // Helper function to recursively build the tree\n function arrayToTree(left: number, right: number): TreeNode | null {\n // Base case: if there are no elements to construct the tree\n if (left > right) {\n return null;\n }\n\n // Select the current element from preorder as the root and increment the index\n let rootValue = preorder[preorderIndex++];\n let root = new TreeNode(rootValue);\n\n // Build the left subtree using elements to the left of the root in the inorder array\n root.left = arrayToTree(left, inorderIndexMap.get(rootValue)! - 1);\n\n // Build the right subtree using elements to the right of the root in the inorder array\n root.right = arrayToTree(inorderIndexMap.get(rootValue)! + 1, right);\n\n // Return the constructed subtree rooted at this node\n return root;\n }\n\n // Start constructing the tree from the full range of the inorder array\n return arrayToTree(0, preorder.length - 1);\n}\n`;function s(n){let e=Object.assign({h2:\"h2\",p:\"p\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},n.components);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u9012\\u5F52\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u76EE\\u6807\\u662F\\u4ECE\\u5176\\u5148\\u5E8F\\u904D\\u5386\\u548C\\u4E2D\\u5E8F\\u904D\\u5386\\u91CD\\u5EFA\\u4E8C\\u53C9\\u6811\\u3002\\u5728\\u5148\\u5E8F\\u904D\\u5386\\u4E2D\\uFF0C\\u7B2C\\u4E00\\u4E2A\\u5143\\u7D20\\u59CB\\u7EC8\\u662F\\u6811\\u7684\\u6839\\u3002\\u4E2D\\u5E8F\\u904D\\u5386\\u6839\\u636E\\u6839\\u7684\\u4F4D\\u7F6E\\u5C06\\u6811\\u5206\\u6210\\u5176\\u5DE6\\u5B50\\u6811\\u548C\\u53F3\\u5B50\\u6811\\u3002\\u901A\\u8FC7\\u7ED3\\u5408\\u8FD9\\u4E24\\u4E2A\\u904D\\u5386\\uFF0C\\u53EF\\u4EE5\\u8BC6\\u522B\\u6839\\u5E76\\u9012\\u5F52\\u5730\\u91CD\\u5EFA\\u5DE6\\u5B50\\u6811\\u548C\\u53F3\\u5B50\\u6811\\u3002\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u4E3A\\u4E86\\u4F18\\u5316\\u6B64\\u8FC7\\u7A0B\\uFF0C\\u521B\\u5EFA\\u4E00\\u4E2A\\u6620\\u5C04\\u6765\\u5B58\\u50A8\\u4E2D\\u5E8F\\u904D\\u5386\\u4E2D\\u5143\\u7D20\\u7684\\u7D22\\u5F15\\uFF0C\\u4ECE\\u800C\\u5141\\u8BB8 O(1) \\u67E5\\u627E\\u6839\\u5728\\u4E2D\\u5E8F\\u6570\\u7EC4\\u4E2D\\u7684\\u4F4D\\u7F6E\\u3002\\u4F7F\\u7528\\u6B64\\u6620\\u5C04\\uFF0C\\u8BE5\\u7B97\\u6CD5\\u907F\\u514D\\u4E86\\u5728\\u4E2D\\u5E8F\\u904D\\u5386\\u4E2D\\u91CD\\u590D\\u641C\\u7D22\\u5143\\u7D20\\uFF0C\\u5426\\u5219\\u4F1A\\u5BFC\\u81F4\\u66F4\\u9AD8\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u3002\"}),`\n`,(0,r.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,r.jsxs)(e.ol,{children:[`\n`,(0,r.jsx)(e.li,{children:\"\\u521B\\u5EFA\\u4E00\\u4E2A\\u6620\\u5C04\\uFF0C\\u7528\\u4E8E\\u5B58\\u50A8\\u4E2D\\u5E8F\\u6570\\u7EC4\\u4E2D\\u6BCF\\u4E2A\\u503C\\u7684\\u7D22\\u5F15\\uFF0C\\u4EE5\\u4FBF\\u5FEB\\u901F\\u67E5\\u627E\\u3002\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u9012\\u5F52\\u51FD\\u6570\\uFF0C\\u7528\\u4E8E\\u5728\\u7ED9\\u5B9A\\u7684\\u4E2D\\u5E8F\\u6570\\u7EC4\\u8303\\u56F4\\u5185\\u6784\\u9020\\u6811\\u3002\"}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5728\\u9012\\u5F52\\u51FD\\u6570\\u4E2D\\uFF1A\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"\\u9009\\u62E9\\u5148\\u5E8F\\u6570\\u7EC4\\u4E2D\\u7684\\u5F53\\u524D\\u5143\\u7D20\\u4F5C\\u4E3A\\u6839\\uFF0C\\u5E76\\u9012\\u589E\\u5148\\u5E8F\\u7D22\\u5F15\\u3002\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u4F7F\\u7528\\u4E2D\\u5E8F\\u6620\\u5C04\\u6765\\u5B9A\\u4F4D\\u6839\\u5728\\u4E2D\\u5E8F\\u6570\\u7EC4\\u4E2D\\u7684\\u4F4D\\u7F6E\\u3002\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u4F7F\\u7528\\u4E2D\\u5E8F\\u6570\\u7EC4\\u4E2D\\u6839\\u5DE6\\u4FA7\\u7684\\u5143\\u7D20\\u9012\\u5F52\\u5730\\u6784\\u5EFA\\u5DE6\\u5B50\\u6811\\u3002\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u4F7F\\u7528\\u4E2D\\u5E8F\\u6570\\u7EC4\\u4E2D\\u6839\\u53F3\\u4FA7\\u7684\\u5143\\u7D20\\u9012\\u5F52\\u5730\\u6784\\u5EFA\\u53F3\\u5B50\\u6811\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,r.jsx)(e.li,{children:\"\\u5728\\u5904\\u7406\\u5B8C\\u5148\\u5E8F\\u6570\\u7EC4\\u4E2D\\u7684\\u6240\\u6709\\u5143\\u7D20\\u540E\\uFF0C\\u8FD4\\u56DE\\u6784\\u9020\\u7684\\u6811\\u3002\"}),`\n`]}),`\n`,(0,r.jsx)(u,{children:c}),`\n`,(0,r.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u6BCF\\u4E2A\\u8282\\u70B9\\u53EA\\u5904\\u7406\\u4E00\\u6B21\\uFF0C\\u5E76\\u4E14\\u8BE5\\u6620\\u5C04\\u5141\\u8BB8\\u5728\\u4E2D\\u5E8F\\u6570\\u7EC4\\u4E2D\\u8FDB\\u884C O(1) \\u7D22\\u5F15\\u67E5\\u627E\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u7A7A\\u95F4\\u7528\\u4E8E\\u9012\\u5F52\\u5806\\u6808\\u548C\\u5B58\\u50A8\\u4E2D\\u5E8F\\u6570\\u7EC4\\u4E2D\\u5143\\u7D20\\u7D22\\u5F15\\u7684\\u6620\\u5C04\\u3002\"]}),`\n`]})]})}function N(n={}){let{wrapper:e}=n.components||{};return e?(0,r.jsx)(e,Object.assign({},n,{children:(0,r.jsx)(s,n)})):s(n)}var j=N;return M(O);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/binary-tree-serialization-deserialization/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/binary-tree-serialization-deserialization/locales/zh-CN.json new file mode 100644 index 000000000..046aedf1b --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/binary-tree-serialization-deserialization/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var l=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty;var g=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),N=(r,e)=>{for(var i in e)l(r,i,{get:e[i],enumerable:!0})},d=(r,e,i,a)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let t of f(e))!T.call(r,t)&&t!==i&&l(r,t,{get:()=>e[t],enumerable:!(a=m(e,t))||a.enumerable});return r};var z=(r,e,i)=>(i=r!=null?p(x(r)):{},d(e||!r||!r.__esModule?l(i,\"default\",{value:r,enumerable:!0}):i,r)),_=r=>d(l({},\"__esModule\",{value:!0}),r);var c=g((w,o)=>{o.exports=_jsx_runtime});var X={};N(X,{default:()=>D,frontmatter:()=>M});var n=z(c());var h=MDXTestExamples;var s=[{input:[[\"root\",[5,3,8,1,4,6,9]]],output:[5,3,8,1,4,6,9],explanation:\"The tree structure remains unchanged after serialization and deserialization.\"},{input:[[\"root\",[1,null,2]]],output:[1,null,2],explanation:\"The tree structure remains unchanged after serialization and deserialization.\"},{input:[[\"root\",[2,1,7]]],output:[2,1,7],explanation:\"The tree structure remains unchanged after serialization and deserialization.\"}];var M={title:\"\\u4E8C\\u53C9\\u6811\\u5E8F\\u5217\\u5316\\u548C\\u53CD\\u5E8F\\u5217\\u5316\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u5E8F\\u5217\\u5316\\u548C\\u53CD\\u5E8F\\u5217\\u5316\\u4E8C\\u53C9\\u6811\\u7684\\u51FD\\u6570\"};function u(r){let e=Object.assign({p:\"p\",code:\"code\",pre:\"pre\",h3:\"h3\",h4:\"h4\",ul:\"ul\",li:\"li\",a:\"a\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.p,{children:\"\\u8BBE\\u8BA1\\u4E00\\u79CD\\u5E8F\\u5217\\u5316\\u548C\\u53CD\\u5E8F\\u5217\\u5316\\u4E8C\\u53C9\\u6811\\u7684\\u65B9\\u6CD5\\u3002\\u5BF9\\u5E8F\\u5217\\u5316\\u548C\\u53CD\\u5E8F\\u5217\\u5316\\u7684\\u5B9E\\u73B0\\u65B9\\u5F0F\\u6CA1\\u6709\\u5177\\u4F53\\u9650\\u5236\\uFF1B\\u5173\\u952E\\u8981\\u6C42\\u662F\\u5E8F\\u5217\\u5316\\u7684\\u4E8C\\u53C9\\u6811\\u5FC5\\u987B\\u80FD\\u591F\\u8F6C\\u6362\\u56DE\\u539F\\u59CB\\u6811\\u7ED3\\u6784\\u3002\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E8C\\u53C9\\u6811\\u7531\",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\"\\u7684\\u96C6\\u5408\\u8868\\u793A\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u8282\\u70B9\\u90FD\\u6709\\u53EF\\u9009\\u7684\",(0,n.jsx)(e.code,{children:\"left\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"right\"}),\"\\u5B50\\u8282\\u70B9\\uFF0C\\u5B83\\u4EEC\\u4E5F\\u662F\",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A\",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\"\\u5177\\u6709\\u4EE5\\u4E0B\\u63A5\\u53E3\\uFF1A\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-ts\",children:`interface TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n}\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsx)(e.h4,{children:(0,n.jsx)(e.code,{children:\"serializeBinaryTree\"})}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"root: TreeNode\"}),\": \\u6811\\u7684\\u6839\\u8282\\u70B9\\u3002\\u793A\\u4F8B\\u663E\\u793A\\u6811\\u7684\",(0,n.jsx)(e.a,{href:\"https://en.wikipedia.org/wiki/Breadth-first_search\",children:\"\\u5C42\\u5E8F\\u904D\\u5386\"})]}),`\n`]}),`\n`,(0,n.jsx)(e.h4,{children:(0,n.jsx)(e.code,{children:\"deserializeBinaryTree\"})}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"data: string\"}),\": \\u6811\\u7684\\u5B57\\u7B26\\u4E32\\u8868\\u793A\\u5F62\\u5F0F\\u3002\\u683C\\u5F0F\\u7531\\u60A8\\u8BBE\\u8BA1\"]}),`\n`]}),`\n`,(0,n.jsx)(h,{testCases:s}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"1 <= \\u8282\\u70B9\\u6570 <= 10,000\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"TreeNode.val\"}),\" <= 1,000,000\"]}),`\n`]})]})}function C(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(u,r)})):u(r)}var D=C;return _(X);})();\n;return Component;", + "info": { + "excerpt": "实现一个序列化和反序列化二叉树的函数", + "title": "二叉树序列化和反序列化" + }, + "solution": "var Component=(()=>{var m=Object.create;var t=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var T=(l,e)=>()=>(e||l((e={exports:{}}).exports,e),e.exports),N=(l,e)=>{for(var r in e)t(l,r,{get:e[r],enumerable:!0})},o=(l,e,r,d)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of g(e))!z.call(l,i)&&i!==r&&t(l,i,{get:()=>e[i],enumerable:!(d=f(e,i))||d.enumerable});return l};var v=(l,e,r)=>(r=l!=null?m(p(l)):{},o(e||!l||!l.__esModule?t(r,\"default\",{value:l,enumerable:!0}):r,l)),x=l=>o(t({},\"__esModule\",{value:!0}),l);var h=T((b,s)=>{s.exports=_jsx_runtime});var D={};N(D,{default:()=>B});var n=v(h());var c=MDXCodeBlock;var a=`class TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n\n constructor(\n val: number,\n left: TreeNode | null = null,\n right: TreeNode | null = null,\n ) {\n this.val = val;\n this.left = left;\n this.right = right;\n }\n}\n\nfunction serializeImpl(root: TreeNode | null, str: string): string {\n // Base case: if the node is null, add \"null,\" to the string\n if (root === null) {\n str += 'null,';\n } else {\n // Otherwise, add the current node's value to the string\n str += root.val.toString() + ',';\n // Recursively serialize the left and right subtrees\n str = serializeImpl(root.left, str);\n str = serializeImpl(root.right, str);\n }\n return str;\n}\n\nexport function serializeBinaryTree(root: TreeNode | null): string {\n return serializeImpl(root, '');\n}\n\nfunction deserializeImpl(dataList: string[]): TreeNode | null {\n // Base case: if the current element is \"null\", remove it and return null\n if (dataList[0] === 'null') {\n dataList.shift(); // Remove the first element from the list\n return null;\n }\n\n // Otherwise, create a new TreeNode with the first element of the list\n const root = new TreeNode(Number(dataList[0]));\n dataList.shift(); // Remove the first element from the list\n\n // Recursively deserialize the left and right subtrees\n root.left = deserializeImpl(dataList);\n root.right = deserializeImpl(dataList);\n\n return root;\n}\n\nexport function deserializeBinaryTree(data: string): TreeNode | null {\n // Split the serialized string into a list of strings\n const dataArray = data.split(',');\n const dataList = dataArray.filter((item) => item !== ''); // Remove any empty strings\n\n return deserializeImpl(dataList);\n}\n`;function u(l){let e=Object.assign({h2:\"h2\",p:\"p\",h4:\"h4\",ul:\"ul\",li:\"li\",code:\"code\",h3:\"h3\",ol:\"ol\",strong:\"strong\"},l.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528 DFS\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u4E8C\\u53C9\\u6811\\u7684\\u5E8F\\u5217\\u5316\\u548C\\u53CD\\u5E8F\\u5217\\u5316\\u5206\\u522B\\u6D89\\u53CA\\u5C06\\u6811\\u7ED3\\u6784\\u8F6C\\u6362\\u4E3A\\u5B57\\u7B26\\u4E32\\u8868\\u793A\\u5F62\\u5F0F\\uFF0C\\u4EE5\\u53CA\\u4ECE\\u5B57\\u7B26\\u4E32\\u91CD\\u5EFA\\u6811\\u3002\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u6DF1\\u5EA6\\u4F18\\u5148\\u904D\\u5386 (DFS) \\u65B9\\u6CD5\\u6765\\u5B9E\\u73B0\\u6B64\\u76EE\\u7684\\u3002\"}),`\n`,(0,n.jsx)(e.h4,{children:\"\\u5E8F\\u5217\\u5316\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u6BCF\\u4E2A\\u8282\\u70B9\\u7684\\u503C\\u9644\\u52A0\\u5230\\u5B57\\u7B26\\u4E32\\u4E2D\\uFF0C\\u7136\\u540E\\u9012\\u5F52\\u5730\\u5E8F\\u5217\\u5316\\u5176\\u5DE6\\u5B50\\u6811\\u548C\\u53F3\\u5B50\\u6811\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u8282\\u70B9\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u5219\\u8868\\u793A\\u4E3A\\u5B57\\u7B26\\u4E32 \",(0,n.jsx)(e.code,{children:'\"null\"'}),\" \\u4EE5\\u4FDD\\u7559\\u6811\\u7684\\u7ED3\\u6784\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h4,{children:\"\\u53CD\\u5E8F\\u5217\\u5316\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u5E8F\\u5217\\u5316\\u5B57\\u7B26\\u4E32\\u88AB\\u62C6\\u5206\\u6210\\u4E00\\u4E2A\\u8282\\u70B9\\u503C\\u7684\\u5217\\u8868\\u4EE5\\u8FDB\\u884C\\u904D\\u5386\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"null\"}),\" \\u503C\\u8868\\u793A\\u5206\\u652F\\u7684\\u7ED3\\u5C3E\\uFF0C\\u800C\\u5176\\u4ED6\\u503C\\u7528\\u4E8E\\u521B\\u5EFA\\u6811\\u8282\\u70B9\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u9012\\u5F52\\u5730\\uFF0C\\u53CD\\u5E8F\\u5217\\u5316\\u5DE6\\u5B50\\u6811\\u548C\\u53F3\\u5B50\\u6811\\u4EE5\\u91CD\\u5EFA\\u6811\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsx)(e.h4,{children:\"\\u5E8F\\u5217\\u5316\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u5F53\\u524D\\u8282\\u70B9\\u662F\\u5426\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\u3002\\u5982\\u679C\\u662F\\uFF0C\\u5219\\u5C06 \",(0,n.jsx)(e.code,{children:'\"null,\"'}),\" \\u9644\\u52A0\\u5230\\u5B57\\u7B26\\u4E32\\u5E76\\u8FD4\\u56DE\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5C06\\u5F53\\u524D\\u8282\\u70B9\\u7684\\u503C\\u9644\\u52A0\\u5230\\u5B57\\u7B26\\u4E32\\uFF0C\\u540E\\u8DDF\\u4E00\\u4E2A\\u9017\\u53F7\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u9012\\u5F52\\u5730\\u5E8F\\u5217\\u5316\\u5DE6\\u5B50\\u6811\\u5E76\\u5C06\\u5176\\u9644\\u52A0\\u5230\\u5B57\\u7B26\\u4E32\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u9012\\u5F52\\u5730\\u5E8F\\u5217\\u5316\\u53F3\\u5B50\\u6811\\u5E76\\u5C06\\u5176\\u9644\\u52A0\\u5230\\u5B57\\u7B26\\u4E32\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8FD4\\u56DE\\u5E8F\\u5217\\u5316\\u540E\\u7684\\u5B57\\u7B26\\u4E32\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(e.h4,{children:\"\\u53CD\\u5E8F\\u5217\\u5316\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u6309\\u9017\\u53F7\\u5206\\u5272\\u5E8F\\u5217\\u5316\\u5B57\\u7B26\\u4E32\\uFF0C\\u5F62\\u6210\\u8282\\u70B9\\u503C\\u7684\\u5217\\u8868\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u5217\\u8868\\u4E2D\\u7B2C\\u4E00\\u4E2A\\u5143\\u7D20\\u662F\\u5426\\u4E3A \",(0,n.jsx)(e.code,{children:'\"null\"'}),\"\\u3002\\u5982\\u679C\\u662F\\uFF0C\\u5219\\u5C06\\u5176\\u4ECE\\u5217\\u8868\\u4E2D\\u5220\\u9664\\u5E76\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u5217\\u8868\\u7684\\u7B2C\\u4E00\\u4E2A\\u5143\\u7D20\\u521B\\u5EFA\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\"\\uFF0C\\u5C06\\u5176\\u8F6C\\u6362\\u4E3A\\u6570\\u5B57\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u4ECE\\u5217\\u8868\\u4E2D\\u5220\\u9664\\u7B2C\\u4E00\\u4E2A\\u5143\\u7D20\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u9012\\u5F52\\u5730\\u53CD\\u5E8F\\u5217\\u5316\\u5DE6\\u5B50\\u6811\\u5E76\\u5C06\\u5176\\u5206\\u914D\\u7ED9\\u8282\\u70B9\\u7684\\u5DE6\\u5B50\\u8282\\u70B9\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u9012\\u5F52\\u5730\\u53CD\\u5E8F\\u5217\\u5316\\u53F3\\u5B50\\u6811\\u5E76\\u5C06\\u5176\\u5206\\u914D\\u7ED9\\u8282\\u70B9\\u7684\\u53F3\\u5B50\\u8282\\u70B9\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8FD4\\u56DE\\u91CD\\u5EFA\\u7684\\u6811\\u8282\\u70B9\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(c,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u5E8F\\u5217\\u5316\\u548C\\u53CD\\u5E8F\\u5217\\u5316\\u90FD\\u904D\\u5386\\u4E8C\\u53C9\\u6811\\u7684\\u6240\\u6709 \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u4E2A\\u8282\\u70B9\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002DFS \\u7684\\u9012\\u5F52\\u5806\\u6808\\u4EE5\\u53CA\\u5B58\\u50A8\\u5E8F\\u5217\\u5316\\u5B57\\u7B26\\u4E32\\u6216\\u5217\\u8868\\u6240\\u9700\\u7684\\u7A7A\\u95F4\\u968F\\u6811\\u7684\\u5927\\u5C0F\\u800C\\u6269\\u5C55\\u3002\"]}),`\n`]})]})}function L(l={}){let{wrapper:e}=l.components||{};return e?(0,n.jsx)(e,Object.assign({},l,{children:(0,n.jsx)(u,l)})):u(l)}var B=L;return x(D);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/binary-tree-subtree/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/binary-tree-subtree/locales/zh-CN.json new file mode 100644 index 000000000..60cd8e9e5 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/binary-tree-subtree/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var d=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var g=(o,e)=>()=>(e||o((e={exports:{}}).exports,e),e.exports),T=(o,e)=>{for(var r in e)d(o,r,{get:e[r],enumerable:!0})},c=(o,e,r,l)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let t of f(e))!x.call(o,t)&&t!==r&&d(o,t,{get:()=>e[t],enumerable:!(l=b(e,t))||l.enumerable});return o};var R=(o,e,r)=>(r=o!=null?p(m(o)):{},c(e||!o||!o.__esModule?d(r,\"default\",{value:o,enumerable:!0}):r,o)),N=o=>c(d({},\"__esModule\",{value:!0}),o);var h=g((D,i)=>{i.exports=_jsx_runtime});var k={};T(k,{default:()=>M,frontmatter:()=>j});var n=R(h());var s=MDXTestExamples;var u=[{input:[[\"root\",[1,2,3]],[\"subRoot\",[1,2]]],output:!1,explanation:\"SubRoot cannot be a subtree since the root node structure differs.\"},{input:[[\"root\",[12,8,6,3,5]],[\"subRoot\",[8,3,5]]],output:!0,explanation:\"The subtree rooted at node 8 matches subRoot.\"},{input:[[\"root\",[5,4,8,11,null,13,4,7,2,null,null,null,null,5,1]],[\"subRoot\",[11,7,2,5,1]]],output:!0,explanation:\"The subtree rooted at node 11 matches subRoot.\"}];var j={title:\"\\u4E8C\\u53C9\\u6811\\u5B50\\u6811\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u68C0\\u67E5\\u4E00\\u4E2A\\u4E8C\\u53C9\\u6811\\u662F\\u5426\\u662F\\u53E6\\u4E00\\u4E2A\\u4E8C\\u53C9\\u6811\\u7684\\u5B50\\u6811\"};function a(o){let e=Object.assign({p:\"p\",code:\"code\",pre:\"pre\",ol:\"ol\",li:\"li\",strong:\"strong\",h3:\"h3\",ul:\"ul\",a:\"a\"},o.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E24\\u68F5\\u4E8C\\u53C9\\u6811\\u7684\\u6839\\u8282\\u70B9 \",(0,n.jsx)(e.code,{children:\"root\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"subRoot\"}),\"\\uFF0C\\u786E\\u5B9A \",(0,n.jsx)(e.code,{children:\"subRoot\"}),\" \\u662F\\u5426\\u662F \",(0,n.jsx)(e.code,{children:\"root\"}),\" \\u7684\\u5B50\\u6811\\u3002\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"root\"}),\" \\u4E2D\\u5B58\\u5728\\u4E00\\u4E2A\\u5B50\\u6811\\uFF0C\\u5176\\u7ED3\\u6784\\u548C\\u8282\\u70B9\\u503C\\u4E0E \",(0,n.jsx)(e.code,{children:\"subRoot\"}),\" \\u76F8\\u540C\\uFF0C\\u5219\\u8BE5\\u51FD\\u6570\\u5E94\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\\u5982\\u679C\\u4E0D\\u5B58\\u5728\\u8FD9\\u6837\\u7684\\u5B50\\u6811\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E8C\\u53C9\\u6811\\u7531 \",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\" \\u7684\\u96C6\\u5408\\u8868\\u793A\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u8282\\u70B9\\u90FD\\u6709\\u53EF\\u9009\\u7684 \",(0,n.jsx)(e.code,{children:\"left\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"right\"}),\" \\u5B50\\u8282\\u70B9\\uFF0C\\u5B83\\u4EEC\\u4E5F\\u662F \",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"TreeNode\"}),\" \\u5177\\u6709\\u4EE5\\u4E0B\\u63A5\\u53E3\\uFF1A\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-ts\",children:`interface TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n}\n`})}),`\n`,(0,n.jsx)(e.p,{children:\"\\u4E8C\\u53C9\\u6811\\u7684\\u5B50\\u6811\\u5B9A\\u4E49\\u4E3A\\u6811\\u7684\\u4E00\\u90E8\\u5206\\uFF0C\\u5B83\\u7531\\u4E00\\u4E2A\\u8282\\u70B9\\u53CA\\u5176\\u6240\\u6709\\u540E\\u4EE3\\u7EC4\\u6210\\u3002\\u5B50\\u6811\\u5177\\u6709\\u4EE5\\u4E0B\\u5C5E\\u6027\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7ED3\\u6784\\u5339\\u914D\"}),\"\\uFF1A\\u4E3A\\u4E86\\u4F7F \",(0,n.jsx)(e.code,{children:\"subRoot\"}),\" \\u6210\\u4E3A \",(0,n.jsx)(e.code,{children:\"root\"}),\" \\u7684\\u5B50\\u6811\\uFF0C\",(0,n.jsx)(e.code,{children:\"subRoot\"}),\" \\u4E2D\\u7684\\u8282\\u70B9\\u5FC5\\u987B\\u4E0E \",(0,n.jsx)(e.code,{children:\"root\"}),\" \\u7684\\u76F8\\u5E94\\u90E8\\u5206\\u4E2D\\u7684\\u8282\\u70B9\\u5728\\u503C\\u548C\\u7ED3\\u6784\\u4E0A\\u5339\\u914D\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u81EA\\u5305\\u542B\"}),\"\\uFF1A\\u4E00\\u68F5\\u6811\\u59CB\\u7EC8\\u88AB\\u8BA4\\u4E3A\\u662F\\u5176\\u81EA\\u8EAB\\u7684\\u5B50\\u6811\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"root: TreeNode\"}),\"\\uFF1A\\u6811\\u7684\\u6839\\u8282\\u70B9\\u3002\\u793A\\u4F8B\\u663E\\u793A\\u6811\\u7684\",(0,n.jsx)(e.a,{href:\"https://en.wikipedia.org/wiki/Breadth-first_search\",children:\"\\u5C42\\u5E8F\\u904D\\u5386\"})]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"subRoot: TreeNode\"}),\"\\uFF1A\\u5B50\\u6811\\u7684\\u6839\\u8282\\u70B9\\u3002\\u793A\\u4F8B\\u663E\\u793A\\u6811\\u7684\",(0,n.jsx)(e.a,{href:\"https://en.wikipedia.org/wiki/Breadth-first_search\",children:\"\\u5C42\\u5E8F\\u904D\\u5386\"})]}),`\n`]}),`\n`,(0,n.jsx)(s,{testCases:u}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"1 <= \\u8282\\u70B9\\u6570 <= 100\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"-10,000 <= \",(0,n.jsx)(e.code,{children:\"TreeNode.val\"}),\" <= 10,000\"]}),`\n`]})]})}function w(o={}){let{wrapper:e}=o.components||{};return e?(0,n.jsx)(e,Object.assign({},o,{children:(0,n.jsx)(a,o)})):a(o)}var M=w;return N(k);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来检查一个二叉树是否是另一个二叉树的子树", + "title": "二叉树子树" + }, + "solution": "var Component=(()=>{var b=Object.create;var l=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var T=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty;var N=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),O=(r,e)=>{for(var o in e)l(r,o,{get:e[o],enumerable:!0})},h=(r,e,o,d)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let t of g(e))!p.call(r,t)&&t!==o&&l(r,t,{get:()=>e[t],enumerable:!(d=m(e,t))||d.enumerable});return r};var y=(r,e,o)=>(o=r!=null?b(T(r)):{},h(e||!r||!r.__esModule?l(o,\"default\",{value:r,enumerable:!0}):o,r)),R=r=>h(l({},\"__esModule\",{value:!0}),r);var s=N((v,c)=>{c.exports=_jsx_runtime});var D={};O(D,{default:()=>x});var n=y(s());var i=MDXCodeBlock;var u=`interface TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n}\n\nexport default function binaryTreeSubtree(\n root: TreeNode | null,\n subRoot: TreeNode | null,\n): boolean {\n // If 'root' is null, it means there is no tree to check against 'subRoot'\n // As per the constraints, 'subRoot' will always be non-null\n if (root === null) {\n return false;\n }\n\n // Check if the tree rooted at 'root' is identical to the tree rooted at 'subRoot'\n if (isIdentical(root, subRoot)) {\n return true;\n }\n\n // Recursively check the left and right subtrees of 'root'\n // If either subtree is identical to 'subRoot', return true\n return (\n binaryTreeSubtree(root.left, subRoot) ||\n binaryTreeSubtree(root.right, subRoot)\n );\n}\n\nfunction isIdentical(node1: TreeNode | null, node2: TreeNode | null): boolean {\n // If either of the nodes is null, they are identical only if both are null\n if (node1 === null || node2 === null) {\n return node1 === null && node2 === null;\n }\n\n // If both nodes are non-null, check:\n // 1. Their values are equal\n // 2. Their left subtrees are identical\n // 3. Their right subtrees are identical\n return (\n node1.val === node2.val &&\n isIdentical(node1.left, node2.left) &&\n isIdentical(node1.right, node2.right)\n );\n}\n`;var a=`interface TreeNode {\n val: number;\n left: TreeNode | null;\n right: TreeNode | null;\n}\n\n// Constants for hashing\nconst MOD_1 = 1000000007;\nconst MOD_2 = 2147483647;\n\n// Vector to store hashed values of each node\nlet memo: Array<[number, number]> = [];\n\nfunction hashSubtreeAtNode(\n node: TreeNode | null,\n needToAdd: boolean,\n): [number, number] {\n if (node === null) {\n return [3, 7]; // Base case for null nodes\n }\n\n // Recursively hash the left and right subtrees\n const left = hashSubtreeAtNode(node.left, needToAdd);\n const right = hashSubtreeAtNode(node.right, needToAdd);\n\n // Compute the hash values for the current node\n const left1 = (left[0] << 5) % MOD_1;\n const right1 = (right[0] << 1) % MOD_1;\n const left2 = (left[1] << 7) % MOD_2;\n const right2 = (right[1] << 1) % MOD_2;\n\n const hashpair: [number, number] = [\n (left1 + right1 + node.val) % MOD_1,\n (left2 + right2 + node.val) % MOD_2,\n ];\n\n // If \\`needToAdd\\` is true, add the hashpair to the memo array\n if (needToAdd) {\n memo.push(hashpair);\n }\n\n return hashpair;\n}\n\nexport default function binaryTreeSubtree(\n root: TreeNode | null,\n subRoot: TreeNode | null,\n): boolean {\n // Clear the memo array before starting\n memo = [];\n\n // Hash the entire tree rooted at \\`root\\` and store the hashes\n hashSubtreeAtNode(root, true);\n\n // Hash the tree rooted at \\`subRoot\\` without storing the hash\n const s = hashSubtreeAtNode(subRoot, false);\n\n // Check if the hash of \\`subRoot\\` exists in the memo array\n return memo.some((hash) => hash[0] === s[0] && hash[1] === s[1]);\n}\n`;function f(r){let e=Object.assign({h2:\"h2\",p:\"p\",h3:\"h3\",ol:\"ol\",li:\"li\",code:\"code\",ul:\"ul\",h4:\"h4\",strong:\"strong\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u9012\\u5F52\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u95EE\\u9898\\u9700\\u8981\\u786E\\u5B9A\\u4E00\\u4E2A\\u4E8C\\u53C9\\u6811\\u662F\\u5426\\u662F\\u53E6\\u4E00\\u4E2A\\u4E8C\\u53C9\\u6811\\u7684\\u5B50\\u6811\\u3002\\u5B50\\u6811\\u5FC5\\u987B\\u5728\\u7ED3\\u6784\\u548C\\u8282\\u70B9\\u503C\\u4E0A\\u4E0E\\u8F83\\u5927\\u6811\\u7684\\u4E00\\u90E8\\u5206\\u5B8C\\u5168\\u5339\\u914D\\u3002 \\u6311\\u6218\\u5728\\u4E8E\\u6709\\u6548\\u5730\\u6BD4\\u8F83\\u5B50\\u6811\\uFF0C\\u540C\\u65F6\\u907F\\u514D\\u5197\\u4F59\\u68C0\\u67E5\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u4E00\\u79CD\\u86EE\\u529B\\u89E3\\u51B3\\u65B9\\u6848\\u6D89\\u53CA\\u5C06\\u8F83\\u5927\\u6811\\u4E2D\\u7684\\u6BCF\\u4E2A\\u53EF\\u80FD\\u7684\\u5B50\\u6811\\u4E0E\\u8F83\\u5C0F\\u7684\\u6811\\u8FDB\\u884C\\u6BD4\\u8F83\\uFF0C\\u4F46\\u8FD9\\u79CD\\u65B9\\u6CD5\\u4F1A\\u5BFC\\u81F4\\u5927\\u91CF\\u4E0D\\u5FC5\\u8981\\u7684\\u5DE5\\u4F5C\\u3002 \\u4E3A\\u4E86\\u4F18\\u5316\\uFF0C\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u9012\\u5F52\\u65B9\\u6CD5\\u76F4\\u63A5\\u9A8C\\u8BC1\\u5F53\\u524D\\u5B50\\u6811\\u662F\\u5426\\u4E0E\\u7ED9\\u5B9A\\u7684\\u8F83\\u5C0F\\u6811\\u5339\\u914D\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u5176\\u76F4\\u89C9\\u57FA\\u4E8E\\u5C06\\u95EE\\u9898\\u7B80\\u5316\\u4E3A\\u66F4\\u5C0F\\u7684\\u5B50\\u95EE\\u9898\\uFF1A\\u5982\\u679C\\u5F53\\u524D\\u5B50\\u6811\\u4E0D\\u5339\\u914D\\uFF0C\\u5219\\u89E3\\u51B3\\u65B9\\u6848\\u68C0\\u67E5\\u5F53\\u524D\\u8282\\u70B9\\u7684\\u5DE6\\u5B50\\u6811\\u548C\\u53F3\\u5B50\\u6811\\u3002 \\u4E3A\\u4E86\\u786E\\u5B9A\\u4E24\\u68F5\\u6811\\u662F\\u5426\\u76F8\\u540C\\uFF0C\\u4E00\\u4E2A\\u8F85\\u52A9\\u51FD\\u6570\\u9A8C\\u8BC1\\u5B83\\u4EEC\\u7684\\u6839\\u503C\\u5E76\\u9012\\u5F52\\u5730\\u6BD4\\u8F83\\u5B83\\u4EEC\\u7684\\u5DE6\\u5B50\\u6811\\u548C\\u53F3\\u5B50\\u6811\\u3002 \\u8FD9\\u6D88\\u9664\\u4E86\\u4E0D\\u5FC5\\u8981\\u7684\\u91CD\\u590D\\u6BD4\\u8F83\\uFF0C\\u5E76\\u786E\\u4FDD\\u4E86\\u6709\\u6548\\u7684\\u5B50\\u6811\\u5339\\u914D\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5 \",(0,n.jsx)(e.code,{children:\"root\"}),\" \\u662F\\u5426\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\u3002 \\u5982\\u679C\\u662F\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\uFF0C\\u56E0\\u4E3A\\u627E\\u4E0D\\u5230\\u5B50\\u6811\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u8F85\\u52A9\\u51FD\\u6570\\u9A8C\\u8BC1\\u5F53\\u524D\\u5B50\\u6811\\u662F\\u5426\\u4E0E \",(0,n.jsx)(e.code,{children:\"subRoot\"}),\" \\u76F8\\u540C\\u3002\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u76F8\\u540C\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u9012\\u5F52\\u5730\\u68C0\\u67E5\\u5F53\\u524D\\u8282\\u70B9\\u7684\\u5DE6\\u5B50\\u6811\\u548C\\u53F3\\u5B50\\u6811\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u4EFB\\u4F55\\u9012\\u5F52\\u8C03\\u7528\\u627E\\u5230\\u5339\\u914D\\u9879\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\uFF1B\\u5426\\u5219\\uFF0C\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(i,{children:u}),`\n`,(0,n.jsxs)(e.h4,{children:[(0,n.jsx)(e.code,{children:\"isIdentical\"}),\" \\u8F85\\u52A9\\u51FD\\u6570\\uFF1A\"]}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u4EFB\\u4E00\\u6811\\u4E3A\\u7A7A\\uFF0C\\u5219\\u4EC5\\u5F53\\u4E24\\u8005\\u90FD\\u4E3A\\u7A7A\\u65F6\\u624D\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u4E24\\u68F5\\u6811\\u90FD\\u975E\\u7A7A\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u6BD4\\u8F83\\u6BCF\\u68F5\\u6811\\u6839\\u8282\\u70B9\\u7684\\u503C\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u9012\\u5F52\\u68C0\\u67E5\\u5DE6\\u5B50\\u6811\\u662F\\u5426\\u76F8\\u540C\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u9012\\u5F52\\u68C0\\u67E5\\u53F3\\u5B50\\u6811\\u662F\\u5426\\u76F8\\u540C\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4EC5\\u5F53\\u503C\\u548C\\u7ED3\\u6784\\u5B8C\\u5168\\u5339\\u914D\\u65F6\\u624D\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m.n)\"}),\"\\u3002 \\u5BF9\\u4E8E\\u8F83\\u5927\\u6811\\u4E2D\\u7684\\u6BCF\\u4E2A\\u8282\\u70B9 (O(m))\\uFF0C\\u5B50\\u6811\\u4E0E\\u8F83\\u5C0F\\u7684\\u6811 (O(n)) \\u8FDB\\u884C\\u6BD4\\u8F83\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(h)\"}),\"\\u3002 \\u7531\\u4E8E\\u9012\\u5F52\\u8C03\\u7528\\uFF0C\\u4F7F\\u7528\\u7684\\u7A7A\\u95F4\\u4E0E\\u8F83\\u5927\\u6811\\u7684\\u9AD8\\u5EA6\\u6210\\u6B63\\u6BD4\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u54C8\\u5E0C\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u95EE\\u9898\\u6D89\\u53CA\\u786E\\u5B9A\\u4E00\\u4E2A\\u4E8C\\u53C9\\u6811\\u662F\\u5426\\u662F\\u53E6\\u4E00\\u4E2A\\u4E8C\\u53C9\\u6811\\u7684\\u5B50\\u6811\\u3002 \\u8BE5\\u65B9\\u6CD5\\u6CA1\\u6709\\u91CD\\u590D\\u5730\\u76F4\\u63A5\\u6BD4\\u8F83\\u8282\\u70B9\\u548C\\u7ED3\\u6784\\uFF0C\\u800C\\u662F\\u4F7F\\u7528\\u54C8\\u5E0C\\u6765\\u5C06\\u5B50\\u6811\\u8868\\u793A\\u4E3A\\u7D27\\u51D1\\u7684\\u54C8\\u5E0C\\u503C\\u3002 \\u8FD9\\u901A\\u8FC7\\u4F7F\\u7528\\u54C8\\u5E0C\\u51FD\\u6570\\u7684\\u5C5E\\u6027\\u6765\\u6709\\u6548\\u5730\\u68C0\\u6D4B\\u5B50\\u6811\\u5339\\u914D\\uFF0C\\u4ECE\\u800C\\u6D88\\u9664\\u4E86\\u5197\\u4F59\\u7684\\u7ED3\\u6784\\u6BD4\\u8F83\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u76F4\\u89C9\\u662F\\u4E3A\\u8F83\\u5927\\u6811\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5B50\\u6811\\u8BA1\\u7B97\\u552F\\u4E00\\u7684\\u54C8\\u5E0C\\u503C\\uFF0C\\u5E76\\u5C06\\u5B83\\u4EEC\\u4E0E\\u8F83\\u5C0F\\u6811\\u7684\\u54C8\\u5E0C\\u503C\\u8FDB\\u884C\\u6BD4\\u8F83\\u3002 \\u5B50\\u6811\\u54C8\\u5E0C\\u53D6\\u51B3\\u4E8E\\u8282\\u70B9\\u503C\\u53CA\\u5176\\u5DE6\\u53F3\\u5B50\\u8282\\u70B9\\u7684\\u54C8\\u5E0C\\u503C\\uFF0C\\u786E\\u4FDD\\u4E0D\\u540C\\u5B50\\u6811\\u7ED3\\u6784\\u7684\\u552F\\u4E00\\u6027\\u3002 \\u901A\\u8FC7\\u5C06\\u6240\\u6709\\u5B50\\u6811\\u54C8\\u5E0C\\u5B58\\u50A8\\u5728\\u96C6\\u5408\\u4E2D\\uFF0C\\u53EF\\u4EE5\\u5728\\u6BCF\\u6B21\\u54C8\\u5E0C\\u6BD4\\u8F83\\u4E2D\\u4EE5\\u6052\\u5B9A\\u7684\\u65F6\\u95F4\\u68C0\\u67E5\\u8F83\\u5C0F\\u6811\\u662F\\u5426\\u5B58\\u5728\\u4F5C\\u4E3A\\u5B50\\u6811\\u3002 \\u8FD9\\u907F\\u514D\\u4E86\\u91CD\\u590D\\u7684\\u7ED3\\u6784\\u68C0\\u67E5\\u5E76\\u63D0\\u9AD8\\u4E86\\u6548\\u7387\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u8F85\\u52A9\\u51FD\\u6570 \",(0,n.jsx)(e.code,{children:\"hashSubtreeAtNode\"}),\"\\uFF0C\\u7528\\u4E8E\\u8BA1\\u7B97\\u4EE5\\u7ED9\\u5B9A\\u8282\\u70B9\\u4E3A\\u6839\\u7684\\u5B50\\u6811\\u7684\\u54C8\\u5E0C\\u503C\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E \",(0,n.jsx)(e.code,{children:\"null\"}),\" \\u8282\\u70B9\\uFF0C\\u8FD4\\u56DE\\u9884\\u5B9A\\u4E49\\u7684\\u57FA\\u54C8\\u5E0C\\u503C\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u9012\\u5F52\\u8BA1\\u7B97\\u5DE6\\u5B50\\u6811\\u548C\\u53F3\\u5B50\\u6811\\u7684\\u54C8\\u5E0C\\u503C\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u4F7F\\u7528\\u5F53\\u524D\\u8282\\u70B9\\u7684\\u503C\\u53CA\\u5176\\u5B50\\u8282\\u70B9\\u7684\\u54C8\\u5E0C\\u503C\\u8BA1\\u7B97\\u5F53\\u524D\\u8282\\u70B9\\u7684\\u54C8\\u5E0C\\u503C\\uFF0C\\u5E94\\u7528\\u6A21\\u8FD0\\u7B97\\u4EE5\\u9632\\u6B62\\u6EA2\\u51FA\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u9700\\u8981\\uFF0C\\u5C06\\u54C8\\u5E0C\\u503C\\u5B58\\u50A8\\u5728\\u5168\\u5C40\\u96C6\\u5408\\u4E2D\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u7A7A\\u96C6\\u5408 \",(0,n.jsx)(e.code,{children:\"memo\"}),\" \\u4EE5\\u5B58\\u50A8\\u8F83\\u5927\\u6811\\u4E2D\\u6240\\u6709\\u5B50\\u6811\\u7684\\u54C8\\u5E0C\\u503C\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8BA1\\u7B97\\u6574\\u4E2A\\u8F83\\u5927\\u6811\\u7684\\u54C8\\u5E0C\\u503C\\uFF0C\\u5C06\\u6BCF\\u4E2A\\u5B50\\u6811\\u7684\\u54C8\\u5E0C\\u503C\\u5B58\\u50A8\\u5728 \",(0,n.jsx)(e.code,{children:\"memo\"}),\" \\u4E2D\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8BA1\\u7B97\\u8F83\\u5C0F\\u6811\\u7684\\u54C8\\u5E0C\\u503C\\uFF0C\\u800C\\u4E0D\\u5C06\\u5176\\u6DFB\\u52A0\\u5230\\u96C6\\u5408\\u4E2D\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u8F83\\u5C0F\\u6811\\u7684\\u8BA1\\u7B97\\u54C8\\u5E0C\\u503C\\u662F\\u5426\\u5B58\\u5728\\u4E8E \",(0,n.jsx)(e.code,{children:\"memo\"}),\" \\u96C6\\u5408\\u4E2D\\u3002 \\u5982\\u679C\\u627E\\u5230\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\uFF1B\\u5426\\u5219\\uFF0C\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(i,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n + m)\"}),\"\\u3002 \\u8F83\\u5927\\u6811\\u6709 \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u4E2A\\u8282\\u70B9\\uFF0C\\u8F83\\u5C0F\\u6811\\u6709 \",(0,n.jsx)(e.code,{children:\"m\"}),\" \\u4E2A\\u8282\\u70B9\\uFF0C\\u5728\\u54C8\\u5E0C\\u671F\\u95F4\\u5206\\u522B\\u904D\\u5386\\u4E00\\u6B21\\uFF0C\\u5BFC\\u81F4\\u603B\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(n + m)\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002 \\u8F83\\u5927\\u6811\\u4E2D\\u6240\\u6709 \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u4E2A\\u8282\\u70B9\\u7684\\u54C8\\u5E0C\\u503C\\u90FD\\u5B58\\u50A8\\u5728 \",(0,n.jsx)(e.code,{children:\"memo\"}),\" \\u96C6\\u5408\\u4E2D\\u3002\"]}),`\n`]})]})}function M(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(f,r)})):f(r)}var x=M;return R(D);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/binary-tree/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/binary-tree/locales/zh-CN.json new file mode 100644 index 000000000..2cd17be26 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/binary-tree/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var a=Object.create;var d=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var O=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var g=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),x=(r,e)=>{for(var c in e)d(r,c,{get:e[c],enumerable:!0})},t=(r,e,c,l)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of p(e))!m.call(r,i)&&i!==c&&d(r,i,{get:()=>e[i],enumerable:!(l=u(e,i))||l.enumerable});return r};var B=(r,e,c)=>(c=r!=null?a(O(r)):{},t(e||!r||!r.__esModule?d(c,\"default\",{value:r,enumerable:!0}):c,r)),j=r=>t(d({},\"__esModule\",{value:!0}),r);var h=g((b,o)=>{o.exports=_jsx_runtime});var _={};x(_,{default:()=>T,frontmatter:()=>y});var n=B(h()),y={title:\"\\u4E8C\\u53C9\\u6811\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u4E8C\\u53C9\\u6811\\u6570\\u636E\\u7ED3\\u6784\\uFF0C\\u5305\\u62EC\\u57FA\\u672C\\u64CD\\u4F5C\"};function s(r){let e=Object.assign({p:\"p\",ul:\"ul\",li:\"li\",code:\"code\",blockquote:\"blockquote\",h2:\"h2\",pre:\"pre\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.p,{children:\"\\u4F7F\\u7528\\u4EE5\\u4E0B\\u64CD\\u4F5C\\u5B9E\\u73B0\\u4E8C\\u53C9\\u6811\\u6570\\u636E\\u7ED3\\u6784\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"new BinaryTree()\"}),\"\\uFF1A\\u521B\\u5EFA\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"BinaryTree\"}),\" \\u5B9E\\u4F8B\\u3002\\u6839\\u8282\\u70B9\\u521D\\u59CB\\u5316\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u8868\\u793A\\u6811\\u5F00\\u59CB\\u4E3A\\u7A7A\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"size()\"}),\"\\uFF1A\\u8FD4\\u56DE\\u6811\\u4E2D\\u8282\\u70B9\\u7684\\u6570\\u91CF\\u3002\\u6240\\u9700\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\\uFF0C\\u5176\\u4E2D n \\u662F\\u6811\\u4E2D\\u8282\\u70B9\\u7684\\u6570\\u91CF\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"height()\"}),\"\\uFF1A\\u8FD4\\u56DE\\u6811\\u7684\\u9AD8\\u5EA6\\uFF0C\\u5B9A\\u4E49\\u4E3A\\u4ECE\\u6839\\u5230\\u53F6\\u5B50\\u7684\\u6700\\u957F\\u8DEF\\u5F84\\u4E0A\\u7684\\u8FB9\\u6570\\u3002\\u7A7A\\u6811\\u7684\\u9AD8\\u5EA6\\u4E3A 0\\u3002\\u6240\\u9700\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"inOrder()\"}),\"\\uFF1A\\u8FD4\\u56DE\\u4E00\\u4E2A\\u6309\\u4E2D\\u5E8F\\u904D\\u5386\\u7684\\u503C\\u7684\\u6570\\u7EC4\\u3002\\u6240\\u9700\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"preOrder()\"}),\"\\uFF1A\\u8FD4\\u56DE\\u4E00\\u4E2A\\u6309\\u524D\\u5E8F\\u904D\\u5386\\u7684\\u503C\\u7684\\u6570\\u7EC4\\u3002\\u6240\\u9700\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"postOrder()\"}),\"\\uFF1A\\u8FD4\\u56DE\\u4E00\\u4E2A\\u6309\\u540E\\u5E8F\\u904D\\u5386\\u7684\\u503C\\u7684\\u6570\\u7EC4\\u3002\\u6240\\u9700\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"isBalanced()\"}),\"\\uFF1A\\u5982\\u679C\\u6811\\u662F\\u5E73\\u8861\\u7684\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\\u5982\\u679C\\u5BF9\\u4E8E\\u6811\\u4E2D\\u7684\\u6BCF\\u4E2A\\u8282\\u70B9\\uFF0C\\u5176\\u5DE6\\u5B50\\u6811\\u548C\\u53F3\\u5B50\\u6811\\u7684\\u9AD8\\u5EA6\\u5DEE\\u6700\\u591A\\u4E3A 1\\uFF0C\\u5219\\u4E8C\\u53C9\\u6811\\u662F\\u5E73\\u8861\\u7684\\u3002\\u6240\\u9700\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"isComplete()\"}),\"\\uFF1A\\u5982\\u679C\\u6811\\u662F\\u5B8C\\u5168\\u7684\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\\u5982\\u679C\\u6240\\u6709\\u5C42\\u90FD\\u5DF2\\u5B8C\\u5168\\u586B\\u5145\\uFF0C\\u9664\\u4E86\\u6700\\u540E\\u4E00\\u5C42\\uFF0C\\u6700\\u540E\\u4E00\\u5C42\\u5FC5\\u987B\\u4ECE\\u5DE6\\u5230\\u53F3\\u586B\\u5145\\uFF0C\\u5219\\u4E8C\\u53C9\\u6811\\u662F\\u5B8C\\u5168\\u7684\\u3002\\u6240\\u9700\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\\u3002\"]}),`\n`]}),`\n`,(0,n.jsxs)(e.blockquote,{children:[`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4F7F\\u7528\\u8F85\\u52A9\\u7C7B \",(0,n.jsx)(e.code,{children:\"BinaryTreeNode\"}),\" \\u6765\\u8868\\u793A\\u8282\\u70B9\\uFF0C\\u5177\\u6709 \",(0,n.jsx)(e.code,{children:\"value\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"left\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"right\"}),\" \\u5C5E\\u6027\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"\\u4F8B\\u5B50\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`const tree = new BinaryTree();\ntree.root = new BinaryTreeNode(10);\ntree.root.left = new BinaryTreeNode(5);\ntree.root.right = new BinaryTreeNode(15);\n\ntree.size(); // 3\ntree.height(); // 1\ntree.inOrder(); // [5, 10, 15]\ntree.preOrder(); // [10, 5, 15]\ntree.postOrder(); // [5, 15, 10]\ntree.isBalanced(); // true\ntree.isComplete(); // true\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"0 <= \\u8282\\u70B9\\u6570 <= 100\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u4E8C\\u53C9\\u6811\\u4E2D\\u7684\\u6BCF\\u4E2A\\u8282\\u70B9\\u6700\\u591A\\u6709\\u4E00\\u4E2A\\u5DE6\\u5B50\\u8282\\u70B9\\u548C\\u4E00\\u4E2A\\u53F3\\u5B50\\u8282\\u70B9\"}),`\n`]})]})}function f(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(s,r)})):s(r)}var T=f;return j(_);})();\n;return Component;", + "info": { + "excerpt": "实现一个二叉树数据结构,包括基本操作", + "title": "二叉树" + }, + "solution": "var Component=(()=>{var f=Object.create;var t=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var T=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var v=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),m=(n,e)=>{for(var l in e)t(n,l,{get:e[l],enumerable:!0})},d=(n,e,l,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of H(e))!y.call(n,i)&&i!==l&&t(n,i,{get:()=>e[i],enumerable:!(o=g(e,i))||o.enumerable});return n};var O=(n,e,l)=>(l=n!=null?f(T(n)):{},d(e||!n||!n.__esModule?t(l,\"default\",{value:n,enumerable:!0}):l,n)),b=n=>d(t({},\"__esModule\",{value:!0}),n);var c=v((w,h)=>{h.exports=_jsx_runtime});var z={};m(z,{default:()=>A});var r=O(c());var a=MDXCodeBlock;var s=`export class BinaryTreeNode {\n constructor(value) {\n this.value = value;\n this.left = null;\n this.right = null;\n }\n}\n\nexport class BinaryTree {\n /**\n * Initialize the Binary Tree.\n * @param {*} value The value of the root node.\n */\n constructor(value) {\n this.root = value == null ? null : new BinaryTreeNode(value);\n }\n\n /**\n * Get the number of nodes in the tree.\n * @return {number} The number of nodes in the tree.\n */\n size() {\n const sizeHelper = (node) => {\n if (!node) {\n return 0;\n }\n return 1 + sizeHelper(node.left) + sizeHelper(node.right);\n };\n return this.root ? sizeHelper(this.root) : 0;\n }\n\n /**\n * Get the height of the tree.\n * @return {number} The height of the tree.\n */\n height() {\n const heightHelper = (node) => {\n if (!node) {\n return -1;\n }\n return 1 + Math.max(heightHelper(node.left), heightHelper(node.right));\n };\n return this.root ? heightHelper(this.root) : 0;\n }\n\n /**\n * Traverse the tree in an in-order fashion.\n * @return {Array<*>} An array of values of the nodes in in-order traversal.\n */\n inOrder() {\n const arr = [];\n const inOrderHelper = (node) => {\n if (node == null) {\n return;\n }\n\n inOrderHelper(node.left);\n arr.push(node.value);\n inOrderHelper(node.right);\n };\n inOrderHelper(this.root);\n return arr;\n }\n\n /**\n * Traverse the tree in a pre-order fashion.\n * @return {Array<*>} An array of values of the nodes in pre-order traversal.\n */\n preOrder() {\n const arr = [];\n const preOrderHelper = (node) => {\n if (!node) {\n return;\n }\n\n arr.push(node.value);\n preOrderHelper(node.left);\n preOrderHelper(node.right);\n };\n preOrderHelper(this.root);\n return arr;\n }\n\n /**\n * Traverse the tree in a post-order fashion.\n * @return {Array<*>} An array of values of the nodes in post-order traversal.\n */\n postOrder() {\n const arr = [];\n const postOrderHelper = (node) => {\n if (!node) {\n return;\n }\n\n postOrderHelper(node.left);\n postOrderHelper(node.right);\n arr.push(node.value);\n };\n postOrderHelper(this.root);\n return arr;\n }\n\n /**\n * Checks if the binary tree is balanced, i.e. depth of the two subtrees of\n * every node never differ by more than 1.\n * @return {boolean}\n */\n isBalanced() {\n const isBalancedHelper = (node) => {\n if (!node) {\n return 0;\n }\n\n const leftHeight = isBalancedHelper(node.left);\n const rightHeight = isBalancedHelper(node.right);\n\n if (\n leftHeight === -1 ||\n rightHeight === -1 ||\n Math.abs(leftHeight - rightHeight) > 1\n ) {\n return -1;\n }\n\n return 1 + Math.max(leftHeight, rightHeight);\n };\n return isBalancedHelper(this.root) !== -1;\n }\n\n /**\n * Checks if the binary tree is complete, i.e., all levels are completely filled except possibly the last level,\n * which is filled from left to right.\n * @return {boolean} True if the binary tree is complete, false otherwise.\n */\n isComplete() {\n if (!this.root) return true;\n\n const queue = [this.root];\n let foundNull = false;\n\n while (queue.length > 0) {\n const node = queue.shift();\n\n if (node === null) {\n foundNull = true;\n } else {\n if (foundNull) {\n return false; // Found a non-null node after a null one\n }\n queue.push(node.left);\n queue.push(node.right);\n }\n }\n\n return true;\n }\n}\n`;var u=`export class BinaryTreeNode {\n public value: T;\n public left: BinaryTreeNode | null;\n public right: BinaryTreeNode | null;\n\n constructor(value: T) {\n this.value = value;\n this.left = null;\n this.right = null;\n }\n}\n\nexport class BinaryTree {\n public root: BinaryTreeNode | null;\n\n /**\n * Initialize the Binary Tree.\n * @param {T} value The value of the root node.\n */\n constructor(value?: T) {\n this.root = value == null ? null : new BinaryTreeNode(value);\n }\n\n /**\n * Get the number of nodes in the tree.\n * @return {number} The number of nodes in the tree.\n */\n size(): number {\n const sizeHelper = (node: BinaryTreeNode | null): number => {\n if (!node) {\n return 0;\n }\n return 1 + sizeHelper(node.left) + sizeHelper(node.right);\n };\n return this.root ? sizeHelper(this.root) : 0;\n }\n\n /**\n * Get the height of the tree.\n * @return {number} The height of the tree.\n */\n height(): number {\n const heightHelper = (node: BinaryTreeNode | null): number => {\n if (!node) {\n return -1;\n }\n return 1 + Math.max(heightHelper(node.left), heightHelper(node.right));\n };\n return this.root ? heightHelper(this.root) : 0;\n }\n\n /**\n * Traverse the tree in an in-order fashion.\n * @return {Array} An array of values of the nodes in in-order traversal.\n */\n inOrder(): Array {\n const arr: Array = [];\n const inOrderHelper = (node: BinaryTreeNode | null) => {\n if (node == null) {\n return;\n }\n\n inOrderHelper(node.left);\n arr.push(node.value);\n inOrderHelper(node.right);\n };\n inOrderHelper(this.root);\n return arr;\n }\n\n /**\n * Traverse the tree in a pre-order fashion.\n * @return {Array} An array of values of the nodes in pre-order traversal.\n */\n preOrder(): Array {\n const arr: Array = [];\n const preOrderHelper = (node: BinaryTreeNode | null) => {\n if (!node) {\n return;\n }\n\n arr.push(node.value);\n preOrderHelper(node.left);\n preOrderHelper(node.right);\n };\n preOrderHelper(this.root);\n return arr;\n }\n\n /**\n * Traverse the tree in a post-order fashion.\n * @return {Array} An array of values of the nodes in post-order traversal.\n */\n postOrder(): Array {\n const arr: Array = [];\n const postOrderHelper = (node: BinaryTreeNode | null) => {\n if (!node) {\n return;\n }\n\n postOrderHelper(node.left);\n postOrderHelper(node.right);\n arr.push(node.value);\n };\n postOrderHelper(this.root);\n return arr;\n }\n\n /**\n * Checks if the binary tree is balanced, i.e. depth of the two subtrees of\n * every node never differ by more than 1.\n * @return {boolean}\n */\n isBalanced(): boolean {\n const isBalancedHelper = (node: BinaryTreeNode | null): number => {\n if (!node) {\n return 0;\n }\n\n const leftHeight = isBalancedHelper(node.left);\n const rightHeight = isBalancedHelper(node.right);\n\n if (\n leftHeight === -1 ||\n rightHeight === -1 ||\n Math.abs(leftHeight - rightHeight) > 1\n ) {\n return -1;\n }\n\n return 1 + Math.max(leftHeight, rightHeight);\n };\n return isBalancedHelper(this.root) !== -1;\n }\n\n /**\n * Checks if the binary tree is complete, i.e., all levels are completely filled except possibly the last level,\n * which is filled from left to right.\n * @return {boolean} True if the binary tree is complete, false otherwise.\n */\n isComplete(): boolean {\n if (!this.root) return true;\n\n const queue: Array | null> = [this.root];\n let foundNull = false;\n\n while (queue.length > 0) {\n const node = queue.shift();\n\n if (node === undefined || node === null) {\n foundNull = true;\n } else {\n if (foundNull) {\n return false; // A non-null node appeared after a null one\n }\n queue.push(node.left);\n queue.push(node.right);\n }\n }\n\n return true;\n }\n}\n`;function p(n){let e=Object.assign({p:\"p\",code:\"code\",ul:\"ul\",li:\"li\",strong:\"strong\",h3:\"h3\",ol:\"ol\",h2:\"h2\"},n.components);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(e.p,{children:[\"\\u4E8C\\u53C9\\u6811\\u662F\\u4E00\\u79CD\\u5206\\u5C42\\u6570\\u636E\\u7ED3\\u6784\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u8282\\u70B9\\u6700\\u591A\\u6709\\u4E24\\u4E2A\\u5B50\\u8282\\u70B9\\uFF1A\",(0,r.jsx)(e.code,{children:\"left\"}),\"\\u5B50\\u8282\\u70B9\\u548C\",(0,r.jsx)(e.code,{children:\"right\"}),\"\\u5B50\\u8282\\u70B9\\u3002\\u8BE5\\u7ED3\\u6784\\u7531\\u5B58\\u50A8\",(0,r.jsx)(e.code,{children:\"value\"}),\"\\u548C\\u5BF9\\u5176\\u5B50\\u8282\\u70B9\\u7684\\u5F15\\u7528\\u7684\\u8282\\u70B9\\u7EC4\\u6210\\u3002\\u6700\\u9876\\u5C42\\u7684\\u8282\\u70B9\\u79F0\\u4E3A\",(0,r.jsx)(e.code,{children:\"root\"}),\"\\u3002\"]}),`\n`,(0,r.jsxs)(e.p,{children:[\"\\u6B64\\u5B9E\\u73B0\\u5C06\\u4E8C\\u53C9\\u6811\\u7ED3\\u6784\\uFF08\",(0,r.jsx)(e.code,{children:\"BinaryTree\"}),\"\\uFF09\\u4E0E\\u5176\\u5404\\u4E2A\\u8282\\u70B9\\uFF08\",(0,r.jsx)(e.code,{children:\"BinaryTreeNode\"}),\"\\uFF09\\u5206\\u5F00\\u3002\\u6BCF\\u4E2A\\u8282\\u70B9\\u5305\\u542B\\u4E00\\u4E2A\",(0,r.jsx)(e.code,{children:\"value\"}),\"\\uFF0C\\u4EE5\\u53CA\\u6307\\u5411\\u5176\",(0,r.jsx)(e.code,{children:\"left\"}),\"\\u548C\",(0,r.jsx)(e.code,{children:\"right\"}),\"\\u5B50\\u8282\\u70B9\\u7684\\u6307\\u9488\\u3002\"]}),`\n`,(0,r.jsx)(e.p,{children:\"\\u6838\\u5FC3\\u64CD\\u4F5C\\u53EF\\u4EE5\\u4F7F\\u7528\\u9012\\u5F52\\u65B9\\u6CD5\\u5B9E\\u73B0\\uFF0C\\u8FD9\\u5BF9\\u4E8E\\u4E8C\\u53C9\\u6811\\u6765\\u8BF4\\u662F\\u81EA\\u7136\\u4E14\\u9AD8\\u6548\\u7684\\uFF0C\\u56E0\\u4E3A\\u6BCF\\u4E2A\\u5B50\\u6811\\u672C\\u8EAB\\u5C31\\u662F\\u4E00\\u68F5\\u4E8C\\u53C9\\u6811\\uFF1A\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u904D\\u5386\\u65B9\\u6CD5\"}),\"\\uFF08\",(0,r.jsx)(e.code,{children:\"inOrder\"}),\"\\u3001\",(0,r.jsx)(e.code,{children:\"preOrder\"}),\"\\u3001\",(0,r.jsx)(e.code,{children:\"postOrder\"}),\"\\uFF09\\u4F7F\\u7528\\u7B80\\u5355\\u7684\\u6DF1\\u5EA6\\u4F18\\u5148\\u9012\\u5F52\\u4EE5\\u6B63\\u786E\\u7684\\u987A\\u5E8F\\u8BBF\\u95EE\\u8282\\u70B9\\uFF0C\\u5E76\\u5C06\\u5176\\u503C\\u6536\\u96C6\\u5230\\u4E00\\u4E2A\\u6570\\u7EC4\\u4E2D\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"size()\"}),\"\\u548C\",(0,r.jsx)(e.code,{children:\"height()\"}),\"\\u901A\\u8FC7\\u8BBF\\u95EE\\u6BCF\\u4E2A\\u8282\\u70B9\\u4E00\\u6B21\\u6765\\u9012\\u5F52\\u8BA1\\u7B97\\uFF0C\\u7ED3\\u5408\\u5DE6\\u53F3\\u5B50\\u8282\\u70B9\\u7684\\u7ED3\\u679C\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"isBalanced()\"}),\"\\u4F7F\\u7528\\u9012\\u5F52\\u65B9\\u6CD5\\u4ECE\\u5E95\\u90E8\\u5411\\u4E0A\\u904D\\u5386\\u6811\\uFF0C\\u68C0\\u67E5\\u6BCF\\u4E2A\\u5B50\\u6811\\u662F\\u5426\\u5E73\\u8861\\u3002\\u5728\\u6267\\u884C\\u6B64\\u64CD\\u4F5C\\u65F6\\uFF0C\\u5B83\\u8FD8\\u4F1A\\u8BA1\\u7B97\\u6BCF\\u4E2A\\u8282\\u70B9\\u7684\\u9AD8\\u5EA6\\u3002\\u5982\\u679C\\u5B83\\u53D1\\u73B0\\u4E00\\u4E2A\\u5B50\\u6811\\u7684\\u9AD8\\u5EA6\\u5DEE > 1\\uFF0C\\u5B83\\u4F1A\\u7ACB\\u5373\\u8FD4\\u56DE -1\\uFF0C\\u8FD9\\u4F1A\\u5192\\u6CE1\\u5E76\\u505C\\u6B62\\u8FDB\\u4E00\\u6B65\\u7684\\u68C0\\u67E5\\uFF0C\\u4F7F\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4FDD\\u6301\\u5728 O(n)\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"isComplete()\"}),\"\\u4F7F\\u7528\\u5C42\\u5E8F\\u904D\\u5386\\uFF08BFS\\uFF09\\u6765\\u786E\\u4FDD\\u6240\\u6709\\u5C42\\u90FD\\u5DF2\\u5B8C\\u5168\\u586B\\u5145\\uFF0C\\u5E76\\u4E14\\u6700\\u540E\\u4E00\\u5C42\\u4ECE\\u5DE6\\u5230\\u53F3\\u586B\\u5145\\uFF0C\\u6CA1\\u6709\\u95F4\\u9699\\u3002\"]}),`\n`]}),`\n`,(0,r.jsx)(a,{languages:{jsx:s,tsx:u}}),`\n`,(0,r.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,r.jsxs)(e.ol,{children:[`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"new BinaryTree(value)\"}),\":\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u68F5\\u6811\\u3002\\u5982\\u679C\\u4F20\\u9012\\u4E86\",(0,r.jsx)(e.code,{children:\"value\"}),\"\\uFF0C\\u5219\\u5C06\\u6839\\u8BBE\\u7F6E\\u4E3A\\u5177\\u6709\\u8BE5\\u503C\\u7684\\u65B0\\u7684\",(0,r.jsx)(e.code,{children:\"BinaryTreeNode\"}),\"\\u3002\\u5982\\u679C\\u6CA1\\u6709\\uFF0C\\u5219\\u6839\\u4E3A\",(0,r.jsx)(e.code,{children:\"null\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"size()\"}),\":\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u57FA\\u672C\\u60C5\\u51B5\\uFF1A\\u5982\\u679C\",(0,r.jsx)(e.code,{children:\"node\"}),\"\\u4E3A\",(0,r.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u5219\\u8FD4\\u56DE 0\\u3002\"]}),`\n`,(0,r.jsx)(e.li,{children:\"\\u9012\\u5F52\\u60C5\\u51B5\\uFF1A1 + \\u5DE6\\u5B50\\u6811\\u7684\\u5927\\u5C0F + \\u53F3\\u5B50\\u6811\\u7684\\u5927\\u5C0F\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"height()\"}),\":\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u57FA\\u672C\\u60C5\\u51B5\\uFF1A\\u5982\\u679C\",(0,r.jsx)(e.code,{children:\"node\"}),\"\\u4E3A\",(0,r.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u5219\\u8FD4\\u56DE -1\\u3002\"]}),`\n`,(0,r.jsx)(e.li,{children:\"\\u9012\\u5F52\\u60C5\\u51B5\\uFF1A1 + max(\\u5DE6\\u5B50\\u6811\\u7684\\u9AD8\\u5EA6\\uFF0C\\u53F3\\u5B50\\u6811\\u7684\\u9AD8\\u5EA6)\\u3002\"}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u7A7A\\u6811\\uFF0C\",(0,r.jsx)(e.code,{children:\"height()\"}),\"\\u8FD4\\u56DE 0\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u65B9\\u6CD5\\uFF08\",(0,r.jsx)(e.code,{children:\"inOrder()\"}),\"\\u3001\",(0,r.jsx)(e.code,{children:\"preOrder()\"}),\"\\u3001\",(0,r.jsx)(e.code,{children:\"postOrder()\"}),\"):\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u8FD9\\u4E9B\\u65B9\\u6CD5\\u6839\\u636E\\u4E0D\\u540C\\u7684\\u904D\\u5386\\u987A\\u5E8F\\u8FD4\\u56DE\\u8282\\u70B9\\u503C\\u7684\\u6570\\u7EC4\\uFF1A\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"\\u4E2D\\u5E8F\\u904D\\u5386\\uFF08\\u5DE6 \\u2192 \\u6839 \\u2192 \\u53F3\\uFF09\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u524D\\u5E8F\\u904D\\u5386\\uFF08\\u6839 \\u2192 \\u5DE6 \\u2192 \\u53F3\\uFF09\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u540E\\u5E8F\\u904D\\u5386\\uFF08\\u5DE6 \\u2192 \\u53F3 \\u2192 \\u6839\\uFF09\"}),`\n`]}),`\n`]}),`\n`,(0,r.jsx)(e.li,{children:\"\\u6BCF\\u79CD\\u65B9\\u6CD5\\u90FD\\u4F7F\\u7528\\u4E00\\u4E2A\\u9012\\u5F52\\u52A9\\u624B\\uFF0C\\u8BE5\\u52A9\\u624B\\u4F7F\\u7528 DFS \\u4ECE\\u6839\\u904D\\u5386\\u6811\\uFF0C\\u5E76\\u6309\\u6307\\u5B9A\\u7684\\u987A\\u5E8F\\u8BBF\\u95EE\\u5B50\\u8282\\u70B9\\u3002\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u5728\\u9012\\u5F52\\u8C03\\u7528\\u671F\\u95F4\\u6784\\u5EFA\\u4E00\\u4E2A\\u4E34\\u65F6\\u6570\\u7EC4\\uFF0C\\u4EE5\\u6309\\u6B63\\u786E\\u7684\\u987A\\u5E8F\\u6536\\u96C6\\u503C\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"isBalanced()\"}),\":\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"\\u9012\\u5F52\\u52A9\\u624B\\u8FD4\\u56DE\\u9AD8\\u5EA6\\uFF08\\u5982\\u679C\\u5B50\\u6811\\u5E73\\u8861\\uFF09\\uFF0C\\u6216\\u8005\\u5982\\u679C\\u672A\\u5E73\\u8861\\u5219\\u8FD4\\u56DE -1\\u3002\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u4E3B\\u65B9\\u6CD5\\u68C0\\u67E5\\u7ED3\\u679C\\u662F\\u5426\\u4E0D\\u4E3A -1\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"isComplete()\"}),\":\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"\\u4F7F\\u7528 BFS\\uFF08\\u5C42\\u5E8F\\u904D\\u5386\\uFF09\\u4E0E\\u961F\\u5217\\u3002\"}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5F53\\u8282\\u70B9\\u51FA\\u961F\\u65F6\\uFF0C\\u5982\\u679C\\u627E\\u5230\",(0,r.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u5219\\u6240\\u6709\\u540E\\u7EED\\u8282\\u70B9\\u4E5F\\u5FC5\\u987B\\u4E3A\",(0,r.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u624D\\u80FD\\u8BA4\\u4E3A\\u6811\\u662F\\u5B8C\\u6574\\u7684\\u3002\\u5982\\u679C\\u5728 null \\u4E4B\\u540E\\u51FA\\u73B0\\u4EFB\\u4F55\\u975E null \\u8282\\u70B9\\uFF0C\\u5219\\u6811\\u4E0D\\u5B8C\\u6574\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,r.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,r.jsxs)(e.p,{children:[\"\\u8BBE\",(0,r.jsx)(e.code,{children:\"n\"}),\"\\u4E3A\\u8282\\u70B9\\u7684\\u6570\\u91CF\\uFF0C\",(0,r.jsx)(e.code,{children:\"h\"}),\"\\u4E3A\\u6811\\u7684\\u9AD8\\u5EA6\\u3002\"]}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\"}),\"\\uFF1A\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"size()\"}),\"\\u3001\",(0,r.jsx)(e.code,{children:\"height()\"}),\"\\u3001\",(0,r.jsx)(e.code,{children:\"inOrder()\"}),\"\\u3001\",(0,r.jsx)(e.code,{children:\"preOrder()\"}),\"\\u3001\",(0,r.jsx)(e.code,{children:\"postOrder()\"}),\"\\u3001\",(0,r.jsx)(e.code,{children:\"isBalanced()\"}),\"\\u3001\",(0,r.jsx)(e.code,{children:\"isComplete()\"}),\"\\uFF1AO(n)\\u3002\\u6BCF\\u4E2A\\u8282\\u70B9\\u8BBF\\u95EE\\u4E00\\u6B21\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\"}),\"\\uFF1A\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u9012\\u5F52\\u65B9\\u6CD5\\uFF08\",(0,r.jsx)(e.code,{children:\"size()\"}),\"\\u3001\",(0,r.jsx)(e.code,{children:\"height()\"}),\"\\u3001\\u904D\\u5386\\u3001\",(0,r.jsx)(e.code,{children:\"isBalanced()\"}),\"\\uFF09\\uFF1AO(h) \\u7531\\u4E8E\\u8C03\\u7528\\u5806\\u6808\\u3002\\u5728\\u6700\\u574F\\u7684\\u60C5\\u51B5\\u4E0B\\uFF08\\u503E\\u659C\\u6811\\uFF09\\uFF0Ch = O(n)\\u3002\\u5728\\u5E73\\u8861\\u6811\\u4E2D\\uFF0Ch = O(log n)\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"isComplete()\"}),\"\\uFF1A\\u5728\\u6700\\u574F\\u7684\\u60C5\\u51B5\\u4E0B\\u4E3A O(n)\\uFF0C\\u56E0\\u4E3A BFS \\u961F\\u5217\\u5728\\u5B8C\\u6574\\u6811\\u7684\\u6700\\u540E\\u4E00\\u5C42\\u6700\\u591A\\u53EF\\u4EE5\\u5BB9\\u7EB3 n/2 \\u4E2A\\u8282\\u70B9\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,r.jsx)(e.h2,{children:\"\\u8FB9\\u7F18\\u60C5\\u51B5\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u7A7A\\u6811\"}),\"\\uFF1A\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"size()\"}),\"\\u4E3A 0\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"height()\"}),\"\\u4E3A 0\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u8FD4\\u56DE\",(0,r.jsx)(e.code,{children:\"[]\"})]}),`\n`,(0,r.jsx)(e.li,{children:\"\\u6811\\u65E2\\u5E73\\u8861\\u53C8\\u5B8C\\u6574\"}),`\n`]}),`\n`]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u5355\\u8282\\u70B9\\u6811\"}),\"\\uFF1A\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"size()\"}),\"\\u4E3A 1\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"height()\"}),\"\\u4E3A 0\"]}),`\n`,(0,r.jsx)(e.li,{children:\"\\u6811\\u65E2\\u5E73\\u8861\\u53C8\\u5B8C\\u6574\"}),`\n`]}),`\n`]}),`\n`]})]})}function N(n={}){let{wrapper:e}=n.components||{};return e?(0,r.jsx)(e,Object.assign({},n,{children:(0,r.jsx)(p,n)})):p(n)}var A=N;return b(z);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/bit-counting/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/bit-counting/locales/zh-CN.json new file mode 100644 index 000000000..bf0a3646e --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/bit-counting/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var s=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var y=(i,n)=>()=>(n||i((n={exports:{}}).exports,n),n.exports),j=(i,n)=>{for(var t in n)s(i,t,{get:n[t],enumerable:!0})},o=(i,n,t,c)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let r of b(n))!f.call(i,r)&&r!==t&&s(i,r,{get:()=>n[r],enumerable:!(c=m(n,r))||c.enumerable});return i};var _=(i,n,t)=>(t=i!=null?p(x(i)):{},o(n||!i||!i.__esModule?s(t,\"default\",{value:i,enumerable:!0}):t,i)),T=i=>o(s({},\"__esModule\",{value:!0}),i);var l=y((F,d)=>{d.exports=_jsx_runtime});var X={};j(X,{default:()=>D,frontmatter:()=>g});var e=_(l());var a=MDXTestExamples;var u=[{input:[[\"n\",1]],output:[0,1],explanation:\"The number of set bits in 0 (binary: 0) is 0, and in 1 (binary: 1) is 1.\"},{input:[[\"n\",2]],output:[0,1,1],explanation:\"The number of set bits in 0 (binary: 0) is 0, in 1 (binary: 1) is 1, and in 2 (binary: 10) is 1.\"},{input:[[\"n\",3]],output:[0,1,1,2],explanation:\"The number of set bits in 0 (binary: 0) is 0, in 1 (binary: 1) is 1, in 2 (binary: 10) is 1, and in 3 (binary: 11) is 2.\"}];var g={title:\"\\u4F4D\\u8BA1\\u6570\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u7528\\u4E8E\\u67E5\\u627E\\u4ECE 0 \\u5230 n \\u7684\\u8BBE\\u7F6E\\u4F4D\\u6570\\u91CF\"};function h(i){let n=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},i.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)(n.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u975E\\u8D1F\\u6574\\u6570 \",(0,e.jsx)(n.code,{children:\"n\"}),\"\\uFF0C\\u7F16\\u5199\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u8BE5\\u51FD\\u6570\\u63A5\\u53D7\\u975E\\u8D1F\\u6574\\u6570 \",(0,e.jsx)(n.code,{children:\"n\"}),\" \\u5E76\\u8FD4\\u56DE\\u4E00\\u4E2A\\u5927\\u5C0F\\u4E3A \",(0,e.jsx)(n.code,{children:\"n + 1\"}),\" \\u7684\\u6570\\u7EC4 \",(0,e.jsx)(n.code,{children:\"result\"}),\"\\uFF0C\\u5176\\u4E2D \",(0,e.jsx)(n.code,{children:\"result[i]\"}),\" \\u8868\\u793A\\u6574\\u6570 \",(0,e.jsx)(n.code,{children:\"i\"}),\" \\u7684\\u4E8C\\u8FDB\\u5236\\u8868\\u793A\\u4E2D\\u6D3B\\u52A8\\u4F4D\\uFF08\\u8BBE\\u7F6E\\u4E3A 1 \\u7684\\u4F4D\\uFF09\\u7684\\u6570\\u91CF\\uFF08\\u5176\\u4E2D 0 <= \",(0,e.jsx)(n.code,{children:\"i\"}),\" <= \",(0,e.jsx)(n.code,{children:\"n\"}),\"\\uFF09\\u3002\"]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"n: number\"}),\": \\u4E00\\u4E2A\\u6574\\u6570\"]}),`\n`]}),`\n`,(0,e.jsx)(a,{testCases:u}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"0 <= \",(0,e.jsx)(n.code,{children:\"n\"}),\" <= 10,000\"]}),`\n`]})]})}function C(i={}){let{wrapper:n}=i.components||{};return n?(0,e.jsx)(n,Object.assign({},i,{children:(0,e.jsx)(h,i)})):h(i)}var D=C;return T(X);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,用于查找从 0 到 n 的设置位数量", + "title": "位计数" + }, + "solution": "var Component=(()=>{var g=Object.create;var l=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var B=(i,n)=>()=>(n||i((n={exports:{}}).exports,n),n.exports),C=(i,n)=>{for(var c in n)l(i,c,{get:n[c],enumerable:!0})},h=(i,n,c,o)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let d of x(n))!w.call(i,d)&&d!==c&&l(i,d,{get:()=>n[d],enumerable:!(o=f(n,d))||o.enumerable});return i};var O=(i,n,c)=>(c=i!=null?g(p(i)):{},h(n||!i||!i.__esModule?l(c,\"default\",{value:i,enumerable:!0}):c,i)),M=i=>h(l({},\"__esModule\",{value:!0}),i);var u=B((I,t)=>{t.exports=_jsx_runtime});var S={};C(S,{default:()=>k});var e=O(u());var r=MDXCodeBlock;var s=`export default function bitCounting(n: number): number[] {\n // Initialize the counting result vector with 0s for all values from 0 to n\n const counts: number[] = new Array(n + 1).fill(0);\n\n // Build the table using dynamic programming\n for (let i = 1; i <= n; i++) {\n // Least significant bit (LSB) can be obtained using bitwise AND with 1\n const leastSignificantBit = i & 1;\n // Inherit the count from the previous even number (i / 2)\n counts[i] = counts[Math.floor(i / 2)] + leastSignificantBit;\n }\n\n return counts;\n}\n`;var a=`export default function bitCounting(n: number): number[] {\n // Initialize the counting answer vector with 0s for all values from 0 to n\n const ans: number[] = new Array(n + 1).fill(0);\n let x = 0;\n let b = 1;\n\n // Iterate through ranges [0, b), [b, 2b), ..., up to n\n while (b <= n) {\n // Generate values for [b, 2b) based on values from [0, b)\n while (x < b && x + b <= n) {\n ans[x + b] = ans[x] + 1;\n ++x;\n }\n x = 0; // Reset x to start from the beginning\n b <<= 1; // Double the range (b = 2b)\n }\n\n return ans;\n}\n`;var b=`export default function bitCounting(n: number): number[] {\n const ans: number[] = [];\n\n // Iterate through each number from 0 to n\n for (let i = 0; i <= n; i++) {\n // Count the number of 1s in the binary representation of i\n let count = 0;\n let num = i;\n\n while (num > 0) {\n count += num & 1; // Add the least significant bit\n num >>= 1; // Right shift to process the next bit\n }\n\n ans.push(count);\n }\n\n return ans;\n}\n`;function m(i){let n=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},i.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"1. \\u4F7F\\u7528\\u4EBA\\u53E3\\u8BA1\\u6570\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u4F7F\\u7528\\u7B80\\u5355\\u7684\\u4F4D\\u64CD\\u4F5C\\u6280\\u672F\\u6765\\u8BA1\\u7B97\\u6BCF\\u4E2A\\u6570\\u5B57\\u4E2D \",(0,e.jsx)(n.code,{children:\"1\"}),\" \\u7684\\u6570\\u91CF\\u3002 \\u5173\\u952E\\u7684\\u76F4\\u89C9\\u662F\\uFF0C\\u4E00\\u4E2A\\u6570\\u5B57\\u7684\\u4E8C\\u8FDB\\u5236\\u8868\\u793A\\u53EF\\u4EE5\\u901A\\u8FC7\\u9010\\u4F4D\\u5904\\u7406\\u6765\\u68C0\\u67E5\\u5176\\u6700\\u4F4E\\u6709\\u6548\\u4F4D\\uFF0C\\u7136\\u540E\\u53F3\\u79FB\\u8BE5\\u6570\\u5B57\\u4EE5\\u68C0\\u67E5\\u4E0B\\u4E00\\u4F4D\\u3002 \\u8FD9\\u4E2A\\u8FC7\\u7A0B\\u4E00\\u76F4\\u6301\\u7EED\\u5230\\u6570\\u5B57\\u53D8\\u4E3A \",(0,e.jsx)(n.code,{children:\"0\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u904D\\u5386\\u4ECE \",(0,e.jsx)(n.code,{children:\"0\"}),\" \\u5230 \",(0,e.jsx)(n.code,{children:\"n\"}),\" \\u7684\\u6240\\u6709\\u6570\\u5B57\\uFF0C\\u5E76\\u5728 O(k) \\u65F6\\u95F4\\u5185\\u5904\\u7406\\u6BCF\\u4E2A\\u6570\\u5B57\\uFF0C\\u5176\\u4E2D \",(0,e.jsx)(n.code,{children:\"k\"}),\" \\u662F\\u6570\\u5B57\\u4E2D\\u7684\\u4F4D\\u6570\\u3002\"]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u7A7A\\u6570\\u7EC4 \",(0,e.jsx)(n.code,{children:\"ans\"}),\" \\u6765\\u5B58\\u50A8\\u7ED3\\u679C\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u904D\\u5386\\u4ECE \",(0,e.jsx)(n.code,{children:\"0\"}),\" \\u5230 \",(0,e.jsx)(n.code,{children:\"n\"}),\" \\u7684\\u6240\\u6709\\u6570\\u5B57\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5C06\\u53D8\\u91CF \",(0,e.jsx)(n.code,{children:\"count\"}),\" \\u8BBE\\u7F6E\\u4E3A \",(0,e.jsx)(n.code,{children:\"0\"}),\" \\u4EE5\\u8DDF\\u8E2A\\u5F53\\u524D\\u6570\\u5B57\\u4E2D \",(0,e.jsx)(n.code,{children:\"1\"}),\" \\u7684\\u6570\\u91CF\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5C06\\u5F53\\u524D\\u6570\\u5B57\\u5206\\u914D\\u7ED9\\u4E34\\u65F6\\u53D8\\u91CF \",(0,e.jsx)(n.code,{children:\"num\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"while\"}),\" \\u5FAA\\u73AF\\u5904\\u7406\\u8BE5\\u6570\\u5B57\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5C06\\u6700\\u4F4E\\u6709\\u6548\\u4F4D (\",(0,e.jsx)(n.code,{children:\"num & 1\"}),\") \\u6DFB\\u52A0\\u5230 \",(0,e.jsx)(n.code,{children:\"count\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"num >>= 1\"}),\" \\u5C06\\u8BE5\\u6570\\u5B57\\u53F3\\u79FB\\u4E00\\u4F4D\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5C06 \",(0,e.jsx)(n.code,{children:\"count\"}),\" \\u9644\\u52A0\\u5230 \",(0,e.jsx)(n.code,{children:\"ans\"}),\" \\u6570\\u7EC4\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u8FD4\\u56DE\\u6570\\u7EC4 \",(0,e.jsx)(n.code,{children:\"ans\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(r,{children:b}),`\n`,(0,e.jsx)(n.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n.k)\"}),\"\\u3002 \\u8BE5\\u7B97\\u6CD5\\u5904\\u7406\\u4ECE \",(0,e.jsx)(n.code,{children:\"0\"}),\" \\u5230 \",(0,e.jsx)(n.code,{children:\"n\"}),\" \\u7684\\u6BCF\\u4E2A\\u6570\\u5B57\\uFF0C\\u5176\\u4E2D \",(0,e.jsx)(n.code,{children:\"k\"}),\" \\u662F\\u8BE5\\u6570\\u5B57\\u7684\\u4E8C\\u8FDB\\u5236\\u8868\\u793A\\u4E2D\\u7684\\u4F4D\\u6570\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002 \\u6570\\u7EC4 \",(0,e.jsx)(n.code,{children:\"ans\"}),\" \\u5B58\\u50A8\\u4ECE \",(0,e.jsx)(n.code,{children:\"0\"}),\" \\u5230 \",(0,e.jsx)(n.code,{children:\"n\"}),\" \\u7684\\u6240\\u6709\\u6570\\u5B57\\u7684\\u7ED3\\u679C\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"2. \\u4F7F\\u7528\\u52A8\\u6001\\u89C4\\u5212\\u548C MSB\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5177\\u6709\\u6700\\u9AD8\\u6709\\u6548\\u4F4D\\u7684\\u52A8\\u6001\\u89C4\\u5212\\u65B9\\u6CD5\\u901A\\u8FC7\\u4F7F\\u7528\\u5148\\u524D\\u8BA1\\u7B97\\u7684\\u7ED3\\u679C\\u6765\\u63D0\\u9AD8\\u6548\\u7387\\u3002 \\u5173\\u952E\\u7684\\u76F4\\u89C9\\u662F\\uFF0C\\u4E00\\u4E2A\\u6570\\u5B57\\u7684\\u4E8C\\u8FDB\\u5236\\u8868\\u793A\\u4E2D \",(0,e.jsx)(n.code,{children:\"1\"}),\" \\u7684\\u6570\\u91CF\\u53EF\\u4EE5\\u901A\\u8FC7\\u5C06 \",(0,e.jsx)(n.code,{children:\"1\"}),\" \\u6DFB\\u52A0\\u5230\\u8F83\\u5C0F\\u8303\\u56F4\\u5185\\u7684\\u6570\\u5B57\\u4E2D \",(0,e.jsx)(n.code,{children:\"1\"}),\" \\u7684\\u8BA1\\u6570\\u6765\\u786E\\u5B9A\\u3002 \\u5177\\u4F53\\u6765\\u8BF4\\uFF0C\\u5982\\u679C \",(0,e.jsx)(n.code,{children:\"b\"}),\" \\u662F 2 \\u7684\\u5E42\\uFF0C\\u5219\\u8303\\u56F4 \",(0,e.jsx)(n.code,{children:\"[b, 2b)\"}),\" \\u4E2D\\u7684\\u4EFB\\u4F55\\u6570\\u5B57\\u90FD\\u4E0E \",(0,e.jsx)(n.code,{children:\"[0, b)\"}),\" \\u4E2D\\u7684\\u6570\\u5B57\\u5177\\u6709\\u76F8\\u540C\\u7684\\u4F4D\\u6A21\\u5F0F\\uFF0C\\u5E76\\u8BBE\\u7F6E\\u4E86\\u989D\\u5916\\u7684\\u6700\\u9AD8\\u6709\\u6548\\u4F4D \",(0,e.jsx)(n.code,{children:\"1\"}),\"\\u3002\"]}),`\n`,(0,e.jsx)(n.p,{children:\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u6D88\\u9664\\u4E86\\u50CF\\u6734\\u7D20\\u89E3\\u6CD5\\u90A3\\u6837\\u91CD\\u590D\\u5904\\u7406\\u6BCF\\u4E2A\\u6570\\u5B57\\u7684\\u6BCF\\u4E00\\u4F4D\\u7684\\u9700\\u8981\\u3002 \\u76F8\\u53CD\\uFF0C\\u5B83\\u901A\\u8FC7\\u52A0\\u500D\\u8303\\u56F4\\u548C\\u91CD\\u7528\\u5148\\u524D\\u8BA1\\u7B97\\u7684\\u8BA1\\u6570\\u6765\\u52A8\\u6001\\u6784\\u5EFA\\u7ED3\\u679C\\uFF0C\\u4ECE\\u800C\\u51CF\\u5C11\\u4E86\\u5197\\u4F59\\u5DE5\\u4F5C\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u5927\\u5C0F\\u4E3A \",(0,e.jsx)(n.code,{children:\"n + 1\"}),\" \\u7684\\u6570\\u7EC4 \",(0,e.jsx)(n.code,{children:\"ans\"}),\"\\uFF0C\\u5E76\\u5C06\\u6240\\u6709\\u503C\\u8BBE\\u7F6E\\u4E3A \",(0,e.jsx)(n.code,{children:\"0\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5C06 \",(0,e.jsx)(n.code,{children:\"x\"}),\" \\u8BBE\\u7F6E\\u4E3A \",(0,e.jsx)(n.code,{children:\"0\"}),\"\\uFF0C\\u5C06 \",(0,e.jsx)(n.code,{children:\"b\"}),\" \\u8BBE\\u7F6E\\u4E3A \",(0,e.jsx)(n.code,{children:\"1\"}),\"\\uFF0C\\u5176\\u4E2D \",(0,e.jsx)(n.code,{children:\"b\"}),\" \\u8868\\u793A\\u5F53\\u524D\\u7684 2 \\u7684\\u5E42\\u8303\\u56F4\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"while\"}),\" \\u5FAA\\u73AF\\u5904\\u7406\\u8303\\u56F4\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5F53 \",(0,e.jsx)(n.code,{children:\"b\"}),\" \\u5C0F\\u4E8E\\u6216\\u7B49\\u4E8E \",(0,e.jsx)(n.code,{children:\"n\"}),\" \\u65F6\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u904D\\u5386\\u8303\\u56F4 \",(0,e.jsx)(n.code,{children:\"[b, 2b)\"}),\" \\u4E2D\\u7684\\u6570\\u5B57\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5BF9\\u4E8E\\u8303\\u56F4\\u5185\\u6BCF\\u4E2A\\u6570\\u5B57 \",(0,e.jsx)(n.code,{children:\"x + b\"}),\"\\uFF0C\\u8BA1\\u7B97 \",(0,e.jsx)(n.code,{children:\"1\"}),\" \\u7684\\u8BA1\\u6570\\u4E3A \",(0,e.jsx)(n.code,{children:\"ans[x] + 1\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u9012\\u589E \",(0,e.jsx)(n.code,{children:\"x\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5C06 \",(0,e.jsx)(n.code,{children:\"x\"}),\" \\u91CD\\u7F6E\\u4E3A \",(0,e.jsx)(n.code,{children:\"0\"}),\" \\u5E76\\u5C06 \",(0,e.jsx)(n.code,{children:\"b\"}),\" \\u52A0\\u500D\\u4EE5\\u5904\\u7406\\u4E0B\\u4E00\\u4E2A\\u8303\\u56F4\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u8FD4\\u56DE\\u6570\\u7EC4 \",(0,e.jsx)(n.code,{children:\"ans\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(r,{children:a}),`\n`,(0,e.jsx)(n.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002 \\u7531\\u4E8E\\u8303\\u56F4\\u9012\\u589E\\u52A0\\u500D\\uFF0C\\u56E0\\u6B64\\u6BCF\\u4E2A\\u6570\\u5B57\\u53EA\\u5904\\u7406\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002 \",(0,e.jsx)(n.code,{children:\"ans\"}),\" \\u6570\\u7EC4\\u9700\\u8981\\u7684\\u7A7A\\u95F4\\u4E0E\\u8F93\\u5165\\u5927\\u5C0F \",(0,e.jsx)(n.code,{children:\"n\"}),\" \\u6210\\u6B63\\u6BD4\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"3. \\u4F7F\\u7528\\u52A8\\u6001\\u89C4\\u5212\\u548C LSB\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u53E6\\u4E00\\u79CD\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u6700\\u4F4E\\u6709\\u6548\\u4F4D\\u4E0E\\u52A8\\u6001\\u89C4\\u5212\\u65B9\\u6CD5\\u76F8\\u7ED3\\u5408\\u6765\\u8BA1\\u7B97\\u4ECE \",(0,e.jsx)(n.code,{children:\"0\"}),\" \\u5230 \",(0,e.jsx)(n.code,{children:\"n\"}),\" \\u7684\\u6574\\u6570\\u7684\\u4E8C\\u8FDB\\u5236\\u8868\\u793A\\u4E2D \",(0,e.jsx)(n.code,{children:\"1\"}),\" \\u7684\\u6570\\u91CF\\u3002 \\u5173\\u952E\\u7684\\u76F4\\u89C9\\u662F\\uFF0C\\u6570\\u5B57 \",(0,e.jsx)(n.code,{children:\"i\"}),\" \\u4E2D \",(0,e.jsx)(n.code,{children:\"1\"}),\" \\u7684\\u6570\\u91CF\\u53EF\\u4EE5\\u4ECE \",(0,e.jsx)(n.code,{children:\"i / 2\"}),\"\\uFF08\",(0,e.jsx)(n.code,{children:\"i\"}),\" \\u7684\\u53F3\\u79FB\\u503C\\uFF09\\u548C \",(0,e.jsx)(n.code,{children:\"i\"}),\" \\u7684\\u6700\\u4F4E\\u6709\\u6548\\u4F4D\\u63A8\\u5BFC\\u51FA\\u6765\\u3002 \\u6700\\u4F4E\\u6709\\u6548\\u4F4D\\u53EF\\u4EE5\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"i & 1\"}),\" \\u786E\\u5B9A\\u3002\"]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u5927\\u5C0F\\u4E3A \",(0,e.jsx)(n.code,{children:\"n + 1\"}),\" \\u7684\\u6570\\u7EC4 \",(0,e.jsx)(n.code,{children:\"counts\"}),\"\\uFF0C\\u5E76\\u5C06\\u6240\\u6709\\u503C\\u8BBE\\u7F6E\\u4E3A \",(0,e.jsx)(n.code,{children:\"0\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u904D\\u5386\\u4ECE \",(0,e.jsx)(n.code,{children:\"1\"}),\" \\u5230 \",(0,e.jsx)(n.code,{children:\"n\"}),\" \\u7684\\u6570\\u5B57\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"i & 1\"}),\" \\u8BA1\\u7B97\\u5F53\\u524D\\u6570\\u5B57\\u7684\\u6700\\u4F4E\\u6709\\u6548\\u4F4D\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528\\u52A8\\u6001\\u89C4\\u5212\\u516C\\u5F0F \",(0,e.jsx)(n.code,{children:\"counts[i] = counts[Math.floor(i / 2)] + least significant bit\"}),\" \\u8BA1\\u7B97 \",(0,e.jsx)(n.code,{children:\"1\"}),\" \\u7684\\u8BA1\\u6570\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u8FD4\\u56DE\\u6570\\u7EC4 \",(0,e.jsx)(n.code,{children:\"counts\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(r,{children:s}),`\n`,(0,e.jsx)(n.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u4ECE \",(0,e.jsx)(n.code,{children:\"1\"}),\" \\u5230 \",(0,e.jsx)(n.code,{children:\"n\"}),\" \\u7684\\u6BCF\\u4E2A\\u6570\\u5B57\\u90FD\\u53EA\\u5904\\u7406\\u4E00\\u6B21\\uFF0C\\u5E76\\u4E14\\u6BCF\\u4E2A\\u6570\\u5B57\\u7684\\u64CD\\u4F5C\\u90FD\\u662F\\u6052\\u5B9A\\u65F6\\u95F4\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u6570\\u7EC4 \",(0,e.jsx)(n.code,{children:\"counts\"}),\" \\u9700\\u8981\\u4E0E\\u8F93\\u5165\\u5927\\u5C0F \",(0,e.jsx)(n.code,{children:\"n\"}),\" \\u6210\\u6BD4\\u4F8B\\u7684\\u7A7A\\u95F4\\u3002\"]}),`\n`]})]})}function _(i={}){let{wrapper:n}=i.components||{};return n?(0,e.jsx)(n,Object.assign({},i,{children:(0,e.jsx)(m,i)})):m(i)}var k=_;return M(S);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/bit-reversal/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/bit-reversal/locales/zh-CN.json new file mode 100644 index 000000000..f7bb8e108 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/bit-reversal/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var h=Object.create;var r=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var g=(e,n)=>()=>(n||e((n={exports:{}}).exports,n),n.exports),j=(e,n)=>{for(var i in n)r(e,i,{get:n[i],enumerable:!0})},o=(e,n,i,c)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let s of x(n))!f.call(e,s)&&s!==i&&r(e,s,{get:()=>n[s],enumerable:!(c=p(n,s))||c.enumerable});return e};var _=(e,n,i)=>(i=e!=null?h(b(e)):{},o(n||!e||!e.__esModule?r(i,\"default\",{value:e,enumerable:!0}):i,e)),M=e=>o(r({},\"__esModule\",{value:!0}),e);var a=g((A,l)=>{l.exports=_jsx_runtime});var X={};j(X,{default:()=>D,frontmatter:()=>y});var t=_(a());var u=MDXTestExamples;var m=[{input:[[\"n\",8]],output:268435456,explanation:\"8 in binary is 00000000000000000000000000001000. After reversing its bits, it becomes 00010000000000000000000000000000, which is 268435456 in decimal.\"},{input:[[\"n\",3]],output:3221225472,explanation:\"3 in binary is 00000000000000000000000000000011. After reversing its bits, it becomes 11000000000000000000000000000000, which is 3221225472 in decimal.\"},{input:[[\"n\",0]],output:0,explanation:\"0 in binary is 00000000000000000000000000000000. After reversing its bits, it becomes 00000000000000000000000000000000, which is 0 in decimal.\"}];var y={title:\"\\u4F4D\\u7FFB\\u8F6C\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u7FFB\\u8F6C\\u7ED9\\u5B9A\\u6570\\u5B57\\u4E2D\\u7684\\u4F4D\\u987A\\u5E8F\"};function d(e){let n=Object.assign({p:\"p\",h3:\"h3\",ul:\"ul\",li:\"li\",code:\"code\"},e.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n.p,{children:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u8BE5\\u51FD\\u6570\\u53CD\\u8F6C\\u7ED9\\u5B9A 32 \\u4F4D\\u65E0\\u7B26\\u53F7\\u6574\\u6570\\u7684\\u4F4D\\u987A\\u5E8F\\uFF0C\\u5E76\\u8FD4\\u56DE\\u5176\\u5BF9\\u5E94\\u7684\\u5341\\u8FDB\\u5236\\u8868\\u793A\\u5F62\\u5F0F\\u3002\"}),`\n`,(0,t.jsx)(n.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,t.jsxs)(n.ul,{children:[`\n`,(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:\"n: number\"}),\": \\u4E00\\u4E2A\\u6574\\u6570\"]}),`\n`]}),`\n`,(0,t.jsx)(u,{testCases:m}),`\n`,(0,t.jsx)(n.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,t.jsxs)(n.ul,{children:[`\n`,(0,t.jsxs)(n.li,{children:[\"0 <= \",(0,t.jsx)(n.code,{children:\"n\"}),\" <= 1,000,000\"]}),`\n`]})]})}function C(e={}){let{wrapper:n}=e.components||{};return n?(0,t.jsx)(n,Object.assign({},e,{children:(0,t.jsx)(d,e)})):d(e)}var D=C;return M(X);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来翻转给定数字中的位顺序", + "title": "位翻转" + }, + "solution": "var Component=(()=>{var x=Object.create;var l=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var v=(i,n)=>()=>(n||i((n={exports:{}}).exports,n),n.exports),O=(i,n)=>{for(var r in n)l(i,r,{get:n[r],enumerable:!0})},t=(i,n,r,h)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let c of g(n))!b.call(i,c)&&c!==r&&l(i,c,{get:()=>n[c],enumerable:!(h=p(n,c))||h.enumerable});return i};var S=(i,n,r)=>(r=i!=null?x(m(i)):{},t(n||!i||!i.__esModule?l(r,\"default\",{value:i,enumerable:!0}):r,i)),B=i=>t(l({},\"__esModule\",{value:!0}),i);var s=v((C,o)=>{o.exports=_jsx_runtime});var L={};O(L,{default:()=>w});var e=S(s());var d=MDXCodeBlock;var a=`export default function bitReversal(n: number): number {\n // Initialize result as 0\n let reversed = 0;\n\n // Iterate over each bit position\n for (let i = 0; i < 32; i++) {\n // Extract the least significant bit (LSB)\n const leastSignificantBit = n & 1;\n\n // Shift the LSB to the most significant position of the reversed number\n reversed = (reversed << 1) | leastSignificantBit;\n\n // Right shift the original number to process the next bit\n n >>= 1;\n }\n\n return reversed >>> 0; // Ensure the result is an unsigned 32-bit integer\n}\n`;var f=`export default function bitReversal(n: number): number {\n // Swap the left and right halves\n n = (n >>> 16) | (n << 16);\n // Swap consecutive bytes\n n = ((n & 0xff00ff00) >>> 8) | ((n & 0x00ff00ff) << 8);\n // Swap consecutive 4-bit groups\n n = ((n & 0xf0f0f0f0) >>> 4) | ((n & 0x0f0f0f0f) << 4);\n // Swap consecutive pairs of bits\n n = ((n & 0xcccccccc) >>> 2) | ((n & 0x33333333) << 2);\n // Swap individual bits\n n = ((n & 0xaaaaaaaa) >>> 1) | ((n & 0x55555555) << 1);\n\n return n >>> 0; // Ensure unsigned 32-bit result\n}\n`;function u(i){let n=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},i.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"1. \\u4F7F\\u7528\\u63A9\\u7801\\u548C\\u79FB\\u4F4D\\u65B9\\u6CD5\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u7528\\u4E8E\\u4F4D\\u53CD\\u8F6C\\u7684\\u63A9\\u7801\\u548C\\u79FB\\u4F4D\\u65B9\\u6CD5\\u4F7F\\u7528\\u4F4D\\u8FD0\\u7B97\\u6765\\u6709\\u6548\\u5730\\u53CD\\u8F6C 32 \\u4F4D\\u65E0\\u7B26\\u53F7\\u6574\\u6570\\u7684\\u4F4D\\u3002 \\u5173\\u952E\\u76F4\\u89C9\\u662F\\uFF0C\\u53CD\\u8F6C\\u53EF\\u4EE5\\u901A\\u8FC7\\u5206\\u5C42\\u6267\\u884C\\uFF0C\\u65B9\\u6CD5\\u662F\\u4EA4\\u6362\\u8D8A\\u6765\\u8D8A\\u5C0F\\u7684\\u4F4D\\u7EC4\\u3002 \\u4ECE\\u5927\\u7EC4\\u5F00\\u59CB\\uFF0C\\u4F8B\\u5982 16 \\u4F4D\\u7684\\u4E00\\u534A\\uFF0C\\u8BE5\\u7B97\\u6CD5\\u7EE7\\u7EED\\u4EA4\\u6362\\u8F83\\u5C0F\\u7684\\u7EC4\\uFF08\\u5B57\\u8282\\u30014 \\u4F4D\\u534A\\u5B57\\u8282\\u3001\\u6210\\u5BF9\\u7684\\u4F4D\\uFF0C\\u6700\\u540E\\u662F\\u5355\\u4E2A\\u4F4D\\uFF09\\uFF0C\\u76F4\\u5230\\u6240\\u6709\\u4F4D\\u90FD\\u5904\\u4E8E\\u5176\\u53CD\\u8F6C\\u4F4D\\u7F6E\\u3002\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u4F7F\\u7528\\u4F4D\\u63A9\\u7801\\u53EF\\u786E\\u4FDD\\u5728\\u6BCF\\u4E2A\\u6B65\\u9AA4\\u4E2D\\u4EC5\\u64CD\\u4F5C\\u76F8\\u5173\\u4F4D\\uFF0C\\u5E76\\u4E14\\u79FB\\u4F4D\\uFF08\",(0,e.jsx)(n.code,{children:\">>>\"}),\" \\u7528\\u4E8E\\u65E0\\u7B26\\u53F7\\u53F3\\u79FB\\uFF0C\",(0,e.jsx)(n.code,{children:\"<<\"}),\" \\u7528\\u4E8E\\u5DE6\\u79FB\\uFF09\\u5C06\\u4EA4\\u6362\\u7684\\u4F4D\\u91CD\\u65B0\\u5B9A\\u4F4D\\u5230\\u5B83\\u4EEC\\u6B63\\u786E\\u7684\\u4F4D\\u7F6E\\u3002 \\u8FD9\\u79CD\\u65B9\\u6CD5\\u6D88\\u9664\\u4E86\\u5355\\u72EC\\u5904\\u7406\\u6BCF\\u4E2A\\u4F4D\\u7684\\u9700\\u8981\\uFF0C\\u4ECE\\u800C\\u4F7F\\u7B97\\u6CD5\\u975E\\u5E38\\u9AD8\\u6548\\u3002\"]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4EA4\\u6362\\u5DE6\\u53F3 16 \\u4F4D\\u7684\\u4E00\\u534A\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"n >>> 16\"}),\" \\u5C06\\u53F3\\u534A\\u90E8\\u5206\\u79FB\\u5230\\u6700\\u5DE6\\u8FB9\\u7684\\u4F4D\\u7F6E\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"n << 16\"}),\" \\u5C06\\u5DE6\\u534A\\u90E8\\u5206\\u79FB\\u5230\\u6700\\u53F3\\u8FB9\\u7684\\u4F4D\\u7F6E\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528\\u6309\\u4F4D OR \\u8FD0\\u7B97 (\",(0,e.jsx)(n.code,{children:\"|\"}),\") \\u7EC4\\u5408\\u7ED3\\u679C\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4EA4\\u6362\\u8FDE\\u7EED\\u7684\\u5B57\\u8282\\uFF088 \\u4F4D\\uFF09\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528\\u63A9\\u7801 \",(0,e.jsx)(n.code,{children:\"0xff00ff00\"}),\" \\u9694\\u79BB\\u6700\\u5DE6\\u8FB9\\u548C\\u6700\\u53F3\\u8FB9\\u7684\\u5B57\\u8282\\uFF0C\\u5E76\\u5C06\\u5B83\\u4EEC\\u53F3\\u79FB 8 \\u4F4D\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528\\u63A9\\u7801 \",(0,e.jsx)(n.code,{children:\"0x00ff00ff\"}),\" \\u9694\\u79BB\\u5185\\u90E8\\u5B57\\u8282\\uFF0C\\u5E76\\u5C06\\u5B83\\u4EEC\\u5DE6\\u79FB 8 \\u4F4D\\u3002\"]}),`\n`,(0,e.jsx)(n.li,{children:\"\\u4F7F\\u7528\\u6309\\u4F4D OR \\u8FD0\\u7B97\\u7EC4\\u5408\\u7ED3\\u679C\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4EA4\\u6362\\u8FDE\\u7EED\\u7684 4 \\u4F4D\\u7EC4\\uFF08\\u534A\\u5B57\\u8282\\uFF09\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528\\u63A9\\u7801 \",(0,e.jsx)(n.code,{children:\"0xf0f0f0f0\"}),\" \\u9694\\u79BB 4 \\u4F4D\\u7EC4\\uFF0C\\u5E76\\u5C06\\u5B83\\u4EEC\\u53F3\\u79FB 4 \\u4F4D\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528\\u63A9\\u7801 \",(0,e.jsx)(n.code,{children:\"0x0f0f0f0f\"}),\" \\u9694\\u79BB\\u5176\\u4ED6\\u7EC4\\uFF0C\\u5E76\\u5C06\\u5B83\\u4EEC\\u5DE6\\u79FB 4 \\u4F4D\\u3002\"]}),`\n`,(0,e.jsx)(n.li,{children:\"\\u4F7F\\u7528\\u6309\\u4F4D OR \\u8FD0\\u7B97\\u7EC4\\u5408\\u7ED3\\u679C\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4EA4\\u6362\\u8FDE\\u7EED\\u7684\\u4F4D\\u5BF9\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528\\u63A9\\u7801 \",(0,e.jsx)(n.code,{children:\"0xcccccccc\"}),\" \\u9694\\u79BB\\u4F4D\\u5BF9\\uFF0C\\u5E76\\u5C06\\u5B83\\u4EEC\\u53F3\\u79FB 2 \\u4F4D\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528\\u63A9\\u7801 \",(0,e.jsx)(n.code,{children:\"0x33333333\"}),\" \\u9694\\u79BB\\u5176\\u4ED6\\u5BF9\\uFF0C\\u5E76\\u5C06\\u5B83\\u4EEC\\u5DE6\\u79FB 2 \\u4F4D\\u3002\"]}),`\n`,(0,e.jsx)(n.li,{children:\"\\u4F7F\\u7528\\u6309\\u4F4D OR \\u8FD0\\u7B97\\u7EC4\\u5408\\u7ED3\\u679C\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4EA4\\u6362\\u5355\\u4E2A\\u4F4D\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528\\u63A9\\u7801 \",(0,e.jsx)(n.code,{children:\"0xaaaaaaaa\"}),\" \\u9694\\u79BB\\u4EA4\\u66FF\\u4F4D\\uFF0C\\u5E76\\u5C06\\u5B83\\u4EEC\\u53F3\\u79FB 1 \\u4F4D\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528\\u63A9\\u7801 \",(0,e.jsx)(n.code,{children:\"0x55555555\"}),\" \\u9694\\u79BB\\u5176\\u4ED6\\u4EA4\\u66FF\\u4F4D\\uFF0C\\u5E76\\u5C06\\u5B83\\u4EEC\\u5DE6\\u79FB 1 \\u4F4D\\u3002\"]}),`\n`,(0,e.jsx)(n.li,{children:\"\\u4F7F\\u7528\\u6309\\u4F4D OR \\u8FD0\\u7B97\\u7EC4\\u5408\\u7ED3\\u679C\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\">>> 0\"}),\" \\u5C06\\u6700\\u7EC8\\u7ED3\\u679C\\u4F5C\\u4E3A\\u65E0\\u7B26\\u53F7 32 \\u4F4D\\u6574\\u6570\\u8FD4\\u56DE\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(d,{children:f}),`\n`,(0,e.jsx)(n.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002 \\u65E0\\u8BBA\\u8F93\\u5165\\u503C\\u5982\\u4F55\\uFF0C\\u8BE5\\u7B97\\u6CD5\\u90FD\\u4F1A\\u6267\\u884C\\u56FA\\u5B9A\\u6570\\u91CF\\u7684\\u4F4D\\u8FD0\\u7B97\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002 \\u9664\\u4E86\\u5B58\\u50A8\\u4E2D\\u95F4\\u7ED3\\u679C\\u7684\\u51E0\\u4E2A\\u53D8\\u91CF\\u4E4B\\u5916\\uFF0C\\u4E0D\\u9700\\u8981\\u989D\\u5916\\u7684\\u7A7A\\u95F4\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"2. \\u4F7F\\u7528\\u4F4D\\u8FD0\\u7B97\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u7528\\u4E8E\\u4F4D\\u53CD\\u8F6C\\u7684\\u4F4D\\u8FD0\\u7B97\\u65B9\\u6CD5\\u4F9D\\u8D56\\u4E8E\\u904D\\u5386\\u7ED9\\u5B9A\\u6574\\u6570\\u7684\\u6240\\u6709 32 \\u4F4D\\uFF0C\\u5E76\\u5728\\u65B0\\u53D8\\u91CF\\u4E2D\\u91CD\\u5EFA\\u53CD\\u8F6C\\u7684\\u4F4D\\u5E8F\\u5217\\u3002 \\u5173\\u952E\\u601D\\u60F3\\u662F\\u63D0\\u53D6\\u8F93\\u5165\\u6570\\u5B57\\u7684\\u6700\\u4F4E\\u6709\\u6548\\u4F4D (LSB)\\uFF0C\\u5C06\\u5176\\u79FB\\u5230\\u53CD\\u8F6C\\u6570\\u5B57\\u4E2D\\u7684\\u65B0\\u4F4D\\u7F6E\\uFF0C\\u7136\\u540E\\u901A\\u8FC7\\u53F3\\u79FB\\u8F93\\u5165\\u6570\\u5B57\\u79FB\\u5230\\u4E0B\\u4E00\\u4F4D\\u3002 \\u6B64\\u8FC7\\u7A0B\\u5C06\\u4E00\\u76F4\\u6301\\u7EED\\u5230\\u6240\\u6709\\u4F4D\\u90FD\\u88AB\\u53CD\\u8F6C\\u3002\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u53CD\\u8F6C\\u7684\\u4F4D\\u901A\\u8FC7\\u5DE6\\u79FB\\u53CD\\u8F6C\\u7684\\u6570\\u5B57\\u5E76\\u5728\\u6BCF\\u4E2A\\u6B65\\u9AA4\\u4E2D\\u9644\\u52A0\\u63D0\\u53D6\\u7684\\u4F4D\\u6765\\u9010\\u6B65\\u6784\\u5EFA\\u3002 \\u8BE5\\u65B9\\u6CD5\\u901A\\u8FC7\\u76F4\\u63A5\\u64CD\\u4F5C\\u5355\\u4E2A\\u4F4D\\u6765\\u786E\\u4FDD\\u6B63\\u786E\\u6027\\u548C\\u6548\\u7387\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5C06\\u53D8\\u91CF \",(0,e.jsx)(n.code,{children:\"reversed\"}),\" \\u521D\\u59CB\\u5316\\u4E3A \",(0,e.jsx)(n.code,{children:\"0\"}),\" \\u4EE5\\u5B58\\u50A8\\u53CD\\u8F6C\\u7684\\u4F4D\\u5E8F\\u5217\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5FAA\\u73AF 32 \\u6B21\\u4EE5\\u5904\\u7406\\u8F93\\u5165\\u6570\\u5B57\\u7684\\u6BCF\\u4E00\\u4F4D\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"n & 1\"}),\" \\u63D0\\u53D6\\u6570\\u5B57\\u7684\\u6700\\u4F4E\\u6709\\u6548\\u4F4D (LSB)\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5C06 \",(0,e.jsx)(n.code,{children:\"reversed\"}),\" \\u5DE6\\u79FB\\u4E00\\u4F4D\\uFF0C\\u5E76\\u4F7F\\u7528\\u6309\\u4F4D OR \\u8FD0\\u7B97 (\",(0,e.jsx)(n.code,{children:\"|\"}),\") \\u9644\\u52A0 LSB\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5C06\\u8F93\\u5165\\u6570\\u5B57 (\",(0,e.jsx)(n.code,{children:\"n\"}),\") \\u53F3\\u79FB\\u4E00\\u4F4D\\u4EE5\\u5904\\u7406\\u4E0B\\u4E00\\u4F4D\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\">>> 0\"}),\" \\u5C06 \",(0,e.jsx)(n.code,{children:\"reversed\"}),\" \\u503C\\u4F5C\\u4E3A\\u65E0\\u7B26\\u53F7 32 \\u4F4D\\u6574\\u6570\\u8FD4\\u56DE\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(d,{children:a}),`\n`,(0,e.jsx)(n.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002 \\u8BE5\\u7B97\\u6CD5\\u5904\\u7406\\u56FA\\u5B9A\\u6570\\u91CF\\u7684 32 \\u4F4D\\uFF0C\\u56E0\\u6B64\\u8FD0\\u884C\\u65F6\\u4E0D\\u4F9D\\u8D56\\u4E8E\\u8F93\\u5165\\u5927\\u5C0F\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002 \\u9664\\u4E86\\u5B58\\u50A8\\u4E2D\\u95F4\\u7ED3\\u679C\\u7684\\u51E0\\u4E2A\\u53D8\\u91CF\\u4E4B\\u5916\\uFF0C\\u6CA1\\u6709\\u4F7F\\u7528\\u989D\\u5916\\u7684\\u7A7A\\u95F4\\u3002\"]}),`\n`]})]})}function _(i={}){let{wrapper:n}=i.components||{};return n?(0,e.jsx)(n,Object.assign({},i,{children:(0,e.jsx)(u,i)})):u(i)}var w=_;return B(L);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/breadth-first-search/locales/en-US.json b/apps/web/src/__generated__/questions/algo/breadth-first-search/locales/en-US.json index b1679cad5..cd002d07f 100644 --- a/apps/web/src/__generated__/questions/algo/breadth-first-search/locales/en-US.json +++ b/apps/web/src/__generated__/questions/algo/breadth-first-search/locales/en-US.json @@ -1,5 +1,5 @@ { - "description": "var Component=(()=>{var l=Object.create;var i=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var m=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),b=(t,e)=>{for(var r in e)i(t,r,{get:e[r],enumerable:!0})},h=(t,e,r,s)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let a of p(e))!f.call(t,a)&&a!==r&&i(t,a,{get:()=>e[a],enumerable:!(s=g(e,a))||s.enumerable});return t};var v=(t,e,r)=>(r=t!=null?l(u(t)):{},h(e||!t||!t.__esModule?i(r,\"default\",{value:t,enumerable:!0}):r,t)),F=t=>h(i({},\"__esModule\",{value:!0}),t);var d=m((E,o)=>{o.exports=_jsx_runtime});var y={};b(y,{default:()=>x,frontmatter:()=>B});var n=v(d()),B={title:\"Breadth-first Search\",excerpt:\"Implement a breadth-first search algorithm that traverses a directed graph in a breadth-first manner\"};function c(t){let e=Object.assign({p:\"p\",h2:\"h2\",pre:\"pre\",code:\"code\",ol:\"ol\",li:\"li\",a:\"a\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.p,{children:\"Write a function that implements the breadth-first search (BFS) algorithm on a directed graph (in adjacency list format), given a starting node.\"}),`\n`,(0,n.jsx)(e.p,{children:\"BFS is an algorithm used for traversing a graph or a tree, starting from the root node and exploring all the neighbors at the current depth before moving on to nodes at the next depth level. The output from BFS is an array of the graph's nodes in the order they were traversed. Visiting neighboring nodes in any order is a valid BFS, but for this question, please visit each node's neighbors from left to right.\"}),`\n`,(0,n.jsx)(e.h2,{children:\"Examples\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`const graph1 = {\n A: ['B', 'C', 'D'],\n B: ['E', 'F'],\n C: ['G', 'H'],\n D: ['I', 'J'],\n E: ['D'],\n F: [],\n G: [],\n H: [],\n I: [],\n J: [],\n};\n\nbreadthFirstSearch(graph1, 'A'); // ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']\n`})}),`\n`,(0,n.jsx)(\"center\",{children:(0,n.jsx)(\"img\",{src:\"/img/questions/breadth-first-search/graph1a.png\",alt:\"Illustration of graph1 from node 'A' \",style:{width:\"50%\"}})}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`breadthFirstSearch(graph1, 'B'); // ['B', 'E', 'F', 'D', 'I', 'J']\n`})}),`\n`,(0,n.jsx)(\"center\",{children:(0,n.jsx)(\"img\",{src:\"/img/questions/breadth-first-search/graph1b.png\",alt:\"Illustration of graph1 from node 'B' \",style:{width:\"30%\"}})}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`const graph2 = {\n A: ['B', 'C'],\n B: ['D', 'E'],\n C: ['F', 'G'],\n D: [],\n E: [],\n F: [],\n G: [],\n};\n\nbreadthFirstSearch(graph2, 'A'); // ['A', 'B', 'C', 'D', 'E', 'F', 'G']\n`})}),`\n`,(0,n.jsx)(\"center\",{children:(0,n.jsx)(\"img\",{src:\"/img/questions/breadth-first-search/graph2a.png\",alt:\"Illustration of graph2 from node 'A' \",style:{width:\"50%\"}})}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`breadthFirstSearch(graph2, 'E'); // ['E']\n`})}),`\n`,(0,n.jsxs)(e.p,{children:[\"A \",(0,n.jsx)(e.code,{children:\"Queue\"}),\" data structure is also provided for you at the bottom of the skeleton code.\"]}),`\n`,(0,n.jsx)(e.h2,{children:\"Recap (Hint)\"}),`\n`,(0,n.jsx)(e.p,{children:\"Breadth-first search (BFS) is an algorithm used for traversing a graph or a tree. Here is an overview of how BFS works to traverse a graph, using the standard implementation that takes in an adjacency list (we use an array instead) and the root node:\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"Initialize a queue to store nodes to be visited. Enqueue the root node.\"}),`\n`,(0,n.jsx)(e.li,{children:\"Initialize a set to track visited nodes.\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"Enter a loop that continues until the queue is empty. In each iteration of the loop:\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"Dequeue from the queue and mark it as visited.\"}),`\n`,(0,n.jsx)(e.li,{children:\"Retrieve the neighbors of the node from the input graph.\"}),`\n`,(0,n.jsx)(e.li,{children:\"For each neighbor, check if it has been visited. If it has not been visited, enqueue the node.\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.li,{children:\"Return the set of visited nodes.\"}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"Breadth-first search is useful for the same purposes as \",(0,n.jsx)(e.a,{href:\"/questions/javascript/depth-first-search\",children:\"Depth-first search\"}),\", and it is especially useful for finding the shortest path between two nodes.\"]})]})}function j(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(c,t)})):c(t)}var x=j;return F(y);})();\n;return Component;", + "description": "var Component=(()=>{var l=Object.create;var a=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var m=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),b=(r,e)=>{for(var t in e)a(r,t,{get:e[t],enumerable:!0})},h=(r,e,t,s)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of g(e))!f.call(r,i)&&i!==t&&a(r,i,{get:()=>e[i],enumerable:!(s=p(e,i))||s.enumerable});return r};var v=(r,e,t)=>(t=r!=null?l(u(r)):{},h(e||!r||!r.__esModule?a(t,\"default\",{value:r,enumerable:!0}):t,r)),F=r=>h(a({},\"__esModule\",{value:!0}),r);var d=m((D,o)=>{o.exports=_jsx_runtime});var x={};b(x,{default:()=>j,frontmatter:()=>B});var n=v(d()),B={title:\"Breadth-first Search\",excerpt:\"Implement a breadth-first search algorithm that traverses a directed graph in a breadth-first manner\"};function c(r){let e=Object.assign({p:\"p\",code:\"code\",h2:\"h2\",pre:\"pre\",strong:\"strong\",ul:\"ul\",li:\"li\",ol:\"ol\",a:\"a\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"Write a function \",(0,n.jsx)(e.code,{children:\"breadthFirstSearch(graph, source)\"}),\" that implements the breadth-first search (BFS) algorithm on a directed graph (in adjacency list format), given a starting node (\",(0,n.jsx)(e.code,{children:\"source\"}),\").\"]}),`\n`,(0,n.jsx)(e.p,{children:\"BFS is an algorithm used for traversing a graph or a tree, starting from the root node and exploring all the neighbors at the current depth before moving on to nodes at the next depth level. The output from BFS is an array of the graph's nodes in the order they were traversed. Visiting neighboring nodes in any order is a valid BFS, but for this question, please visit each node's neighbors from left to right.\"}),`\n`,(0,n.jsx)(e.h2,{children:\"Examples\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`const graph1 = {\n A: ['B', 'C', 'D'],\n B: ['E', 'F'],\n C: ['G', 'H'],\n D: ['I', 'J'],\n E: ['D'],\n F: [],\n G: [],\n H: [],\n I: [],\n J: [],\n};\n\nbreadthFirstSearch(graph1, 'A'); // ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']\n`})}),`\n`,(0,n.jsx)(\"center\",{children:(0,n.jsx)(\"img\",{src:\"/img/questions/breadth-first-search/graph1a.png\",alt:\"Illustration of graph1 from node 'A' \",style:{width:\"50%\"}})}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`breadthFirstSearch(graph1, 'B'); // ['B', 'E', 'F', 'D', 'I', 'J']\n`})}),`\n`,(0,n.jsx)(\"center\",{children:(0,n.jsx)(\"img\",{src:\"/img/questions/breadth-first-search/graph1b.png\",alt:\"Illustration of graph1 from node 'B' \",style:{width:\"30%\"}})}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`const graph2 = {\n A: ['B', 'C'],\n B: ['D', 'E'],\n C: ['F', 'G'],\n D: [],\n E: [],\n F: [],\n G: [],\n};\n\nbreadthFirstSearch(graph2, 'A'); // ['A', 'B', 'C', 'D', 'E', 'F', 'G']\n`})}),`\n`,(0,n.jsx)(\"center\",{children:(0,n.jsx)(\"img\",{src:\"/img/questions/breadth-first-search/graph2a.png\",alt:\"Illustration of graph2 from node 'A' \",style:{width:\"50%\"}})}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`breadthFirstSearch(graph2, 'E'); // ['E']\nbreadthFirstSearch({}, ''); // []\n`})}),`\n`,(0,n.jsx)(e.p,{children:(0,n.jsx)(e.strong,{children:\"Note:\"})}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"Return an empty array if the graph is empty.\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"The \",(0,n.jsx)(e.code,{children:\"source\"}),\" node, if provided, is guaranteed to be present in \",(0,n.jsx)(e.code,{children:\"graph\"}),\".\"]}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"A \",(0,n.jsx)(e.code,{children:\"Queue\"}),\" data structure is also provided for you at the bottom of the skeleton code.\"]}),`\n`,(0,n.jsx)(e.h2,{children:\"Recap (Hint)\"}),`\n`,(0,n.jsx)(e.p,{children:\"Breadth-first search (BFS) is an algorithm used for traversing a graph or a tree. Here is an overview of how BFS works to traverse a graph, using the standard implementation that takes in an adjacency list (we use an array instead) and the root node:\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"Initialize a queue to store nodes to be visited. Enqueue the root node.\"}),`\n`,(0,n.jsx)(e.li,{children:\"Initialize a set to track visited nodes.\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"Enter a loop that continues until the queue is empty. In each iteration of the loop:\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"Dequeue from the queue and mark it as visited.\"}),`\n`,(0,n.jsx)(e.li,{children:\"Retrieve the neighbors of the node from the input graph.\"}),`\n`,(0,n.jsx)(e.li,{children:\"For each neighbor, check if it has been visited. If it has not been visited, enqueue the node.\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.li,{children:\"Return the set of visited nodes.\"}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"Breadth-first search is useful for the same purposes as \",(0,n.jsx)(e.a,{href:\"/questions/javascript/depth-first-search\",children:\"Depth-first search\"}),\", and it is especially useful for finding the shortest path between two nodes.\"]})]})}function y(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(c,r)})):c(r)}var j=y;return F(x);})();\n;return Component;", "info": { "excerpt": "Implement a breadth-first search algorithm that traverses a directed graph in a breadth-first manner", "title": "Breadth-first Search" diff --git a/apps/web/src/__generated__/questions/algo/breadth-first-search/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/breadth-first-search/locales/zh-CN.json new file mode 100644 index 000000000..b757275bd --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/breadth-first-search/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var o=Object.create;var h=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var F=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports),f=(r,n)=>{for(var c in n)h(r,c,{get:n[c],enumerable:!0})},t=(r,n,c,l)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let i of p(n))!m.call(r,i)&&i!==c&&h(r,i,{get:()=>n[i],enumerable:!(l=g(n,i))||l.enumerable});return r};var B=(r,n,c)=>(c=r!=null?o(u(r)):{},t(n||!r||!r.__esModule?h(c,\"default\",{value:r,enumerable:!0}):c,r)),b=r=>t(h({},\"__esModule\",{value:!0}),r);var s=F((A,a)=>{a.exports=_jsx_runtime});var D={};f(D,{default:()=>x,frontmatter:()=>j});var e=B(s()),j={title:\"\\u5E7F\\u5EA6\\u4F18\\u5148\\u641C\\u7D22\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u5E7F\\u5EA6\\u4F18\\u5148\\u641C\\u7D22\\u7B97\\u6CD5\\uFF0C\\u8BE5\\u7B97\\u6CD5\\u4EE5\\u5E7F\\u5EA6\\u4F18\\u5148\\u7684\\u65B9\\u5F0F\\u904D\\u5386\\u6709\\u5411\\u56FE\"};function d(r){let n=Object.assign({p:\"p\",code:\"code\",h2:\"h2\",pre:\"pre\",strong:\"strong\",ul:\"ul\",li:\"li\",ol:\"ol\",a:\"a\"},r.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)(n.p,{children:[\"\\u7F16\\u5199\\u4E00\\u4E2A\\u51FD\\u6570\",(0,e.jsx)(n.code,{children:\"breadthFirstSearch(graph, source)\"}),\"\\uFF0C\\u8BE5\\u51FD\\u6570\\u5728\\u6709\\u5411\\u56FE\\uFF08\\u90BB\\u63A5\\u8868\\u683C\\u5F0F\\uFF09\\u4E0A\\u5B9E\\u73B0\\u5E7F\\u5EA6\\u4F18\\u5148\\u641C\\u7D22\\uFF08BFS\\uFF09\\u7B97\\u6CD5\\uFF0C\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u8D77\\u59CB\\u8282\\u70B9\\uFF08\",(0,e.jsx)(n.code,{children:\"source\"}),\"\\uFF09\\u3002\"]}),`\n`,(0,e.jsx)(n.p,{children:\"BFS \\u662F\\u4E00\\u79CD\\u7528\\u4E8E\\u904D\\u5386\\u56FE\\u6216\\u6811\\u7684\\u7B97\\u6CD5\\uFF0C\\u4ECE\\u6839\\u8282\\u70B9\\u5F00\\u59CB\\uFF0C\\u5728\\u79FB\\u52A8\\u5230\\u4E0B\\u4E00\\u6DF1\\u5EA6\\u7EA7\\u522B\\u4E0A\\u7684\\u8282\\u70B9\\u4E4B\\u524D\\uFF0C\\u5148\\u63A2\\u7D22\\u5F53\\u524D\\u6DF1\\u5EA6\\u7684\\u6240\\u6709\\u90BB\\u5C45\\u3002BFS \\u7684\\u8F93\\u51FA\\u662F\\u4E00\\u4E2A\\u6570\\u7EC4\\uFF0C\\u5176\\u4E2D\\u5305\\u542B\\u56FE\\u7684\\u8282\\u70B9\\uFF0C\\u6309\\u7167\\u5B83\\u4EEC\\u88AB\\u904D\\u5386\\u7684\\u987A\\u5E8F\\u6392\\u5217\\u3002\\u4EE5\\u4EFB\\u4F55\\u987A\\u5E8F\\u8BBF\\u95EE\\u76F8\\u90BB\\u8282\\u70B9\\u90FD\\u662F\\u6709\\u6548\\u7684 BFS\\uFF0C\\u4F46\\u5BF9\\u4E8E\\u8FD9\\u4E2A\\u95EE\\u9898\\uFF0C\\u8BF7\\u4ECE\\u5DE6\\u5230\\u53F3\\u8BBF\\u95EE\\u6BCF\\u4E2A\\u8282\\u70B9\\u7684\\u90BB\\u5C45\\u3002\"}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u793A\\u4F8B\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-js\",children:`const graph1 = {\n A: ['B', 'C', 'D'],\n B: ['E', 'F'],\n C: ['G', 'H'],\n D: ['I', 'J'],\n E: ['D'],\n F: [],\n G: [],\n H: [],\n I: [],\n J: [],\n};\n\nbreadthFirstSearch(graph1, 'A'); // ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']\n`})}),`\n`,(0,e.jsx)(\"center\",{children:(0,e.jsx)(\"img\",{src:\"/img/questions/breadth-first-search/graph1a.png\",alt:\"Illustration of graph1 from node 'A' \",style:{width:\"50%\"}})}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-js\",children:`breadthFirstSearch(graph1, 'B'); // ['B', 'E', 'F', 'D', 'I', 'J']\n`})}),`\n`,(0,e.jsx)(\"center\",{children:(0,e.jsx)(\"img\",{src:\"/img/questions/breadth-first-search/graph1b.png\",alt:\"Illustration of graph1 from node 'B' \",style:{width:\"30%\"}})}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-js\",children:`const graph2 = {\n A: ['B', 'C'],\n B: ['D', 'E'],\n C: ['F', 'G'],\n D: [],\n E: [],\n F: [],\n G: [],\n};\n\nbreadthFirstSearch(graph2, 'A'); // ['A', 'B', 'C', 'D', 'E', 'F', 'G']\n`})}),`\n`,(0,e.jsx)(\"center\",{children:(0,e.jsx)(\"img\",{src:\"/img/questions/breadth-first-search/graph2a.png\",alt:\"Illustration of graph2 from node 'A' \",style:{width:\"50%\"}})}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-js\",children:`breadthFirstSearch(graph2, 'E'); // ['E']\nbreadthFirstSearch({}, ''); // []\n`})}),`\n`,(0,e.jsx)(n.p,{children:(0,e.jsx)(n.strong,{children:\"\\u6CE8\\u610F\\uFF1A\"})}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5982\\u679C\\u56FE\\u4E3A\\u7A7A\\uFF0C\\u5219\\u8FD4\\u56DE\\u4E00\\u4E2A\\u7A7A\\u6570\\u7EC4\\u3002\"}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5982\\u679C\\u63D0\\u4F9B\\u4E86\",(0,e.jsx)(n.code,{children:\"source\"}),\"\\u8282\\u70B9\\uFF0C\\u5219\\u4FDD\\u8BC1\\u5B83\\u5B58\\u5728\\u4E8E\",(0,e.jsx)(n.code,{children:\"graph\"}),\"\\u4E2D\\u3002\"]}),`\n`]}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5728\\u9AA8\\u67B6\\u4EE3\\u7801\\u7684\\u5E95\\u90E8\\u4E5F\\u4E3A\\u60A8\\u63D0\\u4F9B\\u4E86\\u4E00\\u4E2A\",(0,e.jsx)(n.code,{children:\"Queue\"}),\"\\u6570\\u636E\\u7ED3\\u6784\\u3002\"]}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u56DE\\u987E\\uFF08\\u63D0\\u793A\\uFF09\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5E7F\\u5EA6\\u4F18\\u5148\\u641C\\u7D22\\uFF08BFS\\uFF09\\u662F\\u4E00\\u79CD\\u7528\\u4E8E\\u904D\\u5386\\u56FE\\u6216\\u6811\\u7684\\u7B97\\u6CD5\\u3002\\u4EE5\\u4E0B\\u662F BFS \\u5982\\u4F55\\u904D\\u5386\\u56FE\\u7684\\u6982\\u8FF0\\uFF0C\\u4F7F\\u7528\\u63A5\\u53D7\\u90BB\\u63A5\\u8868\\uFF08\\u6211\\u4EEC\\u4F7F\\u7528\\u6570\\u7EC4\\u4EE3\\u66FF\\uFF09\\u548C\\u6839\\u8282\\u70B9\\u7684\\u6807\\u51C6\\u5B9E\\u73B0\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u961F\\u5217\\u6765\\u5B58\\u50A8\\u8981\\u8BBF\\u95EE\\u7684\\u8282\\u70B9\\u3002\\u5C06\\u6839\\u8282\\u70B9\\u5165\\u961F\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u96C6\\u5408\\u6765\\u8DDF\\u8E2A\\u5DF2\\u8BBF\\u95EE\\u7684\\u8282\\u70B9\\u3002\"}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u8FDB\\u5165\\u4E00\\u4E2A\\u5FAA\\u73AF\\uFF0C\\u8BE5\\u5FAA\\u73AF\\u5C06\\u6301\\u7EED\\u5230\\u961F\\u5217\\u4E3A\\u7A7A\\u3002\\u5728\\u5FAA\\u73AF\\u7684\\u6BCF\\u6B21\\u8FED\\u4EE3\\u4E2D\\uFF1A\",`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u4ECE\\u961F\\u5217\\u4E2D\\u51FA\\u961F\\u5E76\\u5C06\\u5176\\u6807\\u8BB0\\u4E3A\\u5DF2\\u8BBF\\u95EE\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u4ECE\\u8F93\\u5165\\u56FE\\u4E2D\\u68C0\\u7D22\\u8282\\u70B9\\u7684\\u90BB\\u5C45\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u90BB\\u5C45\\uFF0C\\u68C0\\u67E5\\u5B83\\u662F\\u5426\\u5DF2\\u88AB\\u8BBF\\u95EE\\u3002\\u5982\\u679C\\u5C1A\\u672A\\u8BBF\\u95EE\\uFF0C\\u5219\\u5C06\\u8282\\u70B9\\u5165\\u961F\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,e.jsx)(n.li,{children:\"\\u8FD4\\u56DE\\u5DF2\\u8BBF\\u95EE\\u8282\\u70B9\\u7684\\u96C6\\u5408\\u3002\"}),`\n`]}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5E7F\\u5EA6\\u4F18\\u5148\\u641C\\u7D22\\u4E0E\",(0,e.jsx)(n.a,{href:\"/questions/javascript/depth-first-search\",children:\"\\u6DF1\\u5EA6\\u4F18\\u5148\\u641C\\u7D22\"}),\"\\u7684\\u7528\\u9014\\u76F8\\u540C\\uFF0C\\u5E76\\u4E14\\u7279\\u522B\\u9002\\u7528\\u4E8E\\u67E5\\u627E\\u4E24\\u4E2A\\u8282\\u70B9\\u4E4B\\u95F4\\u7684\\u6700\\u77ED\\u8DEF\\u5F84\\u3002\"]})]})}function S(r={}){let{wrapper:n}=r.components||{};return n?(0,e.jsx)(n,Object.assign({},r,{children:(0,e.jsx)(d,r)})):d(r)}var x=S;return b(D);})();\n;return Component;", + "info": { + "excerpt": "实现一个广度优先搜索算法,该算法以广度优先的方式遍历有向图", + "title": "广度优先搜索" + }, + "solution": "var Component=(()=>{var p=Object.create;var s=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var b=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),w=(n,e)=>{for(var i in e)s(n,i,{get:e[i],enumerable:!0})},h=(n,e,i,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of m(e))!y.call(n,r)&&r!==i&&s(n,r,{get:()=>e[r],enumerable:!(o=q(e,r))||o.enumerable});return n};var x=(n,e,i)=>(i=n!=null?p(f(n)):{},h(e||!n||!n.__esModule?s(i,\"default\",{value:n,enumerable:!0}):i,n)),N=n=>h(s({},\"__esModule\",{value:!0}),n);var d=b((B,a)=>{a.exports=_jsx_runtime});var k={};w(k,{default:()=>j});var t=x(d());var u=MDXCodeBlock;var l=`/**\n * @param {Record>} graph The adjacency list representing the graph.\n * @param {string} source The source node to start traversal from. Has to be a valid node if graph is non-empty.\n * @return {Array} A BFS-traversed order of nodes.\n */\nexport default function breadthFirstSearch(graph, source) {\n // If there are no nodes in the graph, just return an empty array\n if (Object.keys(graph).length === 0) {\n return [];\n }\n\n // Create a queue to store the nodes to be visited.\n // Add the root node since we're doing a level-order BFS.\n const queue = new Queue();\n queue.enqueue(source);\n\n // Initialize a set that tracks visited nodes.\n const visited = new Set();\n\n // While there are nodes to visit.\n while (!queue.isEmpty()) {\n // Dequeue the node at the front of the queue.\n const node = queue.dequeue();\n\n // Mark the node as visited.\n visited.add(node);\n\n // Enqueue the neighbors of the current node.\n graph[node].forEach((neighbor) => {\n // Skip nodes that have already been visited.\n if (visited.has(neighbor)) {\n return;\n }\n\n queue.enqueue(neighbor);\n });\n }\n\n // The visited nodes is the traversal order.\n return Array.from(visited);\n}\n\n/* Auxiliary classes */\n\n/**\n * A Queue class with O(1) enqueue and dequeue is provided for you.\n * You can use it directly should you wish to.\n *\n * Example usage:\n * const q = new Queue();\n * q.enqueue('a');\n * q.enqueue('b');\n * q.dequeue(); //'a'\n * q.isEmpty(); // False\n */\nclass Node {\n constructor(value) {\n this.value = value;\n this.next = null;\n }\n}\n\nclass Queue {\n constructor() {\n this.head = null;\n this.tail = null;\n this.length = 0;\n }\n\n isEmpty() {\n return this.length === 0;\n }\n\n enqueue(item) {\n const newNode = new Node(item);\n if (this.isEmpty()) {\n this.head = newNode;\n } else if (this.tail) {\n this.tail.next = newNode;\n }\n this.tail = newNode;\n this.length++;\n }\n\n dequeue() {\n if (this.isEmpty() || !this.head) {\n return null;\n } else {\n const removedNode = this.head;\n this.head = this.head.next;\n removedNode.next = null;\n this.length--;\n if (this.isEmpty()) {\n this.tail = null;\n }\n return removedNode.value;\n }\n }\n}\n`;var c=`export default function breadthFirstSearch(\n graph: Record>,\n source: string,\n): Array {\n // If there are no nodes in the graph, just return an empty array\n if (Object.keys(graph).length === 0) {\n return [];\n }\n\n // Create a queue to store the nodes to be visited.\n // Add the root node since we're doing a level-order BFS.\n const queue = new Queue();\n queue.enqueue(source);\n\n // Initialize a set that tracks visited nodes.\n const visited = new Set();\n\n // While there are nodes to visit.\n while (!queue.isEmpty()) {\n // Dequeue the node at the front of the queue.\n const node = queue.dequeue()!;\n\n // Mark the node as visited.\n visited.add(node);\n\n // Enqueue the neighbors of the current node.\n graph[node].forEach((neighbor) => {\n // Skip nodes that have already been visited.\n if (visited.has(neighbor)) {\n return;\n }\n\n queue.enqueue(neighbor);\n });\n }\n\n // The visited nodes is the traversal order.\n return Array.from(visited);\n}\n\n/* Auxiliary classes */\n\n/**\n * A Queue class with O(1) enqueue and dequeue is provided for you.\n * You can use it directly should you wish to.\n *\n * Example usage:\n * const q = new Queue();\n * q.enqueue('a');\n * q.enqueue('b');\n * q.dequeue(); //'a'\n * q.isEmpty(); // False\n */\nclass Node {\n value: T;\n next: Node | null;\n\n constructor(value: T) {\n this.value = value;\n this.next = null;\n }\n}\n\nclass Queue {\n head: Node | null;\n tail: Node | null;\n length: number;\n\n constructor() {\n this.head = null;\n this.tail = null;\n this.length = 0;\n }\n\n isEmpty(): boolean {\n return this.length === 0;\n }\n\n enqueue(item: T): void {\n const newNode = new Node(item);\n if (this.isEmpty()) {\n this.head = newNode;\n } else if (this.tail) {\n this.tail.next = newNode;\n }\n this.tail = newNode;\n this.length++;\n }\n\n dequeue(): T | null {\n if (this.isEmpty() || !this.head) {\n return null;\n } else {\n const removedNode = this.head;\n this.head = this.head.next;\n removedNode.next = null;\n this.length--;\n if (this.isEmpty()) {\n this.tail = null;\n }\n return removedNode.value;\n }\n }\n}\n`;var v=`/**\n * @param {Object} graph Node to array of neighboring nodes.\n * @param {string} source Source node to start traversal from. Has to be a valid node if graph is non-empty.\n * @return {Array} A BFS-traversed order of nodes.\n */\nexport default function breadthFirstSearch(graph, source) {\n // If there are no nodes in the graph, just return an empty array\n if (Object.keys(graph).length === 0) {\n return [];\n }\n\n // Initialize a queue to keep track of nodes to visit.\n const queue = new Queue();\n const visited = new Set();\n\n // Add the source node to the queue and mark it as visited.\n queue.enqueue(source);\n visited.add(source);\n\n function traverse() {\n // If the queue is empty, we have visited all nodes, so return the visited nodes.\n if (queue.isEmpty()) {\n return Array.from(visited);\n }\n\n // Get the next node to visit from the queue.\n const node = queue.dequeue();\n\n // Visit each neighbor that hasn't been visited before.\n graph[node].forEach((neighbor) => {\n if (!visited.has(neighbor)) {\n visited.add(neighbor);\n queue.enqueue(neighbor);\n }\n });\n\n // Recursively call traverse to visit the next node in the queue.\n return traverse();\n }\n\n // Call traverse to start the traversal.\n return traverse();\n}\n\n/* Auxiliary classes */\n\n/**\n * A Queue class with O(1) enqueue and dequeue is provided for you.\n * You can use it directly should you wish to.\n *\n * Example usage:\n * const q = new Queue();\n * q.enqueue('a');\n * q.enqueue('b');\n * q.dequeue(); //'a'\n * q.isEmpty(); // False\n */\nclass Node {\n constructor(value) {\n this.value = value;\n this.next = null;\n }\n}\n\nclass Queue {\n constructor() {\n this.head = null;\n this.tail = null;\n this.length = 0;\n }\n\n isEmpty() {\n return this.length === 0;\n }\n\n enqueue(item) {\n const newNode = new Node(item);\n if (this.isEmpty()) {\n this.head = newNode;\n } else if (this.tail) {\n this.tail.next = newNode;\n }\n this.tail = newNode;\n this.length++;\n }\n\n dequeue() {\n if (this.isEmpty() || !this.head) {\n return null;\n } else {\n const removedNode = this.head;\n this.head = this.head.next;\n removedNode.next = null;\n this.length--;\n if (this.isEmpty()) {\n this.tail = null;\n }\n return removedNode.value;\n }\n }\n}\n`;function g(n){let e=Object.assign({h2:\"h2\",p:\"p\",ul:\"ul\",li:\"li\",strong:\"strong\",h3:\"h3\",code:\"code\"},n.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(e.h2,{children:\"\\u6F84\\u6E05\\u95EE\\u9898\"}),`\n`,(0,t.jsx)(e.p,{children:\"\\u5982\\u679C\\u672A\\u6307\\u5B9A\\uFF1A\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsx)(e.li,{children:\"\\u904D\\u5386\\u987A\\u5E8F\\uFF1A\\u6211\\u4EEC\\u5E94\\u8BE5\\u4F7F\\u7528\\u6807\\u51C6\\u7684\\u5148\\u5E8F\\u904D\\u5386\\u8FD8\\u662F\\u5176\\u4ED6\\u904D\\u5386\\u987A\\u5E8F\\uFF1F\"}),`\n`,(0,t.jsx)(e.li,{children:\"\\u8F93\\u5165\\u683C\\u5F0F\\uFF1A\\u8F93\\u5165\\u6570\\u636E\\u7684\\u683C\\u5F0F\\u662F\\u4EC0\\u4E48\\uFF1F\\u6211\\u4EEC\\u53EF\\u4EE5\\u5047\\u8BBE\\u8F93\\u5165\\u5C06\\u662F\\u4E00\\u4E2A JavaScript \\u5BF9\\u8C61\\u7684\\u90BB\\u63A5\\u8868\\uFF0C\\u5176\\u4E2D\\u952E\\u662F\\u8282\\u70B9\\uFF0C\\u503C\\u662F\\u5B50\\u8282\\u70B9\\u5417\\uFF1F\"}),`\n`,(0,t.jsx)(e.li,{children:\"\\u8F93\\u51FA\\u683C\\u5F0F\\uFF1A\\u8F93\\u51FA\\u5E94\\u8BE5\\u5982\\u4F55\\u683C\\u5F0F\\u5316\\uFF1F\\u662F\\u5426\\u6709\\u5177\\u4F53\\u8981\\u6C42\\uFF0C\\u6216\\u8005\\u6211\\u4EEC\\u53EF\\u4EE5\\u8FD4\\u56DE\\u4E00\\u4E2A\\u5305\\u542B\\u904D\\u5386\\u987A\\u5E8F\\u5143\\u7D20\\u7684\\u6570\\u7EC4\\uFF1F\"}),`\n`,(0,t.jsx)(e.li,{children:\"\\u4E0D\\u8FDE\\u901A\\u56FE\\uFF1A\\u6211\\u4EEC\\u662F\\u5426\\u5FC5\\u987B\\u8003\\u8651\\u6216\\u5904\\u7406\\u4E0D\\u8FDE\\u901A\\u56FE\\u7684\\u60C5\\u51B5\\uFF0C\\u5373\\u5B58\\u5728\\u591A\\u4E2A\\u5F7C\\u6B64\\u4E0D\\u8FDE\\u63A5\\u7684\\u5B50\\u56FE\\uFF1F\"}),`\n`]}),`\n`,(0,t.jsx)(e.h2,{children:\"\\u8FED\\u4EE3\\u89E3\\u6CD5\"}),`\n`,(0,t.jsx)(e.p,{children:\"\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u5B9E\\u73B0\\u4E86\\u63CF\\u8FF0\\u4E2D\\u6982\\u8FF0\\u7684\\u7B97\\u6CD5\\u3002\"}),`\n`,(0,t.jsx)(u,{languages:{jsx:l,tsx:c}}),`\n`,(0,t.jsx)(e.h2,{children:\"\\u9012\\u5F52\\u89E3\\u6CD5\"}),`\n`,(0,t.jsx)(e.p,{children:\"\\u6211\\u4EEC\\u4E5F\\u53EF\\u4EE5\\u9012\\u5F52\\u5730\\u6267\\u884C BFS\\uFF0C\\u8FD9\\u5728\\u67D0\\u4E9B\\u60C5\\u51B5\\u4E0B\\u53EF\\u80FD\\u66F4\\u76F4\\u89C2\\u3002\\u9012\\u5F52\\u8C03\\u7528\\u5806\\u6808\\u662F\\u4E00\\u4E2A\\u9690\\u5F0F\\u5806\\u6808\\uFF0C\\u7528\\u4E8E\\u8DDF\\u8E2A\\u63A5\\u4E0B\\u6765\\u8981\\u8BBF\\u95EE\\u7684\\u8282\\u70B9\\u3002\"}),`\n`,(0,t.jsx)(u,{children:v}),`\n`,(0,t.jsx)(e.h2,{children:\"\\u8FB9\\u7F18\\u60C5\\u51B5\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:\"\\u7A7A\\u56FE\"}),\"\\uFF1A\\u8FD4\\u56DE\\u4E00\\u4E2A\\u7A7A\\u6570\\u7EC4\\uFF0C\\u4E0D\\u4F1A\\u5D29\\u6E83\\u3002\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:\"\\u53EA\\u6709\\u4E00\\u4E24\\u4E2A\\u8282\\u70B9\\u7684\\u56FE\"}),\"\\uFF1A\\u904D\\u5386\\uFF0C\\u4E0D\\u4F1A\\u5D29\\u6E83\\u3002\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:\"\\u5FAA\\u73AF\\u56FE\"}),\"\\uFF1A\\u786E\\u4FDD\\u4E0D\\u518D\\u904D\\u5386\\u5DF2\\u8BBF\\u95EE\\u7684\\u8282\\u70B9\\u3002\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:\"\\u4E0D\\u76F8\\u4EA4\\u56FE\"}),\"\\uFF1A\\u4E0D\\u9700\\u8981\\u7279\\u6B8A\\u5904\\u7406\\uFF0C\\u4F46\\u6700\\u597D\\u77E5\\u9053\\u3002\"]}),`\n`]}),`\n`,(0,t.jsx)(e.h2,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,t.jsx)(e.p,{children:\"\\u8BA9\\u6211\\u4EEC\\u5206\\u6790\\u4E00\\u4E0B\\u7B97\\u6CD5\\u7684\\u65F6\\u95F4\\u548C\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u3002\"}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\"}),`\n`,(0,t.jsx)(e.p,{children:\"\\u5728\\u6700\\u574F\\u7684\\u60C5\\u51B5\\u4E0B\\uFF0CBFS \\u8BBF\\u95EE\\u56FE\\u7684\\u6BCF\\u4E2A\\u9876\\u70B9\\u548C\\u6BCF\\u6761\\u8FB9\\u4E00\\u6B21\\u3002\\u56E0\\u6B64\\uFF0CBFS \\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(V + E)\\uFF0C\\u5176\\u4E2D V \\u662F\\u56FE\\u4E2D\\u9876\\u70B9\\u7684\\u6570\\u91CF\\uFF0CE \\u662F\\u8FB9\\u7684\\u6570\\u91CF\\u3002\\u8FD9\\u662F\\u56E0\\u4E3A BFS \\u5FC5\\u987B\\u63A2\\u7D22\\u6240\\u6709\\u9876\\u70B9\\u548C\\u8FB9\\uFF0C\\u4EE5\\u786E\\u4FDD\\u5B83\\u8986\\u76D6\\u6574\\u4E2A\\u56FE\\u3002\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"\\u8BF7\\u6CE8\\u610F\\uFF0C\\u60A8\\u4E0D\\u5E94\\u8BE5\\u4F7F\\u7528 \",(0,t.jsx)(e.code,{children:\"Array.shift()\"}),\"\\uFF0C\\u56E0\\u4E3A\\u5B83\\u9700\\u8981 O(n) \\u65F6\\u95F4\\u6765\\u51FA\\u5217\\uFF0C\\u5176\\u4E2D n \\u662F\\u6570\\u7EC4\\u4E2D\\u7684\\u5143\\u7D20\\u6570\\u3002\"]}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\"}),`\n`,(0,t.jsx)(e.p,{children:\"BFS \\u4F7F\\u7528\\u961F\\u5217\\u6765\\u8DDF\\u8E2A\\u8981\\u8BBF\\u95EE\\u7684\\u8282\\u70B9\\u3002\\u5728\\u4EFB\\u4F55\\u7ED9\\u5B9A\\u65F6\\u95F4\\uFF0C\\u961F\\u5217\\u90FD\\u5305\\u542B\\u6B63\\u5728\\u63A2\\u7D22\\u7684\\u56FE\\u7684\\u5F53\\u524D\\u7EA7\\u522B\\u7684\\u8282\\u70B9\\u3002\\u56E0\\u6B64\\uFF0CBFS \\u7684\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(\\u56FE\\u4E2D\\u4EFB\\u4F55\\u7EA7\\u522B\\u7684\\u6700\\u5927\\u8282\\u70B9\\u6570)\\u3002\"})]})}function A(n={}){let{wrapper:e}=n.components||{};return e?(0,t.jsx)(e,Object.assign({},n,{children:(0,t.jsx)(g,n)})):g(n)}var j=A;return N(k);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/bubble-sort/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/bubble-sort/locales/zh-CN.json new file mode 100644 index 000000000..d891b1852 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/bubble-sort/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var d=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var g=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),x=(n,e)=>{for(var r in e)i(n,r,{get:e[r],enumerable:!0})},o=(n,e,r,c)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let s of u(e))!m.call(n,s)&&s!==r&&i(n,s,{get:()=>e[s],enumerable:!(c=p(e,s))||c.enumerable});return n};var j=(n,e,r)=>(r=n!=null?d(h(n)):{},o(e||!n||!n.__esModule?i(r,\"default\",{value:n,enumerable:!0}):r,n)),_=n=>o(i({},\"__esModule\",{value:!0}),n);var b=g((F,l)=>{l.exports=_jsx_runtime});var C={};x(C,{default:()=>M,frontmatter:()=>f});var t=j(b()),f={title:\"\\u5192\\u6CE1\\u6392\\u5E8F\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u6267\\u884C\\u5192\\u6CE1\\u6392\\u5E8F\\u7684\\u51FD\\u6570\"};function a(n){let e=Object.assign({p:\"p\",h2:\"h2\",pre:\"pre\",code:\"code\",img:\"img\"},n.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(e.p,{children:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u6267\\u884C\\u5192\\u6CE1\\u6392\\u5E8F\\u7684\\u51FD\\u6570\\u3002\\u8BE5\\u51FD\\u6570\\u5E94\\u63A5\\u6536\\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4\\uFF0C\\u5E76\\u8FD4\\u56DE\\u4E00\\u4E2A\\u6309\\u5347\\u5E8F\\u6392\\u5E8F\\u6574\\u6570\\u7684\\u6570\\u7EC4\\u3002\\u8F93\\u5165\\u6570\\u7EC4\\u5DF2\\u4FEE\\u6539\\u3002\"}),`\n`,(0,t.jsx)(e.h2,{children:\"\\u4F8B\\u5B50\"}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-js\",children:`bubbleSort([9, 3, 6, 2, 1, 11]); // [1, 2, 3, 6, 9, 11]\nbubbleSort([12, 16, 14, 1, 2, 3]); // [1, 2, 3, 12, 14, 16]\n`})}),`\n`,(0,t.jsx)(e.h2,{children:\"\\u56DE\\u987E\"}),`\n`,(0,t.jsx)(e.p,{children:\"\\u5192\\u6CE1\\u6392\\u5E8F\\u662F\\u4E00\\u79CD\\u7B80\\u5355\\u7684\\u6392\\u5E8F\\u7B97\\u6CD5\\uFF0C\\u5B83\\u6BD4\\u8F83\\u5E76\\u4EA4\\u6362\\u76F8\\u90BB\\u7684\\u5143\\u7D20\\uFF0C\\u4F7F\\u5F97\\u5728\\u5BF9\\u6570\\u7EC4\\u8FDB\\u884C\\u6BCF\\u6B21\\u8FED\\u4EE3\\u540E\\uFF0C\\u53C8\\u4E00\\u4E2A\\u5143\\u7D20\\u5C06\\u88AB\\u6392\\u5E8F/\\u6B63\\u786E\\u653E\\u7F6E\\uFF0C\\u4ECE\\u6700\\u5927\\u7684\\u5143\\u7D20\\u5F00\\u59CB\\u3002\"}),`\n`,(0,t.jsx)(e.p,{children:\"\\u8BE5\\u7B97\\u6CD5\\u9996\\u5148\\u904D\\u5386\\u6570\\u7EC4\\uFF0C\\u6BD4\\u8F83\\u6BCF\\u5BF9\\u76F8\\u90BB\\u7684\\u5143\\u7D20\\uFF0C\\u5982\\u679C\\u8F83\\u5927\\u7684\\u5143\\u7D20\\u5728\\u5DE6\\u8FB9\\uFF0C\\u5219\\u4EA4\\u6362\\u5B83\\u4EEC\\u3002\\u8FD9\\u5C06\\u786E\\u4FDD\\u5728\\u4E00\\u6B21\\u5B8C\\u6574\\u7684\\u8FED\\u4EE3\\u4E4B\\u540E\\uFF0C\\u6570\\u7EC4\\u4E2D\\u6700\\u5927\\u7684\\u5143\\u7D20\\u5C06\\u5728\\u6700\\u540E\\u4E00\\u4E2A\\u7D22\\u5F15\\u5904\\u3002\"}),`\n`,(0,t.jsx)(e.p,{children:(0,t.jsx)(e.img,{src:\"/img/questions/bubble-sort/bubble-sort-first-iteration.jpg\",alt:\"\\u5192\\u6CE1\\u6392\\u5E8F\\u7B97\\u6CD5\\u7684\\u7B2C\\u4E00\\u6B21\\u8FED\\u4EE3\\u63D2\\u56FE\"})}),`\n`,(0,t.jsx)(e.p,{children:\"\\u7136\\u540E\\uFF0C\\u8BE5\\u7B97\\u6CD5\\u7EE7\\u7EED\\u904D\\u5386\\u6570\\u7EC4\\u5E76\\u6BD4\\u8F83\\u76F8\\u90BB\\u7684\\u5BF9\\uFF0C\\u4F7F\\u5F97\\u7B2C\\u4E8C\\u4E2A\\u6700\\u5927\\u7684\\u5143\\u7D20\\u5C06\\u5728\\u5012\\u6570\\u7B2C\\u4E8C\\u4E2A\\u7D22\\u5F15\\u5904\\u3002\\u76F8\\u90BB\\u5BF9\\u7684\\u6BD4\\u8F83\\u53EF\\u4EE5\\u5FFD\\u7565\\u6700\\u540E\\u4E00\\u4E2A\\u5143\\u7D20\\uFF0C\\u56E0\\u4E3A\\u5B83\\u5DF2\\u7ECF\\u901A\\u8FC7\\u7B2C\\u4E00\\u6B21\\u8FED\\u4EE3\\u786E\\u8BA4\\u662F\\u6570\\u7EC4\\u4E2D\\u6700\\u5927\\u7684\\u5143\\u7D20\\u3002\"}),`\n`,(0,t.jsx)(e.p,{children:\"\\u4F8B\\u5982\\uFF0C\\u4ECE\\u4E0A\\u9762\\u7684\\u7B97\\u6CD5\\u7EE7\\u7EED\\uFF0C\\u8BE5\\u7B97\\u6CD5\\u5C06\\u8FDB\\u5165\\u7B2C 3 \\u6B21\\u8FED\\u4EE3\\uFF0C\\u6BD4\\u8F83\\u76F8\\u90BB\\u7684\\u5BF9\\uFF0C\\u540C\\u65F6\\u5FFD\\u7565\\u6700\\u540E\\u4E00\\u4E2A\\u548C\\u5012\\u6570\\u7B2C\\u4E8C\\u4E2A\\u5143\\u7D20\\uFF0C\\u56E0\\u4E3A\\u5B83\\u4EEC\\u5DF2\\u7ECF\\u6309\\u6B63\\u786E\\u7684\\u987A\\u5E8F\\u6392\\u5217\\u3002\"}),`\n`,(0,t.jsx)(e.p,{children:(0,t.jsx)(e.img,{src:\"/img/questions/bubble-sort/bubble-sort-subsequent-iteration.png\",alt:\"\\u5192\\u6CE1\\u6392\\u5E8F\\u7B97\\u6CD5\\u7684\\u540E\\u7EED\\u8FED\\u4EE3\\u63D2\\u56FE\"})})]})}function q(n={}){let{wrapper:e}=n.components||{};return e?(0,t.jsx)(e,Object.assign({},n,{children:(0,t.jsx)(a,n)})):a(n)}var M=q;return _(C);})();\n;return Component;", + "info": { + "excerpt": "实现一个执行冒泡排序的函数", + "title": "冒泡排序" + }, + "solution": "var Component=(()=>{var m=Object.create;var a=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var y=(n,r)=>()=>(r||n((r={exports:{}}).exports,r),r.exports),x=(n,r)=>{for(var t in r)a(n,t,{get:r[t],enumerable:!0})},h=(n,r,t,l)=>{if(r&&typeof r==\"object\"||typeof r==\"function\")for(let i of g(r))!b.call(n,i)&&i!==t&&a(n,i,{get:()=>r[i],enumerable:!(l=j(r,i))||l.enumerable});return n};var _=(n,r,t)=>(t=n!=null?m(f(n)):{},h(r||!n||!n.__esModule?a(t,\"default\",{value:n,enumerable:!0}):t,n)),D=n=>h(a({},\"__esModule\",{value:!0}),n);var c=y((F,o)=>{o.exports=_jsx_runtime});var A={};x(A,{default:()=>v});var e=_(c());var d=MDXCodeBlock;var s=`/**\n * @param {Array} arr The input integer array to be sorted.\n * @return {Array}\n */\nexport default function bubbleSort(arr) {\n // Do multiple iterations over the array.\n for (let i = 0; i < arr.length; i++) {\n // For each iteration, compare every adjacent pairs while ignoring the last i elements that are already sorted.\n for (let j = 0; j < arr.length - i; j++) {\n // If the left element in the pair is larger than the right one, swap their positions to ensure that elements are sorted ascendingly.\n if (arr[j] > arr[j + 1]) {\n let temp = arr[j];\n arr[j] = arr[j + 1];\n arr[j + 1] = temp;\n }\n }\n }\n\n // Return the sorted array.\n return arr;\n}\n`;var u=`export default function bubbleSort(arr: Array): Array {\n // Do multiple iterations over the array.\n for (let i: number = 0; i < arr.length; i++) {\n // For each iteration, compare every adjacent pairs while ignoring the last i elements that are already sorted.\n for (let j: number = 0; j < arr.length - i; j++) {\n // If the left element in the pair is larger than the right one, swap their positions to ensure that elements are sorted ascendingly.\n if (arr[j] > arr[j + 1]) {\n let temp: number = arr[j];\n arr[j] = arr[j + 1];\n arr[j + 1] = temp;\n }\n }\n }\n\n // Return the sorted array.\n return arr;\n}\n`;function p(n){let r=Object.assign({p:\"p\",h2:\"h2\",ul:\"ul\",li:\"li\",code:\"code\",pre:\"pre\",h3:\"h3\"},n.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(r.p,{children:\"\\u5192\\u6CE1\\u6392\\u5E8F\\u662F\\u4E00\\u79CD\\u7A33\\u5B9A\\u7684\\u3001\\u539F\\u5730\\u7684\\u3001\\u57FA\\u4E8E\\u6BD4\\u8F83\\u7684\\u7B97\\u6CD5\\uFF0C\\u9002\\u7528\\u4E8E\\u5C0F\\u578B\\u5230\\u4E2D\\u578B\\u6570\\u7EC4\\u4EE5\\u53CA\\u90E8\\u5206\\u6392\\u5E8F\\u7684\\u6570\\u7EC4\\u3002\"}),`\n`,(0,e.jsx)(r.h2,{children:\"\\u6F84\\u6E05\\u95EE\\u9898\"}),`\n`,(0,e.jsx)(r.p,{children:\"\\u5982\\u679C\\u672A\\u6307\\u5B9A\\uFF1A\"}),`\n`,(0,e.jsxs)(r.ul,{children:[`\n`,(0,e.jsx)(r.li,{children:\"\\u5E94\\u8BE5\\u6309\\u5347\\u5E8F\\u8FD8\\u662F\\u964D\\u5E8F\\u5BF9\\u6570\\u636E\\u8FDB\\u884C\\u6392\\u5E8F\\uFF1F\"}),`\n`,(0,e.jsxs)(r.li,{children:[\"\\u6211\\u4EEC\\u9700\\u8981\\u5904\\u7406\\u4EC0\\u4E48\\u6837\\u7684\\u8F93\\u5165\\uFF1F\",`\n`,(0,e.jsxs)(r.ul,{children:[`\n`,(0,e.jsx)(r.li,{children:\"\\u5B83\\u53EA\\u662F\\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4\\uFF0C\\u8FD8\\u662F\\u6211\\u4EEC\\u5E94\\u8BE5\\u5904\\u7406\\u5176\\u4ED6\\u6570\\u636E\\u7C7B\\u578B\\uFF1F\"}),`\n`,(0,e.jsx)(r.li,{children:\"\\u662F\\u5426\\u5B58\\u5728\\u5927\\u91CF\\u91CD\\u590D\\u5143\\u7D20\\uFF1F\"}),`\n`,(0,e.jsx)(r.li,{children:\"\\u5E94\\u8BE5\\u5982\\u4F55\\u5904\\u7406\\u8D1F\\u6570\\uFF1F\"}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,e.jsx)(r.h2,{children:\"\\u89E3\\u51B3\\u65B9\\u6848\"}),`\n`,(0,e.jsx)(r.p,{children:\"\\u6CE8\\u610F\\uFF1A\\u8FD9\\u4E2A\\u95EE\\u9898\\u5904\\u7406\\u7684\\u662F\\u539F\\u5730\\u6392\\u5E8F\\uFF0C\\u4EE5\\u5347\\u5E8F\\u8F93\\u51FA\\u3002\\u8BF7\\u53C2\\u9605\\u4E0B\\u9762\\u7684\\u201C\\u6CE8\\u91CA\\u201D\\u90E8\\u5206\\uFF0C\\u4E86\\u89E3\\u5982\\u4F55\\u5904\\u7406\\u5176\\u4ED6\\u60C5\\u51B5\\u3002\"}),`\n`,(0,e.jsx)(d,{languages:{jsx:s,tsx:u}}),`\n`,(0,e.jsx)(r.h2,{children:\"\\u8FB9\\u7F18\\u60C5\\u51B5\"}),`\n`,(0,e.jsxs)(r.ul,{children:[`\n`,(0,e.jsx)(r.li,{children:\"\\u975E\\u6574\\u6570\\u5143\\u7D20\\u8F93\\u5165\\uFF1A\\u5982\\u679C\\u8F93\\u5165\\u6570\\u7EC4\\u5305\\u542B\\u4E0D\\u540C\\u6570\\u636E\\u7C7B\\u578B\\u7684\\u5143\\u7D20\\uFF0C\\u60A8\\u53EF\\u80FD\\u9700\\u8981\\u8FD4\\u56DE\\u4E00\\u4E2A\\u9519\\u8BEF\\u6216\\u6EE1\\u8DB3\\u4E8E\\u5C3D\\u529B\\u6392\\u5E8F\\uFF0C\\u4F8B\\u5982\\uFF0C\\u4EC5\\u5BF9\\u8F93\\u5165\\u6570\\u636E\\u7684\\u5B50\\u96C6\\u8FDB\\u884C\\u6392\\u5E8F\\uFF0C\\u751A\\u81F3\\u4E3A\\u975E\\u6574\\u6570\\u5B9A\\u4E49\\u81EA\\u5B9A\\u4E49\\u6BD4\\u8F83\\u51FD\\u6570\\u3002\"}),`\n`,(0,e.jsx)(r.li,{children:\"\\u5355\\u4E2A\\u5143\\u7D20/\\u7A7A\\u8F93\\u5165\\uFF1A\\u8FD4\\u56DE\\u539F\\u59CB\\u6570\\u636E\\u7ED3\\u6784\\u3001\\u5F15\\u53D1\\u9519\\u8BEF\\u6216\\u6F84\\u6E05\\u6240\\u9700\\u5904\\u7406\\u3002\"}),`\n`,(0,e.jsx)(r.li,{children:\"\\u65E0\\u6548\\u8F93\\u5165\\uFF1A\\u5982\\u679C\\u8F93\\u5165\\u4E0D\\u662F\\u6570\\u7EC4\\uFF0C\\u8BF7\\u8003\\u8651\\u629B\\u51FA\\u9519\\u8BEF\\u3002\"}),`\n`]}),`\n`,(0,e.jsx)(r.h2,{children:\"\\u6CE8\\u91CA\"}),`\n`,(0,e.jsxs)(r.ul,{children:[`\n`,(0,e.jsxs)(r.li,{children:[\"\\u5982\\u679C\\u8981\\u6C42\\u4EE5\\u964D\\u5E8F\\u6392\\u5E8F\\uFF1A\\u53EA\\u9700\\u5C06\\u6BD4\\u8F83\\u66F4\\u6539\\u4E3A \",(0,e.jsx)(r.code,{children:\"<\"}),\" \\u800C\\u4E0D\\u662F \",(0,e.jsx)(r.code,{children:\">\"}),\"\\uFF0C\\u5982\\u4E0B\\u6240\\u793A\\uFF1A\"]}),`\n`]}),`\n`,(0,e.jsx)(r.pre,{children:(0,e.jsx)(r.code,{className:\"language-js\",children:`if (arr[j] < arr[j + 1])\n`})}),`\n`,(0,e.jsx)(r.h2,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsx)(r.p,{children:\"\\u8BA9\\u6211\\u4EEC\\u5206\\u6790\\u4E00\\u4E0B\\u7B97\\u6CD5\\u7684\\u65F6\\u95F4\\u548C\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u3002\"}),`\n`,(0,e.jsx)(r.h3,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\"}),`\n`,(0,e.jsxs)(r.p,{children:[\"\\u5BF9\\u4E8E\\u5192\\u6CE1\\u6392\\u5E8F\\uFF0C\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(n\",(0,e.jsx)(\"sup\",{children:\"2\"}),\")\\uFF0C\\u56E0\\u4E3A\\u5B83\\u9700\\u8981\\u4E00\\u4E2A\\u5D4C\\u5957\\u5FAA\\u73AF\\u7ED3\\u6784\\u3002\\u5916\\u5FAA\\u73AF\\u5BF9\\u6570\\u7EC4\\u8FDB\\u884C\\u591A\\u6B21\\u8FED\\u4EE3\\uFF0C\\u5185\\u5FAA\\u73AF\\u904D\\u5386\\u6570\\u7EC4\\u4EE5\\u6BD4\\u8F83\\u6BCF\\u4E2A\\u76F8\\u90BB\\u5BF9\\uFF0C\\u5E76\\u6839\\u636E\\u5B83\\u4EEC\\u7684\\u6B63\\u786E\\u987A\\u5E8F\\u4EA4\\u6362\\u5143\\u7D20\\u3002\"]}),`\n`,(0,e.jsx)(r.h3,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\"}),`\n`,(0,e.jsx)(r.p,{children:\"\\u5192\\u6CE1\\u6392\\u5E8F\\u7684\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(1)\\uFF0C\\u56E0\\u4E3A\\u5B83\\u8FDB\\u884C\\u539F\\u5730\\u6392\\u5E8F\\uFF0C\\u4E0D\\u9700\\u8981\\u4E0E\\u8F93\\u5165\\u5927\\u5C0F\\u6210\\u6BD4\\u4F8B\\u7684\\u989D\\u5916\\u5B58\\u50A8\\u3002\"})]})}function O(n={}){let{wrapper:r}=n.components||{};return r?(0,e.jsx)(r,Object.assign({},n,{children:(0,e.jsx)(p,n)})):p(n)}var v=O;return D(A);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/coin-change/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/coin-change/locales/zh-CN.json new file mode 100644 index 000000000..c89597262 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/coin-change/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var m=Object.create;var r=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var b=(t,n)=>()=>(n||t((n={exports:{}}).exports,n),n.exports),j=(t,n)=>{for(var i in n)r(t,i,{get:n[i],enumerable:!0})},l=(t,n,i,c)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let o of g(n))!x.call(t,o)&&o!==i&&r(t,o,{get:()=>n[o],enumerable:!(c=p(n,o))||c.enumerable});return t};var T=(t,n,i)=>(i=t!=null?m(f(t)):{},l(n||!t||!t.__esModule?r(i,\"default\",{value:t,enumerable:!0}):i,t)),_=t=>l(r({},\"__esModule\",{value:!0}),t);var a=b((X,s)=>{s.exports=_jsx_runtime});var C={};j(C,{default:()=>y,frontmatter:()=>v});var e=T(a());var h=MDXTestExamples;var d=[{input:[[\"coins\",[3,7,4]],[\"target\",14]],output:2,explanation:\"We can form the target amount (14) using the following combination of coins: 7 + 7. This requires a minimum of 2 coins.\"},{input:[[\"coins\",[1]],[\"target\",0]],output:0,explanation:\"The target amount is 0, which requires no coins to reach. Even though there's only a 1 coin available, you can still form 0 using no coins.\"},{input:[[\"coins\",[2]],[\"target\",3]],output:-1,explanation:\"The only available coin denomination is 2. However, it's impossible to form the target amount (3) using just multiples of 2. Therefore, no combination of coins can reach 3, and the output is -1.\"}];var v={title:\"\\u627E\\u96F6\\u6240\\u9700\\u7684\\u6700\\u5C11\\u786C\\u5E01\\u6570\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u8FD4\\u56DE\\u7EC4\\u6210\\u7ED9\\u5B9A\\u91D1\\u989D\\u6240\\u9700\\u7684\\u6700\\u5C11\\u786C\\u5E01\\u6570\"};function u(t){let n=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)(n.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4 \",(0,e.jsx)(n.code,{children:\"coins\"}),\"\\uFF0C\\u8868\\u793A\\u4E0D\\u540C\\u9762\\u989D\\u7684\\u786C\\u5E01\\uFF0C\\u4EE5\\u53CA\\u4E00\\u4E2A\\u6574\\u6570 \",(0,e.jsx)(n.code,{children:\"target\"}),\"\\uFF0C\\u8868\\u793A\\u603B\\u91D1\\u989D\\uFF0C\\u8FD4\\u56DE\\u7EC4\\u6210 \",(0,e.jsx)(n.code,{children:\"target\"}),\" \\u6240\\u9700\\u7684\\u6700\\u5C11\\u786C\\u5E01\\u6570\\u3002\\u5982\\u679C\\u65E0\\u6CD5\\u901A\\u8FC7\\u4EFB\\u4F55\\u786C\\u5E01\\u7EC4\\u5408\\u7EC4\\u6210 \",(0,e.jsx)(n.code,{children:\"target\"}),\"\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,e.jsx)(n.code,{children:\"-1\"}),\"\\u3002\"]}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5047\\u8BBE\\u6BCF\\u79CD\\u786C\\u5E01\\u90FD\\u6709\\u65E0\\u9650\\u4F9B\\u5E94\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"coins: number[]\"}),\": \\u6574\\u6570\\u6570\\u7EC4\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"target: number\"}),\": \\u6574\\u6570\"]}),`\n`]}),`\n`,(0,e.jsx)(h,{testCases:d}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"1 <= \",(0,e.jsx)(n.code,{children:\"coins.length\"}),\" <= 12\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"1 <= \",(0,e.jsx)(n.code,{children:\"coins[i]\"}),\" <= 1,000,000\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"0 <= \",(0,e.jsx)(n.code,{children:\"target\"}),\" <= 10,000\"]}),`\n`]})]})}function w(t={}){let{wrapper:n}=t.components||{};return n?(0,e.jsx)(n,Object.assign({},t,{children:(0,e.jsx)(u,t)})):u(t)}var y=w;return _(C);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,返回组成给定金额所需的最少硬币数", + "title": "找零所需的最少硬币数" + }, + "solution": "var Component=(()=>{var g=Object.create;var c=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var F=(i,n)=>()=>(n||i((n={exports:{}}).exports,n),n.exports),x=(i,n)=>{for(var r in n)c(i,r,{get:n[r],enumerable:!0})},l=(i,n,r,t)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let o of C(n))!b.call(i,o)&&o!==r&&c(i,o,{get:()=>n[o],enumerable:!(t=f(n,o))||t.enumerable});return i};var I=(i,n,r)=>(r=i!=null?g(p(i)):{},l(n||!i||!i.__esModule?c(r,\"default\",{value:i,enumerable:!0}):r,i)),O=i=>l(c({},\"__esModule\",{value:!0}),i);var m=F((w,h)=>{h.exports=_jsx_runtime});var X={};x(X,{default:()=>A});var e=I(m());var d=MDXCodeBlock;var a=`export default function minimumCoinsForChange(\n coins: number[],\n target: number,\n): number {\n // Initialize a dp array with a large value (Infinity)\n const dp: number[] = new Array(target + 1).fill(Number.MAX_VALUE);\n\n // Base case: 0 coins are needed to make amount 0\n dp[0] = 0;\n\n // Iterate over each amount from 1 to the target amount\n for (let i = 1; i <= target; i++) {\n // Check each coin to see if it can contribute to the current amount\n for (const coin of coins) {\n if (i - coin >= 0) {\n dp[i] = Math.min(dp[i], dp[i - coin] + 1);\n }\n }\n }\n\n // If the value at dp[amount] is still Infinity, return -1 (not possible)\n // Otherwise, return the minimum number of coins needed for the target amount\n return dp[target] === Number.MAX_VALUE ? -1 : dp[target];\n}\n`;var s=`function minimumCoinsForChangeHelper(coins: number[], target: number): number {\n // Base case: If the amount is 0, no coins are needed.\n if (target === 0) {\n return 0;\n }\n\n let minCoins = Infinity;\n\n // Try each coin denomination.\n for (const coin of coins) {\n // Check if the coin denomination is not greater than the amount.\n if (coin <= target) {\n // Recursively calculate the minimum coins needed for the remaining amount.\n const remainingCoins = minimumCoinsForChangeHelper(coins, target - coin);\n\n // If a valid solution is found and it requires fewer coins, update minCoins.\n if (remainingCoins !== -1 && remainingCoins + 1 < minCoins) {\n minCoins = remainingCoins + 1;\n }\n }\n }\n\n // If no valid solution was found, return -1. Otherwise, return the minimum coins.\n return minCoins === Infinity ? -1 : minCoins;\n}\n\nexport default function minimumCoinsForChange(\n coins: number[],\n target: number,\n): number {\n return minimumCoinsForChangeHelper(coins, target);\n}\n`;function u(i){let n=Object.assign({h2:\"h2\",p:\"p\",h3:\"h3\",ol:\"ol\",li:\"li\",code:\"code\",ul:\"ul\",strong:\"strong\"},i.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"1. \\u4F7F\\u7528\\u9012\\u5F52\\u7684\\u86EE\\u529B\\u65B9\\u6CD5\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u76EE\\u6807\\u662F\\u786E\\u5B9A\\u4F7F\\u7528\\u53EF\\u7528\\u7684\\u786C\\u5E01\\u9762\\u989D\\u7EC4\\u6210\\u7ED9\\u5B9A\\u76EE\\u6807\\u91D1\\u989D\\u6240\\u9700\\u7684\\u6700\\u5C11\\u786C\\u5E01\\u6570\\u91CF\\u3002\\u86EE\\u529B\\u65B9\\u6CD5\\u9012\\u5F52\\u5730\\u5C1D\\u8BD5\\u6BCF\\u4E00\\u79CD\\u53EF\\u80FD\\u7684\\u786C\\u5E01\\u7EC4\\u5408\\uFF0C\\u4EE5\\u627E\\u5230\\u786C\\u5E01\\u6700\\u5C11\\u7684\\u89E3\\u51B3\\u65B9\\u6848\\u3002\\u9012\\u5F52\\u63A2\\u7D22\\u51CF\\u5C11\\u76EE\\u6807\\u91D1\\u989D\\u5230\\u96F6\\u7684\\u6240\\u6709\\u6709\\u6548\\u65B9\\u6CD5\\uFF0C\\u5E76\\u8DDF\\u8E2A\\u6240\\u9700\\u7684\\u6700\\u5C11\\u786C\\u5E01\\u6570\\u91CF\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u8F85\\u52A9\\u51FD\\u6570\",(0,e.jsx)(n.code,{children:\"minimumCoinsForChangeHelper\"}),\"\\uFF0C\\u8BE5\\u51FD\\u6570\\u63A5\\u53D7\\u786C\\u5E01\\u6570\\u7EC4\\u548C\\u5269\\u4F59\\u7684\\u76EE\\u6807\\u91D1\\u989D\\u4F5C\\u4E3A\\u53C2\\u6570\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5982\\u679C\\u76EE\\u6807\\u91D1\\u989D\\u4E3A\",(0,e.jsx)(n.code,{children:\"0\"}),\"\\uFF0C\\u5219\\u8FD4\\u56DE\",(0,e.jsx)(n.code,{children:\"0\"}),\"\\uFF0C\\u56E0\\u4E3A\\u4E0D\\u9700\\u8981\\u786C\\u5E01\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5C06\\u53D8\\u91CF\",(0,e.jsx)(n.code,{children:\"minCoins\"}),\"\\u521D\\u59CB\\u5316\\u4E3A\",(0,e.jsx)(n.code,{children:\"Infinity\"}),\"\\uFF0C\\u4EE5\\u8DDF\\u8E2A\\u6240\\u9700\\u7684\\u6700\\u5C11\\u786C\\u5E01\\u6570\\u91CF\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u904D\\u5386\\u786C\\u5E01\\u6570\\u7EC4\\uFF1A\",`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u68C0\\u67E5\\u5F53\\u524D\\u786C\\u5E01\\u9762\\u989D\\u662F\\u5426\\u5C0F\\u4E8E\\u6216\\u7B49\\u4E8E\\u5269\\u4F59\\u7684\\u76EE\\u6807\\u91D1\\u989D\\u3002\"}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u9012\\u5F52\\u8C03\\u7528\\u8F85\\u52A9\\u51FD\\u6570\\uFF0C\\u4F20\\u5165\\u5269\\u4F59\\u91D1\\u989D\\uFF08\",(0,e.jsx)(n.code,{children:\"target - coin\"}),\"\\uFF09\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5982\\u679C\\u627E\\u5230\\u6709\\u6548\\u7684\\u89E3\\u51B3\\u65B9\\u6848\\u5E76\\u4E14\\u4F7F\\u7528\\u7684\\u786C\\u5E01\\u6570\\u91CF\\u5C0F\\u4E8E\",(0,e.jsx)(n.code,{children:\"minCoins\"}),\"\\uFF0C\\u5219\\u66F4\\u65B0\",(0,e.jsx)(n.code,{children:\"minCoins\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u904D\\u5386\\u6240\\u6709\\u786C\\u5E01\\u540E\\uFF0C\\u5982\\u679C\\u6CA1\\u6709\\u627E\\u5230\\u6709\\u6548\\u7684\\u89E3\\u51B3\\u65B9\\u6848\\uFF0C\\u5219\\u8FD4\\u56DE\",(0,e.jsx)(n.code,{children:\"-1\"}),\"\\uFF1B\\u5426\\u5219\\uFF0C\\u8FD4\\u56DE\",(0,e.jsx)(n.code,{children:\"minCoins\"}),\"\\u7684\\u503C\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4E3B\\u51FD\\u6570\",(0,e.jsx)(n.code,{children:\"minimumCoinsForChange\"}),\"\\u901A\\u8FC7\\u4F7F\\u7528\\u5B8C\\u6574\\u7684\\u76EE\\u6807\\u91D1\\u989D\\u8C03\\u7528\\u8F85\\u52A9\\u51FD\\u6570\\u6765\\u521D\\u59CB\\u5316\\u9012\\u5F52\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(d,{children:s}),`\n`,(0,e.jsx)(n.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsxs)(n.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(c\",(0,e.jsx)(\"sup\",{children:\"t\"}),\")\"]}),\"\\u3002 \\u9012\\u5F52\\u63A2\\u7D22\\u76EE\\u6807\\u91D1\\u989D\",(0,e.jsx)(n.code,{children:\"t\"}),\"\\u7684\\u6240\\u6709\",(0,e.jsx)(n.code,{children:\"c\"}),\"\\u786C\\u5E01\\u7EC4\\u5408\\uFF0C\\u5BFC\\u81F4\\u6307\\u6570\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(t)\"}),\"\\u3002 \\u9012\\u5F52\\u8C03\\u7528\\u6808\\u4E0E\\u76EE\\u6807\\u91D1\\u989D\",(0,e.jsx)(n.code,{children:\"t\"}),\"\\u6210\\u6B63\\u6BD4\\u589E\\u957F\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"2. \\u4F7F\\u7528\\u52A8\\u6001\\u89C4\\u5212\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u52A8\\u6001\\u89C4\\u5212\\u65B9\\u6CD5\\u901A\\u8FC7\\u907F\\u514D\\u5BF9\\u76F8\\u540C\\u5B50\\u95EE\\u9898\\u7684\\u91CD\\u590D\\u8BA1\\u7B97\\u6765\\u6539\\u8FDB\\u86EE\\u529B\\u89E3\\u51B3\\u65B9\\u6848\\u3002\\u8BE5\\u65B9\\u6CD5\\u6CA1\\u6709\\u9012\\u5F52\\u5730\\u89E3\\u51B3\\u6BCF\\u4E00\\u79CD\\u53EF\\u80FD\\u7684\\u786C\\u5E01\\u7EC4\\u5408\\uFF0C\\u800C\\u662F\\u4F7F\\u7528\",(0,e.jsx)(n.code,{children:\"dp\"}),\"\\u6570\\u7EC4\\u6765\\u5B58\\u50A8\\u7EC4\\u6210\\u4ECE\",(0,e.jsx)(n.code,{children:\"0\"}),\"\\u5230\\u76EE\\u6807\\u91D1\\u989D\\u6240\\u9700\\u7684\\u6700\\u5C11\\u786C\\u5E01\\u6570\\u91CF\\u3002\\u901A\\u8FC7\\u5EFA\\u7ACB\\u5728\\u5148\\u524D\\u8BA1\\u7B97\\u7684\\u503C\\u4E4B\\u4E0A\\uFF0C\\u8FED\\u4EE3\\u5730\\u8BA1\\u7B97\\u6BCF\\u4E2A\\u503C\\uFF0C\\u786E\\u4FDD\\u6BCF\\u4E2A\\u5B50\\u95EE\\u9898\\u53EA\\u89E3\\u51B3\\u4E00\\u6B21\\u3002\\u8FD9\\u6D88\\u9664\\u4E86\\u5197\\u4F59\\u5DE5\\u4F5C\\uFF0C\\u5E76\\u663E\\u7740\\u964D\\u4F4E\\u4E86\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u3002\"]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u5927\\u5C0F\\u4E3A\",(0,e.jsx)(n.code,{children:\"target + 1\"}),\"\\u7684\",(0,e.jsx)(n.code,{children:\"dp\"}),\"\\u6570\\u7EC4\\uFF0C\\u6240\\u6709\\u503C\\u90FD\\u8BBE\\u7F6E\\u4E3A\",(0,e.jsx)(n.code,{children:\"Number.MAX_VALUE\"}),\"\\uFF0C\\u4EE5\\u8868\\u793A\\u4E0D\\u53EF\\u8FBE\\u72B6\\u6001\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5C06\",(0,e.jsx)(n.code,{children:\"dp[0]\"}),\"\\u8BBE\\u7F6E\\u4E3A\",(0,e.jsx)(n.code,{children:\"0\"}),\"\\uFF0C\\u56E0\\u4E3A\\u4E0D\\u9700\\u8981\\u786C\\u5E01\\u6765\\u7EC4\\u6210\\u91D1\\u989D\",(0,e.jsx)(n.code,{children:\"0\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u8FED\\u4EE3\\u91D1\\u989D\\u4ECE\",(0,e.jsx)(n.code,{children:\"1\"}),\"\\u5230\",(0,e.jsx)(n.code,{children:\"target\"}),\"\\uFF1A\",`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u91D1\\u989D\\uFF0C\\u904D\\u5386\\u786C\\u5E01\\u5217\\u8868\\u3002\"}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5982\\u679C\\u5F53\\u524D\\u786C\\u5E01\\u53EF\\u4EE5\\u8D21\\u732E\\u5230\\u8BE5\\u91D1\\u989D\\uFF08\",(0,e.jsx)(n.code,{children:\"i - coin >= 0\"}),\"\\uFF09\\uFF0C\\u5219\\u4F7F\\u7528\\u5176\\u5F53\\u524D\\u503C\\u6216\",(0,e.jsx)(n.code,{children:\"dp[i - coin] + 1\"}),\"\\u7684\\u6700\\u5C0F\\u503C\\u6765\\u66F4\\u65B0\",(0,e.jsx)(n.code,{children:\"dp[i]\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u586B\\u5145\",(0,e.jsx)(n.code,{children:\"dp\"}),\"\\u6570\\u7EC4\\u540E\\uFF0C\\u68C0\\u67E5\",(0,e.jsx)(n.code,{children:\"dp[target]\"}),\"\\u5904\\u7684\\u503C\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5982\\u679C\\u5B83\\u4ECD\\u7136\\u662F\",(0,e.jsx)(n.code,{children:\"Number.MAX_VALUE\"}),\"\\uFF0C\\u5219\\u8FD4\\u56DE\",(0,e.jsx)(n.code,{children:\"-1\"}),\"\\uFF0C\\u56E0\\u4E3A\\u76EE\\u6807\\u91D1\\u989D\\u65E0\\u6CD5\\u5B9E\\u73B0\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5426\\u5219\\uFF0C\\u8FD4\\u56DE\",(0,e.jsx)(n.code,{children:\"dp[target]\"}),\"\\u4F5C\\u4E3A\\u6240\\u9700\\u7684\\u6700\\u5C11\\u786C\\u5E01\\u6570\\u91CF\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,e.jsx)(d,{children:a}),`\n`,(0,e.jsx)(n.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n.t)\"}),\"\\u3002 \\u904D\\u5386\",(0,e.jsx)(n.code,{children:\"target\"}),\"\\u91D1\\u989D\\u5E76\\u68C0\\u67E5\\u6BCF\\u4E2A\",(0,e.jsx)(n.code,{children:\"n\"}),\"\\u786C\\u5E01\\uFF0C\\u7ED3\\u679C\\u4E3AO(n.t)\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(t)\"}),\"\\u3002 \",(0,e.jsx)(n.code,{children:\"dp\"}),\"\\u6570\\u7EC4\\u6240\\u9700\\u7684\\u7A7A\\u95F4\\u4E0E\\u76EE\\u6807\\u91D1\\u989D\",(0,e.jsx)(n.code,{children:\"t\"}),\"\\u6210\\u6B63\\u6BD4\\u3002\"]}),`\n`]})]})}function M(i={}){let{wrapper:n}=i.components||{};return n?(0,e.jsx)(n,Object.assign({},i,{children:(0,e.jsx)(u,i)})):u(i)}var A=M;return O(X);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/combinations-target-sum/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/combinations-target-sum/locales/zh-CN.json new file mode 100644 index 000000000..02e98cc35 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/combinations-target-sum/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var m=Object.create;var l=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var f=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),j=(t,e)=>{for(var r in e)l(t,r,{get:e[r],enumerable:!0})},o=(t,e,r,c)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of b(e))!g.call(t,i)&&i!==r&&l(t,i,{get:()=>e[i],enumerable:!(c=p(e,i))||c.enumerable});return t};var _=(t,e,r)=>(r=t!=null?m(x(t)):{},o(e||!t||!t.__esModule?l(r,\"default\",{value:t,enumerable:!0}):r,t)),T=t=>o(l({},\"__esModule\",{value:!0}),t);var d=f((O,s)=>{s.exports=_jsx_runtime});var E={};j(E,{default:()=>X,frontmatter:()=>C});var n=_(d());var a=MDXTestExamples;var h=[{input:[[\"numbers\",[1,2,3]],[\"target\",4]],output:7,explanation:\"The possible combinations are: (1, 1, 1, 1), (1, 1, 2), (1, 2, 1), (1, 3), (2, 1, 1), (2, 2), (3, 1)\"},{input:[[\"numbers\",[7]],[\"target\",2]],output:0,explanation:\"There is no combination of elements in [7] that can add up to 2.\"},{input:[[\"numbers\",[2,4]],[\"target\",6]],output:3,explanation:\"The possible combinations are: (2, 2, 2), (2, 4), (4, 2)\"}];var C={title:\"\\u76EE\\u6807\\u548C\\u7684\\u7EC4\\u5408\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u8BA1\\u7B97\\u603B\\u548C\\u4E3A\\u76EE\\u6807\\u503C\\u7684\\u7EC4\\u5408\"};function u(t){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u552F\\u4E00\\u7684\\u6574\\u6570\\u5217\\u8868 \",(0,n.jsx)(e.code,{children:\"numbers\"}),\" \\u548C\\u4E00\\u4E2A\\u6574\\u6570 \",(0,n.jsx)(e.code,{children:\"target\"}),\"\\uFF0C\\u627E\\u5230 \",(0,n.jsx)(e.code,{children:\"numbers\"}),\" \\u4E2D\\u5143\\u7D20\\u7684\\u4E0D\\u540C\\u7EC4\\u5408\\u7684\\u6570\\u91CF\\uFF0C\\u8FD9\\u4E9B\\u7EC4\\u5408\\u52A0\\u8D77\\u6765\\u7B49\\u4E8E\\u76EE\\u6807\\u503C\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"numbers: number[]\"}),\": \\u6574\\u6570\\u6570\\u7EC4\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"target: number\"}),\": \\u4E00\\u4E2A\\u6574\\u6570\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u6CE8\\u610F\\u4E8B\\u9879\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u6D4B\\u8BD5\\u7528\\u4F8B\\u7ECF\\u8FC7\\u7CBE\\u5FC3\\u6311\\u9009\\uFF0C\\u4EE5\\u786E\\u4FDD\\u8F93\\u51FA\\u843D\\u5728 32 \\u4F4D\\u6574\\u6570\\u7684\\u9650\\u5236\\u8303\\u56F4\\u5185\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u7531\\u76F8\\u540C\\u5143\\u7D20\\u7EC4\\u6210\\u4F46\\u987A\\u5E8F\\u4E0D\\u540C\\u7684\\u7EC4\\u5408\\u88AB\\u8BA4\\u4E3A\\u662F\\u4E0D\\u540C\\u7684\"}),`\n`]}),`\n`,(0,n.jsx)(a,{testCases:h}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"numbers.length\"}),\" <= 200\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"numbers[i]\"}),\" <= 1000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"target\"}),\" <= 1000\"]}),`\n`,(0,n.jsx)(e.li,{children:\"numbers \\u7684\\u6240\\u6709\\u5143\\u7D20\\u90FD\\u662F\\u552F\\u4E00\\u7684\"}),`\n`]})]})}function D(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(u,t)})):u(t)}var X=D;return T(E);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来计算总和为目标值的组合", + "title": "目标和的组合" + }, + "solution": "var Component=(()=>{var b=Object.create;var c=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var x=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),y=(r,e)=>{for(var i in e)c(r,i,{get:e[i],enumerable:!0})},d=(r,e,i,l)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let t of p(e))!S.call(r,t)&&t!==i&&c(r,t,{get:()=>e[t],enumerable:!(l=g(e,t))||l.enumerable});return r};var w=(r,e,i)=>(i=r!=null?b(f(r)):{},d(e||!r||!r.__esModule?c(i,\"default\",{value:r,enumerable:!0}):i,r)),O=r=>d(c({},\"__esModule\",{value:!0}),r);var h=x((z,m)=>{m.exports=_jsx_runtime});var I={};y(I,{default:()=>D});var n=w(h());var o=MDXCodeBlock;var a=`export default function combinationTargetSum(\n numbers: number[],\n target: number,\n): number {\n // Initialize a dynamic programming (DP) array to store the number of\n // combinations for each sum up to the target\n const dp: number[] = new Array(target + 1).fill(0);\n\n // Base case: There's one way to reach a sum of 0 (using no elements)\n dp[0] = 1;\n\n // Iterate through all possible target sums from 1 to the actual target\n for (let combSum = 1; combSum <= target; combSum++) {\n // Iterate through each number in the 'nums' array\n for (const num of numbers) {\n // Check if the current number can be subtracted from the current target sum\n // without going below zero. This ensures we only consider valid combinations\n if (combSum - num >= 0) {\n // If valid, add the number of combinations for the remaining sum\n // (combSum - num) to the current sum's combination count. This leverages\n // previously calculated subproblems\n dp[combSum] += dp[combSum - num];\n }\n }\n }\n\n // The final element in the DP array (dp[target]) holds the number of\n // combinations that add up to the target sum\n return dp[target];\n}\n`;var u=`export default function combinationTargetSum(\n numbers: number[],\n target: number,\n): number {\n // Initialize the memoization map\n const memo = new Map();\n\n // Helper function for recursion with memoization\n function combs(remain: number): number {\n // Base case: if remaining target is 0, there is one valid combination\n if (remain === 0) return 1;\n // If the result for the current remaining target is already computed, return it\n if (memo.has(remain)) return memo.get(remain)!;\n\n let result = 0;\n // Iterate through the numbers to calculate combinations\n for (const num of numbers) {\n // Only proceed if the remaining target after subtracting the current number is non-negative\n if (remain - num >= 0) {\n result += combs(remain - num);\n }\n }\n // Store the computed result in the memoization map\n memo.set(remain, result);\n return result;\n }\n\n // Start the recursive function\n return combs(target);\n}\n`;function s(r){let e=Object.assign({h2:\"h2\",p:\"p\",h3:\"h3\",ol:\"ol\",li:\"li\",code:\"code\",ul:\"ul\",strong:\"strong\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u81EA\\u5E95\\u5411\\u4E0A\\u52A8\\u6001\\u89C4\\u5212\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u89E3\\u51B3\\u7EC4\\u5408\\u76EE\\u6807\\u548C\\u95EE\\u9898\\u7684\\u52A8\\u6001\\u89C4\\u5212\\u65B9\\u6CD5\\u901A\\u8FC7\\u5C06\\u95EE\\u9898\\u5206\\u89E3\\u4E3A\\u66F4\\u5C0F\\u7684\\u5B50\\u95EE\\u9898\\u6765\\u5DE5\\u4F5C\\u3002\\u5173\\u952E\\u7684\\u76F4\\u89C9\\u662F\\uFF0C\\u5B9E\\u73B0\\u7279\\u5B9A\\u548C\\u7684\\u65B9\\u6CD5\\u7684\\u6570\\u91CF\\u53EF\\u4EE5\\u4ECE\\u5B9E\\u73B0\\u66F4\\u5C0F\\u548C\\u7684\\u65B9\\u6CD5\\u7684\\u6570\\u91CF\\u63A8\\u5BFC\\u51FA\\u6765\\u3002\\u901A\\u8FC7\\u4ECE\\u6700\\u5C0F\\u7684\\u5B50\\u95EE\\u9898\\uFF08\\u548C\\u4E3A 0\\uFF09\\u5230\\u76EE\\u6807\\u548C\\u8FED\\u4EE3\\u5730\\u6784\\u5EFA\\u89E3\\u51B3\\u65B9\\u6848\\uFF0C\\u8BE5\\u7B97\\u6CD5\\u786E\\u4FDD\\u4E86\\u6240\\u6709\\u4E2D\\u95F4\\u7ED3\\u679C\\u90FD\\u88AB\\u91CD\\u7528\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u5BF9\\u4E8E\\u4ECE 1 \\u5230\\u76EE\\u6807\\u503C\\u7684\\u6BCF\\u4E2A\\u53EF\\u80FD\\u7684\\u548C\\uFF0C\\u90FD\\u4F1A\\u8003\\u8651\\u8F93\\u5165\\u6570\\u7EC4\\u4E2D\\u7684\\u6BCF\\u4E2A\\u6570\\u5B57\\u3002\\u5982\\u679C\\u8BE5\\u6570\\u5B57\\u53EF\\u4EE5\\u4ECE\\u5F53\\u524D\\u548C\\u4E2D\\u51CF\\u53BB\\u800C\\u4E0D\\u4F1A\\u5BFC\\u81F4\\u8D1F\\u503C\\uFF0C\\u5219\\u5C06\\u5269\\u4F59\\u548C\\u7684\\u7EC4\\u5408\\u6DFB\\u52A0\\u5230\\u5F53\\u524D\\u548C\\u7684\\u7EC4\\u5408\\u4E2D\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\\u6240\\u6709\\u5BF9\\u5F53\\u524D\\u548C\\u7684\\u6709\\u6548\\u8D21\\u732E\\u90FD\\u88AB\\u8003\\u8651\\u5728\\u5185\\u3002\\u57FA\\u672C\\u60C5\\u51B5\\u662F\\uFF0C\\u5F62\\u6210\\u548C\\u4E3A 0 \\u7684\\u65B9\\u6CD5\\u6070\\u597D\\u6709\\u4E00\\u79CD\\uFF08\\u4E0D\\u4F7F\\u7528\\u4EFB\\u4F55\\u5143\\u7D20\\uFF09\\uFF0C\\u8FD9\\u786E\\u4FDD\\u4E86\\u8BE5\\u8FC7\\u7A0B\\u6B63\\u786E\\u5F00\\u59CB\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u907F\\u514D\\u4E86\\u86EE\\u529B\\u89E3\\u51B3\\u65B9\\u6848\\u7684\\u4F4E\\u6548\\u7387\\uFF0C\\u86EE\\u529B\\u89E3\\u51B3\\u65B9\\u6848\\u4F1A\\u751F\\u6210\\u5E76\\u68C0\\u67E5\\u6570\\u7EC4\\u7684\\u6240\\u6709\\u53EF\\u80FD\\u5B50\\u96C6\\u3002\\u76F8\\u53CD\\uFF0C\\u5B83\\u901A\\u8FC7\\u4F7F\\u7528\\u5148\\u524D\\u8BA1\\u7B97\\u7684\\u7ED3\\u679C\\u6765\\u8FED\\u4EE3\\u5730\\u6784\\u5EFA\\u89E3\\u51B3\\u65B9\\u6848\\uFF0C\\u4ECE\\u800C\\u6D88\\u9664\\u4E86\\u5197\\u4F59\\u8BA1\\u7B97\\u5E76\\u663E\\u7740\\u964D\\u4F4E\\u4E86\\u8FD0\\u884C\\u65F6\\u590D\\u6742\\u5EA6\\u3002\"}),`\n`,(0,n.jsx)(o,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u5927\\u5C0F\\u4E3A \",(0,n.jsx)(e.code,{children:\"target + 1\"}),\" \\u7684 \",(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u6570\\u7EC4\\uFF0C\\u5E76\\u7528 \",(0,n.jsx)(e.code,{children:\"0\"}),\" \\u586B\\u5145\\u3002\\u6B64\\u6570\\u7EC4\\u5C06\\u5B58\\u50A8\\u4ECE \",(0,n.jsx)(e.code,{children:\"0\"}),\" \\u5230 \",(0,n.jsx)(e.code,{children:\"target\"}),\" \\u7684\\u6BCF\\u4E2A\\u548C\\u7684\\u7EC4\\u5408\\u6570\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8BBE\\u7F6E \",(0,n.jsx)(e.code,{children:\"dp[0] = 1\"}),\" \\u4EE5\\u8868\\u793A\\u57FA\\u672C\\u60C5\\u51B5\\uFF0C\\u5176\\u4E2D\\u5B9E\\u73B0\\u548C\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\" \\u7684\\u65B9\\u6CD5\\u6070\\u597D\\u6709\\u4E00\\u79CD\\uFF08\\u4E0D\\u4F7F\\u7528\\u4EFB\\u4F55\\u5143\\u7D20\\uFF09\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FED\\u4EE3\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u548C (\",(0,n.jsx)(e.code,{children:\"combSum\"}),\")\\uFF0C\\u4ECE \",(0,n.jsx)(e.code,{children:\"1\"}),\" \\u5230 \",(0,n.jsx)(e.code,{children:\"target\"}),\"\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u548C\\uFF0C\\u8FED\\u4EE3\\u8F93\\u5165\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"numbers\"}),\" \\u7684\\u5143\\u7D20\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u5F53\\u524D\\u6570\\u5B57\\u662F\\u5426\\u53EF\\u4EE5\\u4ECE \",(0,n.jsx)(e.code,{children:\"combSum\"}),\" \\u4E2D\\u51CF\\u53BB\\u800C\\u4E0D\\u4F1A\\u5BFC\\u81F4\\u8D1F\\u503C\\u3002\\u8FD9\\u786E\\u4FDD\\u53EA\\u8003\\u8651\\u6709\\u6548\\u7684\\u7EC4\\u5408\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u6709\\u6548\\uFF0C\\u901A\\u8FC7\\u6DFB\\u52A0 \",(0,n.jsx)(e.code,{children:\"dp[combSum - num]\"}),\" \\u7684\\u503C\\u6765\\u66F4\\u65B0 \",(0,n.jsx)(e.code,{children:\"dp[combSum]\"}),\"\\u3002\\u8FD9\\u4F1A\\u5C06\\u5B9E\\u73B0\\u5269\\u4F59\\u548C (\",(0,n.jsx)(e.code,{children:\"combSum - num\"}),\") \\u7684\\u65B9\\u6CD5\\u6570\\u6DFB\\u52A0\\u5230\\u5F53\\u524D\\u548C\\u7684\\u8BA1\\u6570\\u4E2D\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"dp[target]\"}),\"\\uFF0C\\u5B83\\u4FDD\\u5B58\\u5B9E\\u73B0\\u76EE\\u6807\\u548C\\u7684\\u4E0D\\u540C\\u7EC4\\u5408\\u7684\\u6570\\u91CF\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n.t)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u8FED\\u4EE3\\u4ECE \",(0,n.jsx)(e.code,{children:\"1\"}),\" \\u5230 \",(0,n.jsx)(e.code,{children:\"target\"}),\" \\u7684\\u6240\\u6709\\u548C\\uFF08\\u5916\\u5FAA\\u73AF\\uFF09\\uFF0C\\u5E76\\u5904\\u7406 \",(0,n.jsx)(e.code,{children:\"numbers\"}),\" \\u6570\\u7EC4\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5143\\u7D20\\uFF08\\u5185\\u5FAA\\u73AF\\uFF09\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(t)\"}),\"\\u3002\",(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u6570\\u7EC4\\u9700\\u8981\\u7684\\u7A7A\\u95F4\\u4E0E\\u76EE\\u6807\\u503C\\u6210\\u6B63\\u6BD4\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u81EA\\u9876\\u5411\\u4E0B\\u52A8\\u6001\\u89C4\\u5212\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u81EA\\u9876\\u5411\\u4E0B\\u52A8\\u6001\\u89C4\\u5212\\u65B9\\u6CD5\\u4F7F\\u7528\\u5E26\\u6709\\u8BB0\\u5FC6\\u7684\\u9012\\u5F52\\u3002\\u5173\\u952E\\u601D\\u60F3\\u662F\\u901A\\u8FC7\\u8003\\u8651\\u4ECE\\u6570\\u7EC4\\u4E2D\\u51CF\\u53BB\\u6BCF\\u4E2A\\u6570\\u5B57\\u540E\\u5269\\u4F59\\u7684\\u76EE\\u6807\\uFF0C\\u5C06\\u95EE\\u9898\\u5206\\u89E3\\u4E3A\\u66F4\\u5C0F\\u7684\\u5B50\\u95EE\\u9898\\u3002\\u5BF9\\u4E8E\\u7ED9\\u5B9A\\u7684\\u76EE\\u6807\\uFF0C\\u7EC4\\u5408\\u7684\\u6570\\u91CF\\u662F\\u53EF\\u4EE5\\u901A\\u8FC7\\u51CF\\u53BB\\u6BCF\\u4E2A\\u6570\\u5B57\\u5F62\\u6210\\u7684\\u8F83\\u5C0F\\u76EE\\u6807\\u7684\\u7EC4\\u5408\\u7684\\u603B\\u548C\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u907F\\u514D\\u4E86\\u91CD\\u65B0\\u8BA1\\u7B97\\u91CD\\u53E0\\u5B50\\u95EE\\u9898\\u7684\\u4F4E\\u6548\\u7387\\uFF0C\\u8FD9\\u662F\\u86EE\\u529B\\u9012\\u5F52\\u89E3\\u51B3\\u65B9\\u6848\\u4E2D\\u5E38\\u89C1\\u7684\\u74F6\\u9888\\u3002\\u8BB0\\u5FC6\\u5316\\u5C06\\u5148\\u524D\\u89E3\\u51B3\\u7684\\u5B50\\u95EE\\u9898\\u7684\\u7ED3\\u679C\\u5B58\\u50A8\\u5728\\u6620\\u5C04\\u4E2D\\uFF0C\\u5141\\u8BB8\\u5728\\u540E\\u7EED\\u8BA1\\u7B97\\u4E2D\\u8FDB\\u884C\\u6052\\u5B9A\\u65F6\\u95F4\\u68C0\\u7D22\\u3002\\u4E0E\\u6734\\u7D20\\u7684\\u9012\\u5F52\\u65B9\\u6CD5\\u76F8\\u6BD4\\uFF0C\\u8FD9\\u51CF\\u5C11\\u4E86\\u5197\\u4F59\\u8BA1\\u7B97\\u5E76\\u63D0\\u9AD8\\u4E86\\u6548\\u7387\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"memo\"}),\" \\u6620\\u5C04\\uFF0C\\u4EE5\\u5B58\\u50A8\\u6BCF\\u4E2A\\u5269\\u4F59\\u76EE\\u6807\\u7684\\u7EC4\\u5408\\u6570\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u9012\\u5F52\\u8F85\\u52A9\\u51FD\\u6570 \",(0,n.jsx)(e.code,{children:\"combs(remain)\"}),\"\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5 \",(0,n.jsx)(e.code,{children:\"remain\"}),\" \\u662F\\u5426\\u7B49\\u4E8E 0\\u3002\\u5982\\u679C\\u662F\\uFF0C\\u5219\\u8FD4\\u56DE 1\\uFF0C\\u56E0\\u4E3A\\u5B58\\u5728\\u4E00\\u4E2A\\u6709\\u6548\\u7684\\u7EC4\\u5408\\uFF08\\u4E0D\\u4F7F\\u7528\\u5176\\u4ED6\\u6570\\u5B57\\uFF09\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"memo\"}),\" \\u6620\\u5C04\\u5305\\u542B \",(0,n.jsx)(e.code,{children:\"remain\"}),\" \\u7684\\u7ED3\\u679C\\uFF0C\\u5219\\u8FD4\\u56DE\\u5B58\\u50A8\\u7684\\u503C\\u4EE5\\u907F\\u514D\\u5197\\u4F59\\u8BA1\\u7B97\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u53D8\\u91CF \",(0,n.jsx)(e.code,{children:\"result\"}),\" \\u4E3A 0\\uFF0C\\u4EE5\\u5B58\\u50A8\\u5F53\\u524D \",(0,n.jsx)(e.code,{children:\"remain\"}),\" \\u7684\\u7EC4\\u5408\\u6570\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FED\\u4EE3 \",(0,n.jsx)(e.code,{children:\"numbers\"}),\" \\u6570\\u7EC4\\u4E2D\\u7684\\u6BCF\\u4E2A\\u6570\\u5B57\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"remain - num\"}),\" \\u4E3A\\u975E\\u8D1F\\u6570\\uFF0C\\u5219\\u9012\\u5F52\\u8C03\\u7528 \",(0,n.jsx)(e.code,{children:\"combs(remain - num)\"}),\" \\u5E76\\u5C06\\u7ED3\\u679C\\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"result\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u8BA1\\u7B97\\u51FA\\u7684 \",(0,n.jsx)(e.code,{children:\"result\"}),\" \\u5B58\\u50A8\\u5728 \",(0,n.jsx)(e.code,{children:\"memo\"}),\" \\u6620\\u5C04\\u4E2D\\u4EE5\\u4F9B\\u5C06\\u6765\\u53C2\\u8003\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE\\u8C03\\u7528 \",(0,n.jsx)(e.code,{children:\"combs(target)\"}),\" \\u7684\\u7ED3\\u679C\\uFF0C\\u4F5C\\u4E3A\\u7ED9\\u5B9A\\u76EE\\u6807\\u7684\\u603B\\u7EC4\\u5408\\u6570\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(o,{children:u}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n.t)\"}),\"\\u3002\\u6BCF\\u4E2A\\u76EE\\u6807\\u503C\\u7684\\u5B50\\u95EE\\u9898\\u53EA\\u89E3\\u51B3\\u4E00\\u6B21\\uFF0C\\u89E3\\u51B3\\u6BCF\\u4E2A\\u95EE\\u9898\\u90FD\\u6D89\\u53CA\\u8FED\\u4EE3 \",(0,n.jsx)(e.code,{children:\"numbers\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(t)\"}),\"\\u3002\",(0,n.jsx)(e.code,{children:\"memo\"}),\" \\u6620\\u5C04\\u5B58\\u50A8\\u4E86\\u591A\\u8FBE \",(0,n.jsx)(e.code,{children:\"target\"}),\" \\u4E2A\\u4E0D\\u540C\\u503C\\u7684\\u7ED3\\u679C\\uFF0C\\u5E76\\u4E14\\u9012\\u5F52\\u5806\\u6808\\u5728\\u6700\\u574F\\u7684\\u60C5\\u51B5\\u4E0B\\u53EF\\u4EE5\\u6DF1\\u5165\\u5230 \",(0,n.jsx)(e.code,{children:\"target\"}),\"\\u3002\"]}),`\n`]})]})}function v(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(s,r)})):s(r)}var D=v;return O(I);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/count-ones-in-binary/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/count-ones-in-binary/locales/zh-CN.json new file mode 100644 index 000000000..bc6b9cdcb --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/count-ones-in-binary/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var r=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var g=(e,n)=>()=>(n||e((n={exports:{}}).exports,n),n.exports),j=(e,n)=>{for(var i in n)r(e,i,{get:n[i],enumerable:!0})},a=(e,n,i,s)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let o of x(n))!f.call(e,o)&&o!==i&&r(e,o,{get:()=>n[o],enumerable:!(s=d(n,o))||s.enumerable});return e};var _=(e,n,i)=>(i=e!=null?p(b(e)):{},a(n||!e||!e.__esModule?r(i,\"default\",{value:e,enumerable:!0}):i,e)),T=e=>a(r({},\"__esModule\",{value:!0}),e);var l=g((w,u)=>{u.exports=_jsx_runtime});var X={};j(X,{default:()=>D,frontmatter:()=>y});var t=_(l());var c=MDXTestExamples;var m=[{input:[[\"num\",8]],output:1,explanation:\"The given number in binary (1000) has a total of one set bit\"},{input:[[\"num\",9]],output:2,explanation:\"The given number in binary (1001) has a total of two set bit\"},{input:[[\"num\",123]],output:6,explanation:\"The given number in binary (1111011) has a total of six set bit\"}];var y={title:\"\\u8BA1\\u7B97\\u4E8C\\u8FDB\\u5236\\u6570\\u4E2D\\u7684\\u8BBE\\u7F6E\\u4F4D\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u67E5\\u627E\\u7ED9\\u5B9A\\u6574\\u6570\\u7684\\u4E8C\\u8FDB\\u5236\\u8868\\u793A\\u4E2D\\u7684\\u8BBE\\u7F6E\\u4F4D\"};function h(e){let n=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},e.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(n.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u6B63\\u6574\\u6570\",(0,t.jsx)(n.code,{children:\"num\"}),\"\\uFF0C\\u786E\\u5B9A\\u7ED9\\u5B9A\\u6570\\u5B57\\u7684\\u4E8C\\u8FDB\\u5236\\u8868\\u793A\\u4E2D\\u5B58\\u5728\\u7684\\u8BBE\\u7F6E\\u4F4D\\uFF081s\\uFF09\\u7684\\u6570\\u91CF\\uFF0C\\u901A\\u5E38\\u79F0\\u4E3A\\u6C49\\u660E\\u6743\\u91CD\\u3002\"]}),`\n`,(0,t.jsx)(n.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,t.jsxs)(n.ul,{children:[`\n`,(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:\"num: number\"}),\": \\u4E00\\u4E2A\\u6B63\\u6574\\u6570\"]}),`\n`]}),`\n`,(0,t.jsx)(c,{testCases:m}),`\n`,(0,t.jsx)(n.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,t.jsxs)(n.ul,{children:[`\n`,(0,t.jsxs)(n.li,{children:[\"1 <= \",(0,t.jsx)(n.code,{children:\"num\"}),\" <= 2^31 - 1\"]}),`\n`]})]})}function C(e={}){let{wrapper:n}=e.components||{};return n?(0,t.jsx)(n,Object.assign({},e,{children:(0,t.jsx)(h,e)})):h(e)}var D=C;return T(X);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来查找给定整数的二进制表示中的设置位", + "title": "计算二进制数中的设置位" + }, + "solution": "var Component=(()=>{var m=Object.create;var t=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty;var x=(i,n)=>()=>(n||i((n={exports:{}}).exports,n),n.exports),B=(i,n)=>{for(var r in n)t(i,r,{get:n[r],enumerable:!0})},o=(i,n,r,l)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let c of f(n))!p.call(i,c)&&c!==r&&t(i,c,{get:()=>n[c],enumerable:!(l=g(n,c))||l.enumerable});return i};var j=(i,n,r)=>(r=i!=null?m(b(i)):{},o(n||!i||!i.__esModule?t(r,\"default\",{value:i,enumerable:!0}):r,i)),O=i=>o(t({},\"__esModule\",{value:!0}),i);var h=x((X,d)=>{d.exports=_jsx_runtime});var M={};B(M,{default:()=>D});var e=j(h());var u=MDXCodeBlock;var s=`export default function countOnesInBinary(num: number): number {\n // Count the number of set bits using Brian Kernighan's algorithm\n let count: number = 0;\n while (num !== 0) {\n count += num & 1; // Check the least significant bit whether it is a set bit and update the counting result\n num >>>= 1; // Unsigned right shift by 1 bit\n }\n return count;\n}\n`;function a(i){let n=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},i.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"1. \\u4F7F\\u7528 Brian Kernighan \\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"Brian Kernighan \\u7B97\\u6CD5\\u7528\\u4E8E\\u904D\\u5386\\u6570\\u5B57\\u7684\\u4E8C\\u8FDB\\u5236\\u8868\\u793A\\u3002\\u8BE5\\u65B9\\u6CD5\\u4E0D\\u662F\\u76F4\\u63A5\\u904D\\u5386\\u6240\\u6709\\u4F4D\\uFF0C\\u800C\\u662F\\u5728\\u6BCF\\u6B21\\u8FED\\u4EE3\\u4E2D\\u68C0\\u67E5\\u6700\\u4F4E\\u6709\\u6548\\u4F4D\\uFF0C\\u5982\\u679C\\u8BE5\\u4F4D\\u4E3A \",(0,e.jsx)(n.code,{children:\"1\"}),\"\\uFF0C\\u5219\\u66F4\\u65B0\\u8BA1\\u6570\\uFF0C\\u7136\\u540E\\u8FDB\\u884C\\u53F3\\u79FB\\u4EE5\\u4E22\\u5F03\\u6700\\u4F4E\\u6709\\u6548\\u4F4D\\u3002\\u6B64\\u8FC7\\u7A0B\\u5C06\\u6301\\u7EED\\u5230\\u6240\\u6709\\u4F4D\\u90FD\\u88AB\\u5904\\u7406\\u3002\"]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u53D8\\u91CF \",(0,e.jsx)(n.code,{children:\"count\"}),\"\\uFF0C\\u7528\\u4E8E\\u5B58\\u50A8\\u5728\\u4E8C\\u8FDB\\u5236\\u8868\\u793A\\u4E2D\\u9047\\u5230\\u7684 \",(0,e.jsx)(n.code,{children:\"1\"}),\" \\u7684\\u6570\\u91CF\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528\\u5FAA\\u73AF\\u5904\\u7406\\u8F93\\u5165\\u6570\\u5B57\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528\\u6570\\u5B57\\u548C \",(0,e.jsx)(n.code,{children:\"1\"}),\" \\u4E4B\\u95F4\\u7684\\u6309\\u4F4D \",(0,e.jsx)(n.code,{children:\"AND\"}),\" \\u8FD0\\u7B97\\u6765\\u68C0\\u67E5\\u6700\\u4F4E\\u6709\\u6548\\u4F4D\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5982\\u679C\\u6700\\u4F4E\\u6709\\u6548\\u4F4D\\u662F \",(0,e.jsx)(n.code,{children:\"1\"}),\"\\uFF0C\\u5219\\u9012\\u589E \",(0,e.jsx)(n.code,{children:\"count\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5BF9\\u6570\\u5B57\\u8FDB\\u884C\\u65E0\\u7B26\\u53F7\\u53F3\\u79FB \",(0,e.jsx)(n.code,{children:\"1\"}),\" \\u4F4D\\uFF0C\\u4EE5\\u4E22\\u5F03\\u6700\\u4F4E\\u6709\\u6548\\u4F4D\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u7EE7\\u7EED\\u5FAA\\u73AF\\uFF0C\\u76F4\\u5230\\u6570\\u5B57\\u53D8\\u4E3A \",(0,e.jsx)(n.code,{children:\"0\"}),\"\\uFF0C\\u8FD9\\u610F\\u5473\\u7740\\u6240\\u6709\\u4F4D\\u90FD\\u5DF2\\u5904\\u7406\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u8FD4\\u56DE \",(0,e.jsx)(n.code,{children:\"count\"}),\" \\u7684\\u503C\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(u,{children:s}),`\n`,(0,e.jsx)(n.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u8F93\\u5165\\u6570\\u5B57\\u662F\\u4E00\\u4E2A 32 \\u4F4D\\u6574\\u6570\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u4F7F\\u7528\\u6052\\u5B9A\\u7684\\u7A7A\\u95F4\\u91CF\\uFF0C\\u4E0E\\u8F93\\u5165\\u5927\\u5C0F\\u65E0\\u5173\\u3002\"]}),`\n`]})]})}function C(i={}){let{wrapper:n}=i.components||{};return n?(0,e.jsx)(n,Object.assign({},i,{children:(0,e.jsx)(a,i)})):a(i)}var D=C;return O(M);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/course-dependency/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/course-dependency/locales/zh-CN.json new file mode 100644 index 000000000..fb88c3827 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/course-dependency/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var i=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var q=(c,e)=>()=>(e||c((e={exports:{}}).exports,e),e.exports),g=(c,e)=>{for(var n in e)i(c,n,{get:e[n],enumerable:!0})},t=(c,e,n,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let s of b(e))!x.call(c,s)&&s!==n&&i(c,s,{get:()=>e[s],enumerable:!(o=m(e,s))||o.enumerable});return c};var T=(c,e,n)=>(n=c!=null?p(f(c)):{},t(e||!c||!c.__esModule?i(n,\"default\",{value:c,enumerable:!0}):n,c)),j=c=>t(i({},\"__esModule\",{value:!0}),c);var l=q((X,d)=>{d.exports=_jsx_runtime});var C={};g(C,{default:()=>M,frontmatter:()=>w});var r=T(l());var u=MDXTestExamples;var h=[{input:[[\"courses\",4],[\"prerequisites\",[[1,0],[2,1],[3,2],[1,3]]]],output:!1,explanation:\"There are 4 courses labeled from 0 to 3. The prerequisite relationships are as follows: course 1 requires course 0 to be completed first, course 2 requires course 1, course 3 requires course 2, and course 1 requires course 3. This creates a circular dependency: course 1 depends on course 3, which in turn depends on course 2, which then depends on course 1 again. Since it is impossible to break this cycle and complete all courses, the output is false.\"},{input:[[\"courses\",2],[\"prerequisites\",[[1,0]]]],output:!0,explanation:\"The prerequisite [1, 0] indicates that course 0 must be completed before course 1. Since there are no other dependencies or cycles, it is straightforward to complete the courses in the order: course 0, then course 1. Therefore, the output is true.\"}];var w={title:\"\\u8BFE\\u7A0B\\u4F9D\\u8D56\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u7528\\u4E8E\\u68C0\\u67E5\\u5728\\u7ED9\\u5B9A\\u5148\\u51B3\\u6761\\u4EF6\\u7684\\u60C5\\u51B5\\u4E0B\\u662F\\u5426\\u53EF\\u4EE5\\u5B8C\\u6210\\u6240\\u6709\\u8BFE\\u7A0B\"};function a(c){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},c.components);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(e.p,{children:[\"\\u6709\\u4E00\\u7EC4\\u8BFE\\u7A0B\\uFF0C\\u7F16\\u53F7\\u4ECE\",(0,r.jsx)(e.code,{children:\"0\"}),\"\\u5230\",(0,r.jsx)(e.code,{children:\"courses - 1\"}),\"\\u3002\\u6BCF\\u95E8\\u8BFE\\u7A0B\\u53EF\\u80FD\\u6709\\u5148\\u51B3\\u6761\\u4EF6\\uFF0C\\u8FD9\\u4E9B\\u5148\\u51B3\\u6761\\u4EF6\\u51B3\\u5B9A\\u4E86\\u5FC5\\u987B\\u4FEE\\u8BFB\\u8BFE\\u7A0B\\u7684\\u987A\\u5E8F\\u3002\\u8FD9\\u4E9B\\u5148\\u51B3\\u6761\\u4EF6\\u4EE5\\u5BF9\\u5217\\u8868\\u7684\\u5F62\\u5F0F\\u7ED9\\u51FA\\uFF0C\\u5176\\u4E2D\\u6BCF\\u5BF9\",(0,r.jsx)(e.code,{children:\"[a, b]\"}),\"\\u8868\\u793A\\u5FC5\\u987B\\u5728\\u8BFE\\u7A0B\",(0,r.jsx)(e.code,{children:\"a\"}),\"\\u4E4B\\u524D\\u5B8C\\u6210\\u8BFE\\u7A0B\",(0,r.jsx)(e.code,{children:\"b\"}),\"\\u3002\"]}),`\n`,(0,r.jsxs)(e.p,{children:[\"\\u786E\\u5B9A\\u662F\\u5426\\u53EF\\u4EE5\\u5728\\u4E0D\\u8FDD\\u53CD\\u4EFB\\u4F55\\u5148\\u51B3\\u6761\\u4EF6\\u7EA6\\u675F\\u7684\\u60C5\\u51B5\\u4E0B\\u5B8C\\u6210\\u6240\\u6709\\u8BFE\\u7A0B\\u3002\\u5982\\u679C\\u53EF\\u4EE5\\u5B8C\\u6210\\u6240\\u6709\\u8BFE\\u7A0B\\uFF0C\\u5219\\u8FD4\\u56DE\",(0,r.jsx)(e.code,{children:\"true\"}),\"\\uFF1B\\u5426\\u5219\\uFF0C\\u8FD4\\u56DE\",(0,r.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`,(0,r.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"courses: number\"}),\": \\u4E00\\u4E2A\\u6574\\u6570\\uFF0C\\u8868\\u793A\\u8BFE\\u7A0B\\u7684\\u603B\\u6570\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"prerequisites: Array<[number, number]>\"}),\": \\u4E00\\u4E2A\\u4E8C\\u7EF4\\u6570\\u7EC4\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u5143\\u7D20\",(0,r.jsx)(e.code,{children:\"[a, b]\"}),\"\\u8868\\u793A\\u8BFE\\u7A0B\",(0,r.jsx)(e.code,{children:\"b\"}),\"\\u662F\\u8BFE\\u7A0B\",(0,r.jsx)(e.code,{children:\"a\"}),\"\\u7684\\u5148\\u51B3\\u6761\\u4EF6\"]}),`\n`]}),`\n`,(0,r.jsx)(u,{testCases:h}),`\n`,(0,r.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"1 <= \",(0,r.jsx)(e.code,{children:\"courses\"}),\" <= 1000\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"0 <= \",(0,r.jsx)(e.code,{children:\"prerequisites.length\"}),\" <= 1000\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"prerequisites[i].length\"}),\" == 2\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"0 <= \",(0,r.jsx)(e.code,{children:\"a\"}),\", \",(0,r.jsx)(e.code,{children:\"b\"}),\" < courses\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"prerequisites\"}),\"\\u4E2D\\u7684\\u6240\\u6709\\u5BF9\",(0,r.jsx)(e.code,{children:\"[a, b]\"}),\"\\u90FD\\u662F\\u552F\\u4E00\\u7684\"]}),`\n`]})]})}function y(c={}){let{wrapper:e}=c.components||{};return e?(0,r.jsx)(e,Object.assign({},c,{children:(0,r.jsx)(a,c)})):a(c)}var M=y;return j(C);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,用于检查在给定先决条件的情况下是否可以完成所有课程", + "title": "课程依赖" + }, + "solution": "var Component=(()=>{var p=Object.create;var d=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var j=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),q=(i,e)=>{for(var r in e)d(i,r,{get:e[r],enumerable:!0})},t=(i,e,r,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let c of m(e))!v.call(i,c)&&c!==r&&d(i,c,{get:()=>e[c],enumerable:!(o=g(e,c))||o.enumerable});return i};var k=(i,e,r)=>(r=i!=null?p(b(i)):{},t(e||!i||!i.__esModule?d(r,\"default\",{value:i,enumerable:!0}):r,i)),S=i=>t(d({},\"__esModule\",{value:!0}),i);var h=j((B,s)=>{s.exports=_jsx_runtime});var x={};q(x,{default:()=>w});var n=k(h());var l=MDXCodeBlock;var a=`export default function canCompleteCourse(\n courses: number,\n prerequisites: number[][],\n): boolean {\n const indegree: number[] = new Array(courses).fill(0);\n const adj: number[][] = new Array(courses).fill(0).map(() => []);\n\n // Build the adjacency list and the indegree array\n for (const prerequisite of prerequisites) {\n adj[prerequisite[1]].push(prerequisite[0]);\n indegree[prerequisite[0]]++;\n }\n\n const queue: number[] = [];\n // Push all the nodes with indegree zero into the queue.\n for (let i = 0; i < courses; i++) {\n if (indegree[i] === 0) {\n queue.push(i);\n }\n }\n\n let nodesVisited = 0;\n // Process the queue\n while (queue.length > 0) {\n const node = queue.shift()!;\n nodesVisited++;\n\n for (const neighbor of adj[node]) {\n // Decrease the indegree of the neighbor\n indegree[neighbor]--;\n if (indegree[neighbor] === 0) {\n queue.push(neighbor);\n }\n }\n }\n\n // If we visited all the courses, return true\n return nodesVisited === courses;\n}\n`;var u=`/**\n * Performs a depth-first search to detect cycles in the graph.\n * @param node - The current node being visited.\n * @param adj - The adjacency list representing the graph.\n * @param visit - Array to track visited nodes.\n * @param inStack - Array to track nodes in the current recursion stack.\n * @returns True if a cycle is detected, false otherwise.\n */\nfunction dfs(\n node: number,\n adj: number[][],\n visit: boolean[],\n inStack: boolean[],\n): boolean {\n // If the node is already in the stack, we have a cycle.\n if (inStack[node]) {\n return true;\n }\n // If the node is already visited, no need to visit it again.\n if (visit[node]) {\n return false;\n }\n // Mark the current node as visited and part of the current recursion stack.\n visit[node] = true;\n inStack[node] = true;\n // Visit all the neighbors of the current node.\n for (const neighbor of adj[node]) {\n if (dfs(neighbor, adj, visit, inStack)) {\n return true;\n }\n }\n // Remove the node from the recursion stack.\n inStack[node] = false;\n return false;\n}\n\n/**\n * Determines if it is possible to finish all courses given the prerequisites.\n * @param courses - The total number of courses.\n * @param prerequisites - The list of prerequisite pairs.\n * @returns True if it is possible to finish all courses, false otherwise.\n */\nexport default function canCompleteCourse(\n courses: number,\n prerequisites: number[][],\n): boolean {\n const adj: number[][] = Array.from({ length: courses }, () => []);\n\n // Build the adjacency list from the prerequisites.\n for (const prerequisite of prerequisites) {\n adj[prerequisite[1]].push(prerequisite[0]);\n }\n\n const visit: boolean[] = new Array(courses).fill(false);\n const inStack: boolean[] = new Array(courses).fill(false);\n\n // Perform DFS for each course to check for cycles.\n for (let i = 0; i < courses; i++) {\n if (dfs(i, adj, visit, inStack)) {\n return false;\n }\n }\n\n return true;\n}\n`;function f(i){let e=Object.assign({h2:\"h2\",p:\"p\",ul:\"ul\",li:\"li\",h3:\"h3\",ol:\"ol\",code:\"code\",strong:\"strong\"},i.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. Kahn's Topological Sort\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u95EE\\u9898\\u6D89\\u53CA\\u786E\\u5B9A\\u662F\\u5426\\u53EF\\u4EE5\\u5728\\u7ED9\\u5B9A\\u4E00\\u7EC4\\u5148\\u51B3\\u6761\\u4EF6\\u7684\\u60C5\\u51B5\\u4E0B\\u5B8C\\u6210\\u6240\\u6709\\u8BFE\\u7A0B\\u3002\\u8FD9\\u662F\\u4E00\\u4E2A\\u7ECF\\u5178\\u7684\\u6709\\u5411\\u56FE\\u5FAA\\u73AF\\u68C0\\u6D4B\\u95EE\\u9898\\u3002\\u5982\\u679C\\u5B58\\u5728\\u5FAA\\u73AF\\uFF0C\\u5219\\u65E0\\u6CD5\\u5B8C\\u6210\\u6240\\u6709\\u8BFE\\u7A0B\\u3002Kahn \\u7B97\\u6CD5\\u662F\\u4E00\\u79CD\\u62D3\\u6251\\u6392\\u5E8F\\u65B9\\u6CD5\\uFF0C\\u7528\\u4E8E\\u901A\\u8FC7\\u7CFB\\u7EDF\\u5730\\u5220\\u9664\\u6CA1\\u6709\\u4F20\\u5165\\u8FB9\\u7684\\u8282\\u70B9\\u6765\\u89E3\\u51B3\\u8BE5\\u95EE\\u9898\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u5173\\u952E\\u601D\\u60F3\\u662F\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u4F7F\\u7528\\u90BB\\u63A5\\u8868\\u6784\\u5EFA\\u56FE\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8DDF\\u8E2A\\u6BCF\\u95E8\\u8BFE\\u7A0B\\u7684\\u5148\\u51B3\\u6761\\u4EF6\\uFF08\\u5165\\u5EA6\\uFF09\\u7684\\u6570\\u91CF\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u4ECE\\u6CA1\\u6709\\u5148\\u51B3\\u6761\\u4EF6\\u7684\\u8BFE\\u7A0B\\u5F00\\u59CB\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5904\\u7406\\u6BCF\\u95E8\\u8BFE\\u7A0B\\uFF0C\\u51CF\\u5C11\\u5176\\u90BB\\u5C45\\u7684\\u5165\\u5EA6\\u3002\\u5982\\u679C\\u90BB\\u5C45\\u7684\\u5165\\u5EA6\\u53D8\\u4E3A 0\\uFF0C\\u5219\\u5C06\\u5176\\u6DFB\\u52A0\\u5230\\u5904\\u7406\\u961F\\u5217\\u4E2D\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u6240\\u6709\\u8BFE\\u7A0B\\u90FD\\u5DF2\\u5904\\u7406\\u5B8C\\u6BD5\\uFF0C\\u800C\\u6CA1\\u6709\\u4EFB\\u4F55\\u672A\\u8BBF\\u95EE\\u7684\\u8282\\u70B9\\uFF0C\\u5219\\u8868\\u793A\\u6CA1\\u6709\\u5FAA\\u73AF\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"indegree\"}),\" \\u6570\\u7EC4\\uFF0C\\u4EE5\\u8BA1\\u7B97\\u6BCF\\u95E8\\u8BFE\\u7A0B\\u7684\\u5148\\u51B3\\u6761\\u4EF6\\u6570\\u91CF\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u90BB\\u63A5\\u8868 (\",(0,n.jsx)(e.code,{children:\"adj\"}),\") \\u6765\\u8868\\u793A\\u6709\\u5411\\u56FE\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u8FED\\u4EE3\\u5148\\u51B3\\u6761\\u4EF6\\u6765\\u586B\\u5145\\u90BB\\u63A5\\u8868\\u548C \",(0,n.jsx)(e.code,{children:\"indegree\"}),\" \\u6570\\u7EC4\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u5BF9 \",(0,n.jsx)(e.code,{children:\"[a, b]\"}),\"\\uFF0C\\u5728 \",(0,n.jsx)(e.code,{children:\"adj\"}),\" \\u4E2D\\u5C06 \",(0,n.jsx)(e.code,{children:\"a\"}),\" \\u6DFB\\u52A0\\u4E3A \",(0,n.jsx)(e.code,{children:\"b\"}),\" \\u7684\\u90BB\\u5C45\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u589E\\u52A0 \",(0,n.jsx)(e.code,{children:\"a\"}),\" \\u7684\\u5165\\u5EA6\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u961F\\u5217\\uFF0C\\u5E76\\u5C06\\u6240\\u6709 \",(0,n.jsx)(e.code,{children:\"indegree\"}),\" \\u4E3A 0 \\u7684\\u8BFE\\u7A0B\\u6DFB\\u52A0\\u5230\\u961F\\u5217\\u4E2D\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u8BA1\\u6570\\u5668 \",(0,n.jsx)(e.code,{children:\"nodesVisited\"}),\" \\u6765\\u8DDF\\u8E2A\\u5DF2\\u5904\\u7406\\u7684\\u8BFE\\u7A0B\\u6570\\u91CF\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u6267\\u884C BFS\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u961F\\u5217\\u4E2D\\u5220\\u9664\\u4E00\\u95E8\\u8BFE\\u7A0B\\u5E76\\u589E\\u52A0 \",(0,n.jsx)(e.code,{children:\"nodesVisited\"}),\"\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5BF9\\u4E8E\\u5F53\\u524D\\u8BFE\\u7A0B\\u7684\\u6BCF\\u4E2A\\u90BB\\u5C45\\uFF0C\\u51CF\\u5C11\\u5176\\u5165\\u5EA6\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u90BB\\u5C45\\u7684\\u5165\\u5EA6\\u53D8\\u4E3A 0\\uFF0C\\u5219\\u5C06\\u5176\\u6DFB\\u52A0\\u5230\\u961F\\u5217\\u4E2D\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5904\\u7406\\u5B8C\\u6240\\u6709\\u8282\\u70B9\\u540E\\uFF0C\\u68C0\\u67E5 \",(0,n.jsx)(e.code,{children:\"nodesVisited\"}),\" \\u662F\\u5426\\u7B49\\u4E8E\\u8BFE\\u7A0B\\u603B\\u6570\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u4E3A\\u771F\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\uFF08\\u6240\\u6709\\u8BFE\\u7A0B\\u90FD\\u53EF\\u4EE5\\u5B8C\\u6210\\uFF09\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5426\\u5219\\uFF0C\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\uFF08\\u5B58\\u5728\\u5FAA\\u73AF\\uFF09\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(l,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(v + e)\"}),\"\\u3002\\u56FE\\u5728 O(e) \\u4E2D\\u6784\\u5EFA\\uFF0C\\u5176\\u4E2D \",(0,n.jsx)(e.code,{children:\"e\"}),\" \\u662F\\u5148\\u51B3\\u6761\\u4EF6\\u7684\\u6570\\u91CF\\u3002BFS \\u904D\\u5386\\u6BCF\\u4E2A\\u8BFE\\u7A0B\\u548C\\u8FB9\\u4E00\\u6B21\\uFF0C\\u9700\\u8981 O(v + e)\\uFF0C\\u5176\\u4E2D \",(0,n.jsx)(e.code,{children:\"v\"}),\" \\u662F\\u8BFE\\u7A0B\\u7684\\u6570\\u91CF\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(v + e)\"}),\"\\u3002\\u90BB\\u63A5\\u8868\\u548C\\u961F\\u5217\\u9700\\u8981 O(v + e) \\u7A7A\\u95F4\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528 DFS\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u95EE\\u9898\\u6D89\\u53CA\\u786E\\u5B9A\\u662F\\u5426\\u53EF\\u4EE5\\u5728\\u7ED9\\u5B9A\\u4E00\\u7EC4\\u5148\\u51B3\\u6761\\u4EF6\\u7684\\u60C5\\u51B5\\u4E0B\\u5B8C\\u6210\\u6240\\u6709\\u8BFE\\u7A0B\\u3002\\u8FD9\\u662F\\u4E00\\u4E2A\\u6709\\u5411\\u56FE\\u4E2D\\u7684\\u56FE\\u5FAA\\u73AF\\u68C0\\u6D4B\\u95EE\\u9898\\u3002\\u5982\\u679C\\u5B58\\u5728\\u5FAA\\u73AF\\uFF0C\\u5219\\u5E76\\u975E\\u6240\\u6709\\u8BFE\\u7A0B\\u90FD\\u53EF\\u4EE5\\u5B8C\\u6210\\uFF0C\\u56E0\\u4E3A\\u81F3\\u5C11\\u6709\\u4E00\\u95E8\\u8BFE\\u7A0B\\u76F4\\u63A5\\u6216\\u95F4\\u63A5\\u4F9D\\u8D56\\u4E8E\\u81EA\\u8EAB\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u7B97\\u6CD5\\u4F7F\\u7528\\u6DF1\\u5EA6\\u4F18\\u5148\\u641C\\u7D22 (DFS) \\u6765\\u68C0\\u6D4B\\u5FAA\\u73AF\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u6BCF\\u95E8\\u8BFE\\u7A0B\\u90FD\\u8868\\u793A\\u4E3A\\u56FE\\u4E2D\\u7684\\u4E00\\u4E2A\\u8282\\u70B9\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5148\\u51B3\\u6761\\u4EF6\\u8868\\u793A\\u4E3A\\u8282\\u70B9\\u4E4B\\u95F4\\u7684\\u6709\\u5411\\u8FB9\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5728 DFS \\u671F\\u95F4\\uFF0C\\u8282\\u70B9\\u88AB\\u6807\\u8BB0\\u4E3A\\u5DF2\\u8BBF\\u95EE\\u5E76\\u6DFB\\u52A0\\u5230\\u9012\\u5F52\\u5806\\u6808 (\",(0,n.jsx)(e.code,{children:\"inStack\"}),\") \\u4E2D\\u4EE5\\u68C0\\u6D4B\\u5FAA\\u73AF\\u3002\\u5982\\u679C\\u5728\\u9012\\u5F52\\u5806\\u6808\\u4E2D\\u91CD\\u65B0\\u8BBF\\u95EE\\u4E00\\u4E2A\\u8282\\u70B9\\uFF0C\\u5219\\u68C0\\u6D4B\\u5230\\u5FAA\\u73AF\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u5728\\u8BBF\\u95EE\\u6240\\u6709\\u8282\\u70B9\\u540E\\u672A\\u627E\\u5230\\u5FAA\\u73AF\\uFF0C\\u5219\\u53EF\\u4EE5\\u5B8C\\u6210\\u6240\\u6709\\u8BFE\\u7A0B\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u90BB\\u63A5\\u8868 \",(0,n.jsx)(e.code,{children:\"adj\"}),\" \\u6765\\u8868\\u793A\\u56FE\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u8FED\\u4EE3 \",(0,n.jsx)(e.code,{children:\"prerequisites\"}),\" \\u6570\\u7EC4\\u6765\\u6784\\u5EFA\\u56FE\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u5BF9 \",(0,n.jsx)(e.code,{children:\"[a, b]\"}),\"\\uFF0C\\u5728 \",(0,n.jsx)(e.code,{children:\"adj\"}),\" \\u4E2D\\u5C06 \",(0,n.jsx)(e.code,{children:\"a\"}),\" \\u6DFB\\u52A0\\u4E3A \",(0,n.jsx)(e.code,{children:\"b\"}),\" \\u7684\\u90BB\\u5C45\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E24\\u4E2A\\u6570\\u7EC4\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"visit\"}),\" \\u7528\\u4E8E\\u8DDF\\u8E2A\\u8282\\u70B9\\u662F\\u5426\\u5DF2\\u88AB\\u8BBF\\u95EE\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"inStack\"}),\" \\u7528\\u4E8E\\u8DDF\\u8E2A\\u8282\\u70B9\\u662F\\u5426\\u5728\\u5F53\\u524D\\u7684\\u9012\\u5F52\\u5806\\u6808\\u4E2D\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"dfs\"}),\" \\u51FD\\u6570\\u6765\\u6267\\u884C\\u4EE5\\u4E0B\\u64CD\\u4F5C\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5F53\\u524D\\u8282\\u70B9\\u5728\\u9012\\u5F52\\u5806\\u6808 (\",(0,n.jsx)(e.code,{children:\"inStack\"}),\") \\u4E2D\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\uFF08\\u68C0\\u6D4B\\u5230\\u5FAA\\u73AF\\uFF09\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5F53\\u524D\\u8282\\u70B9\\u5DF2\\u88AB\\u8BBF\\u95EE\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5C06\\u5F53\\u524D\\u8282\\u70B9\\u6807\\u8BB0\\u4E3A\\u5DF2\\u8BBF\\u95EE\\u5E76\\u5C06\\u5176\\u6DFB\\u52A0\\u5230\\u9012\\u5F52\\u5806\\u6808\\u4E2D\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u5F53\\u524D\\u8282\\u70B9\\u7684\\u6BCF\\u4E2A\\u90BB\\u5C45\\uFF0C\\u9012\\u5F52\\u8C03\\u7528 \",(0,n.jsx)(e.code,{children:\"dfs\"}),\"\\u3002\\u5982\\u679C\\u4EFB\\u4F55\\u8C03\\u7528\\u68C0\\u6D4B\\u5230\\u5FAA\\u73AF\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u9012\\u5F52\\u5806\\u6808\\u4E2D\\u5220\\u9664\\u5F53\\u524D\\u8282\\u70B9\\u5E76\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\uFF08\\u672A\\u68C0\\u6D4B\\u5230\\u5FAA\\u73AF\\uFF09\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u6BCF\\u4E2A\\u8282\\u70B9\\u6267\\u884C DFS\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u68C0\\u6D4B\\u5230\\u5FAA\\u73AF\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5728\\u672A\\u68C0\\u6D4B\\u5230\\u5FAA\\u73AF\\u7684\\u60C5\\u51B5\\u4E0B\\u5904\\u7406\\u4E86\\u6240\\u6709\\u8282\\u70B9\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(l,{children:u}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(v + e)\"}),\"\\u3002\\u6784\\u5EFA\\u56FE\\u9700\\u8981 O(e)\\uFF0C\\u5176\\u4E2D \",(0,n.jsx)(e.code,{children:\"e\"}),\" \\u662F\\u5148\\u51B3\\u6761\\u4EF6\\u7684\\u6570\\u91CF\\u3002DFS \\u8BBF\\u95EE\\u6BCF\\u4E2A\\u8282\\u70B9\\u548C\\u8FB9\\u4E00\\u6B21\\uFF0C\\u9700\\u8981 O(v + e)\\uFF0C\\u5176\\u4E2D \",(0,n.jsx)(e.code,{children:\"v\"}),\" \\u662F\\u8BFE\\u7A0B\\u7684\\u6570\\u91CF\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(v + e)\"}),\"\\u3002\\u90BB\\u63A5\\u8868\\u9700\\u8981 O(e) \\u7A7A\\u95F4\\uFF0C\\u800C \",(0,n.jsx)(e.code,{children:\"visit\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"inStack\"}),\" \\u6570\\u7EC4\\u9700\\u8981 O(v) \\u7A7A\\u95F4\\u3002\"]}),`\n`]})]})}function O(i={}){let{wrapper:e}=i.components||{};return e?(0,n.jsx)(e,Object.assign({},i,{children:(0,n.jsx)(f,i)})):f(i)}var w=O;return S(x);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/depth-first-search/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/depth-first-search/locales/zh-CN.json new file mode 100644 index 000000000..a48274789 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/depth-first-search/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var a=Object.create;var c=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var m=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports),x=(r,n)=>{for(var i in n)c(r,i,{get:n[i],enumerable:!0})},t=(r,n,i,h)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let l of D(n))!g.call(r,l)&&l!==i&&c(r,l,{get:()=>n[l],enumerable:!(h=p(n,l))||h.enumerable});return r};var E=(r,n,i)=>(i=r!=null?a(F(r)):{},t(n||!r||!r.__esModule?c(i,\"default\",{value:r,enumerable:!0}):i,r)),j=r=>t(c({},\"__esModule\",{value:!0}),r);var o=m((G,d)=>{d.exports=_jsx_runtime});var S={};x(S,{default:()=>C,frontmatter:()=>u});var e=E(o()),u={title:\"\\u6DF1\\u5EA6\\u4F18\\u5148\\u641C\\u7D22\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u6DF1\\u5EA6\\u4F18\\u5148\\u641C\\u7D22\\u7B97\\u6CD5\\uFF0C\\u4EE5\\u6DF1\\u5EA6\\u4F18\\u5148\\u7684\\u65B9\\u5F0F\\u904D\\u5386\\u6709\\u5411\\u56FE\"};function s(r){let n=Object.assign({p:\"p\",h2:\"h2\",pre:\"pre\",code:\"code\",ol:\"ol\",li:\"li\"},r.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.p,{children:\"\\u7F16\\u5199\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u8BE5\\u51FD\\u6570\\u5728\\u7ED9\\u5B9A\\u8D77\\u59CB\\u8282\\u70B9\\u7684\\u60C5\\u51B5\\u4E0B\\uFF0C\\u5BF9\\u6709\\u5411\\u56FE\\uFF08\\u90BB\\u63A5\\u8868\\u683C\\u5F0F\\uFF09\\u5B9E\\u73B0\\u6DF1\\u5EA6\\u4F18\\u5148\\u641C\\u7D22\\u7B97\\u6CD5\\u3002\"}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u4F8B\\u5B50\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-js\",children:`const graph1 = {\n A: ['B', 'C', 'D'],\n B: ['E', 'F'],\n C: ['G', 'H'],\n D: ['I', 'J'],\n E: ['D'],\n F: [],\n G: [],\n H: [],\n I: [],\n J: [],\n};\ndepthFirstSearch(graph1, 'A'); // ['A', 'B', 'E', 'D', 'I', 'J', 'F', 'C', 'G', 'H']\ndepthFirstSearch(graph1, 'B'); // ['B', 'E', 'D', 'I', 'J', 'F']\n\nconst graph2 = {\n A: ['B', 'C'],\n B: ['D', 'E'],\n C: ['F', 'G'],\n D: [],\n E: [],\n F: [],\n G: [],\n};\ndepthFirstSearch(graph2, 'A'); // ['A', 'B', 'D', 'E', 'C', 'F', 'G']\ndepthFirstSearch(graph2, 'E'); // ['E']\n`})}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u56DE\\u987E\\uFF08\\u63D0\\u793A\\uFF09\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u6DF1\\u5EA6\\u4F18\\u5148\\u641C\\u7D22 (DFS) \\u662F\\u4E00\\u79CD\\u7528\\u4E8E\\u904D\\u5386\\u56FE\\u6216\\u6811\\u7684\\u7B97\\u6CD5\\u3002DFS \\u7684\\u8F93\\u51FA\\u662F\\u56FE\\u4E2D\\u8282\\u70B9\\u6309\\u7167\\u904D\\u5386\\u987A\\u5E8F\\u6392\\u5217\\u7684\\u6570\\u7EC4\\u3002\\u6B64\\u8F93\\u51FA\\u5BF9\\u4E8E\\u5404\\u79CD\\u4E0D\\u540C\\u7684\\u7528\\u4F8B\\u548C\\u76EE\\u7684\\u90FD\\u5F88\\u6709\\u7528\\uFF0C\\u8FD9\\u4F7F\\u5F97 DFS \\u6210\\u4E3A\\u4E00\\u4E2A\\u6709\\u7528\\u7684\\u7B97\\u6CD5\\u3002\\u4E00\\u4E9B\\u7528\\u4F8B\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u67E5\\u627E\\u7279\\u5B9A\\u8282\\u70B9\\u6216\\u8282\\u70B9\\u7EC4\\u3002\\u8FD9\\u5728\\u524D\\u7AEF\\u5F88\\u5E38\\u89C1\\uFF0C\\u7528\\u4E8E\\u5728 DOM \\u6811\\u4E2D\\u67E5\\u627E\\u7279\\u5B9A\\u7684 DOM \\u8282\\u70B9\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u68C0\\u67E5\\u56FE\\u662F\\u5426\\u5DF2\\u8FDE\\u63A5\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u67E5\\u627E\\u56FE\\u4E2D\\u4E24\\u4E2A\\u8282\\u70B9\\u4E4B\\u95F4\\u7684\\u8DEF\\u5F84\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u751F\\u6210\\u6709\\u5411\\u65E0\\u73AF\\u56FE (DAG) \\u7684\\u62D3\\u6251\\u6392\\u5E8F\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u8BC6\\u522B\\u56FE\\u4E2D\\u7684\\u5FAA\\u73AF\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u4F5C\\u4E3A\\u5176\\u4ED6\\u7B97\\u6CD5\\u7684\\u6784\\u5EFA\\u5757\\u3002\"}),`\n`]}),`\n`,(0,e.jsx)(n.p,{children:\"\\u4EE5\\u4E0B\\u662F DFS \\u5982\\u4F55\\u904D\\u5386\\u56FE\\u7684\\u6982\\u8FF0\\uFF0C\\u4F7F\\u7528\\u63A5\\u53D7\\u90BB\\u63A5\\u8868\\uFF08\\u6211\\u4EEC\\u4F7F\\u7528\\u6570\\u7EC4\\u4EE3\\u66FF\\uFF09\\u548C\\u6839\\u8282\\u70B9\\u7684\\u6807\\u51C6\\u5B9E\\u73B0\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u6570\\u7EC4\\u6216\\u5806\\u6808\\u6765\\u5B58\\u50A8\\u8981\\u8BBF\\u95EE\\u7684\\u8282\\u70B9\\u3002\\u63A8\\u9001\\u6839\\u8282\\u70B9\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u96C6\\u5408\\u6765\\u8DDF\\u8E2A\\u5DF2\\u8BBF\\u95EE\\u7684\\u8282\\u70B9\\u3002\"}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u8FDB\\u5165\\u4E00\\u4E2A\\u5FAA\\u73AF\\uFF0C\\u8BE5\\u5FAA\\u73AF\\u5C06\\u6301\\u7EED\\u5230\\u5806\\u6808\\u4E3A\\u7A7A\\u3002\\u5728\\u5FAA\\u73AF\\u7684\\u6BCF\\u6B21\\u8FED\\u4EE3\\u4E2D\\uFF1A\",`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u4ECE\\u6570\\u7EC4/\\u5806\\u6808\\u4E2D\\u5F39\\u51FA\\u9876\\u90E8\\u8282\\u70B9\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u4ECE\\u8F93\\u5165\\u56FE\\u4E2D\\u68C0\\u7D22\\u8282\\u70B9\\u7684\\u90BB\\u5C45\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u90BB\\u5C45\\uFF0C\\u68C0\\u67E5\\u5B83\\u662F\\u5426\\u5DF2\\u88AB\\u8BBF\\u95EE\\u3002\\u5982\\u679C\\u5C1A\\u672A\\u8BBF\\u95EE\\uFF0C\\u5219\\u5C06\\u5176\\u6DFB\\u52A0\\u5230\\u8981\\u8BBF\\u95EE\\u7684\\u8282\\u70B9\\u96C6\\u4E2D\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,e.jsx)(n.li,{children:\"\\u8FD4\\u56DE\\u5DF2\\u8BBF\\u95EE\\u8282\\u70B9\\u7684\\u96C6\\u5408\\u3002\"}),`\n`]})]})}function B(r={}){let{wrapper:n}=r.components||{};return n?(0,e.jsx)(n,Object.assign({},r,{children:(0,e.jsx)(s,r)})):s(r)}var C=B;return j(S);})();\n;return Component;", + "info": { + "excerpt": "实现一个深度优先搜索算法,以深度优先的方式遍历有向图", + "title": "深度优先搜索" + }, + "solution": "var Component=(()=>{var v=Object.create;var s=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var j=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),S=(t,e)=>{for(var i in e)s(t,i,{get:e[i],enumerable:!0})},d=(t,e,i,a)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let n of b(e))!m.call(t,n)&&n!==i&&s(t,n,{get:()=>e[n],enumerable:!(a=f(e,n))||a.enumerable});return t};var F=(t,e,i)=>(i=t!=null?v(y(t)):{},d(e||!t||!t.__esModule?s(i,\"default\",{value:t,enumerable:!0}):i,t)),k=t=>d(s({},\"__esModule\",{value:!0}),t);var c=j((_,h)=>{h.exports=_jsx_runtime});var D={};S(D,{default:()=>A});var r=F(c());var o=MDXCodeBlock;var g=`/**\n * @param {Record} graph The adjacency list representing the graph.\n * @param {string} source The source node to start traversal from. Has to be a valid node if graph is non-empty.\n * @return {string[]} A DFS-traversed order of nodes.\n */\nexport default function depthFirstSearch(graph, source) {\n // If there are no nodes in the graph, just return an empty array\n if (Object.keys(graph).length === 0) {\n return [];\n }\n\n // Create an stack to store the nodes to be visited. We can simulate\n // stacks using arrays in JavaScript.\n // Add the root node since we're doing a pre-order DFS.\n const toBeVisited = [];\n toBeVisited.push(source);\n\n // Initialize a set that tracks visited nodes.\n const visited = new Set();\n\n // Loop as long as array is empty (i.e. there are still nodes to be visited).\n while (toBeVisited.length !== 0) {\n // Pop top node from array (toBeVisited) and add it to the set (visited).\n const node = toBeVisited.pop();\n visited.add(node);\n\n // Retrieve neighbors (values of the adjacency list input Object)\n const neighbors = graph[node];\n // Push neighbors, in reverse order, onto array to be visited\n // to preserve original order of neighbors when visiting (popping off the array).\n for (let i = neighbors.length - 1; i >= 0; i--) {\n const neighbor = neighbors[i];\n // First check if the neighbor has already been visited before adding it.\n if (!visited.has(neighbor)) {\n toBeVisited.push(neighbor);\n }\n }\n }\n\n // The visited nodes is the traversal order.\n return Array.from(visited);\n}\n`;var l=`export default function depthFirstSearch(\n graph: Record>,\n source: string,\n): Array {\n // If there are no nodes in the graph, just return an empty array\n if (Object.keys(graph).length === 0) {\n return [];\n }\n\n // Create an stack to store the nodes to be visited. We can simulate\n // stacks using arrays in JavaScript.\n // Add the root node since we're doing a pre-order DFS.\n const toBeVisited: Array = [];\n toBeVisited.push(source);\n\n // Initialize a set that tracks visited nodes.\n const visited = new Set();\n\n // Loop as long as array is empty (i.e. there are still nodes to be visited).\n while (toBeVisited.length !== 0) {\n // Pop top node from array (toBeVisited) and add it to the set (visited).\n const node = toBeVisited.pop()!;\n visited.add(node);\n\n // Retrieve neighbors (values of the adjacency list input Object)\n const neighbors = graph[node];\n // Push neighbors, in reverse order, onto array to be visited\n // to preserve original order of neighbors when visiting (popping off the array).\n for (let i = neighbors.length - 1; i >= 0; i--) {\n const neighbor = neighbors[i];\n // First check if the neighbor has already been visited before adding it.\n if (!visited.has(neighbor)) {\n toBeVisited.push(neighbor);\n }\n }\n }\n\n // The visited nodes is the traversal order.\n return Array.from(visited);\n}\n`;var p=`/**\n * @param {Object} graph Node to array of neighboring nodes.\n * @param {string} source Source node to start traversal from. Has to be a valid node if graph is non-empty.\n * @return {string[]} A DFS-traversed order of nodes.\n */\nexport default function depthFirstSearch(graph, source) {\n // If there are no nodes in the graph, just return an empty array\n if (Object.keys(graph).length === 0) {\n return [];\n }\n\n // Initialize a set that tracks visited nodes.\n const visited = new Set();\n\n function traverse(node) {\n // Visited before, we can ignore.\n if (visited.has(node)) {\n return;\n }\n\n visited.add(node);\n // Recursively visit each neighbor.\n graph[node].forEach((neighbor) => {\n traverse(neighbor);\n });\n }\n\n // Start traversing from the source.\n traverse(source);\n\n // The visited nodes is the traversal order.\n return Array.from(visited);\n}\n`;function u(t){let e=Object.assign({h2:\"h2\",p:\"p\",ul:\"ul\",li:\"li\"},t.components);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e.h2,{children:\"\\u6F84\\u6E05\\u95EE\\u9898\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u5982\\u679C\\u672A\\u6307\\u5B9A\\uFF1A\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"\\u904D\\u5386\\u987A\\u5E8F\\uFF1A\\u6211\\u4EEC\\u5E94\\u8BE5\\u4F7F\\u7528\\u6807\\u51C6\\u7684\\u5148\\u5E8F\\u904D\\u5386\\u8FD8\\u662F\\u5176\\u4ED6\\u904D\\u5386\\u987A\\u5E8F\\uFF1F\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u8F93\\u5165\\u683C\\u5F0F\\uFF1A\\u8F93\\u5165\\u6570\\u636E\\u7684\\u683C\\u5F0F\\u662F\\u4EC0\\u4E48\\uFF1F\\u6211\\u4EEC\\u53EF\\u4EE5\\u5047\\u8BBE\\u8F93\\u5165\\u5C06\\u662F\\u4E00\\u4E2A JavaScript \\u5BF9\\u8C61\\u7684\\u90BB\\u63A5\\u8868\\uFF0C\\u5176\\u4E2D\\u952E\\u662F\\u8282\\u70B9\\uFF0C\\u503C\\u662F\\u5B50\\u8282\\u70B9\\u5417\\uFF1F\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u8F93\\u51FA\\u683C\\u5F0F\\uFF1A\\u8F93\\u51FA\\u5E94\\u8BE5\\u5982\\u4F55\\u683C\\u5F0F\\u5316\\uFF1F\\u662F\\u5426\\u6709\\u7279\\u5B9A\\u7684\\u8981\\u6C42\\uFF0C\\u6216\\u8005\\u6211\\u4EEC\\u53EF\\u4EE5\\u8FD4\\u56DE\\u4E00\\u4E2A\\u6570\\u7EC4\\uFF0C\\u5176\\u4E2D\\u5305\\u542B\\u6309\\u904D\\u5386\\u987A\\u5E8F\\u6392\\u5217\\u7684\\u5143\\u7D20\\uFF1F\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u975E\\u8FDE\\u901A\\u56FE\\uFF1A\\u6211\\u4EEC\\u662F\\u5426\\u5FC5\\u987B\\u8003\\u8651\\u6216\\u5904\\u7406\\u975E\\u8FDE\\u901A\\u56FE\\u7684\\u60C5\\u51B5\\uFF0C\\u5176\\u4E2D\\u6709\\u591A\\u4E2A\\u5B50\\u56FE\\u5F7C\\u6B64\\u4E0D\\u8FDE\\u63A5\\uFF1F\"}),`\n`]}),`\n`,(0,r.jsx)(e.h2,{children:\"\\u89E3\\u51B3\\u65B9\\u6848\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u5B9E\\u73B0\\u4E86\\u63CF\\u8FF0\\u4E2D\\u6982\\u8FF0\\u7684\\u7B97\\u6CD5\\u3002\"}),`\n`,(0,r.jsx)(o,{languages:{jsx:g,tsx:l}}),`\n`,(0,r.jsx)(e.p,{children:\"\\u6211\\u4EEC\\u4E5F\\u53EF\\u4EE5\\u9012\\u5F52\\u5730\\u6267\\u884C DFS\\uFF0C\\u8FD9\\u5728\\u67D0\\u4E9B\\u60C5\\u51B5\\u4E0B\\u53EF\\u80FD\\u66F4\\u76F4\\u89C2\\u3002\\u9012\\u5F52\\u8C03\\u7528\\u5806\\u6808\\u662F\\u4E00\\u4E2A\\u9690\\u5F0F\\u5806\\u6808\\uFF0C\\u7528\\u4E8E\\u8DDF\\u8E2A\\u63A5\\u4E0B\\u6765\\u8981\\u8BBF\\u95EE\\u7684\\u8282\\u70B9\\u3002\"}),`\n`,(0,r.jsx)(o,{children:p}),`\n`,(0,r.jsx)(e.h2,{children:\"\\u8FB9\\u7F18\\u60C5\\u51B5\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"\\u7A7A\\u56FE\\uFF1A\\u8FD4\\u56DE\\u4E00\\u4E2A\\u7A7A\\u6570\\u7EC4\\uFF0C\\u4E0D\\u4F1A\\u5D29\\u6E83\\u3002\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u53EA\\u6709\\u4E00\\u4E24\\u4E2A\\u8282\\u70B9\\u7684\\u56FE\\uFF1A\\u904D\\u5386\\u800C\\u4E0D\\u4F1A\\u5D29\\u6E83\\u3002\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u5FAA\\u73AF\\u56FE\\uFF1A\\u786E\\u4FDD\\u4E0D\\u518D\\u904D\\u5386\\u5DF2\\u8BBF\\u95EE\\u7684\\u8282\\u70B9\\u3002\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u4E0D\\u76F8\\u4EA4\\u7684\\u56FE\\uFF1A\\u4E0D\\u9700\\u8981\\u7279\\u6B8A\\u5904\\u7406\\uFF0C\\u4F46\\u6700\\u597D\\u77E5\\u9053\\u3002\"}),`\n`]})]})}function w(t={}){let{wrapper:e}=t.components||{};return e?(0,r.jsx)(e,Object.assign({},t,{children:(0,r.jsx)(u,t)})):u(t)}var A=w;return k(D);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/dijkstra/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/dijkstra/locales/zh-CN.json new file mode 100644 index 000000000..1b5a17f1a --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/dijkstra/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var a=Object.create;var l=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var g=(i,n)=>()=>(n||i((n={exports:{}}).exports,n),n.exports),m=(i,n)=>{for(var r in n)l(i,r,{get:n[r],enumerable:!0})},h=(i,n,r,d)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let c of p(n))!D.call(i,c)&&c!==r&&l(i,c,{get:()=>n[c],enumerable:!(d=u(n,c))||d.enumerable});return i};var x=(i,n,r)=>(r=i!=null?a(j(i)):{},h(n||!i||!i.__esModule?l(r,\"default\",{value:i,enumerable:!0}):r,i)),C=i=>h(l({},\"__esModule\",{value:!0}),i);var o=g((G,t)=>{t.exports=_jsx_runtime});var A={};m(A,{default:()=>k,frontmatter:()=>F});var e=x(o()),F={title:\"Dijkstra \\u7B97\\u6CD5\",excerpt:\"\\u5B9E\\u73B0 Dijkstra \\u7B97\\u6CD5\\uFF0C\\u4EE5\\u627E\\u5230\\u56FE\\u4E2D\\u4ECE\\u6E90\\u9876\\u70B9\\u5F00\\u59CB\\u7684\\u6700\\u77ED\\u8DEF\\u5F84\\uFF0C\\u8BE5\\u56FE\\u8868\\u793A\\u4E3A\\u90BB\\u63A5\\u8868\\u3002\"};function s(i){let n=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\",pre:\"pre\",h2:\"h2\",ol:\"ol\"},i.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)(n.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u52A0\\u6743\\u6709\\u5411\\u56FE\\uFF0C\\u8868\\u793A\\u4E3A\\u90BB\\u63A5\\u8868 (\",(0,e.jsx)(n.code,{children:\"graph\"}),\") \\u548C\\u4E00\\u4E2A\\u8D77\\u59CB\\u8282\\u70B9 (\",(0,e.jsx)(n.code,{children:\"source\"}),\")\\uFF0C\\u5B9E\\u73B0 Dijkstra \\u7B97\\u6CD5\\u4EE5\\u627E\\u5230\\u4ECE \",(0,e.jsx)(n.code,{children:\"source\"}),\" \\u5230\\u56FE\\u4E2D\\u6240\\u6709\\u5176\\u4ED6\\u8282\\u70B9\\u7684\\u6700\\u77ED\\u8DEF\\u5F84\\u8DDD\\u79BB\\u3002\\u8BE5\\u56FE\\u5305\\u542B\\u8282\\u70B9\\u548C\\u52A0\\u6743\\u8FB9\\u3002\"]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"graph\"}),\"\\uFF1A\\u4E00\\u4E2A\\u8868\\u793A\\u56FE\\u7684\\u90BB\\u63A5\\u8868\\u7684\\u5BF9\\u8C61\\u3002\\u6BCF\\u4E2A\\u952E\\u90FD\\u662F\\u4E00\\u4E2A\\u8282\\u70B9\\u6807\\u8BC6\\u7B26\\uFF08\\u4F8B\\u5982 \",(0,e.jsx)(n.code,{children:\"'A'\"}),\"\\u3001\",(0,e.jsx)(n.code,{children:\"'B'\"}),\"\\uFF09\\uFF0C\\u5176\\u503C\\u662F\\u53E6\\u4E00\\u4E2A\\u5BF9\\u8C61\\uFF0C\\u5C06\\u6BCF\\u4E2A\\u76F8\\u90BB\\u8282\\u70B9\\u6620\\u5C04\\u5230\\u8FDE\\u63A5\\u5B83\\u4EEC\\u7684\\u8FB9\\u7684\\u975E\\u8D1F\\u6743\\u91CD\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"source\"}),\"\\uFF1A\\u7528\\u4E8E\\u8BA1\\u7B97\\u6700\\u77ED\\u8DEF\\u5F84\\u7684\\u8D77\\u59CB\\u8282\\u70B9\\u7684\\u6807\\u8BC6\\u7B26\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u8F93\\u51FA\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4E00\\u4E2A\\u5BF9\\u8C61\\uFF0C\\u5176\\u4E2D\\u952E\\u662F\\u8282\\u70B9\\u6807\\u8BC6\\u7B26\\uFF0C\\u503C\\u8868\\u793A\\u4ECE \",(0,e.jsx)(n.code,{children:\"source\"}),\" \\u5230\\u8BE5\\u8282\\u70B9\\u7684\\u6700\\u77ED\\u8DDD\\u79BB\\u3002\\u4ECE \",(0,e.jsx)(n.code,{children:\"source\"}),\" \\u65E0\\u6CD5\\u5230\\u8FBE\\u7684\\u8282\\u70B9\\u5E94\\u5C06\\u5176\\u8DDD\\u79BB\\u8BBE\\u7F6E\\u4E3A \",(0,e.jsx)(n.code,{children:\"Infinity\"}),\"\\uFF08\\u4F7F\\u7528\\u5185\\u7F6E\\u7684 \",(0,e.jsx)(n.code,{children:\"Infinity\"}),\" \\u5E38\\u91CF\\uFF09\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u4F8B\\u5B50\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-js\",children:`const graph1 = {\n A: { B: 1, C: 4 },\n B: { E: 3, F: 2 },\n C: { G: 2 },\n D: { C: 3, J: 5 },\n E: { D: 2 },\n F: {},\n G: { H: 1 },\n H: { F: 4, J: 3 },\n I: {},\n J: {},\n};\n\ndijkstra(graph1, 'A'); // Returns distances: { A: 0, B: 1, C: 4, D: 6, E: 4, F: 3, G: 6, H: 7, I: Infinity, J: 10 }\n\nconst graph2 = {\n A: { B: 2, C: 5 },\n B: { D: 1, E: 4 },\n C: { F: 3, G: 2 },\n D: {},\n E: {},\n F: {},\n G: {},\n};\n\ndijkstra(graph2, 'A'); // Returns distances: { A: 0, B: 2, C: 5, D: 3, E: 6, F: 8, G: 7 }\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"1 <= \\u8282\\u70B9\\u6570 <= 1000\"}),`\n`,(0,e.jsx)(n.li,{children:\"0 <= \\u8FB9\\u6743\\u91CD <= 10000\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u56FE\\u53EF\\u80FD\\u5305\\u542B\\u5FAA\\u73AF\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u56FE\\u53EF\\u80FD\\u65AD\\u5F00\\u8FDE\\u63A5\"}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u56DE\\u987E\\uFF08\\u63D0\\u793A\\uFF09\"}),`\n`,(0,e.jsx)(n.p,{children:\"Dijkstra \\u7B97\\u6CD5\\u662F\\u4E00\\u79CD\\u7528\\u4E8E\\u67E5\\u627E\\u52A0\\u6743\\u56FE\\u4E2D\\u8282\\u70B9\\u4E4B\\u95F4\\u6700\\u77ED\\u8DEF\\u5F84\\u7684\\u57FA\\u672C\\u7B97\\u6CD5\\u3002\\u8BE5\\u7B97\\u6CD5\\u53EF\\u4EE5\\u5904\\u7406\\u5177\\u6709\\u975E\\u8D1F\\u6743\\u91CD\\u7684\\u56FE\\uFF0C\\u901A\\u5E38\\u7528\\u4E8E\\u8DEF\\u7531\\u4EE5\\u53CA\\u5176\\u4ED6\\u56FE\\u7B97\\u6CD5\\u7684\\u5B50\\u7A0B\\u5E8F\\u3002\\u4EE5\\u4E0B\\u662F\\u4E00\\u4E9B\\u5178\\u578B\\u7684\\u7528\\u4F8B\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5728 GPS \\u7CFB\\u7EDF\\u4E2D\\uFF0C\\u7528\\u4E8E\\u67E5\\u627E\\u4F4D\\u7F6E\\u4E4B\\u95F4\\u7684\\u6700\\u77ED\\u9A7E\\u9A76\\u8DEF\\u7EBF\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5728\\u7F51\\u7EDC\\u8DEF\\u7531\\u7B97\\u6CD5\\u4E2D\\uFF0C\\u7528\\u4E8E\\u67E5\\u627E\\u6570\\u636E\\u5305\\u7684\\u6700\\u77ED\\u8DEF\\u5F84\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5728\\u8C03\\u5EA6\\u7406\\u8BBA\\u4E2D\\uFF0C\\u7528\\u4E8E\\u67E5\\u627E\\u901A\\u8FC7\\u4E00\\u7CFB\\u5217\\u4EFB\\u52A1\\u7684\\u6700\\u77ED\\uFF08\\u8017\\u65F6\\u6700\\u5C11\\uFF09\\u8DEF\\u5F84\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u751F\\u6210\\u52A0\\u6743\\u56FE\\u7684\\u6700\\u5C0F\\u751F\\u6210\\u6811 (MST)\\u3002\"}),`\n`]}),`\n`,(0,e.jsx)(n.p,{children:\"\\u4EE5\\u4E0B\\u662F Dijkstra \\u7B97\\u6CD5\\u7684\\u5DE5\\u4F5C\\u539F\\u7406\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u4ECE\\u56FE\\u4E2D\\u6240\\u6709\\u8282\\u70B9\\u7684\\u96C6\\u5408\\u5F00\\u59CB\\uFF0C\\u4E3A\\u5B83\\u4EEC\\u5206\\u914D\\u4E00\\u4E2A\\u6682\\u5B9A\\u7684\\u8DDD\\u79BB\\u503C\\uFF1A\\u5BF9\\u4E8E\\u521D\\u59CB\\u8282\\u70B9\\u4E3A\\u96F6\\uFF0C\\u5BF9\\u4E8E\\u6240\\u6709\\u5176\\u4ED6\\u8282\\u70B9\\u4E3A\\u65E0\\u7A77\\u5927\\u3002\\u5C06\\u521D\\u59CB\\u8282\\u70B9\\u8BBE\\u7F6E\\u4E3A\\u5F53\\u524D\\u8282\\u70B9\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5BF9\\u4E8E\\u5F53\\u524D\\u8282\\u70B9\\uFF0C\\u8003\\u8651\\u5176\\u6240\\u6709\\u672A\\u8BBF\\u95EE\\u7684\\u90BB\\u5C45\\u5E76\\u8BA1\\u7B97\\u5B83\\u4EEC\\u7684\\u6682\\u5B9A\\u8DDD\\u79BB\\u3002\\u5C06\\u65B0\\u8BA1\\u7B97\\u7684\\u6682\\u5B9A\\u8DDD\\u79BB\\u4E0E\\u5F53\\u524D\\u5206\\u914D\\u7684\\u503C\\u8FDB\\u884C\\u6BD4\\u8F83\\uFF0C\\u5E76\\u5206\\u914D\\u8F83\\u5C0F\\u7684\\u4E00\\u4E2A\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u4E00\\u65E6\\u6211\\u4EEC\\u8003\\u8651\\u4E86\\u5F53\\u524D\\u8282\\u70B9\\u7684\\u6240\\u6709\\u672A\\u8BBF\\u95EE\\u90BB\\u5C45\\uFF0C\\u5C31\\u5C06\\u5F53\\u524D\\u8282\\u70B9\\u6807\\u8BB0\\u4E3A\\u5DF2\\u8BBF\\u95EE\\u3002\\u5DF2\\u8BBF\\u95EE\\u7684\\u8282\\u70B9\\u5C06\\u4E0D\\u518D\\u88AB\\u68C0\\u67E5\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5982\\u679C\\u76EE\\u6807\\u8282\\u70B9\\u5DF2\\u88AB\\u6807\\u8BB0\\u4E3A\\u5DF2\\u8BBF\\u95EE\\uFF0C\\u6216\\u8005\\u672A\\u8BBF\\u95EE\\u96C6\\u5408\\u4E2D\\u8282\\u70B9\\u4E4B\\u95F4\\u7684\\u6700\\u5C0F\\u6682\\u5B9A\\u8DDD\\u79BB\\u4E3A\\u65E0\\u7A77\\u5927\\uFF08\\u5F53\\u521D\\u59CB\\u8282\\u70B9\\u548C\\u5269\\u4F59\\u672A\\u8BBF\\u95EE\\u8282\\u70B9\\u4E4B\\u95F4\\u6CA1\\u6709\\u8FDE\\u63A5\\u65F6\\u53D1\\u751F\\uFF09\\uFF0C\\u5219\\u505C\\u6B62\\u3002\\u7B97\\u6CD5\\u5DF2\\u5B8C\\u6210\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5426\\u5219\\uFF0C\\u9009\\u62E9\\u6807\\u6709\\u6700\\u5C0F\\u6682\\u5B9A\\u8DDD\\u79BB\\u7684\\u672A\\u8BBF\\u95EE\\u8282\\u70B9\\uFF0C\\u5C06\\u5176\\u8BBE\\u7F6E\\u4E3A\\u65B0\\u7684\\u201C\\u5F53\\u524D\\u8282\\u70B9\\u201D\\uFF0C\\u7136\\u540E\\u8FD4\\u56DE\\u5230\\u6B65\\u9AA4 2\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u7ED3\\u679C\\u662F\\u4ECE\\u521D\\u59CB\\u8282\\u70B9\\u5230\\u6240\\u6709\\u5176\\u4ED6\\u8282\\u70B9\\u7684\\u6700\\u77ED\\u8DDD\\u79BB\\u7684\\u6620\\u5C04\\u3002\"}),`\n`]})]})}function f(i={}){let{wrapper:n}=i.components||{};return n?(0,e.jsx)(n,Object.assign({},i,{children:(0,e.jsx)(s,i)})):s(i)}var k=f;return C(A);})();\n;return Component;", + "info": { + "excerpt": "实现 Dijkstra 算法,以找到图中从源顶点开始的最短路径,该图表示为邻接表。", + "title": "Dijkstra 算法" + }, + "solution": "var Component=(()=>{var u=Object.create;var r=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var x=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),b=(i,e)=>{for(var n in e)r(i,n,{get:e[n],enumerable:!0})},a=(i,e,n,h)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let s of f(e))!v.call(i,s)&&s!==n&&r(i,s,{get:()=>e[s],enumerable:!(h=g(e,s))||h.enumerable});return i};var y=(i,e,n)=>(n=i!=null?u(w(i)):{},a(e||!i||!i.__esModule?r(n,\"default\",{value:i,enumerable:!0}):n,i)),j=i=>a(r({},\"__esModule\",{value:!0}),i);var p=x((R,o)=>{o.exports=_jsx_runtime});var M={};b(M,{default:()=>I});var t=y(p());var l=MDXCodeBlock;var d=`/**\n * MinHeap: A minimum heap implementation to serve as a priority queue.\n * Each heap element is an object of the form { vertex, weight }.\n */\nclass MinHeap {\n constructor() {\n this.heap = [];\n this.position = {}; // Maps each vertex to its index in the heap.\n }\n\n // Helper method to swap two elements and update their positions.\n swap(i, j) {\n [this.heap[i], this.heap[j]] = [this.heap[j], this.heap[i]];\n this.position[this.heap[i].vertex] = i;\n this.position[this.heap[j].vertex] = j;\n }\n\n // Bubbles up the element at index i to restore heap property.\n percolateUp(i) {\n while (i > 0) {\n const parent = Math.floor((i - 1) / 2);\n if (this.heap[parent].weight > this.heap[i].weight) {\n this.swap(i, parent);\n i = parent;\n } else {\n break;\n }\n }\n }\n\n // Bubbles down the element at index i to restore heap property.\n percolateDown(i) {\n const n = this.heap.length;\n while (true) {\n const left = 2 * i + 1;\n const right = 2 * i + 2;\n let smallest = i;\n\n if (left < n && this.heap[left].weight < this.heap[smallest].weight) {\n smallest = left;\n }\n if (right < n && this.heap[right].weight < this.heap[smallest].weight) {\n smallest = right;\n }\n if (smallest !== i) {\n this.swap(i, smallest);\n i = smallest;\n } else {\n break;\n }\n }\n }\n\n /**\n * Inserts a new item into the heap or updates it if it already exists.\n * @param {{vertex: string, weight: number}} item The item to insert or update.\n */\n insert(item) {\n // If the vertex exists, perform a decrease-key operation.\n if (this.position.hasOwnProperty(item.vertex)) {\n const i = this.position[item.vertex];\n if (item.weight < this.heap[i].weight) {\n this.heap[i].weight = item.weight;\n this.percolateUp(i);\n }\n return;\n }\n // Otherwise, add it as a new item.\n this.heap.push(item);\n const idx = this.heap.length - 1;\n this.position[item.vertex] = idx;\n this.percolateUp(idx);\n }\n\n /**\n * Removes and returns the minimum element (the root) from the heap.\n * @return {{vertex: string, weight: number}|undefined} The removed element.\n */\n delete() {\n if (this.heap.length === 0) return undefined;\n const min = this.heap[0];\n const last = this.heap.pop();\n // Remove mapping for the vertex being removed.\n delete this.position[min.vertex];\n if (this.heap.length > 0) {\n this.heap[0] = last;\n this.position[last.vertex] = 0;\n this.percolateDown(0);\n }\n return min;\n }\n\n /**\n * Checks if the heap is empty.\n * @return {boolean} True if the heap is empty; otherwise, false.\n */\n isEmpty() {\n return this.heap.length === 0;\n }\n\n /**\n * Returns the minimum element of the heap without removing it.\n * @return {{vertex: string, weight: number}|undefined}\n */\n findMin() {\n return this.heap.length > 0 ? this.heap[0] : undefined;\n }\n}\n\n/**\n * Executes Dijkstra's algorithm to find the shortest paths from a source node\n * in a weighted graph.\n *\n * @param {Record>} graph - The adjacency list representing the graph with weights.\n * @param {string} source - The source node from which to calculate shortest paths.\n * @return {Record} - A dictionary where keys are node labels and values represent the shortest distances from the source node.\n */\nexport default function dijkstra(graph, source) {\n const distances = {};\n const minHeap = new MinHeap();\n\n // Initialize distances for every vertex.\n for (const vertex in graph) {\n // Set the source distance to 0 and all others to Infinity.\n distances[vertex] = vertex === source ? 0 : Infinity;\n // Insert the source with weight 0.\n // Optionally, we can insert only the source and then add vertices as needed.\n minHeap.insert({ vertex, weight: distances[vertex] });\n }\n\n const visited = new Set();\n\n while (!minHeap.isEmpty()) {\n // Extract the vertex with the smallest tentative distance.\n const { vertex: u, weight } = minHeap.delete();\n if (visited.has(u)) continue;\n visited.add(u);\n\n // For each neighbor of u, try to update its distance.\n for (const neighbor in graph[u]) {\n const newDist = distances[u] + graph[u][neighbor];\n if (newDist < distances[neighbor]) {\n distances[neighbor] = newDist;\n minHeap.insert({ vertex: neighbor, weight: newDist });\n }\n }\n }\n\n return distances;\n}\n`;var c=`type HeapItem = { vertex: string; weight: number };\n\n/**\n * MinHeap: A minimum heap implementation to serve as a priority queue.\n * Each heap element is of type HeapItem.\n */\nclass MinHeap {\n private heap: HeapItem[];\n private position: { [vertex: string]: number };\n\n constructor() {\n this.heap = [];\n this.position = {};\n }\n\n // Helper method to swap two elements and update their positions.\n private swap(i: number, j: number): void {\n [this.heap[i], this.heap[j]] = [this.heap[j], this.heap[i]];\n this.position[this.heap[i].vertex] = i;\n this.position[this.heap[j].vertex] = j;\n }\n\n // Bubbles up the element at index i to restore heap property.\n private percolateUp(i: number): void {\n while (i > 0) {\n const parent = Math.floor((i - 1) / 2);\n if (this.heap[parent].weight > this.heap[i].weight) {\n this.swap(i, parent);\n i = parent;\n } else {\n break;\n }\n }\n }\n\n // Bubbles down the element at index i to restore heap property.\n private percolateDown(i: number): void {\n const n = this.heap.length;\n while (true) {\n const left = 2 * i + 1;\n const right = 2 * i + 2;\n let smallest = i;\n\n if (left < n && this.heap[left].weight < this.heap[smallest].weight) {\n smallest = left;\n }\n if (right < n && this.heap[right].weight < this.heap[smallest].weight) {\n smallest = right;\n }\n if (smallest !== i) {\n this.swap(i, smallest);\n i = smallest;\n } else {\n break;\n }\n }\n }\n\n /**\n * Inserts a new item into the heap or updates it if it already exists.\n * @param item The item to insert or update.\n */\n public insert(item: HeapItem): void {\n // If the vertex already exists, perform a decrease-key operation.\n if (this.position.hasOwnProperty(item.vertex)) {\n const i = this.position[item.vertex];\n if (item.weight < this.heap[i].weight) {\n this.heap[i].weight = item.weight;\n this.percolateUp(i);\n }\n return;\n }\n // Otherwise, add it as a new item.\n this.heap.push(item);\n const idx = this.heap.length - 1;\n this.position[item.vertex] = idx;\n this.percolateUp(idx);\n }\n\n /**\n * Removes and returns the minimum element (the root) from the heap.\n * @returns The removed element or undefined if the heap is empty.\n */\n public delete(): HeapItem | undefined {\n if (this.heap.length === 0) return undefined;\n const min = this.heap[0];\n const last = this.heap.pop();\n // Remove mapping for the vertex being removed.\n delete this.position[min.vertex];\n if (this.heap.length > 0 && last !== undefined) {\n this.heap[0] = last;\n this.position[last.vertex] = 0;\n this.percolateDown(0);\n }\n return min;\n }\n\n /**\n * Checks if the heap is empty.\n * @returns True if the heap is empty; otherwise, false.\n */\n public isEmpty(): boolean {\n return this.heap.length === 0;\n }\n\n /**\n * Returns the minimum element of the heap without removing it.\n * @returns The minimum element, or undefined if the heap is empty.\n */\n public findMin(): HeapItem | undefined {\n return this.heap.length > 0 ? this.heap[0] : undefined;\n }\n}\n\n/**\n * Executes Dijkstra's algorithm to find the shortest paths from a source node\n * in a weighted graph.\n *\n * @param graph - The adjacency list representing the graph with weights.\n * @param source - The source node from which to calculate shortest paths.\n * @returns A dictionary where keys are node labels and values represent the shortest distances from the source node.\n */\nexport default function dijkstra(\n graph: Record>,\n source: string,\n): Record {\n const distances: Record = {};\n const minHeap = new MinHeap();\n\n // Initialize distances for every vertex.\n for (const vertex in graph) {\n distances[vertex] = vertex === source ? 0 : Infinity;\n minHeap.insert({ vertex, weight: distances[vertex] });\n }\n\n const visited = new Set();\n\n while (!minHeap.isEmpty()) {\n // Extract the vertex with the smallest tentative distance.\n const current = minHeap.delete();\n if (!current) break;\n const { vertex: u } = current;\n if (visited.has(u)) continue;\n visited.add(u);\n\n // For each neighbor of u, update its distance if a shorter path is found.\n for (const neighbor in graph[u]) {\n const newDist = distances[u] + graph[u][neighbor];\n if (newDist < distances[neighbor]) {\n distances[neighbor] = newDist;\n minHeap.insert({ vertex: neighbor, weight: newDist });\n }\n }\n }\n\n return distances;\n}\n`;function m(i){let e=Object.assign({h3:\"h3\",p:\"p\",strong:\"strong\",ol:\"ol\",li:\"li\",img:\"img\",h2:\"h2\",ul:\"ul\",code:\"code\"},i.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(e.h3,{children:\"\\u7406\\u7531\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"Dijkstra \\u7B97\\u6CD5\\u8BA1\\u7B97\\u56FE\\u4E2D\\u4ECE\\u5177\\u6709\\u975E\\u8D1F\\u8FB9\\u6743\\u91CD\\u7684\\u6E90\\u8282\\u70B9\\u7684\",(0,t.jsx)(e.strong,{children:\"\\u6700\\u77ED\\u8DEF\\u5F84\"}),\"\\u3002\\u5B83\\u4F7F\\u7528\\u8D2A\\u5FC3\\u65B9\\u6CD5\\uFF1A\\u5728\\u6BCF\\u4E00\\u6B65\\u4E2D\\uFF0C\\u5B83\\u9009\\u62E9\\u5177\\u6709\\u6700\\u5C0F\\u5DF2\\u77E5\\u8DDD\\u79BB\\u7684\\u672A\\u8BBF\\u95EE\\u8282\\u70B9\\u3002 \\u6700\\u5C0F\\u5806\\u53EF\\u4EE5\\u6709\\u6548\\u5730\\u6267\\u884C\\u6B64\\u9009\\u62E9\\u3002 \\u5F53\\u627E\\u5230\\u5230\\u90BB\\u5C45\\u7684\\u66F4\\u77ED\\u8DEF\\u5F84\\u65F6\\uFF0C\\u7B97\\u6CD5\\u4F1A\\u66F4\\u65B0\\u5176\\u8DDD\\u79BB\\uFF08\\u677E\\u5F1B\\uFF09\\u5E76\\u5C06\\u5176\\u63A8\\u5165\\u5806\\u4E2D\\u3002 \\u8FD9\\u79CD\\u7B56\\u7565\\u4FDD\\u8BC1\\u4E86\\u6B63\\u786E\\u6027\\uFF0C\\u56E0\\u4E3A\\u6240\\u6709\\u8FB9\\u6743\\u91CD\\u90FD\\u662F\\u975E\\u8D1F\\u7684\\u3002\"]}),`\n`,(0,t.jsx)(e.p,{children:\"Dijkstra \\u7B97\\u6CD5\\u5047\\u8BBE\\u975E\\u8D1F\\u6743\\u91CD\\u3002 \\u5BF9\\u4E8E\\u5177\\u6709\\u8D1F\\u6743\\u91CD\\u7684\\u56FE\\uFF0C\\u9700\\u8981\\u4F7F\\u7528\\u5176\\u4ED6\\u7B97\\u6CD5\\uFF0C\\u5982 Bellman-Ford\\u3002\"}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,t.jsx)(e.p,{children:\"\\u63D0\\u4F9B\\u7684\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u4F18\\u5148\\u7EA7\\u961F\\u5217\\uFF08\\u6700\\u5C0F\\u5806\\uFF09\\u6765\\u5B9E\\u73B0 Dijkstra \\u7B97\\u6CD5\\uFF0C\\u4EE5\\u63D0\\u9AD8\\u6548\\u7387\\u3002\"}),`\n`,(0,t.jsxs)(e.ol,{children:[`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:\"\\u521D\\u59CB\\u5316\"}),\"\\uFF1A\\u4ECE\\u6240\\u6709\\u8282\\u70B9\\u8BBE\\u7F6E\\u4E3A\\u65E0\\u7A77\\u5927\\u7684\\u8DDD\\u79BB\\u5F00\\u59CB\\uFF0C\\u9664\\u4E86\\u6E90\\u8282\\u70B9\\u8BBE\\u7F6E\\u4E3A\\u96F6\\u3002\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:\"\\u4F18\\u5148\\u7EA7\\u961F\\u5217\"}),\"\\uFF1A\\u4F7F\\u7528\\u4F18\\u5148\\u7EA7\\u961F\\u5217\\u8D2A\\u5A6A\\u5730\\u9009\\u62E9\\u5177\\u6709\\u6700\\u5C0F\\u5DF2\\u77E5\\u8DDD\\u79BB\\u7684\\u4E0B\\u4E00\\u4E2A\\u8282\\u70B9\\u3002\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:\"\\u677E\\u5F1B\"}),\"\\uFF1A\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u9009\\u5B9A\\u7684\\u8282\\u70B9\\uFF0C\\u5982\\u679C\\u901A\\u8FC7\\u5F53\\u524D\\u8282\\u70B9\\u627E\\u5230\\u66F4\\u77ED\\u7684\\u8DEF\\u5F84\\uFF0C\\u5219\\u66F4\\u65B0\\u5230\\u5176\\u76F8\\u90BB\\u8282\\u70B9\\u7684\\u6700\\u77ED\\u8DDD\\u79BB\\u3002 \\u968F\\u540E\\u5728\\u4F18\\u5148\\u7EA7\\u961F\\u5217\\u4E2D\\u6DFB\\u52A0\\u6216\\u66F4\\u65B0\\u8BE5\\u90BB\\u5C45\\u7684\\u8DDD\\u79BB\\u3002\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:\"\\u7EC8\\u6B62\"}),\"\\uFF1A\\u5F53\\u4F18\\u5148\\u7EA7\\u961F\\u5217\\u4E3A\\u7A7A\\u65F6\\uFF0C\\u7B97\\u6CD5\\u7EC8\\u6B62\\uFF0C\\u8868\\u660E\\u6240\\u6709\\u53EF\\u5230\\u8FBE\\u7684\\u8282\\u70B9\\u90FD\\u5DF2\\u5904\\u7406\\u5B8C\\u6BD5\\u3002\"]}),`\n`]}),`\n`,(0,t.jsx)(e.p,{children:(0,t.jsx)(e.img,{src:\"/img/questions/dijkstra/dijkstra.png\",alt:\"Dijkstra Illustration\"})}),`\n`,(0,t.jsx)(l,{languages:{jsx:d,tsx:c}}),`\n`,(0,t.jsx)(e.h2,{children:\"\\u8FB9\\u7F18\\u60C5\\u51B5\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:\"\\u7A7A\\u56FE\"}),\"\\uFF1A\\u8FD4\\u56DE\\u4E00\\u4E2A\\u7A7A\\u5B57\\u5178\\u6216\\u6620\\u5C04\\uFF0C\\u800C\\u4E0D\\u4F1A\\u5D29\\u6E83\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:\"\\u4E00\\u4E2A\\u6216\\u4E24\\u4E2A\\u8282\\u70B9\\u7684\\u56FE\"}),\"\\uFF1A\\u786E\\u4FDD\\u7B97\\u6CD5\\u53EF\\u4EE5\\u5904\\u7406\\u5C0F\\u56FE\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:\"\\u5177\\u6709\\u975E\\u8FDE\\u63A5\\u7EC4\\u4EF6\\u7684\\u56FE\"}),\"\\uFF1A\\u4ECE\\u6E90\\u65E0\\u6CD5\\u5230\\u8FBE\\u7684\\u8282\\u70B9\\u5E94\\u4FDD\\u6301\\u5176\\u8DDD\\u79BB\\u4E3A\\u65E0\\u7A77\\u5927\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:\"\\u5177\\u6709\\u96F6\\u6743\\u91CD\\u8FB9\\u7684\\u56FE\"}),\"\\uFF1A\\u786E\\u8BA4\\u96F6\\u6743\\u91CD\\u8FB9\\u4E0D\\u4F1A\\u5BFC\\u81F4\\u7B97\\u6CD5\\u903B\\u8F91\\u51FA\\u73B0\\u95EE\\u9898\"]}),`\n`]}),`\n`,(0,t.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO((V + E) log V)\"}),\"\\u3002 \\u4F7F\\u7528\\u6700\\u5C0F\\u5806\\uFF0C\\u63D0\\u53D6\\u6700\\u5C0F\\u503C\\u9700\\u8981 O(log V)\\uFF08\\u6700\\u591A\\u6267\\u884C V \\u6B21\\uFF09\\uFF0C\\u5E76\\u4E14\\u677E\\u5F1B\\u6BCF\\u4E2A E \\u8FB9\\u4E5F\\u53EF\\u80FD\\u89E6\\u53D1 O(log V) \\u5806\\u66F4\\u65B0\\u3002\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(v)\"}),\"\\u3002 \\u5B58\\u50A8\\u8DDD\\u79BB\\uFF08\",(0,t.jsx)(e.code,{children:\"O(v)\"}),\"\\uFF09\\u3001\\u5DF2\\u8BBF\\u95EE\\u96C6\\u5408\\uFF08\",(0,t.jsx)(e.code,{children:\"O(v)\"}),\"\\uFF09\\u548C\\u4F18\\u5148\\u7EA7\\u961F\\u5217\\uFF08\\u6700\\u574F\\u60C5\\u51B5\\u4E0B\\u4E3A \",(0,t.jsx)(e.code,{children:\"O(v)\"}),\"\\uFF09\\u3002\"]}),`\n`]})]})}function D(i={}){let{wrapper:e}=i.components||{};return e?(0,t.jsx)(e,Object.assign({},i,{children:(0,t.jsx)(m,i)})):m(i)}var I=D;return j(M);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/disjoint-intervals/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/disjoint-intervals/locales/zh-CN.json new file mode 100644 index 000000000..4c596d832 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/disjoint-intervals/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var u=Object.create;var l=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var f=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),b=(t,e)=>{for(var r in e)l(t,r,{get:e[r],enumerable:!0})},s=(t,e,r,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of v(e))!g.call(t,i)&&i!==r&&l(t,i,{get:()=>e[i],enumerable:!(o=m(e,i))||o.enumerable});return t};var j=(t,e,r)=>(r=t!=null?u(x(t)):{},s(e||!t||!t.__esModule?l(r,\"default\",{value:t,enumerable:!0}):r,t)),_=t=>s(l({},\"__esModule\",{value:!0}),t);var d=f((T,c)=>{c.exports=_jsx_runtime});var D={};b(D,{default:()=>C,frontmatter:()=>M});var n=j(d());var a=MDXTestExamples;var h=[{input:[[\"intervals\",[[1,5],[2,3],[3,4],[4,6]]]],output:1,explanation:\"[1,5] overlaps with multiple intervals, and removing it makes the rest non-overlapping. Since only one interval needs to be removed, the result is 1.\"},{input:[[\"intervals\",[[1,15],[3,5],[6,8],[8,10],[9,11]]]],output:2,explanation:\"[1,15] overlaps with all other intervals, and [9,11] overlaps with [8,10]. Removing these two intervals makes the rest non-overlapping. Since two intervals need to be removed, the result is 2.\"},{input:[[\"intervals\",[[1,4],[4,8]]]],output:0,explanation:\"[1,4] and [4,8] are already non-overlapping, so no intervals need to be removed. Hence, the result is 0.\"}];var M={title:\"\\u4E0D\\u76F8\\u4EA4\\u7684\\u533A\\u95F4\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u4EE5\\u786E\\u5B9A\\u9700\\u8981\\u79FB\\u9664\\u7684\\u6700\\u5C0F\\u6570\\u91CF\\uFF0C\\u4EE5\\u83B7\\u5F97\\u4E0D\\u91CD\\u53E0\\u7684\\u533A\\u95F4\"};function p(t){let e=Object.assign({p:\"p\",code:\"code\",ul:\"ul\",li:\"li\",h3:\"h3\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\",(0,n.jsx)(e.code,{children:\"intervals\"}),\"\\u6570\\u7EC4\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u533A\\u95F4\\u8868\\u793A\\u4E3A\",(0,n.jsx)(e.code,{children:\"[start, end]\"}),\"\\u3002\\u6BCF\\u5BF9\\u8868\\u793A\\u6570\\u8F74\\u4E0A\\u533A\\u95F4\\u7684\\u5F00\\u59CB\\u548C\\u7ED3\\u675F\\u3002\\u4F8B\\u5982\\uFF0C\",(0,n.jsx)(e.code,{children:\"[1, 3]\"}),\"\\u8868\\u793A\\u4E00\\u4E2A\\u4ECE1\\u5F00\\u59CB\\u52303\\u7ED3\\u675F\\u7684\\u533A\\u95F4\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u627E\\u5230\\u9700\\u8981\\u79FB\\u9664\\u7684\\u6700\\u5C0F\\u533A\\u95F4\\u6570\\uFF0C\\u4F7F\\u5269\\u4F59\\u7684\\u533A\\u95F4\\u4E0D\\u76F8\\u4EA4\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u5982\\u679C\\u6570\\u8F74\\u4E0A\\u6CA1\\u6709\\u4E24\\u4E2A\\u533A\\u95F4\\u91CD\\u53E0\\uFF0C\\u5219\\u8BA4\\u4E3A\\u533A\\u95F4\\u4E0D\\u76F8\\u4EA4\\u3002\\u4F8B\\u5982\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"[1, 3]\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"[4, 6]\"}),\" \\u4E0D\\u76F8\\u4EA4\\uFF0C\\u56E0\\u4E3A\\u5B83\\u4EEC\\u6CA1\\u6709\\u4EFB\\u4F55\\u5171\\u540C\\u70B9\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"[1, 5]\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"[4, 6]\"}),\" \\u4E0D\\u76F8\\u4EA4\\uFF0C\\u56E0\\u4E3A\\u5B83\\u4EEC\\u57284\\u548C5\\u4E4B\\u95F4\\u91CD\\u53E0\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"intervals: Array<[number, number]>\"}),\": \\u6574\\u6570\\u5BF9\\u6570\\u7EC4\"]}),`\n`]}),`\n`,(0,n.jsx)(a,{testCases:h}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"0 <= \",(0,n.jsx)(e.code,{children:\"intervals.length\"}),\" <= 100\"]}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.code,{children:\"intervals[i].length == 2\"})}),`\n`,(0,n.jsxs)(e.li,{children:[\"0 <= \",(0,n.jsx)(e.code,{children:\"start\"}),\" <= \",(0,n.jsx)(e.code,{children:\"end\"}),\" <= 10,000\"]}),`\n`]})]})}function y(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(p,t)})):p(t)}var C=y;return _(D);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,以确定需要移除的最小数量,以获得不重叠的区间", + "title": "不相交的区间" + }, + "solution": "var Component=(()=>{var u=Object.create;var c=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var g=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),x=(r,e)=>{for(var l in e)c(r,l,{get:e[l],enumerable:!0})},i=(r,e,l,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let t of v(e))!b.call(r,t)&&t!==l&&c(r,t,{get:()=>e[t],enumerable:!(o=p(e,t))||o.enumerable});return r};var k=(r,e,l)=>(l=r!=null?u(f(r)):{},i(e||!r||!r.__esModule?c(l,\"default\",{value:r,enumerable:!0}):l,r)),O=r=>i(c({},\"__esModule\",{value:!0}),r);var h=g((M,d)=>{d.exports=_jsx_runtime});var C={};x(C,{default:()=>E});var n=k(h());var a=MDXCodeBlock;var s=`const compareSecondElement = (a: number[], b: number[]): number => {\n return a[1] - b[1]; // Return the difference between the second elements\n};\n\nexport default function disjointIntervals(intervals: number[][]): number {\n // Sort intervals by the second element\n intervals.sort(compareSecondElement);\n\n // Initialize answer to count overlaps and k to track the end of the last interval\n let ans = 0;\n let k = Number.MIN_SAFE_INTEGER;\n\n // Iterate through the intervals\n for (const interval of intervals) {\n const x = interval[0];\n const y = interval[1];\n\n if (x >= k) {\n // Case 1: No overlap, update k to the end of the current interval\n k = y;\n } else {\n // Case 2: Overlap, increment the answer\n ans++;\n }\n }\n\n // Return the number of overlaps\n return ans;\n}\n`;function m(r){let e=Object.assign({h2:\"h2\",p:\"p\",h3:\"h3\",ol:\"ol\",li:\"li\",code:\"code\",ul:\"ul\",strong:\"strong\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u8D2A\\u5FC3\\u65B9\\u6CD5\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u95EE\\u9898\\u662F\\u627E\\u5230\\u8981\\u5220\\u9664\\u7684\\u6700\\u5C0F\\u533A\\u95F4\\u6570\\uFF0C\\u4F7F\\u5269\\u4F59\\u7684\\u533A\\u95F4\\u4E0D\\u91CD\\u53E0\\u3002\\u8D2A\\u5FC3\\u65B9\\u6CD5\\u901A\\u8FC7\\u59CB\\u7EC8\\u9009\\u62E9\\u7ED3\\u675F\\u65F6\\u95F4\\u6700\\u65E9\\u7684\\u533A\\u95F4\\u6765\\u4F18\\u5316\\u8FD9\\u4E00\\u70B9\\uFF0C\\u56E0\\u4E3A\\u8FD9\\u4E3A\\u540E\\u7EED\\u533A\\u95F4\\u7559\\u51FA\\u4E86\\u6700\\u5927\\u7684\\u7A7A\\u95F4\\u3002\\u6309\\u7B2C\\u4E8C\\u4E2A\\u5143\\u7D20\\u6392\\u5E8F\\u53EF\\u786E\\u4FDD\\u4F18\\u5148\\u8003\\u8651\\u7ED3\\u675F\\u65F6\\u95F4\\u6700\\u5C0F\\u7684\\u533A\\u95F4\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u8F85\\u52A9\\u51FD\\u6570 \",(0,n.jsx)(e.code,{children:\"compareSecondElement\"}),\" \\u6765\\u6BD4\\u8F83\\u4E24\\u4E2A\\u533A\\u95F4\\u7684\\u7B2C\\u4E8C\\u4E2A\\u5143\\u7D20\\u5E76\\u8FD4\\u56DE\\u5B83\\u4EEC\\u7684\\u5DEE\\u503C\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"compareSecondElement\"}),\" \\u51FD\\u6570\\u5BF9\\u8F93\\u5165 \",(0,n.jsx)(e.code,{children:\"intervals\"}),\" \\u6570\\u7EC4\\u8FDB\\u884C\\u6392\\u5E8F\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316 \",(0,n.jsx)(e.code,{children:\"ans\"}),\" \\u4EE5\\u8DDF\\u8E2A\\u5DF2\\u5220\\u9664\\u7684\\u533A\\u95F4\\u6570\\uFF0C\\u5E76\\u521D\\u59CB\\u5316 \",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u4EE5\\u8DDF\\u8E2A\\u6700\\u540E\\u4E00\\u4E2A\\u4E0D\\u91CD\\u53E0\\u533A\\u95F4\\u7684\\u7ED3\\u675F\\u65F6\\u95F4\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u6392\\u5E8F\\u5217\\u8868\\u4E2D\\u7684\\u6BCF\\u4E2A\\u533A\\u95F4\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u63D0\\u53D6\\u5F53\\u524D\\u533A\\u95F4\\u7684\\u5F00\\u59CB (\",(0,n.jsx)(e.code,{children:\"x\"}),\") \\u548C\\u7ED3\\u675F (\",(0,n.jsx)(e.code,{children:\"y\"}),\")\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5F53\\u524D\\u533A\\u95F4\\u7684\\u5F00\\u59CB\\u65F6\\u95F4\\u5927\\u4E8E\\u6216\\u7B49\\u4E8E \",(0,n.jsx)(e.code,{children:\"k\"}),\"\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u66F4\\u65B0\\u4E3A\\u5F53\\u524D\\u533A\\u95F4\\u7684\\u7ED3\\u675F\\u65F6\\u95F4\\uFF0C\\u56E0\\u4E3A\\u6CA1\\u6709\\u91CD\\u53E0\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5426\\u5219\\uFF0C\\u9012\\u589E \",(0,n.jsx)(e.code,{children:\"ans\"}),\"\\uFF0C\\u56E0\\u4E3A\\u533A\\u95F4\\u91CD\\u53E0\\u5E76\\u4E14\\u9700\\u8981\\u5220\\u9664\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"ans\"}),\"\\uFF0C\\u5B83\\u4FDD\\u5B58\\u4E86\\u4E3A\\u4F7F\\u533A\\u95F4\\u4E0D\\u76F8\\u4EA4\\u800C\\u5220\\u9664\\u7684\\u533A\\u95F4\\u8BA1\\u6570\\u3002\"]}),`\n`]}),`\n`,(0,n.jsxs)(a,{children:[\" \",s,\" \"]}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n log n)\"}),\"\\u3002\\u5BF9\\u533A\\u95F4\\u8FDB\\u884C\\u6392\\u5E8F\\u9700\\u8981 O(n log n)\\uFF0C\\u540E\\u7EED\\u904D\\u5386\\u533A\\u95F4\\u9700\\u8981 O(n)\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u5728\\u6052\\u5B9A\\u7A7A\\u95F4\\u5185\\u8FD0\\u884C\\uFF0C\\u56E0\\u4E3A\\u5B83\\u5C31\\u5730\\u5904\\u7406\\u8F93\\u5165\\u6570\\u7EC4\\u3002\"]}),`\n`]})]})}function j(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(m,r)})):m(r)}var E=j;return O(C);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/extraterrestrial-language/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/extraterrestrial-language/locales/zh-CN.json new file mode 100644 index 000000000..8533718db --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/extraterrestrial-language/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var u=Object.create;var a=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var g=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),w=(t,e)=>{for(var r in e)a(t,r,{get:e[r],enumerable:!0})},o=(t,e,r,s)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of m(e))!x.call(t,i)&&i!==r&&a(t,i,{get:()=>e[i],enumerable:!(s=b(e,i))||s.enumerable});return t};var _=(t,e,r)=>(r=t!=null?u(f(t)):{},o(e||!t||!t.__esModule?a(r,\"default\",{value:t,enumerable:!0}):r,t)),j=t=>o(a({},\"__esModule\",{value:!0}),t);var d=g((k,c)=>{c.exports=_jsx_runtime});var D={};w(D,{default:()=>y,frontmatter:()=>C});var n=_(d());var l=MDXTestExamples;var h=[{input:[[\"words\",[\"cab\",\"abc\",\"bca\"]]],output:\"cab\",explanation:\"Comparing 'cab' and 'abc', the first differing characters are c and a, suggesting c comes before a. Comparing 'abc' and 'bca', the first differing characters are a and b, so a comes before b. Thus, the order of letters in the new alphabet is 'cab'.\"},{input:[[\"words\",[\"abc\",\"ab\"]]],output:\"\",explanation:\"The list is invalid because 'ab' should not come before 'abc'. A shorter word with the same prefix cannot appear after a longer word, so the sequence is impossible, and the result is an empty string.\"},{input:[[\"words\",[\"z\",\"x\",\"z\"]]],output:\"\",explanation:\"The sequence is invalid because 'z' appears both before and after 'x', which creates a contradiction in the order. This inconsistency makes it impossible to deduce a valid letter order, so the result is an empty string.\"}];var C={title:\"\\u5916\\u661F\\u8BED\\u8A00\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u9A8C\\u8BC1\\u5E76\\u8FD4\\u56DE\\u5916\\u661F\\u8BED\\u8A00\\u7684\\u5B57\\u6BCD\\u8868\\u987A\\u5E8F\"};function p(t){let e=Object.assign({p:\"p\",code:\"code\",a:\"a\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u79CD\\u5916\\u661F\\u8BED\\u8A00\\u4F7F\\u7528\\u82F1\\u6587\\u5B57\\u6BCD\\uFF0C\\u4F46\\u5B57\\u6BCD\\u987A\\u5E8F\\u672A\\u77E5\\u3002\\u63D0\\u4F9B\\u4E86\\u4E00\\u4E2A\\u5B57\\u7B26\\u4E32\\u5217\\u8868 \",(0,n.jsx)(e.code,{children:\"words\"}),\"\\uFF0C\\u5B83\\u8868\\u793A\\u5916\\u661F\\u8BED\\u8A00\\u8BCD\\u5178\\u4E2D\\u7684\\u5355\\u8BCD\\uFF0C\\u5E76\\u4E14\\u58F0\\u79F0\\u8FD9\\u4E9B\\u5355\\u8BCD\\u662F\\u6839\\u636E\\u65B0\\u8BED\\u8A00\\u7684\",(0,n.jsx)(e.a,{href:\"https://en.wikipedia.org/wiki/Lexicographic_order\",children:\"\\u5B57\\u5178\\u987A\\u5E8F\"}),\"\\u6392\\u5E8F\\u7684\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5982\\u679C\\u6B64\\u58F0\\u660E\\u4E3A\\u5047\\uFF0C\\u5E76\\u4E14 \",(0,n.jsx)(e.code,{children:\"words\"}),\" \\u4E2D\\u7684\\u5B57\\u7B26\\u4E32\\u6392\\u5217\\u65B9\\u5F0F\\u65E0\\u6CD5\\u5339\\u914D\\u4EFB\\u4F55\\u53EF\\u80FD\\u7684\\u5B57\\u6BCD\\u987A\\u5E8F\\uFF0C\\u5219\\u8FD4\\u56DE\\u4E00\\u4E2A\\u7A7A\\u5B57\\u7B26\\u4E32\\u3002\\u5426\\u5219\\uFF0C\\u8FD4\\u56DE\\u4E00\\u4E2A\\u5B57\\u7B26\\u4E32\\uFF0C\\u5176\\u4E2D\\u5305\\u542B\\u6839\\u636E\\u8BE5\\u8BED\\u8A00\\u89C4\\u5219\\u6392\\u5E8F\\u7684\\u5916\\u661F\\u8BED\\u8A00\\u7684\\u552F\\u4E00\\u5B57\\u6BCD\\u3002\\u5982\\u679C\\u5B58\\u5728\\u591A\\u4E2A\\u6709\\u6548\\u89E3\\u51B3\\u65B9\\u6848\\uFF0C\\u5219\\u63A5\\u53D7\\u5176\\u4E2D\\u4EFB\\u4F55\\u4E00\\u4E2A\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"words: string[]\"}),\": \\u4E00\\u4E2A\\u5B57\\u7B26\\u4E32\\u6570\\u7EC4\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u5B57\\u7B26\\u4E32\\u90FD\\u662F\\u5916\\u661F\\u8BED\\u8A00\\u4E2D\\u7684\\u4E00\\u4E2A\\u5355\\u8BCD\"]}),`\n`]}),`\n`,(0,n.jsx)(l,{testCases:h}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"words.length\"}),\" <= 100\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"words[i].length\"}),\" <= 10\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"words[i]\"}),\" \\u4EC5\\u7531\\u5C0F\\u5199\\u82F1\\u6587\\u5B57\\u6BCD\\u7EC4\\u6210\"]}),`\n`]})]})}function M(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(p,t)})):p(t)}var y=M;return j(D);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来验证并返回外星语言的字母表顺序", + "title": "外星语言" + }, + "solution": "var Component=(()=>{var g=Object.create;var c=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var p=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports),x=(r,n)=>{for(var t in n)c(r,t,{get:n[t],enumerable:!0})},d=(r,n,t,o)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let i of w(n))!j.call(r,i)&&i!==t&&c(r,i,{get:()=>n[i],enumerable:!(o=f(n,i))||o.enumerable});return r};var b=(r,n,t)=>(t=r!=null?g(m(r)):{},d(n||!r||!r.__esModule?c(t,\"default\",{value:r,enumerable:!0}):t,r)),L=r=>d(c({},\"__esModule\",{value:!0}),r);var s=p((k,l)=>{l.exports=_jsx_runtime});var q={};x(q,{default:()=>O});var e=b(s());var h=MDXCodeBlock;var u=`export default function extraterrestrialLanguage(words: string[]): string {\n // Step 0: Create data structures and find all unique letters.\n const adjList: { [key: string]: string[] } = {};\n const counts: { [key: string]: number } = {};\n\n // Initialize the adjacency list and the counts map\n for (const word of words) {\n for (const c of word) {\n if (!counts[c]) {\n counts[c] = 0;\n adjList[c] = [];\n }\n }\n }\n\n // Step 1: Find all edges.\n for (let i = 0; i < words.length - 1; i++) {\n const word1 = words[i];\n const word2 = words[i + 1];\n\n // Check that word2 is not a prefix of word1.\n if (word1.length > word2.length && word1.startsWith(word2)) {\n return '';\n }\n\n // Find the first non-match and insert the corresponding relation.\n for (let j = 0; j < Math.min(word1.length, word2.length); j++) {\n if (word1[j] !== word2[j]) {\n adjList[word1[j]].push(word2[j]);\n counts[word2[j]]++;\n break;\n }\n }\n }\n\n // Step 2: Breadth-first search.\n const sb: string[] = [];\n const queue: string[] = [];\n\n // Enqueue characters with no incoming edges (counts[c] === 0)\n for (const c in counts) {\n if (counts[c] === 0) {\n queue.push(c);\n }\n }\n\n // Perform BFS to build the result string\n while (queue.length > 0) {\n const c = queue.shift()!;\n sb.push(c);\n for (const next of adjList[c]) {\n counts[next]--;\n if (counts[next] === 0) {\n queue.push(next);\n }\n }\n }\n\n // If the result length is less than the number of unique characters, return an empty string\n if (sb.length < Object.keys(counts).length) {\n return '';\n }\n\n return sb.join('');\n}\n`;function a(r){let n=Object.assign({h2:\"h2\",p:\"p\",ul:\"ul\",li:\"li\",h3:\"h3\",ol:\"ol\",code:\"code\",strong:\"strong\"},r.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"1. \\u4F7F\\u7528BFS\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u8BE5\\u95EE\\u9898\\u662F\\u6839\\u636E\\u6309\\u5B57\\u5178\\u987A\\u5E8F\\u6392\\u5E8F\\u7684\\u5355\\u8BCD\\u5217\\u8868\\u6765\\u786E\\u5B9A\\u5916\\u661F\\u8BED\\u8A00\\u4E2D\\u5B57\\u7B26\\u7684\\u987A\\u5E8F\\u3002\\u8FD9\\u6D89\\u53CA\\u4ECE\\u7ED9\\u5B9A\\u7684\\u5355\\u8BCD\\u63A8\\u65AD\\u6709\\u5411\\u65E0\\u73AF\\u56FE (DAG)\\uFF0C\\u5E76\\u5BF9\\u5176\\u6267\\u884C\\u62D3\\u6251\\u6392\\u5E8F\\u3002\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u7B97\\u6CD5\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u6784\\u5EFA\\u4E00\\u4E2A\\u56FE\\uFF0C\\u5176\\u4E2D\\u8282\\u70B9\\u4EE3\\u8868\\u552F\\u4E00\\u7684\\u5B57\\u7B26\\uFF0C\\u6709\\u5411\\u8FB9\\u8868\\u793A\\u5B57\\u7B26\\u7684\\u4F18\\u5148\\u7EA7\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u4F7F\\u7528\\u5E7F\\u5EA6\\u4F18\\u5148\\u641C\\u7D22 (BFS) \\u5BF9\\u56FE\\u6267\\u884C\\u62D3\\u6251\\u6392\\u5E8F\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5904\\u7406\\u65E0\\u6548\\u60C5\\u51B5\\uFF0C\\u4F8B\\u5982\\u524D\\u7F00\\u51B2\\u7A81\\u6216\\u56FE\\u4E2D\\u7684\\u5FAA\\u73AF\\u3002\"}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u90BB\\u63A5\\u8868 \",(0,e.jsx)(n.code,{children:\"adjList\"}),\" \\u6765\\u8868\\u793A\\u56FE\\uFF0C\\u5E76\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"counts\"}),\" \\u6620\\u5C04\\u6765\\u8DDF\\u8E2A\\u6BCF\\u4E2A\\u5B57\\u7B26\\u7684\\u5165\\u5EA6\\u3002\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5C06\\u6240\\u6709\\u552F\\u4E00\\u5B57\\u7B26\\u6DFB\\u52A0\\u5230 \",(0,e.jsx)(n.code,{children:\"adjList\"}),\" \\u548C \",(0,e.jsx)(n.code,{children:\"counts\"}),\" \\u4E2D\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u904D\\u5386\\u5355\\u8BCD\\u5217\\u8868\\u4EE5\\u5EFA\\u7ACB\\u4F18\\u5148\\u7EA7\\u5173\\u7CFB\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u6BD4\\u8F83\\u76F8\\u90BB\\u7684\\u5355\\u8BCD \",(0,e.jsx)(n.code,{children:\"word1\"}),\" \\u548C \",(0,e.jsx)(n.code,{children:\"word2\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u68C0\\u67E5 \",(0,e.jsx)(n.code,{children:\"word2\"}),\" \\u662F \",(0,e.jsx)(n.code,{children:\"word1\"}),\" \\u7684\\u524D\\u7F00\\u4F46\\u66F4\\u77ED\\u7684\\u65E0\\u6548\\u60C5\\u51B5\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5BF9\\u4E8E \",(0,e.jsx)(n.code,{children:\"word1\"}),\" \\u548C \",(0,e.jsx)(n.code,{children:\"word2\"}),\" \\u4E4B\\u95F4\\u7B2C\\u4E00\\u4E2A\\u4E0D\\u540C\\u7684\\u5B57\\u7B26\\uFF0C\\u5728 \",(0,e.jsx)(n.code,{children:\"adjList\"}),\" \\u4E2D\\u6DFB\\u52A0\\u4E00\\u6761\\u6709\\u5411\\u8FB9\\uFF0C\\u5E76\\u589E\\u52A0 \",(0,e.jsx)(n.code,{children:\"counts\"}),\" \\u4E2D\\u7684\\u5165\\u5EA6\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528 BFS \\u6267\\u884C\\u62D3\\u6251\\u6392\\u5E8F\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5C06\\u6240\\u6709\\u5165\\u5EA6\\u4E3A\\u96F6\\u7684\\u5B57\\u7B26\\u6DFB\\u52A0\\u5230\\u961F\\u5217\\u4E2D\\u3002\"}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5904\\u7406\\u961F\\u5217\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5B57\\u7B26\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5C06\\u5176\\u9644\\u52A0\\u5230\\u7ED3\\u679C\\u5B57\\u7B26\\u4E32\\u4E2D\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u51CF\\u5C11\\u5176\\u90BB\\u5C45\\u7684\\u5165\\u5EA6\\uFF0C\\u5E76\\u5C06\\u5165\\u5EA6\\u53D8\\u4E3A\\u96F6\\u7684\\u4EFB\\u4F55\\u90BB\\u5C45\\u52A0\\u5165\\u961F\\u5217\\u3002\"}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,e.jsx)(n.li,{children:\"\\u68C0\\u67E5\\u7ED3\\u679C\\u5B57\\u7B26\\u4E32\\u662F\\u5426\\u5305\\u542B\\u6240\\u6709\\u552F\\u4E00\\u5B57\\u7B26\\u3002\\u5982\\u679C\\u4E0D\\u662F\\uFF0C\\u5219\\u5B58\\u5728\\u5FAA\\u73AF\\uFF0C\\u7ED3\\u679C\\u65E0\\u6548\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5982\\u679C\\u6709\\u6548\\uFF0C\\u5219\\u8FD4\\u56DE\\u7ED3\\u679C\\u5B57\\u7B26\\u4E32\\uFF0C\\u5426\\u5219\\u8FD4\\u56DE\\u4E00\\u4E2A\\u7A7A\\u5B57\\u7B26\\u4E32\\u3002\"}),`\n`]}),`\n`,(0,e.jsx)(h,{children:u}),`\n`,(0,e.jsx)(n.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n + m)\"}),\"\\u3002\\u5904\\u7406\\u6240\\u6709\\u5B57\\u7B26\\u9700\\u8981 O(m)\\uFF0C\\u5176\\u4E2D \",(0,e.jsx)(n.code,{children:\"m\"}),\" \\u662F\\u8F93\\u5165\\u4E2D\\u5B57\\u7B26\\u7684\\u603B\\u6570\\u3002\\u6784\\u5EFA\\u8FB9\\u548C\\u6267\\u884C BFS \\u9700\\u8981 O(n + m)\\uFF0C\\u5176\\u4E2D \",(0,e.jsx)(n.code,{children:\"n\"}),\" \\u662F\\u552F\\u4E00\\u5B57\\u7B26\\u7684\\u6570\\u91CF\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n + m)\"}),\"\\u3002\\u90BB\\u63A5\\u8868\\u548C\\u5165\\u5EA6\\u6620\\u5C04\\u9700\\u8981 O(n + m) \\u7A7A\\u95F4\\u3002\"]}),`\n`]})]})}function F(r={}){let{wrapper:n}=r.components||{};return n?(0,e.jsx)(n,Object.assign({},r,{children:(0,e.jsx)(a,r)})):a(r)}var O=F;return L(q);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/graph-clone/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/graph-clone/locales/zh-CN.json new file mode 100644 index 000000000..0b3f985fb --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/graph-clone/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var u=Object.create;var a=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var b=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),f=(i,e)=>{for(var t in e)a(i,t,{get:e[t],enumerable:!0})},d=(i,e,t,c)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of m(e))!j.call(i,r)&&r!==t&&a(i,r,{get:()=>e[r],enumerable:!(c=g(e,r))||c.enumerable});return i};var y=(i,e,t)=>(t=i!=null?u(x(i)):{},d(e||!i||!i.__esModule?a(t,\"default\",{value:i,enumerable:!0}):t,i)),_=i=>d(a({},\"__esModule\",{value:!0}),i);var h=b((M,l)=>{l.exports=_jsx_runtime});var w={};f(w,{default:()=>T,frontmatter:()=>G});var n=y(h());var o=MDXTestExamples;var s=[{input:[[\"adjList\",[[1,2,3],[0,4,6],[0,6],[0,5],[1],[3],[1,2]]]],output:[[1,2,3],[0,4,6],[0,6],[0,5],[1],[3],[1,2]],explanation:\"The input and output adjacency lists are identical because the given graph has been accurately cloned\"},{input:[[\"adjList\",[[1,2,3,8],[0,4,6],[0],[0,5],[1,10,9],[3,7,9,11],[1],[5],[0],[5,4],[4],[5]]]],output:[[1,2,3,8],[0,4,6],[0],[0,5],[1,10,9],[3,7,9,11],[1],[5],[0],[5,4],[4],[5]],explanation:\"The input and output adjacency lists are identical because the given graph has been accurately cloned\"},{input:[[\"adjList\",[[1,2,3,8],[0,4,6,5],[0],[0,5],[1],[3,7,1],[1],[5],[0]]]],output:[[1,2,3,8],[0,4,6,5],[0],[0,5],[1],[3,7,1],[1],[5],[0]],explanation:\"The input and output adjacency lists are identical because the given graph has been accurately cloned\"}];var G={title:\"\\u56FE\\u7684\\u514B\\u9686\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u6DF1\\u5EA6\\u514B\\u9686\\u4E00\\u4E2A\\u8FDE\\u901A\\u7684\\u65E0\\u5411\\u56FE\"};function p(i){let e=Object.assign({p:\"p\",a:\"a\",code:\"code\",pre:\"pre\",h3:\"h3\",ul:\"ul\",li:\"li\"},i.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u5BF9\",(0,n.jsx)(e.a,{href:\"https://en.wikipedia.org/wiki/Connectivity_(graph_theory)\",children:\"\\u8FDE\\u901A\\u65E0\\u5411\\u56FE\"}),\"\\u4E2D\\u8282\\u70B9\\u7684\\u5F15\\u7528\\uFF0C\\u521B\\u5EFA\\u5E76\\u8FD4\\u56DE\\u8BE5\\u514B\\u9686\\u56FE\\u8282\\u70B9\\u7684\\u6DF1\\u62F7\\u8D1D\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u6DF1\\u62F7\\u8D1D\\u5FC5\\u987B\\u590D\\u5236\\u539F\\u59CB\\u56FE\\u7684\\u6574\\u4E2A\\u7ED3\\u6784\\uFF0C\\u786E\\u4FDD\\u6240\\u6709\\u8282\\u70B9\\u53CA\\u5176\\u8FDE\\u63A5\\u90FD\\u88AB\\u51C6\\u786E\\u590D\\u5236\\uFF0C\\u800C\\u65E0\\u9700\\u5F15\\u7528\\u539F\\u59CB\\u56FE\\u3002\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8BE5\\u56FE\\u7531\",(0,n.jsx)(e.code,{children:\"GraphNode\"}),\"\\u7684\\u96C6\\u5408\\u8868\\u793A\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u8282\\u70B9\\u90FD\\u6709\\u4E00\\u4E2A\",(0,n.jsx)(e.code,{children:\"neighbors\"}),\"\\u5217\\u8868\\uFF0C\\u5B83\\u4EEC\\u4E5F\\u662F\",(0,n.jsx)(e.code,{children:\"GraphNode\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A\",(0,n.jsx)(e.code,{children:\"GraphNode\"}),\"\\u5177\\u6709\\u4EE5\\u4E0B\\u63A5\\u53E3\\uFF1A\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-ts\",children:`interface GraphNode {\n val: number;\n neighbors: GraphNode[];\n}\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"node: GraphNode\"}),\": \\u8FDE\\u901A\\u65E0\\u5411\\u56FE\\u4E2D\\u7684\\u8282\\u70B9\\u3002\\u793A\\u4F8B\\u663E\\u793A\\u4E86\\u8BE5\\u56FE\\u7684\",(0,n.jsx)(e.a,{href:\"https://en.wikipedia.org/wiki/Adjacency_list\",children:\"\\u90BB\\u63A5\\u8868\"}),\"\\u8868\\u793A\"]}),`\n`]}),`\n`,(0,n.jsx)(o,{testCases:s}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u6CE8\\u610F\\u4E8B\\u9879\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u4E0D\\u8981\\u8FD4\\u56DE\\u539F\\u59CB\\u56FE\\u7684\\u4EFB\\u4F55\\u8282\\u70B9\"}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"0 <= \\u8282\\u70B9\\u6570 <= 100\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"0 <= \",(0,n.jsx)(e.code,{children:\"GraphNode.val\"}),\" <= 100\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"GraphNode.val\"}),\" \\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u8282\\u70B9\\u90FD\\u662F\\u552F\\u4E00\\u7684\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8BE5\\u56FE\\u6CA1\\u6709\\u91CD\\u590D\\u7684\\u8FB9\\u6216\\u81EA\\u5FAA\\u73AF\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8BE5\\u56FE\\u662F\\u8FDE\\u901A\\u7684\\uFF0C\\u8FD9\\u610F\\u5473\\u7740\\u4ECE\\u7ED9\\u5B9A\\u8282\\u70B9\\u5F00\\u59CB\\u53EF\\u4EE5\\u8BBF\\u95EE\\u6240\\u6709\\u8282\\u70B9\"}),`\n`]})]})}function v(i={}){let{wrapper:e}=i.components||{};return e?(0,n.jsx)(e,Object.assign({},i,{children:(0,n.jsx)(p,i)})):p(i)}var T=v;return _(w);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,深度克隆一个连通的无向图", + "title": "图的克隆" + }, + "solution": "var Component=(()=>{var g=Object.create;var r=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty;var G=(o,e)=>()=>(e||o((e={exports:{}}).exports,e),e.exports),m=(o,e)=>{for(var d in e)r(o,d,{get:e[d],enumerable:!0})},c=(o,e,d,h)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of v(e))!N.call(o,i)&&i!==d&&r(o,i,{get:()=>e[i],enumerable:!(h=f(e,i))||h.enumerable});return o};var M=(o,e,d)=>(d=o!=null?g(b(o)):{},c(e||!o||!o.__esModule?r(d,\"default\",{value:o,enumerable:!0}):d,o)),F=o=>c(r({},\"__esModule\",{value:!0}),o);var a=G((_,t)=>{t.exports=_jsx_runtime});var C={};m(C,{default:()=>B});var n=M(a());var l=MDXCodeBlock;var s=`class GraphNode {\n val: number;\n neighbors: GraphNode[];\n\n constructor(val?: number, neighbors?: GraphNode[]) {\n this.val = val ?? 0;\n this.neighbors = neighbors ?? [];\n }\n}\n\nexport default function graphClone(node: GraphNode | null): GraphNode | null {\n if (node === null) {\n return null;\n }\n\n const visited = new Map();\n\n function dfs(node: GraphNode): GraphNode {\n // If the node was already visited before\n // Return the clone from the visited dictionary\n if (visited.has(node)) {\n return visited.get(node)!;\n }\n\n // Create a clone for the given node\n // Note that we don't have cloned neighbors as of now, hence []\n let cloneNode = new GraphNode(node.val, []);\n // The key is original node and value being the clone node\n visited.set(node, cloneNode);\n\n // Iterate through each neighbor and push the clone of the neighbor\n // to the neighbors of the cloned node\n for (let neighbor of node.neighbors) {\n cloneNode.neighbors.push(dfs(neighbor));\n }\n\n return cloneNode;\n }\n\n return dfs(node);\n}\n`;var u=`class GraphNode {\n val: number;\n neighbors: GraphNode[];\n\n constructor(val?: number, neighbors?: GraphNode[]) {\n this.val = val ?? 0;\n this.neighbors = neighbors ?? [];\n }\n}\n\nexport default function graphClone(node: GraphNode | null): GraphNode | null {\n if (!node) {\n return node;\n }\n\n // Dictionary to save the visited node and it's respective clone\n // as key and value respectively. This helps to avoid cycles\n let visited: Map = new Map();\n\n // Put the first node in the queue\n let queue: GraphNode[] = [];\n queue.push(node);\n\n // Clone the node and put it in the visited dictionary\n visited.set(node, new GraphNode(node.val, []));\n\n // Start BFS traversal\n while (queue.length > 0) {\n // Pop a node from the from the front of the queue\n let node_: GraphNode = queue.shift()!;\n\n // Iterate through all the neighbors of the node\n for (let neighbor of node_.neighbors) {\n if (!visited.has(neighbor)) {\n // Clone the neighbor and put in the visited, if not present already\n visited.set(neighbor, new GraphNode(neighbor.val, []));\n // Add the newly encountered node to the queue\n queue.push(neighbor);\n }\n\n // Add the clone of the neighbor to the neighbors of the cloned node\n visited.get(node_)?.neighbors.push(visited.get(neighbor) as GraphNode);\n }\n }\n\n // Return the clone of the node from visited\n return visited.get(node) ?? null;\n}\n`;function p(o){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},o.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528 DFS\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u4EFB\\u52A1\\u662F\\u521B\\u5EFA\\u4E00\\u4E2A\\u56FE\\u7684\\u6DF1\\u62F7\\u8D1D\\u3002\\u4E00\\u4E2A\\u56FE\\u7531\\u8282\\u70B9\\u7EC4\\u6210\\uFF0C\\u6BCF\\u4E2A\\u8282\\u70B9\\u90FD\\u6709\\u4E00\\u4E2A\\u503C\\u548C\\u90BB\\u5C45\\u5217\\u8868\\u3002\\u6311\\u6218\\u5728\\u4E8E\\u786E\\u4FDD\\u65B0\\u56FE\\u4E2D\\u7684\\u6BCF\\u4E2A\\u8282\\u70B9\\u90FD\\u662F\\u4E00\\u4E2A\\u5B8C\\u5168\\u72EC\\u7ACB\\u7684\\u526F\\u672C\\uFF0C\\u5E76\\u4E14\\u8282\\u70B9\\u4E4B\\u95F4\\u7684\\u6240\\u6709\\u8FDE\\u63A5\\u90FD\\u5F97\\u5230\\u51C6\\u786E\\u590D\\u5236\\u3002\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5176\\u57FA\\u672C\\u539F\\u7406\\u662F\\u57FA\\u4E8E\\u5BF9\\u56FE\\u7684\\u6DF1\\u5EA6\\u4F18\\u5148\\u641C\\u7D22\\uFF08DFS\\uFF09\\u904D\\u5386\\u3002\\u4ECE\\u4E00\\u4E2A\\u8282\\u70B9\\u5F00\\u59CB\\uFF0C\\u7B97\\u6CD5\\u9012\\u5F52\\u5730\\u8BBF\\u95EE\\u5176\\u6240\\u6709\\u90BB\\u5C45\\uFF0C\\u5E76\\u5728\\u9047\\u5230\\u672A\\u8BBF\\u95EE\\u7684\\u8282\\u70B9\\u65F6\\u521B\\u5EFA\\u65B0\\u7684\\u514B\\u9686\\u8282\\u70B9\\u3002\\u4E3A\\u4E86\\u907F\\u514D\\u91CD\\u590D\\u5DE5\\u4F5C\\u5E76\\u786E\\u4FDD\\u8282\\u70B9\\u4E0D\\u4F1A\\u88AB\\u591A\\u6B21\\u514B\\u9686\\uFF0C\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"Map\"}),\" \\u6765\\u5B58\\u50A8\\u539F\\u59CB\\u8282\\u70B9\\u4E0E\\u5176\\u514B\\u9686\\u5BF9\\u5E94\\u7269\\u4E4B\\u95F4\\u7684\\u5173\\u7CFB\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\\u5F53\\u4E00\\u4E2A\\u8282\\u70B9\\u88AB\\u91CD\\u65B0\\u8BBF\\u95EE\\uFF08\\u7531\\u4E8E\\u5FAA\\u73AF\\u6216\\u5171\\u4EAB\\u90BB\\u5C45\\uFF09\\u65F6\\uFF0C\\u7B97\\u6CD5\\u4F1A\\u91CD\\u7528 \",(0,n.jsx)(e.code,{children:\"Map\"}),\" \\u4E2D\\u7684\\u73B0\\u6709\\u514B\\u9686\\uFF0C\\u800C\\u4E0D\\u662F\\u521B\\u5EFA\\u4E00\\u4E2A\\u65B0\\u7684\\u514B\\u9686\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u53CD\\u6620\\u4E86\\u56FE\\u7684\\u81EA\\u7136\\u8FDE\\u63A5\\u65B9\\u5F0F\\uFF0C\\u5728\\u5904\\u7406\\u6BCF\\u4E2A\\u8282\\u70B9\\u53CA\\u5176\\u8FDE\\u63A5\\u65F6\\u9010\\u6B65\\u6784\\u5EFA\\u514B\\u9686\\u56FE\\u3002\\u901A\\u8FC7\\u9012\\u5F52\\u5904\\u7406\\u90BB\\u5C45\\u5E76\\u5229\\u7528 \",(0,n.jsx)(e.code,{children:\"Map\"}),\" \\u6765\\u63D0\\u9AD8\\u6548\\u7387\\uFF0C\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u907F\\u514D\\u4E86\\u4E0D\\u5FC5\\u8981\\u7684\\u5DE5\\u4F5C\\u91CD\\u590D\\uFF0C\\u5E76\\u4FDD\\u8BC1\\u4E86\\u514B\\u9686\\u56FE\\u7ED3\\u6784\\u7684\\u6B63\\u786E\\u6027\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u8F93\\u5165\\u8282\\u70B9\\u662F\\u5426\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\u3002\\u5982\\u679C\\u662F\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u56E0\\u4E3A\\u6CA1\\u6709\\u8981\\u514B\\u9686\\u7684\\u56FE\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"Map\"}),\" \\u6765\\u5B58\\u50A8\\u539F\\u59CB\\u8282\\u70B9\\u4E0E\\u5176\\u514B\\u9686\\u5BF9\\u5E94\\u7269\\u4E4B\\u95F4\\u7684\\u6620\\u5C04\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u9012\\u5F52\\u7684 \",(0,n.jsx)(e.code,{children:\"dfs\"}),\" \\u51FD\\u6570\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5F53\\u524D\\u8282\\u70B9\\u5DF2\\u88AB\\u8BBF\\u95EE\\uFF0C\\u5219\\u4ECE \",(0,n.jsx)(e.code,{children:\"Map\"}),\" \\u8FD4\\u56DE\\u76F8\\u5E94\\u7684\\u514B\\u9686\\u8282\\u70B9\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521B\\u5EFA\\u4E00\\u4E2A\\u5177\\u6709\\u5F53\\u524D\\u8282\\u70B9\\u7684\\u503C\\u548C\\u7A7A\\u90BB\\u5C45\\u5217\\u8868\\u7684\\u65B0 \",(0,n.jsx)(e.code,{children:\"GraphNode\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u5F53\\u524D\\u8282\\u70B9\\u53CA\\u5176\\u514B\\u9686\\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"Map\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u5F53\\u524D\\u8282\\u70B9\\u7684\\u6BCF\\u4E2A\\u90BB\\u5C45\\uFF0C\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"dfs\"}),\" \\u51FD\\u6570\\u9012\\u5F52\\u5730\\u514B\\u9686\\u90BB\\u5C45\\uFF0C\\u5E76\\u5C06\\u5176\\u6DFB\\u52A0\\u5230\\u514B\\u9686\\u8282\\u70B9\\u7684\\u90BB\\u5C45\\u5217\\u8868\\u4E2D\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u5728\\u8F93\\u5165\\u8282\\u70B9\\u4E0A\\u8C03\\u7528 \",(0,n.jsx)(e.code,{children:\"dfs\"}),\" \\u6765\\u542F\\u52A8\\u514B\\u9686\\u8FC7\\u7A0B\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8FD4\\u56DE\\u514B\\u9686\\u56FE\\u7684\\u6839\\u8282\\u70B9\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(l,{children:s}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(v + e)\"}),\"\\u3002\\u5728 DFS \\u904D\\u5386\\u671F\\u95F4\\uFF0C\\u56FE\\u4E2D\\u7684\\u6BCF\\u4E2A\\u8282\\u70B9 (\",(0,n.jsx)(e.code,{children:\"v\"}),\") \\u548C\\u8FB9 (\",(0,n.jsx)(e.code,{children:\"e\"}),\") \\u90FD\\u53EA\\u88AB\\u8BBF\\u95EE\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(v)\"}),\"\\u3002\",(0,n.jsx)(e.code,{children:\"Map\"}),\" \\u5B58\\u50A8\\u6BCF\\u4E2A\\u8282\\u70B9\\u7684\\u6620\\u5C04\\uFF0C\\u5E76\\u4E14\\u9012\\u5F52\\u5806\\u6808\\u6700\\u591A\\u53EF\\u4EE5\\u589E\\u957F\\u5230\\u56FE\\u4E2D\\u8282\\u70B9\\u7684\\u6570\\u91CF\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528 BFS\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u4F7F\\u7528\\u5E7F\\u5EA6\\u4F18\\u5148\\u641C\\u7D22\\uFF08BFS\\uFF09\\u904D\\u5386\\u6765\\u7CFB\\u7EDF\\u5730\\u8BBF\\u95EE\\u6240\\u6709\\u8282\\u70B9\\u5E76\\u514B\\u9686\\u5B83\\u4EEC\\u3002BFS \\u786E\\u4FDD\\u8282\\u70B9\\u9010\\u5C42\\u8BBF\\u95EE\\uFF0C\\u5E76\\u4E14\\u6BCF\\u4E2A\\u8282\\u70B9\\u53EA\\u5904\\u7406\\u4E00\\u6B21\\u3002\",(0,n.jsx)(e.code,{children:\"Map\"}),\" \\u7528\\u4E8E\\u5B58\\u50A8\\u539F\\u59CB\\u8282\\u70B9\\u4E0E\\u5176\\u514B\\u9686\\u4E4B\\u95F4\\u7684\\u5173\\u7CFB\\u3002\\u8FD9\\u53EF\\u4EE5\\u9632\\u6B62\\u5197\\u4F59\\u514B\\u9686\\u5E76\\u6709\\u6548\\u5730\\u5904\\u7406\\u56FE\\u4E2D\\u7684\\u5FAA\\u73AF\\u3002\\u968F\\u7740\\u904D\\u5386\\u7684\\u8FDB\\u884C\\uFF0C\\u6BCF\\u4E2A\\u8282\\u70B9\\u7684\\u90BB\\u5C45\\u90FD\\u4F1A\\u88AB\\u514B\\u9686\\u5E76\\u6DFB\\u52A0\\u5230\\u76F8\\u5E94\\u514B\\u9686\\u7684\\u90BB\\u5C45\\u5217\\u8868\\u4E2D\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\\u514B\\u9686\\u56FE\\u4FDD\\u6301\\u4E0E\\u539F\\u59CB\\u56FE\\u76F8\\u540C\\u7684\\u7ED3\\u6784\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u6B64\\u65B9\\u6CD5\\u901A\\u8FC7\\u9010\\u5C42\\u5904\\u7406\\u8282\\u70B9\\uFF0C\\u5728\\u9047\\u5230\\u8282\\u70B9\\u53CA\\u5176\\u8FDE\\u63A5\\u65F6\\u514B\\u9686\\u5B83\\u4EEC\\uFF0C\\u5E76\\u901A\\u8FC7\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"Map\"}),\" \\u6765\\u907F\\u514D\\u91CD\\u590D\\uFF0C\\u4ECE\\u800C\\u76F4\\u89C2\\u5730\\u5DE5\\u4F5C\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u8F93\\u5165\\u8282\\u70B9\\u662F\\u5426\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\u3002\\u5982\\u679C\\u662F\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u56E0\\u4E3A\\u6CA1\\u6709\\u8981\\u514B\\u9686\\u7684\\u56FE\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"Map\"}),\" \\u6765\\u5B58\\u50A8\\u539F\\u59CB\\u8282\\u70B9\\u4E0E\\u5176\\u514B\\u9686\\u5BF9\\u5E94\\u7269\\u4E4B\\u95F4\\u7684\\u6620\\u5C04\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u521B\\u5EFA\\u4E00\\u4E2A\\u961F\\u5217\\u5E76\\u5C06\\u8F93\\u5165\\u8282\\u70B9\\u6DFB\\u52A0\\u5230\\u5176\\u4E2D\\u4EE5\\u8FDB\\u884C BFS \\u904D\\u5386\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u514B\\u9686\\u8F93\\u5165\\u8282\\u70B9\\u5E76\\u5C06\\u5176\\u5B58\\u50A8\\u5728 \",(0,n.jsx)(e.code,{children:\"Map\"}),\" \\u4E2D\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5F53\\u961F\\u5217\\u4E0D\\u4E3A\\u7A7A\\u65F6\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u4ECE\\u961F\\u5217\\u7684\\u524D\\u9762\\u5220\\u9664\\u4E00\\u4E2A\\u8282\\u70B9\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u5F53\\u524D\\u8282\\u70B9\\u7684\\u90BB\\u5C45\\u3002\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u90BB\\u5C45\\u5C1A\\u672A\\u88AB\\u514B\\u9686\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u514B\\u9686\\u90BB\\u5C45\\u5E76\\u5C06\\u5176\\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"Map\"}),\"\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5C06\\u90BB\\u5C45\\u6DFB\\u52A0\\u5230\\u961F\\u5217\\u4E2D\\u4EE5\\u8FDB\\u884C\\u8FDB\\u4E00\\u6B65\\u5904\\u7406\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5C06\\u90BB\\u5C45\\u7684\\u514B\\u9686\\u6DFB\\u52A0\\u5230\\u5F53\\u524D\\u8282\\u70B9\\u7684\\u514B\\u9686\\u7684\\u90BB\\u5C45\\u5217\\u8868\\u4E2D\\u3002\"}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE \",(0,n.jsx)(e.code,{children:\"Map\"}),\" \\u8FD4\\u56DE\\u8F93\\u5165\\u8282\\u70B9\\u7684\\u514B\\u9686\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(l,{children:u}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(v + e)\"}),\"\\u3002\\u5728 BFS \\u904D\\u5386\\u671F\\u95F4\\uFF0C\\u56FE\\u4E2D\\u7684\\u6BCF\\u4E2A\\u8282\\u70B9 (\",(0,n.jsx)(e.code,{children:\"v\"}),\") \\u548C\\u8FB9 (\",(0,n.jsx)(e.code,{children:\"e\"}),\") \\u90FD\\u53EA\\u88AB\\u8BBF\\u95EE\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(v)\"}),\"\\u3002\",(0,n.jsx)(e.code,{children:\"Map\"}),\" \\u5B58\\u50A8\\u6BCF\\u4E2A\\u8282\\u70B9\\u7684\\u6620\\u5C04\\uFF0C\\u5E76\\u4E14\\u961F\\u5217\\u5728\\u6700\\u574F\\u7684\\u60C5\\u51B5\\u4E0B\\u6700\\u591A\\u5305\\u542B \",(0,n.jsx)(e.code,{children:\"v\"}),\" \\u4E2A\\u8282\\u70B9\\u3002\"]}),`\n`]})]})}function y(o={}){let{wrapper:e}=o.components||{};return e?(0,n.jsx)(e,Object.assign({},o,{children:(0,n.jsx)(p,o)})):p(o)}var B=y;return F(C);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/graph-count-connected-components/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/graph-count-connected-components/locales/zh-CN.json new file mode 100644 index 000000000..183332ab2 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/graph-count-connected-components/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var m=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var f=(c,e)=>()=>(e||c((e={exports:{}}).exports,e),e.exports),_=(c,e)=>{for(var d in e)i(c,d,{get:e[d],enumerable:!0})},l=(c,e,d,t)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of g(e))!b.call(c,r)&&r!==d&&i(c,r,{get:()=>e[r],enumerable:!(t=p(e,r))||t.enumerable});return c};var j=(c,e,d)=>(d=c!=null?m(x(c)):{},l(e||!c||!c.__esModule?i(d,\"default\",{value:c,enumerable:!0}):d,c)),C=c=>l(i({},\"__esModule\",{value:!0}),c);var h=f((A,o)=>{o.exports=_jsx_runtime});var X={};_(X,{default:()=>T,frontmatter:()=>w});var n=j(h());var s=MDXTestExamples;var a=[{input:[[\"num\",6],[\"edges\",[[0,1],[4,5],[2,4],[1,3],[0,2]]]],output:1,explanation:\"All nodes are connected.\"},{input:[[\"num\",3],[\"edges\",[[0,1],[1,2]]]],output:1,explanation:\"All nodes are connected.\"},{input:[[\"num\",4],[\"edges\",[[0,1],[2,3]]]],output:2,explanation:\"There are two connected components: {0, 1} and {2, 3}.\"}];var w={title:\"\\u56FE\\u8BA1\\u7B97\\u8FDE\\u901A\\u5206\\u91CF\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u8BA1\\u7B97\\u56FE\\u4E2D\\u8FDE\\u901A\\u5206\\u91CF\\u7684\\u6570\\u91CF\"};function u(c){let e=Object.assign({p:\"p\",code:\"code\",a:\"a\",h3:\"h3\",ul:\"ul\",li:\"li\"},c.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u8003\\u8651\\u4E00\\u4E2A\\u5177\\u6709\",(0,n.jsx)(e.code,{children:\"num\"}),\"\\u4E2A\\u8282\\u70B9\\u7684\\u56FE\\uFF0C\\u4ECE\",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u5230\",(0,n.jsx)(e.code,{children:\"num - 1\"}),\"\\u8FDB\\u884C\\u6807\\u8BB0\\u3002\\u7ED9\\u5B9A\",(0,n.jsx)(e.code,{children:\"num\"}),\"\\u548C\\u8FB9\\u5217\\u8868\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\",(0,n.jsx)(e.code,{children:\"edges[i] = [a, b]\"}),\"\\u8868\\u793A\\u8282\\u70B9\",(0,n.jsx)(e.code,{children:\"a\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"b\"}),\"\\u4E4B\\u95F4\\u7684\\u65E0\\u5411\\u8FDE\\u63A5\\uFF0C\\u786E\\u5B9A\\u56FE\\u4E2D\\u8FDE\\u901A\\u5206\\u91CF\\u7684\\u6570\\u91CF\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5728\\u56FE\\u7684\\u4E0A\\u4E0B\\u6587\\u4E2D\\uFF0C\\u65E0\\u5411\\u56FE\\u7684\",(0,n.jsx)(e.a,{href:\"https://en.wikipedia.org/wiki/Component_(graph_theory)\",children:\"component\"}),\"\\u662F\\u4E00\\u4E2A\\u8FDE\\u901A\\u7684\\u5B50\\u56FE\\uFF0C\\u5B83\\u4E0D\\u662F\\u4EFB\\u4F55\\u66F4\\u5927\\u7684\\u8FDE\\u901A\\u5B50\\u56FE\\u7684\\u4E00\\u90E8\\u5206\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"num: number\"}),\": \\u4E00\\u4E2A\\u6574\\u6570\\uFF0C\\u56FE\\u4E2D\\u8282\\u70B9\\u7684\\u6570\\u91CF\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"edges: Array<[number, number]>\"}),\": \\u4E00\\u4E2A\\u4E8C\\u7EF4\\u6570\\u7EC4\\uFF0C\\u5176\\u4E2D\",(0,n.jsx)(e.code,{children:\"edges[i] = [a, b]\"}),\"\\u8868\\u793A\\u8282\\u70B9\",(0,n.jsx)(e.code,{children:\"a\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"b\"}),\"\\u4E4B\\u95F4\\u7684\\u65E0\\u5411\\u8FB9\"]}),`\n`]}),`\n`,(0,n.jsx)(s,{testCases:a}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"num\"}),\" <= 1000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"edges.length\"}),\" <= 2000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"edges[i].length\"}),\" == 2\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"0 <= \",(0,n.jsx)(e.code,{children:\"a\"}),\" < \",(0,n.jsx)(e.code,{children:\"b\"}),\" < \",(0,n.jsx)(e.code,{children:\"num\"})]}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.code,{children:\"a != b\"})}),`\n`,(0,n.jsx)(e.li,{children:\"\\u6CA1\\u6709\\u81EA\\u5FAA\\u73AF\\u6216\\u91CD\\u590D\\u8FB9\"}),`\n`]})]})}function D(c={}){let{wrapper:e}=c.components||{};return e?(0,n.jsx)(e,Object.assign({},c,{children:(0,n.jsx)(u,c)})):u(c)}var T=D;return C(X);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来计算图中连通分量的数量", + "title": "图计算连通分量" + }, + "solution": "var Component=(()=>{var v=Object.create;var c=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var g=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),j=(r,e)=>{for(var i in e)c(r,i,{get:e[i],enumerable:!0})},l=(r,e,i,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let t of f(e))!b.call(r,t)&&t!==i&&c(r,t,{get:()=>e[t],enumerable:!(o=p(e,t))||o.enumerable});return r};var C=(r,e,i)=>(i=r!=null?v(x(r)):{},l(e||!r||!r.__esModule?c(i,\"default\",{value:r,enumerable:!0}):i,r)),z=r=>l(c({},\"__esModule\",{value:!0}),r);var h=g((_,s)=>{s.exports=_jsx_runtime});var L={};j(L,{default:()=>O});var n=C(h());var d=MDXCodeBlock;var a=`// Depth-First Search (DFS) to explore all nodes in a component\nfunction dfs(adjList: number[][], visited: number[], src: number): void {\n // Mark the current node as visited\n visited[src] = 1;\n\n // Traverse all adjacent nodes\n for (const neighbor of adjList[src]) {\n if (visited[neighbor] === 0) {\n dfs(adjList, visited, neighbor);\n }\n }\n}\n\nexport default function graphCountConnectedComponents(\n num: number,\n edges: Array<[number, number]>,\n): number {\n // Edge case: if there are no nodes, return 0\n if (num === 0) return 0;\n\n // Initialize the count of connected components\n let components = 0;\n // Create an array to track visited nodes\n const visited = new Array(num).fill(0);\n // Create an adjacency list to represent the graph\n const adjList: number[][] = Array.from({ length: num }, () => []);\n\n // Build the adjacency list from edges\n for (const [u, v] of edges) {\n adjList[u].push(v);\n adjList[v].push(u);\n }\n\n // Perform DFS for each unvisited node to count components\n for (let i = 0; i < num; i++) {\n if (visited[i] === 0) {\n components++;\n dfs(adjList, visited, i);\n }\n }\n\n return components;\n}\n`;var u=`function find(representative: number[], vertex: number): number {\n if (vertex === representative[vertex]) {\n return vertex;\n }\n // Path compression\n representative[vertex] = find(representative, representative[vertex]);\n return representative[vertex];\n}\n\nfunction combine(\n representative: number[],\n size: number[],\n vertex1: number,\n vertex2: number,\n): number {\n // Find the root representatives of both vertices\n vertex1 = find(representative, vertex1);\n vertex2 = find(representative, vertex2);\n\n // If both vertices are already in the same set\n if (vertex1 === vertex2) {\n return 0; // No union occurred\n } else {\n // Union by size\n if (size[vertex1] > size[vertex2]) {\n size[vertex1] += size[vertex2];\n representative[vertex2] = vertex1;\n } else {\n size[vertex2] += size[vertex1];\n representative[vertex1] = vertex2;\n }\n return 1; // Union occurred\n }\n}\n\nexport default function graphCountConnectedComponents(\n num: number,\n edges: Array<[number, number]>,\n): number {\n // Initialize representative and size arrays\n const representative = new Array(num).fill(0).map((_, index) => index);\n const size = new Array(num).fill(1);\n\n // Initialize the number of components\n let components = num;\n\n // Process each edge and union the components\n for (const [u, v] of edges) {\n components -= combine(representative, size, u, v);\n }\n\n return components;\n}\n`;function m(r){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528 DFS\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u95EE\\u9898\\u9700\\u8981\\u8BA1\\u7B97\\u65E0\\u5411\\u56FE\\u4E2D\\u7684\\u8FDE\\u901A\\u5206\\u91CF\\u6570\\u91CF\\u3002\\u8FDE\\u901A\\u5206\\u91CF\\u662F\\u4E00\\u4E2A\\u5B50\\u56FE\\uFF0C\\u5176\\u4E2D\\u4EFB\\u610F\\u4E24\\u4E2A\\u8282\\u70B9\\u90FD\\u53EF\\u4EE5\\u76F8\\u4E92\\u5230\\u8FBE\\uFF0C\\u5E76\\u4E14\\u5B50\\u56FE\\u4E2D\\u7684\\u4EFB\\u4F55\\u8282\\u70B9\\u90FD\\u4E0D\\u4F1A\\u8FDE\\u63A5\\u5230\\u5B83\\u4E4B\\u5916\\u7684\\u4EFB\\u4F55\\u8282\\u70B9\\u3002\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8BE5\\u65B9\\u6CD5\\u4F7F\\u7528\\u6DF1\\u5EA6\\u4F18\\u5148\\u641C\\u7D22 (DFS) \\u6765\\u63A2\\u7D22\\u56FE\\u3002\\u5176\\u601D\\u8DEF\\u662F\\u5C06\\u56FE\\u89C6\\u4E3A\\u8282\\u70B9\\u548C\\u8FB9\\u7684\\u96C6\\u5408\\uFF0C\\u7531\\u90BB\\u63A5\\u8868\\u8868\\u793A\\u3002\\u901A\\u8FC7\\u4ECE\\u4E00\\u4E2A\\u672A\\u8BBF\\u95EE\\u7684\\u8282\\u70B9\\u5F00\\u59CB\\uFF0CDFS \\u904D\\u5386\\u5C06\\u63A2\\u7D22\\u540C\\u4E00\\u8FDE\\u901A\\u5206\\u91CF\\u4E2D\\u7684\\u6240\\u6709\\u8282\\u70B9\\u3002\\u6BCF\\u6B21\\u9047\\u5230\\u4E00\\u4E2A\\u65B0\\u7684\\u672A\\u8BBF\\u95EE\\u8282\\u70B9\\u65F6\\uFF0C\\u5B83\\u8868\\u793A\\u4E00\\u4E2A\\u65B0\\u7684\\u8FDE\\u901A\\u5206\\u91CF\\u7684\\u5F00\\u59CB\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\\u6240\\u6709\\u8282\\u70B9\\u90FD\\u88AB\\u5904\\u7406\\uFF0C\\u5E76\\u4E14\\u4E0D\\u4F1A\\u9057\\u6F0F\\u4EFB\\u4F55\\u7EC4\\u4EF6\\u3002\",(0,n.jsx)(e.code,{children:\"visited\"}),\" \\u6570\\u7EC4\\u7528\\u4E8E\\u8DDF\\u8E2A\\u5DF2\\u63A2\\u7D22\\u7684\\u8282\\u70B9\\uFF0C\\u907F\\u514D\\u5197\\u4F59\\u904D\\u5386\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u6B64\\u65B9\\u6CD5\\u6D88\\u9664\\u4E86\\u5BF9\\u5DF2\\u77E5\\u8FDE\\u901A\\u5206\\u91CF\\u4E2D\\u5DF2\\u5B58\\u5728\\u7684\\u8282\\u70B9\\u7684\\u975E\\u5FC5\\u8981\\u904D\\u5386\\uFF0C\\u4F7F\\u5176\\u9AD8\\u6548\\u4E14\\u7CFB\\u7EDF\\u5316\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5904\\u7406\\u8282\\u70B9\\u6570 (\",(0,n.jsx)(e.code,{children:\"num\"}),\") \\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\" \\u7684\\u8FB9\\u7F18\\u60C5\\u51B5\\uFF0C\\u7ACB\\u5373\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8BA1\\u6570\\u5668 \",(0,n.jsx)(e.code,{children:\"components\"}),\" \\u7528\\u4E8E\\u8DDF\\u8E2A\\u8FDE\\u901A\\u5206\\u91CF\\u7684\\u6570\\u91CF\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4E00\\u4E2A\\u5927\\u5C0F\\u4E3A \",(0,n.jsx)(e.code,{children:\"num\"}),\" \\u7684\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"visited\"}),\"\\uFF0C\\u6240\\u6709\\u5143\\u7D20\\u90FD\\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u4EE5\\u6807\\u8BB0\\u672A\\u8BBF\\u95EE\\u7684\\u8282\\u70B9\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4E00\\u4E2A\\u90BB\\u63A5\\u8868 \",(0,n.jsx)(e.code,{children:\"adjList\"}),\" \\u6765\\u8868\\u793A\\u56FE\\uFF0C\\u521D\\u59CB\\u5316\\u4E3A\\u4E00\\u4E2A\\u7A7A\\u6570\\u7EC4\\u7684\\u6570\\u7EC4\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u5C06\\u6BCF\\u6761\\u8FB9\\u6DFB\\u52A0\\u5230\\u4E24\\u4E2A\\u8FDE\\u63A5\\u8282\\u70B9\\u7684\\u5217\\u8868\\u4E2D\\uFF0C\\u4ECE\\u7ED9\\u5B9A\\u7684 \",(0,n.jsx)(e.code,{children:\"edges\"}),\" \\u6784\\u5EFA\\u90BB\\u63A5\\u8868\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u6240\\u6709\\u8282\\u70B9\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u4E00\\u4E2A\\u8282\\u70B9\\u672A\\u88AB\\u8BBF\\u95EE\\uFF0C\\u5219\\u589E\\u52A0 \",(0,n.jsx)(e.code,{children:\"components\"}),\" \\u8BA1\\u6570\\u5668\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u4ECE\\u8BE5\\u8282\\u70B9\\u5F00\\u59CB\\u6267\\u884C DFS\\uFF0C\\u5C06\\u5F53\\u524D\\u8FDE\\u901A\\u5206\\u91CF\\u4E2D\\u6240\\u6709\\u53EF\\u5230\\u8FBE\\u7684\\u8282\\u70B9\\u6807\\u8BB0\\u4E3A\\u5DF2\\u8BBF\\u95EE\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"components\"}),\" \\u7684\\u503C\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(d,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(v + e)\"}),\"\\u3002\\u5728 DFS \\u904D\\u5386\\u671F\\u95F4\\uFF0C\\u6BCF\\u4E2A\\u8282\\u70B9 (\",(0,n.jsx)(e.code,{children:\"v\"}),\") \\u548C\\u8FB9 (\",(0,n.jsx)(e.code,{children:\"e\"}),\") \\u90FD\\u53EA\\u88AB\\u5904\\u7406\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(v + e)\"}),\"\\u3002\\u90BB\\u63A5\\u8868\\u9700\\u8981 O(v + e) \\u7A7A\\u95F4\\u6765\\u5B58\\u50A8\\u56FE\\uFF0C\",(0,n.jsx)(e.code,{children:\"visited\"}),\" \\u6570\\u7EC4\\u9700\\u8981 O(v) \\u7A7A\\u95F4\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4E0D\\u76F8\\u4EA4\\u96C6\\u5408\\u5E76\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5176\\u601D\\u8DEF\\u662F\\u6700\\u521D\\u5C06\\u6BCF\\u4E2A\\u8282\\u70B9\\u89C6\\u4E3A\\u5176\\u81EA\\u5DF1\\u7684\\u7EC4\\u4EF6\\u3002\\u5F53\\u5904\\u7406\\u8FB9\\u65F6\\uFF0C\\u5982\\u679C\\u8282\\u70B9\\u5DF2\\u8FDE\\u63A5\\uFF0C\\u5219\\u5C06\\u5B83\\u4EEC\\u5408\\u5E76\\u5230\\u540C\\u4E00\\u7EC4\\u4EF6\\u4E2D\\u3002\\u5E76\\u67E5\\u96C6\\u6570\\u636E\\u7ED3\\u6784\\u901A\\u8FC7\\u4E3A\\u6BCF\\u4E2A\\u96C6\\u5408\\u7EF4\\u62A4\\u4E00\\u4E2A\\u4EE3\\u8868\\u5E76\\u4F7F\\u7528\\u201C\\u6309\\u5927\\u5C0F\\u5408\\u5E76\\u201D\\u7B56\\u7565\\u6765\\u6700\\u5C0F\\u5316\\u6811\\u9AD8\\uFF0C\\u4ECE\\u800C\\u6709\\u6548\\u5730\\u8DDF\\u8E2A\\u7EC4\\u4EF6\\u3002\\u8DEF\\u5F84\\u538B\\u7F29\\u901A\\u8FC7\\u5728\\u67E5\\u627E\\u671F\\u95F4\\u5C55\\u5E73\\u6811\\u7ED3\\u6784\\u6765\\u8FDB\\u4E00\\u6B65\\u4F18\\u5316 \",(0,n.jsx)(e.code,{children:\"find\"}),\" \\u64CD\\u4F5C\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u901A\\u8FC7\\u76F4\\u63A5\\u7BA1\\u7406\\u7EC4\\u4EF6\\u4E4B\\u95F4\\u7684\\u5173\\u7CFB\\u6765\\u907F\\u514D\\u5BF9\\u56FE\\u7684\\u5197\\u4F59\\u904D\\u5386\\uFF0C\\u4F7F\\u7528\\u9AD8\\u6548\\u7684\\u64CD\\u4F5C\\uFF0C\\u975E\\u5E38\\u9002\\u5408\\u7528\\u4E8E\\u8BA1\\u7B97\\u8FDE\\u901A\\u5206\\u91CF\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E24\\u4E2A\\u6570\\u7EC4\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"representative\"}),\" \\u7528\\u4E8E\\u8DDF\\u8E2A\\u6BCF\\u4E2A\\u8282\\u70B9\\u7684\\u4EE3\\u8868\\u3002\\u6700\\u521D\\uFF0C\\u6BCF\\u4E2A\\u8282\\u70B9\\u90FD\\u662F\\u5B83\\u81EA\\u5DF1\\u7684\\u4EE3\\u8868\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"size\"}),\" \\u7528\\u4E8E\\u5B58\\u50A8\\u6BCF\\u4E2A\\u7EC4\\u4EF6\\u7684\\u5927\\u5C0F\\u3002\\u6240\\u6709\\u8282\\u70B9\\u90FD\\u521D\\u59CB\\u5316\\u4E3A\\u5927\\u5C0F \",(0,n.jsx)(e.code,{children:\"1\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u8FDE\\u901A\\u5206\\u91CF\\u7684\\u521D\\u59CB\\u8BA1\\u6570\\u8BBE\\u7F6E\\u4E3A\\u8282\\u70B9\\u6570 (\",(0,n.jsx)(e.code,{children:\"num\"}),\")\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"find\"}),\" \\u51FD\\u6570\\u6765\\u786E\\u5B9A\\u8282\\u70B9\\u7684\\u4EE3\\u8868\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u4E00\\u4E2A\\u8282\\u70B9\\u662F\\u5B83\\u81EA\\u5DF1\\u7684\\u4EE3\\u8868\\uFF0C\\u5219\\u8FD4\\u56DE\\u8BE5\\u8282\\u70B9\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5426\\u5219\\uFF0C\\u9012\\u5F52\\u67E5\\u627E\\u5176\\u7236\\u8282\\u70B9\\u7684\\u4EE3\\u8868\\uFF0C\\u5E94\\u7528\\u8DEF\\u5F84\\u538B\\u7F29\\u4EE5\\u5C55\\u5E73\\u6811\\u7ED3\\u6784\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"combine\"}),\" \\u51FD\\u6570\\u6765\\u5408\\u5E76\\u4E24\\u4E2A\\u96C6\\u5408\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u627E\\u5230\\u4E24\\u4E2A\\u96C6\\u5408\\u7684\\u6839\\u4EE3\\u8868\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u4EE3\\u8868\\u76F8\\u540C\\uFF0C\\u5219\\u8282\\u70B9\\u5DF2\\u5728\\u540C\\u4E00\\u96C6\\u5408\\u4E2D\\u3002\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5426\\u5219\\uFF0C\\u6267\\u884C\\u6309\\u5927\\u5C0F\\u5408\\u5E76\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u5C06\\u8F83\\u5C0F\\u7684\\u96C6\\u5408\\u9644\\u52A0\\u5230\\u8F83\\u5927\\u7684\\u96C6\\u5408\\u5E76\\u66F4\\u65B0\\u5927\\u5C0F\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"1\"}),\" \\u4EE5\\u6307\\u793A\\u53D1\\u751F\\u4E86\\u5408\\u5E76\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u8FB9\\u5217\\u8868\\u3002\\u5BF9\\u4E8E\\u6BCF\\u6761\\u8FB9\\uFF0C\\u8C03\\u7528 \",(0,n.jsx)(e.code,{children:\"combine\"}),\" \\u51FD\\u6570\\u4EE5\\u5408\\u5E76\\u8FDE\\u63A5\\u7684\\u8282\\u70B9\\u5E76\\u51CF\\u5C11\\u8FDE\\u901A\\u5206\\u91CF\\u7684\\u8BA1\\u6570\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8FD4\\u56DE\\u8FDE\\u901A\\u5206\\u91CF\\u7684\\u6700\\u7EC8\\u8BA1\\u6570\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(d,{children:u}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(e.\\u03B1(v))\"}),\"\\u3002\\u7531\\u4E8E\\u8DEF\\u5F84\\u538B\\u7F29\\u548C\\u6309\\u5927\\u5C0F\\u5408\\u5E76\\uFF0C\\u5E76\\u67E5\\u96C6\\u64CD\\u4F5C \",(0,n.jsx)(e.code,{children:\"find\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"union\"}),\" \\u51E0\\u4E4E\\u662F\\u6052\\u5B9A\\u65F6\\u95F4\\uFF0C\\u5176\\u4E2D \\u03B1(v) \\u662F\\u53CD\\u963F\\u514B\\u66FC\\u51FD\\u6570\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(v)\"}),\"\\u3002\",(0,n.jsx)(e.code,{children:\"representative\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"size\"}),\" \\u6570\\u7EC4\\u6240\\u9700\\u7684\\u7A7A\\u95F4\\u4E0E\\u8282\\u70B9\\u6570 (\",(0,n.jsx)(e.code,{children:\"v\"}),\") \\u6210\\u6B63\\u6BD4\\u3002\"]}),`\n`]})]})}function F(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(m,r)})):m(r)}var O=F;return z(L);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/graph-is-tree/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/graph-is-tree/locales/zh-CN.json new file mode 100644 index 000000000..683407c01 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/graph-is-tree/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var l=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var x=(c,e)=>()=>(e||c((e={exports:{}}).exports,e),e.exports),y=(c,e)=>{for(var i in e)l(c,i,{get:e[i],enumerable:!0})},o=(c,e,i,r)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let d of g(e))!b.call(c,d)&&d!==i&&l(c,d,{get:()=>e[d],enumerable:!(r=m(e,d))||r.enumerable});return c};var _=(c,e,i)=>(i=c!=null?p(f(c)):{},o(e||!c||!c.__esModule?l(i,\"default\",{value:c,enumerable:!0}):i,c)),T=c=>o(l({},\"__esModule\",{value:!0}),c);var h=x((X,t)=>{t.exports=_jsx_runtime});var C={};y(C,{default:()=>w,frontmatter:()=>v});var n=_(h());var a=MDXTestExamples;var s=[{input:[[\"num\",5],[\"edges\",[[3,4],[0,3],[1,2],[0,1]]]],output:!0,explanation:\"The graph consists of 5 nodes (0, 1, 2, 3, 4) connected by 4 edges. All nodes are reachable from any other node, and there are no cycles. The graph has exactly num - 1 = 4 edges, satisfying the conditions for a valid tree.\"},{input:[[\"num\",5],[\"edges\",[[0,1],[1,2],[2,3],[3,4],[1,4]]]],output:!1,explanation:\"Although all nodes are connected, the graph contains a cycle (e.g., 1 -> 4 -> 3 -> 1), which violates the condition of being acyclic. Hence, the graph is not a valid tree.\"},{input:[[\"num\",3],[\"edges\",[[0,1]]]],output:!1,explanation:\"The graph consists of 3 nodes (0, 1, 2), but only 1 edge is provided. This leaves node 2 disconnected, violating the condition of being connected. Hence, the graph is not a valid tree.\"}];var v={title:\"\\u56FE\\u662F\\u5426\\u4E3A\\u6811\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u786E\\u5B9A\\u4E00\\u4E2A\\u56FE\\u662F\\u5426\\u4E3A\\u6709\\u6548\\u7684\\u6811\"};function u(c){let e=Object.assign({p:\"p\",code:\"code\",a:\"a\",ol:\"ol\",li:\"li\",h3:\"h3\",ul:\"ul\"},c.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u8003\\u8651\\u4E00\\u4E2A\\u6709\",(0,n.jsx)(e.code,{children:\"num\"}),\"\\u4E2A\\u8282\\u70B9\\u7684\\u56FE\\uFF0C\\u4ECE\",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u5230\",(0,n.jsx)(e.code,{children:\"num - 1\"}),\"\\u8FDB\\u884C\\u6807\\u8BB0\\u3002\\u7ED9\\u5B9A\",(0,n.jsx)(e.code,{children:\"num\"}),\"\\u548C\\u4E00\\u4E2A\\u8FB9\\u5217\\u8868\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\",(0,n.jsx)(e.code,{children:\"edges[i] = [a, b]\"}),\"\\u8868\\u793A\\u8282\\u70B9\",(0,n.jsx)(e.code,{children:\"a\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"b\"}),\"\\u4E4B\\u95F4\\u7684\\u65E0\\u5411\\u8FDE\\u63A5\\uFF0C\\u786E\\u5B9A\\u63D0\\u4F9B\\u7684\\u8FB9\\u662F\\u5426\\u6784\\u6210\\u4E00\\u4E2A\\u6709\\u6548\\u7684\\u6811\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A**\",(0,n.jsx)(e.a,{href:\"https://en.wikipedia.org/wiki/Tree_(abstract_data_type)\",children:\"\\u6709\\u6548\\u7684\\u6811\"}),\"**\\u662F\\u4E00\\u4E2A\\u8FDE\\u901A\\u7684\\u3001\\u65E0\\u73AF\\u7684\\u56FE\\uFF0C\\u5B83\\u8DE8\\u8D8A\\u6240\\u6709\",(0,n.jsx)(e.code,{children:\"num\"}),\"\\u4E2A\\u8282\\u70B9\\u3002\\u8FD9\\u610F\\u5473\\u7740\\uFF1A\"]}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u6240\\u6709\\u8282\\u70B9\\u90FD\\u5FC5\\u987B\\u53EF\\u4EE5\\u4ECE\\u4EFB\\u4F55\\u5176\\u4ED6\\u8282\\u70B9\\u8BBF\\u95EE\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u56FE\\u4E2D\\u4E0D\\u5F97\\u5305\\u542B\\u4EFB\\u4F55\\u5FAA\\u73AF\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u56FE\\u4E2D\\u5FC5\\u987B\\u6070\\u597D\\u6709\",(0,n.jsx)(e.code,{children:\"num - 1\"}),\"\\u6761\\u8FB9\\uFF0C\\u5176\\u4E2D\",(0,n.jsx)(e.code,{children:\"num\"}),\"\\u662F\\u8282\\u70B9\\u7684\\u6570\\u91CF\"]}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5982\\u679C\\u8FB9\\u6784\\u6210\\u6709\\u6548\\u7684\\u6811\\uFF0C\\u5219\\u8FD4\\u56DE\",(0,n.jsx)(e.code,{children:\"true\"}),\"\\uFF1B\\u5426\\u5219\\uFF0C\\u8FD4\\u56DE\",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"num: number\"}),\": \\u56FE\\u4E2D\\u8282\\u70B9\\u7684\\u6570\\u91CF\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"edges: Array<[number, number]>\"}),\": \\u4E00\\u4E2A\\u4E8C\\u7EF4\\u6570\\u7EC4\\uFF0C\\u5176\\u4E2D\",(0,n.jsx)(e.code,{children:\"edges[i] = [a, b]\"}),\"\\u8868\\u793A\\u8282\\u70B9\",(0,n.jsx)(e.code,{children:\"a\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"b\"}),\"\\u4E4B\\u95F4\\u7684\\u65E0\\u5411\\u8FB9\"]}),`\n`]}),`\n`,(0,n.jsx)(a,{testCases:s}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"num\"}),\" <= 1000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"edges.length\"}),\" <= 1000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"edges[i].length\"}),\" == 2\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"0 <= \",(0,n.jsx)(e.code,{children:\"a\"}),\", \",(0,n.jsx)(e.code,{children:\"b\"}),\" < \",(0,n.jsx)(e.code,{children:\"num\"})]}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.code,{children:\"a != b\"})}),`\n`,(0,n.jsx)(e.li,{children:\"\\u6CA1\\u6709\\u81EA\\u5FAA\\u73AF\\u6216\\u91CD\\u590D\\u7684\\u8FB9\"}),`\n`]})]})}function M(c={}){let{wrapper:e}=c.components||{};return e?(0,n.jsx)(e,Object.assign({},c,{children:(0,n.jsx)(u,c)})):u(c)}var w=M;return T(C);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来确定一个图是否为有效的树", + "title": "图是否为树" + }, + "solution": "var Component=(()=>{var f=Object.create;var d=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,A=Object.prototype.hasOwnProperty;var y=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),j=(r,e)=>{for(var i in e)d(r,i,{get:e[i],enumerable:!0})},t=(r,e,i,l)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let c of g(e))!A.call(r,c)&&c!==i&&d(r,c,{get:()=>e[c],enumerable:!(l=p(e,c))||l.enumerable});return r};var B=(r,e,i)=>(i=r!=null?f(b(r)):{},t(e||!r||!r.__esModule?d(i,\"default\",{value:r,enumerable:!0}):i,r)),z=r=>t(d({},\"__esModule\",{value:!0}),r);var s=y((S,h)=>{h.exports=_jsx_runtime});var D={};j(D,{default:()=>x});var n=B(s());var o=MDXCodeBlock;var a=`// Create an adjacency list to represent the graph\nfunction createAdjacencyList(\n num: number,\n edges: Array<[number, number]>,\n): Map {\n const adjacencyList = new Map();\n for (let i = 0; i < num; i++) {\n adjacencyList.set(i, []);\n }\n for (const edge of edges) {\n adjacencyList.get(edge[0])!.push(edge[1]);\n adjacencyList.get(edge[1])!.push(edge[0]);\n }\n return adjacencyList;\n}\n\n// Depth First Search (DFS) function\nfunction dfs(\n node: number,\n parent: number,\n adjacencyList: Map,\n seen: Set,\n): boolean {\n if (seen.has(node)) return false;\n seen.add(node);\n for (const neighbor of adjacencyList.get(node)!) {\n if (parent !== neighbor) {\n const result = dfs(neighbor, node, adjacencyList, seen);\n if (!result) return false;\n }\n }\n return true;\n}\n\n// Main function to check if a given graph is a valid tree\nexport default function graphIsTree(\n num: number,\n edges: Array<[number, number]>,\n): boolean {\n if (edges.length !== num - 1) {\n return false;\n }\n\n const adjacencyList = createAdjacencyList(num, edges);\n const seen = new Set();\n\n // We return true if no cycles were detected,\n // AND the entire graph has been reached.\n return dfs(0, -1, adjacencyList, seen) && seen.size === num;\n}\n`;var u=`// Union-Find data structure with path compression and union by size\nfunction createUnionFind(num: number) {\n const parent: number[] = new Array(num);\n const size: number[] = new Array(num);\n\n for (let node = 0; node < num; node++) {\n parent[node] = node;\n size[node] = 1;\n }\n\n // Find method with path compression\n const find = (A: number): number => {\n let root = A;\n while (parent[root] !== root) {\n root = parent[root];\n }\n while (A !== root) {\n const oldRoot = parent[A];\n parent[A] = root;\n A = oldRoot;\n }\n return root;\n };\n\n // Union method with union by size optimization\n const union = (A: number, B: number): boolean => {\n const rootA = find(A);\n const rootB = find(B);\n\n if (rootA === rootB) {\n return false;\n }\n\n if (size[rootA] < size[rootB]) {\n parent[rootA] = rootB;\n size[rootB] += size[rootA];\n } else {\n parent[rootB] = rootA;\n size[rootA] += size[rootB];\n }\n return true;\n };\n\n return { find, union };\n}\n\nexport default function graphIsTree(\n num: number,\n edges: Array<[number, number]>,\n): boolean {\n // Condition 1: The graph must contain num - 1 edges.\n if (edges.length !== num - 1) {\n return false;\n }\n\n // Condition 2: The graph must contain a single connected component.\n const { union } = createUnionFind(num);\n\n // Add each edge. Check if a merge happened, because if it didn't, there must be a cycle.\n for (const edge of edges) {\n const [A, B] = edge;\n if (!union(A, B)) {\n return false;\n }\n }\n\n // If we got this far, there are no cycles.\n return true;\n}\n`;function m(r){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",ol:\"ol\",li:\"li\",h3:\"h3\",ul:\"ul\",strong:\"strong\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u56FE\\u8BBA\\u548C DFS\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u95EE\\u9898\\u662F\\u786E\\u5B9A\\u7ED9\\u5B9A\\u7684\\u65E0\\u5411\\u56FE\\u662F\\u5426\\u4E3A\\u6709\\u6548\\u6811\\u3002 \\u6811\\u5B9A\\u4E49\\u4E3A\\u65E0\\u73AF\\u7684\\u8FDE\\u901A\\u56FE\\uFF0C\\u5BF9\\u4E8E \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u4E2A\\u8282\\u70B9\\uFF0C\\u6070\\u597D\\u6709 \",(0,n.jsx)(e.code,{children:\"n - 1\"}),\" \\u6761\\u8FB9\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u80CC\\u540E\\u7684\\u76F4\\u89C9\\u662F\\u9A8C\\u8BC1\\u4E24\\u4E2A\\u5173\\u952E\\u5C5E\\u6027\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u56FE\\u5E94\\u8BE5\\u662F\\u8FDE\\u901A\\u7684\\uFF0C\\u8FD9\\u610F\\u5473\\u7740\\u4ECE\\u4EFB\\u4F55\\u8282\\u70B9\\u5F00\\u59CB\\u90FD\\u5FC5\\u987B\\u53EF\\u4EE5\\u5230\\u8FBE\\u6240\\u6709\\u8282\\u70B9\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u56FE\\u4E2D\\u4E0D\\u5E94\\u8BE5\\u6709\\u73AF\\u3002\"}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u6DF1\\u5EA6\\u4F18\\u5148\\u641C\\u7D22 (DFS) \\u7528\\u4E8E\\u904D\\u5386\\u56FE\\uFF0C\\u540C\\u65F6\\u68C0\\u6D4B\\u73AF\\u3002 \\u904D\\u5386\\u4ECE\\u5355\\u4E2A\\u8282\\u70B9\\u5F00\\u59CB\\uFF0C\\u5C06\\u8282\\u70B9\\u6807\\u8BB0\\u4E3A\\u5DF2\\u8BBF\\u95EE\\u5728 \",(0,n.jsx)(e.code,{children:\"Set\"}),\" \\u4E2D\\u3002 \\u5728\\u904D\\u5386\\u671F\\u95F4\\uFF0C\\u5982\\u679C\\u91CD\\u65B0\\u8BBF\\u95EE\\u4E00\\u4E2A\\u8282\\u70B9\\uFF08\\u4E0D\\u5305\\u62EC\\u904D\\u5386\\u4E2D\\u7684\\u7236\\u8282\\u70B9\\uFF09\\uFF0C\\u5219\\u68C0\\u6D4B\\u5230\\u4E00\\u4E2A\\u73AF\\u3002 \\u6B64\\u5916\\uFF0C\\u68C0\\u67E5\\u8FB9\\u7684\\u6570\\u91CF\\u4EE5\\u786E\\u4FDD\\u5B83\\u6070\\u597D\\u662F \",(0,n.jsx)(e.code,{children:\"n - 1\"}),\"\\uFF0C\\u56E0\\u4E3A\\u8FD9\\u662F\\u6709\\u6548\\u6811\\u7684\\u5FC5\\u8981\\u6761\\u4EF6\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u901A\\u8FC7\\u5728\\u5355\\u4E2A DFS \\u904D\\u5386\\u4E2D\\u7ED3\\u5408\\u73AF\\u68C0\\u6D4B\\u548C\\u8FDE\\u901A\\u6027\\u9A8C\\u8BC1\\u6765\\u907F\\u514D\\u5197\\u4F59\\u68C0\\u67E5\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u8FB9\\u7684\\u6570\\u91CF\\u662F\\u5426\\u4E0D\\u7B49\\u4E8E \",(0,n.jsx)(e.code,{children:\"num - 1\"}),\"\\u3002 \\u5982\\u679C\\u662F\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\uFF0C\\u56E0\\u4E3A\\u8BE5\\u56FE\\u4E0D\\u80FD\\u662F\\u6811\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521B\\u5EFA\\u4E00\\u4E2A\\u90BB\\u63A5\\u8868\\u6765\\u8868\\u793A\\u8BE5\\u56FE\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"Map\"}),\"\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u8282\\u70B9\\u6307\\u5411\\u4E00\\u4E2A\\u7A7A\\u6570\\u7EC4\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u901A\\u8FC7\\u5C06\\u6BCF\\u6761\\u8FB9\\u7684\\u4E24\\u4E2A\\u7AEF\\u70B9\\u6DFB\\u52A0\\u5230\\u5F7C\\u6B64\\u7684\\u90BB\\u5C45\\u5217\\u8868\\u4E2D\\u6765\\u586B\\u5145\\u90BB\\u63A5\\u8868\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u540D\\u4E3A \",(0,n.jsx)(e.code,{children:\"seen\"}),\" \\u7684\\u7A7A \",(0,n.jsx)(e.code,{children:\"Set\"}),\"\\uFF0C\\u7528\\u4E8E\\u5728\\u904D\\u5386\\u671F\\u95F4\\u8DDF\\u8E2A\\u5DF2\\u8BBF\\u95EE\\u7684\\u8282\\u70B9\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u9012\\u5F52\\u7684 \",(0,n.jsx)(e.code,{children:\"dfs\"}),\" \\u51FD\\u6570\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5F53\\u524D\\u8282\\u70B9\\u5DF2\\u7ECF\\u5728 \",(0,n.jsx)(e.code,{children:\"seen\"}),\" \\u4E2D\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\uFF0C\\u56E0\\u4E3A\\u8FD9\\u8868\\u793A\\u4E00\\u4E2A\\u73AF\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u5F53\\u524D\\u8282\\u70B9\\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"seen\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u5F53\\u524D\\u8282\\u70B9\\u7684\\u6BCF\\u4E2A\\u90BB\\u5C45\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u8DF3\\u8FC7\\u7236\\u8282\\u70B9\\u4EE5\\u907F\\u514D\\u8BEF\\u62A5\\u73AF\\u68C0\\u6D4B\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u9012\\u5F52\\u5730\\u5BF9\\u90BB\\u5C45\\u8C03\\u7528 \",(0,n.jsx)(e.code,{children:\"dfs\"}),\"\\u3002 \\u5982\\u679C\\u4EFB\\u4F55\\u9012\\u5F52\\u8C03\\u7528\\u68C0\\u6D4B\\u5230\\u73AF\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5728\\u5904\\u7406\\u5B8C\\u6240\\u6709\\u90BB\\u5C45\\u540E\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u8282\\u70B9 \",(0,n.jsx)(e.code,{children:\"0\"}),\" \\u5F00\\u59CB\\u8C03\\u7528 \",(0,n.jsx)(e.code,{children:\"dfs\"}),\"\\uFF0C\\u5E76\\u5C06 \",(0,n.jsx)(e.code,{children:\"-1\"}),\" \\u4F5C\\u4E3A\\u7236\\u8282\\u70B9\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u68C0\\u67E5 \",(0,n.jsx)(e.code,{children:\"seen\"}),\" \\u7684\\u5927\\u5C0F\\u662F\\u5426\\u7B49\\u4E8E \",(0,n.jsx)(e.code,{children:\"num\"}),\" \\u6765\\u9A8C\\u8BC1\\u8BE5\\u56FE\\u662F\\u5426\\u5DF2\\u8FDE\\u63A5\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u672A\\u68C0\\u6D4B\\u5230\\u73AF\\u5E76\\u4E14\\u8BE5\\u56FE\\u5DF2\\u8FDE\\u63A5\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(o,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(v + e)\"}),\"\\u3002 \\u5728 DFS \\u904D\\u5386\\u671F\\u95F4\\uFF0C\\u6BCF\\u4E2A\\u8282\\u70B9 (\",(0,n.jsx)(e.code,{children:\"v\"}),\") \\u548C\\u8FB9 (\",(0,n.jsx)(e.code,{children:\"e\"}),\") \\u90FD\\u4F1A\\u88AB\\u8BBF\\u95EE\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(v)\"}),\"\\u3002 \",(0,n.jsx)(e.code,{children:\"seen\"}),\" \\u96C6\\u5408\\u548C\\u90BB\\u63A5\\u8868\\u6240\\u9700\\u7684\\u7A7A\\u95F4\\u4E0E\\u8282\\u70B9\\u6570\\u6210\\u6B63\\u6BD4\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u56FE\\u8BBA\\u548C\\u5E76\\u67E5\\u96C6\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u95EE\\u9898\\u662F\\u786E\\u5B9A\\u7ED9\\u5B9A\\u7684\\u65E0\\u5411\\u56FE\\u662F\\u5426\\u4E3A\\u6709\\u6548\\u6811\\u3002 \\u6811\\u662F\\u4E00\\u4E2A\\u8FDE\\u901A\\u56FE\\uFF0C\\u6CA1\\u6709\\u73AF\\uFF0C\\u5BF9\\u4E8E \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u4E2A\\u8282\\u70B9\\uFF0C\\u6070\\u597D\\u6709 \",(0,n.jsx)(e.code,{children:\"n - 1\"}),\" \\u6761\\u8FB9\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5E76\\u67E5\\u96C6\\u6570\\u636E\\u7ED3\\u6784\\u7528\\u4E8E\\u6709\\u6548\\u5730\\u8DDF\\u8E2A\\u8FDE\\u901A\\u5206\\u91CF\\u5E76\\u68C0\\u6D4B\\u73AF\\u3002 \\u6700\\u521D\\uFF0C\\u6BCF\\u4E2A\\u8282\\u70B9\\u90FD\\u88AB\\u89C6\\u4E3A\\u5176\\u81EA\\u5DF1\\u7684\\u5206\\u91CF\\u3002 \\u5F53\\u4E00\\u6761\\u8FB9\\u8FDE\\u63A5\\u4E24\\u4E2A\\u8282\\u70B9\\u65F6\\uFF0C\",(0,n.jsx)(e.code,{children:\"union\"}),\" \\u64CD\\u4F5C\\u4F1A\\u5408\\u5E76\\u5206\\u91CF\\uFF0C\\u800C \",(0,n.jsx)(e.code,{children:\"find\"}),\" \\u64CD\\u4F5C\\u4F7F\\u7528\\u8DEF\\u5F84\\u538B\\u7F29\\u786E\\u4FDD\\u5BF9\\u8282\\u70B9\\u5206\\u91CF\\u7684\\u6709\\u6548\\u67E5\\u627E\\u3002 \\u5982\\u679C\\u4E00\\u6761\\u8FB9\\u8FDE\\u63A5\\u4E86\\u5DF2\\u7ECF\\u5728\\u540C\\u4E00\\u5206\\u91CF\\u4E2D\\u7684\\u4E24\\u4E2A\\u8282\\u70B9\\uFF0C\\u5219\\u68C0\\u6D4B\\u5230\\u4E00\\u4E2A\\u73AF\\u3002 \\u6B64\\u5916\\uFF0C\\u8BE5\\u56FE\\u5FC5\\u987B\\u6070\\u597D\\u6709 \",(0,n.jsx)(e.code,{children:\"n - 1\"}),\" \\u6761\\u8FB9\\u624D\\u80FD\\u6210\\u4E3A\\u5355\\u4E2A\\u8FDE\\u901A\\u5206\\u91CF\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u901A\\u8FC7\\u4F7F\\u7528\\u9AD8\\u6548\\u7684\\u5E76\\u67E5\\u96C6\\u64CD\\u4F5C\\u76F4\\u63A5\\u7BA1\\u7406\\u5206\\u91CF\\u4E4B\\u95F4\\u7684\\u5173\\u7CFB\\uFF0C\\u6D88\\u9664\\u4E86\\u5BF9\\u8282\\u70B9\\u548C\\u8FB9\\u7684\\u5197\\u4F59\\u904D\\u5386\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u8FB9\\u7684\\u6570\\u91CF\\u662F\\u5426\\u4E0D\\u7B49\\u4E8E \",(0,n.jsx)(e.code,{children:\"num - 1\"}),\"\\u3002 \\u5982\\u679C\\u662F\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\uFF0C\\u56E0\\u4E3A\\u8BE5\\u56FE\\u4E0D\\u80FD\\u662F\\u6811\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u5E76\\u67E5\\u96C6\\u6570\\u636E\\u7ED3\\u6784\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521B\\u5EFA\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"parent\"}),\" \\u6570\\u7EC4\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u8282\\u70B9\\u6700\\u521D\\u90FD\\u662F\\u5B83\\u81EA\\u5DF1\\u7684\\u7236\\u8282\\u70B9\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521B\\u5EFA\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"size\"}),\" \\u6570\\u7EC4\\u6765\\u8DDF\\u8E2A\\u6BCF\\u4E2A\\u5206\\u91CF\\u7684\\u5927\\u5C0F\\uFF0C\\u5C06\\u6240\\u6709\\u5927\\u5C0F\\u521D\\u59CB\\u5316\\u4E3A \",(0,n.jsx)(e.code,{children:\"1\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49 \",(0,n.jsx)(e.code,{children:\"find\"}),\" \\u51FD\\u6570\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u5411\\u4E0A\\u904D\\u5386\\u7236\\u6307\\u9488\\uFF0C\\u76F4\\u5230\\u5230\\u8FBE\\u5206\\u91CF\\u7684\\u6839\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u901A\\u8FC7\\u4F7F\\u8DEF\\u5F84\\u4E0A\\u7684\\u6240\\u6709\\u8282\\u70B9\\u76F4\\u63A5\\u6307\\u5411\\u6839\\u6765\\u5E94\\u7528\\u8DEF\\u5F84\\u538B\\u7F29\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49 \",(0,n.jsx)(e.code,{children:\"union\"}),\" \\u51FD\\u6570\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"find\"}),\" \\u51FD\\u6570\\u786E\\u5B9A\\u4E24\\u4E2A\\u8282\\u70B9\\u7684\\u6839\\u5206\\u91CF\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u6839\\u76F8\\u540C\\uFF0C\\u5219\\u68C0\\u6D4B\\u5230\\u4E00\\u4E2A\\u73AF\\u3002 \\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5426\\u5219\\uFF0C\\u5C06\\u8F83\\u5C0F\\u7684\\u5206\\u91CF\\u5408\\u5E76\\u5230\\u8F83\\u5927\\u7684\\u5206\\u91CF\\u4E2D\\u5E76\\u66F4\\u65B0\\u5927\\u5C0F\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u8FB9\\u5217\\u8868\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"union\"}),\" \\u51FD\\u6570\\u5408\\u5E76\\u7531\\u6BCF\\u6761\\u8FB9\\u8FDE\\u63A5\\u7684\\u8282\\u70B9\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5728\\u6B64\\u8FC7\\u7A0B\\u4E2D\\u68C0\\u6D4B\\u5230\\u73AF\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u672A\\u68C0\\u6D4B\\u5230\\u73AF\\uFF0C\\u5E76\\u4E14\\u8BE5\\u56FE\\u6709 \",(0,n.jsx)(e.code,{children:\"n - 1\"}),\" \\u6761\\u8FB9\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(o,{children:u}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(e.\\u03B1(v))\"}),\"\\u3002 \\u7531\\u4E8E\\u8DEF\\u5F84\\u538B\\u7F29\\u548C\\u6309\\u5927\\u5C0F\\u5408\\u5E76\\uFF0C\",(0,n.jsx)(e.code,{children:\"union\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"find\"}),\" \\u64CD\\u4F5C\\u51E0\\u4E4E\\u662F\\u6052\\u5B9A\\u65F6\\u95F4\\uFF0C\\u5176\\u4E2D \\u03B1(v) \\u662F\\u53CD\\u963F\\u514B\\u66FC\\u51FD\\u6570\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(v)\"}),\"\\u3002 \",(0,n.jsx)(e.code,{children:\"parent\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"size\"}),\" \\u6570\\u7EC4\\u6240\\u9700\\u7684\\u7A7A\\u95F4\\u4E0E\\u8282\\u70B9\\u6570 (\",(0,n.jsx)(e.code,{children:\"v\"}),\") \\u6210\\u6B63\\u6BD4\\u3002\"]}),`\n`]})]})}function F(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(m,r)})):m(r)}var x=F;return z(D);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/grid-count-islands/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/grid-count-islands/locales/zh-CN.json new file mode 100644 index 000000000..a6564742c --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/grid-count-islands/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var t=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var j=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),_=(i,e)=>{for(var d in e)t(i,d,{get:e[d],enumerable:!0})},o=(i,e,d,c)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of g(e))!f.call(i,r)&&r!==d&&t(i,r,{get:()=>e[r],enumerable:!(c=m(e,r))||c.enumerable});return i};var b=(i,e,d)=>(d=i!=null?p(x(i)):{},o(e||!i||!i.__esModule?t(d,\"default\",{value:i,enumerable:!0}):d,i)),T=i=>o(t({},\"__esModule\",{value:!0}),i);var s=j((F,l)=>{l.exports=_jsx_runtime});var X={};_(X,{default:()=>D,frontmatter:()=>y});var n=b(s());var a=MDXTestExamples;var h=[{input:[[\"grid\",[[1,0],[0,0],[0,1],[0,1],[1,1]]]],output:2,explanation:\"There are 2 islands formed by connecting adjacent lands\"},{input:[[\"grid\",[[1,0,0],[1,1,1],[0,0,1]]]],output:1,explanation:\"There is one island formed by connecting adjacent lands\"},{input:[[\"grid\",[[1,1,1],[0,0,0],[0,0,0]]]],output:1,explanation:\"There is one island formed by connecting adjacent lands\"}];var y={title:\"\\u8BA1\\u7B97\\u7F51\\u683C\\u4E2D\\u7684\\u5C9B\\u5C7F\\u6570\\u91CF\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u8BA1\\u7B97\\u4E8C\\u7EF4\\u4E8C\\u8FDB\\u5236\\u7F51\\u683C\\u4E2D\\u4E0D\\u540C\\u7684\\u5C9B\\u5C7F\\u6570\\u91CF\"};function u(i){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},i.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u4E8C\\u7EF4\\u4E8C\\u8FDB\\u5236\\u7F51\\u683C\",(0,n.jsx)(e.code,{children:\"grid\"}),\"\\uFF0C\\u663E\\u793A\\u5730\\u56FE\\uFF0C\\u5176\\u4E2D\",(0,n.jsx)(e.code,{children:\"1\"}),\"\\u8868\\u793A\\u9646\\u5730\\uFF0C\",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u8868\\u793A\\u6C34\\uFF0C\\u786E\\u5B9A\\u4E0D\\u540C\\u5C9B\\u5C7F\\u7684\\u6570\\u91CF\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5C9B\\u5C7F\\u5B9A\\u4E49\\u4E3A\\u6C34\\u5E73\\u6216\\u5782\\u76F4\\u8FDE\\u63A5\\u7684\\u4E00\\u7EC4\",(0,n.jsx)(e.code,{children:\"1\"}),\"\\uFF0C\\u5E76\\u88AB\",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u6216\\u7F51\\u683C\\u7684\\u8FB9\\u7F18\\u5305\\u56F4\\u3002\\u5047\\u8BBE\\u7F51\\u683C\\u5B8C\\u5168\\u88AB\\u6C34\\u5305\\u56F4\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"grid: number[][]\"}),\": \\u4E00\\u4E2A\\u4E8C\\u7EF4\\u6570\\u7EC4\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u5143\\u7D20\\u662F\",(0,n.jsx)(e.code,{children:\"1\"}),\"\\u6216\",(0,n.jsx)(e.code,{children:\"0\"})]}),`\n`]}),`\n`,(0,n.jsx)(a,{testCases:h}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"grid.length\"}),\", \",(0,n.jsx)(e.code,{children:\"grid[i].length\"}),\" <= 100\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"grid[i][j]\"}),\" is \",(0,n.jsx)(e.code,{children:\"0\"}),\" or \",(0,n.jsx)(e.code,{children:\"1\"})]}),`\n`]})]})}function C(i={}){let{wrapper:e}=i.components||{};return e?(0,n.jsx)(e,Object.assign({},i,{children:(0,n.jsx)(u,i)})):u(i)}var D=C;return T(X);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来计算二维二进制网格中不同的岛屿数量", + "title": "计算网格中的岛屿数量" + }, + "solution": "var Component=(()=>{var f=Object.create;var o=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var p=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports),F=(r,n)=>{for(var l in n)o(r,l,{get:n[l],enumerable:!0})},t=(r,n,l,d)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let i of w(n))!I.call(r,i)&&i!==l&&o(r,i,{get:()=>n[i],enumerable:!(d=m(n,i))||d.enumerable});return r};var S=(r,n,l)=>(l=r!=null?f(b(r)):{},t(n||!r||!r.__esModule?o(l,\"default\",{value:r,enumerable:!0}):l,r)),B=r=>t(o({},\"__esModule\",{value:!0}),r);var s=p((M,h)=>{h.exports=_jsx_runtime});var x={};F(x,{default:()=>C});var e=S(s());var c=MDXCodeBlock;var u=`// Helper function for Depth-First Search (DFS)\nfunction dfs(grid: number[][], row: number, col: number): void {\n // Get the number of rows and columns\n const rows = grid.length;\n const cols = grid[0].length;\n\n // Mark the current cell as visited by setting it to 0\n grid[row][col] = 0;\n\n // Check and visit the cell above the current cell\n if (row - 1 >= 0 && grid[row - 1][col] === 1) {\n dfs(grid, row - 1, col);\n }\n\n // Check and visit the cell below the current cell\n if (row + 1 < rows && grid[row + 1][col] === 1) {\n dfs(grid, row + 1, col);\n }\n\n // Check and visit the cell to the left of the current cell\n if (col - 1 >= 0 && grid[row][col - 1] === 1) {\n dfs(grid, row, col - 1);\n }\n\n // Check and visit the cell to the right of the current cell\n if (col + 1 < cols && grid[row][col + 1] === 1) {\n dfs(grid, row, col + 1);\n }\n}\n\n// Main function to count the number of islands\nexport default function countGridIslands(grid: number[][]): number {\n const rows = grid.length; // Get the number of rows\n if (rows === 0) {\n return 0; // If grid is empty, return 0\n }\n\n const cols = grid[0].length; // Get the number of columns\n\n let numIslands = 0; // Initialize island count\n\n // Iterate through each cell in the grid\n for (let row = 0; row < rows; row++) {\n for (let col = 0; col < cols; col++) {\n // If the cell is land ('1'), it's part of an island\n if (grid[row][col] === 1) {\n ++numIslands; // Increment island count\n dfs(grid, row, col); // Perform DFS to mark the entire island\n }\n }\n }\n\n return numIslands; // Return the total number of islands\n}\n`;var a=`export default function countGridIslands(grid: number[][]): number {\n const rows = grid.length; // Get the number of rows\n if (rows === 0) return 0; // If grid is empty, return 0\n const cols = grid[0].length; // Get the number of columns\n\n let numIslands = 0; // Initialize island count\n\n // Iterate through each cell in the grid\n for (let row = 0; row < rows; row++) {\n for (let col = 0; col < cols; col++) {\n // If the cell is land ('1'), it's part of an island\n if (grid[row][col] === 1) {\n ++numIslands; // Increment island count\n grid[row][col] = 0; // Mark the current cell as visited by setting it to '0'\n const neighbors: [number, number][] = [[row, col]]; // Initialize a queue for BFS\n\n // Perform Breadth-First Search (BFS)\n while (neighbors.length > 0) {\n const [row, col] = neighbors.shift()!; // Dequeue a cell\n\n // Check and visit the cell above the current cell\n if (row - 1 >= 0 && grid[row - 1][col] === 1) {\n neighbors.push([row - 1, col]);\n grid[row - 1][col] = 0;\n }\n\n // Check and visit the cell below the current cell\n if (row + 1 < rows && grid[row + 1][col] === 1) {\n neighbors.push([row + 1, col]);\n grid[row + 1][col] = 0;\n }\n\n // Check and visit the cell to the left of the current cell\n if (col - 1 >= 0 && grid[row][col - 1] === 1) {\n neighbors.push([row, col - 1]);\n grid[row][col - 1] = 0;\n }\n\n // Check and visit the cell to the right of the current cell\n if (col + 1 < cols && grid[row][col + 1] === 1) {\n neighbors.push([row, col + 1]);\n grid[row][col + 1] = 0;\n }\n }\n }\n }\n }\n\n return numIslands; // Return the total number of islands\n}\n`;function g(r){let n=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},r.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"1. \\u4F7F\\u7528 DFS\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u8BE5\\u95EE\\u9898\\u9700\\u8981\\u8BA1\\u7B97\\u4E8C\\u7EF4\\u7F51\\u683C\\u4E2D\\u5C9B\\u5C7F\\u7684\\u6570\\u91CF\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u5355\\u5143\\u683C\\u662F\\u9646\\u5730\\uFF08\",(0,e.jsx)(n.code,{children:\"1\"}),\"\\uFF09\\u6216\\u6C34\\u57DF\\uFF08\",(0,e.jsx)(n.code,{children:\"0\"}),\"\\uFF09\\u3002\\u5C9B\\u5C7F\\u5B9A\\u4E49\\u4E3A\\u6C34\\u5E73\\u6216\\u5782\\u76F4\\u8FDE\\u63A5\\u7684\\u4E00\\u7EC4\\u76F8\\u90BB\\u9646\\u5730\\u5355\\u5143\\u683C\\u3002\\u4EFB\\u52A1\\u662F\\u8BA1\\u7B97\\u7F51\\u683C\\u4E2D\\u6240\\u6709\\u4E0D\\u540C\\u7684\\u5C9B\\u5C7F\\u3002\"]}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u8BE5\\u65B9\\u6CD5\\u4F7F\\u7528\\u6DF1\\u5EA6\\u4F18\\u5148\\u641C\\u7D22\\uFF08DFS\\uFF09\\u6765\\u904D\\u5386\\u548C\\u6807\\u8BB0\\u5C9B\\u5C7F\\u7684\\u6240\\u6709\\u5355\\u5143\\u683C\\uFF0C\\u4ECE\\u9646\\u5730\\u5355\\u5143\\u683C\\u5F00\\u59CB\\u3002\\u7F51\\u683C\\u88AB\\u5C31\\u5730\\u4FEE\\u6539\\uFF0C\\u5C06\\u5DF2\\u8BBF\\u95EE\\u7684\\u5355\\u5143\\u683C\\u6807\\u8BB0\\u4E3A\\u6C34\\u57DF\\uFF08\",(0,e.jsx)(n.code,{children:\"0\"}),\"\\uFF09\\uFF0C\\u4EE5\\u907F\\u514D\\u91CD\\u590D\\u8BBF\\u95EE\\u5B83\\u4EEC\\u3002\\u6BCF\\u6B21\\u9047\\u5230\\u672A\\u8BBF\\u95EE\\u7684\\u9646\\u5730\\u5355\\u5143\\u683C\\u65F6\\uFF0C\\u5B83\\u8868\\u793A\\u4E00\\u4E2A\\u65B0\\u7684\\u5C9B\\u5C7F\\uFF0C\\u5E76\\u542F\\u52A8 DFS \\u4EE5\\u63A2\\u7D22\\u6240\\u6709\\u8FDE\\u63A5\\u7684\\u9646\\u5730\\u5355\\u5143\\u683C\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\\u6BCF\\u4E2A\\u5C9B\\u5C7F\\u53EA\\u88AB\\u8BA1\\u7B97\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,e.jsx)(n.p,{children:\"\\u6B64\\u65B9\\u6CD5\\u6D88\\u9664\\u4E86\\u5BF9\\u5DF2\\u8BBF\\u95EE\\u5355\\u5143\\u683C\\u7684\\u4E0D\\u5FC5\\u8981\\u68C0\\u67E5\\uFF0C\\u5E76\\u901A\\u8FC7\\u76F4\\u63A5\\u4FEE\\u6539\\u7F51\\u683C\\u6765\\u907F\\u514D\\u5197\\u4F59\\u5904\\u7406\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u4ECE\\u7F51\\u683C\\u7EF4\\u5EA6\\u4E2D\\u68C0\\u7D22\\u884C\\u6570\\u548C\\u5217\\u6570\\u3002\"}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u521D\\u59CB\\u5316\\u8BA1\\u6570\\u5668 \",(0,e.jsx)(n.code,{children:\"numIslands\"}),\" \\u4E3A \",(0,e.jsx)(n.code,{children:\"0\"}),\"\\uFF0C\\u4EE5\\u5B58\\u50A8\\u5C9B\\u5C7F\\u7684\\u603B\\u6570\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u904D\\u5386\\u7F51\\u683C\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5355\\u5143\\u683C\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5982\\u679C\\u5355\\u5143\\u683C\\u503C\\u4E3A \",(0,e.jsx)(n.code,{children:\"1\"}),\"\\uFF08\\u9646\\u5730\\uFF09\\uFF0C\\u5219\\u589E\\u52A0 \",(0,e.jsx)(n.code,{children:\"numIslands\"}),\" \\u8BA1\\u6570\\u5668\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4ECE\\u5F53\\u524D\\u5355\\u5143\\u683C\\u6267\\u884C DFS\\uFF0C\\u4EE5\\u63A2\\u7D22\\u6574\\u4E2A\\u5C9B\\u5C7F\\u5E76\\u5C06\\u6240\\u6709\\u8FDE\\u63A5\\u7684\\u9646\\u5730\\u5355\\u5143\\u683C\\u6807\\u8BB0\\u4E3A\\u5DF2\\u8BBF\\u95EE\\uFF0C\\u65B9\\u6CD5\\u662F\\u5C06\\u5176\\u503C\\u8BBE\\u7F6E\\u4E3A \",(0,e.jsx)(n.code,{children:\"0\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u9012\\u5F52\\u7684 \",(0,e.jsx)(n.code,{children:\"dfs\"}),\" \\u51FD\\u6570\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5C06\\u5F53\\u524D\\u5355\\u5143\\u683C\\u6807\\u8BB0\\u4E3A\\u5DF2\\u8BBF\\u95EE\\uFF0C\\u65B9\\u6CD5\\u662F\\u5C06\\u5176\\u503C\\u8BBE\\u7F6E\\u4E3A \",(0,e.jsx)(n.code,{children:\"0\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u9012\\u5F52\\u5730\\u68C0\\u67E5\\u5E76\\u8BBF\\u95EE\\u6240\\u6709\\u76F8\\u90BB\\u5355\\u5143\\u683C\\uFF08\\u4E0A\\u3001\\u4E0B\\u3001\\u5DE6\\u3001\\u53F3\\uFF09\\uFF0C\\u5982\\u679C\\u5B83\\u4EEC\\u5728\\u8303\\u56F4\\u5185\\u4E14\\u5176\\u503C\\u4E3A \",(0,e.jsx)(n.code,{children:\"1\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5904\\u7406\\u5B8C\\u7F51\\u683C\\u4E2D\\u7684\\u6240\\u6709\\u5355\\u5143\\u683C\\u540E\\uFF0C\\u8FD4\\u56DE \",(0,e.jsx)(n.code,{children:\"numIslands\"}),\" \\u8BA1\\u6570\\u5668\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(c,{children:u}),`\n`,(0,e.jsx)(n.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m.n)\"}),\"\\u3002\\u7F51\\u683C\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5355\\u5143\\u683C\\u90FD\\u4F1A\\u88AB\\u8BBF\\u95EE\\u4E00\\u6B21\\uFF0C\\u65E0\\u8BBA\\u662F\\u5728\\u4E3B\\u8FED\\u4EE3\\u671F\\u95F4\\u8FD8\\u662F\\u5728 DFS \\u904D\\u5386\\u671F\\u95F4\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m.n)\"}),\"\\u3002\\u5F53\\u7F51\\u683C\\u5305\\u542B\\u4E00\\u4E2A\\u5927\\u7684\\u8FDE\\u63A5\\u5C9B\\u5C7F\\u65F6\\uFF0C\\u9012\\u5F52\\u5806\\u6808\\u53EF\\u80FD\\u4F1A\\u589E\\u957F\\u5230\\u7F51\\u683C\\u7684\\u5927\\u5C0F\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"2. \\u4F7F\\u7528 BFS\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u6B64\\u65B9\\u6CD5\\u4F7F\\u7528\\u5E7F\\u5EA6\\u4F18\\u5148\\u641C\\u7D22\\uFF08BFS\\uFF09\\u6765\\u904D\\u5386\\u7F51\\u683C\\u3002\\u8BE5\\u65B9\\u6CD5\\u4ECE\\u4EFB\\u4F55\\u672A\\u8BBF\\u95EE\\u7684\\u9646\\u5730\\u5355\\u5143\\u683C\\u5F00\\u59CB\\uFF0C\\u8FD9\\u6807\\u5FD7\\u7740\\u4E00\\u4E2A\\u65B0\\u5C9B\\u5C7F\\u7684\\u5F00\\u59CB\\u3002\\u6267\\u884C BFS \\u904D\\u5386\\u4EE5\\u8BBF\\u95EE\\u6240\\u6709\\u8FDE\\u63A5\\u7684\\u9646\\u5730\\u5355\\u5143\\u683C\\uFF0C\\u5C06\\u5B83\\u4EEC\\u6807\\u8BB0\\u4E3A\\u5DF2\\u8BBF\\u95EE\\uFF0C\\u65B9\\u6CD5\\u662F\\u5C06\\u5176\\u503C\\u8BBE\\u7F6E\\u4E3A \",(0,e.jsx)(n.code,{children:\"0\"}),\"\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\\u6BCF\\u4E2A\\u5C9B\\u5C7F\\u53EA\\u88AB\\u8BA1\\u7B97\\u4E00\\u6B21\\u3002\\u7F51\\u683C\\u88AB\\u5C31\\u5730\\u4FEE\\u6539\\uFF0C\\u4EE5\\u8282\\u7701\\u7528\\u4E8E\\u8DDF\\u8E2A\\u5DF2\\u8BBF\\u95EE\\u5355\\u5143\\u683C\\u7684\\u989D\\u5916\\u7A7A\\u95F4\\u3002\"]}),`\n`,(0,e.jsx)(n.p,{children:\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u7CFB\\u7EDF\\u5730\\u63A2\\u7D22\\u6BCF\\u4E2A\\u5C9B\\u5C7F\\uFF0C\\u540C\\u65F6\\u907F\\u514D\\u5197\\u4F59\\u68C0\\u67E5\\uFF0C\\u4F7F\\u5176\\u5BF9\\u5927\\u578B\\u7F51\\u683C\\u9AD8\\u6548\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u4ECE\\u7F51\\u683C\\u7EF4\\u5EA6\\u4E2D\\u68C0\\u7D22\\u884C\\u6570\\u548C\\u5217\\u6570\\u3002\"}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u521D\\u59CB\\u5316\\u8BA1\\u6570\\u5668 \",(0,e.jsx)(n.code,{children:\"numIslands\"}),\" \\u4E3A \",(0,e.jsx)(n.code,{children:\"0\"}),\"\\uFF0C\\u4EE5\\u8DDF\\u8E2A\\u5C9B\\u5C7F\\u7684\\u6570\\u91CF\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u904D\\u5386\\u7F51\\u683C\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5355\\u5143\\u683C\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5982\\u679C\\u5355\\u5143\\u683C\\u503C\\u4E3A \",(0,e.jsx)(n.code,{children:\"1\"}),\"\\uFF08\\u9646\\u5730\\uFF09\\uFF0C\\u5219\\u589E\\u52A0 \",(0,e.jsx)(n.code,{children:\"numIslands\"}),\" \\u8BA1\\u6570\\u5668\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5C06\\u5355\\u5143\\u683C\\u503C\\u8BBE\\u7F6E\\u4E3A \",(0,e.jsx)(n.code,{children:\"0\"}),\" \\u4EE5\\u5C06\\u5176\\u6807\\u8BB0\\u4E3A\\u5DF2\\u8BBF\\u95EE\\u3002\"]}),`\n`,(0,e.jsx)(n.li,{children:\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u7528\\u4E8E BFS \\u904D\\u5386\\u7684\\u961F\\u5217\\uFF0C\\u5E76\\u5C06\\u5F53\\u524D\\u5355\\u5143\\u683C\\u6DFB\\u52A0\\u5230\\u961F\\u5217\\u4E2D\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528\\u961F\\u5217\\u6267\\u884C BFS\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u4ECE\\u961F\\u5217\\u4E2D\\u51FA\\u961F\\u4E00\\u4E2A\\u5355\\u5143\\u683C\\u3002\"}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5BF9\\u4E8E\\u5B83\\u7684\\u6BCF\\u4E2A\\u90BB\\u5C45\\uFF08\\u4E0A\\u3001\\u4E0B\\u3001\\u5DE6\\u3001\\u53F3\\uFF09\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5982\\u679C\\u90BB\\u5C45\\u5728\\u8303\\u56F4\\u5185\\u4E14\\u5176\\u503C\\u4E3A \",(0,e.jsx)(n.code,{children:\"1\"}),\"\\uFF0C\\u5219\\u5C06\\u5176\\u5165\\u961F\\u5E76\\u5C06\\u5176\\u6807\\u8BB0\\u4E3A\\u5DF2\\u8BBF\\u95EE\\uFF0C\\u65B9\\u6CD5\\u662F\\u5C06\\u5176\\u503C\\u8BBE\\u7F6E\\u4E3A \",(0,e.jsx)(n.code,{children:\"0\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5904\\u7406\\u5B8C\\u7F51\\u683C\\u4E2D\\u7684\\u6240\\u6709\\u5355\\u5143\\u683C\\u540E\\uFF0C\\u8FD4\\u56DE \",(0,e.jsx)(n.code,{children:\"numIslands\"}),\" \\u8BA1\\u6570\\u5668\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(c,{children:a}),`\n`,(0,e.jsx)(n.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m.n)\"}),\"\\u3002\\u7F51\\u683C\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5355\\u5143\\u683C\\u90FD\\u4F1A\\u88AB\\u8BBF\\u95EE\\u4E00\\u6B21\\uFF0C\\u65E0\\u8BBA\\u662F\\u5728 BFS \\u904D\\u5386\\u671F\\u95F4\\u8FD8\\u662F\\u5728\\u4E3B\\u5FAA\\u73AF\\u671F\\u95F4\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(min(m, n))\"}),\"\\u3002\\u5728\\u6700\\u574F\\u7684\\u60C5\\u51B5\\u4E0B\\uFF0CBFS \\u961F\\u5217\\u53EF\\u4EE5\\u589E\\u957F\\u5230\\u8F83\\u5C0F\\u7EF4\\u5EA6\\u7684\\u5C3A\\u5BF8\\uFF0C\\u4F8B\\u5982\\u5F53\\u7F51\\u683C\\u53EA\\u6709\\u4E00\\u884C\\u6216\\u4E00\\u5217\\u9646\\u5730\\u65F6\\u3002\"]}),`\n`]})]})}function D(r={}){let{wrapper:n}=r.components||{};return n?(0,e.jsx)(n,Object.assign({},r,{children:(0,e.jsx)(g,r)})):g(r)}var C=D;return B(x);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/grid-distinct-paths/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/grid-distinct-paths/locales/zh-CN.json new file mode 100644 index 000000000..de99f6d99 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/grid-distinct-paths/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var o=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var f=(t,n)=>()=>(n||t((n={exports:{}}).exports,n),n.exports),b=(t,n)=>{for(var i in n)o(t,i,{get:n[i],enumerable:!0})},a=(t,n,i,c)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let r of x(n))!D.call(t,r)&&r!==i&&o(t,r,{get:()=>n[r],enumerable:!(c=m(n,r))||c.enumerable});return t};var j=(t,n,i)=>(i=t!=null?p(g(t)):{},a(n||!t||!t.__esModule?o(i,\"default\",{value:t,enumerable:!0}):i,t)),w=t=>a(o({},\"__esModule\",{value:!0}),t);var h=f((R,d)=>{d.exports=_jsx_runtime});var X={};b(X,{default:()=>C,frontmatter:()=>T});var e=j(h());var l=MDXTestExamples;var s=[{input:[[\"m\",3],[\"n\",2]],output:3,explanation:\"The robot has 3 unique paths to reach the target point in a 3x2 grid: Right-Down-Down, Down-Down-Right, Down-Right-Down.\"},{input:[[\"m\",5],[\"n\",7]],output:210,explanation:\"The robot can navigate a 5x7 grid using 210 unique paths to reach the target point.\"},{input:[[\"m\",10],[\"n\",4]],output:220,explanation:\"The robot can navigate a 10x4 grid using 220 unique paths to reach the target point.\"}];var T={title:\"\\u7F51\\u683C\\u4E2D\\u7684\\u4E0D\\u540C\\u8DEF\\u5F84\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u8BA1\\u7B97\\u673A\\u5668\\u4EBA\\u79FB\\u52A8\\u5728 m x n \\u7F51\\u683C\\u4E2D\\u7684\\u4E0D\\u540C\\u8DEF\\u5F84\"};function u(t){let n=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)(n.p,{children:[\"\\u4E00\\u4E2A\\u673A\\u5668\\u4EBA\\u4F4D\\u4E8E\\u4E00\\u4E2A \",(0,e.jsx)(n.code,{children:\"m\"}),\" x \",(0,e.jsx)(n.code,{children:\"n\"}),\" \\u7F51\\u683C\\u4E2D\\uFF0C\\u4ECE\\u5DE6\\u4E0A\\u89D2 (\",(0,e.jsx)(n.code,{children:\"grid[0][0]\"}),\") \\u5F00\\u59CB\\uFF0C\\u76EE\\u6807\\u662F\\u5230\\u8FBE\\u53F3\\u4E0B\\u89D2 (\",(0,e.jsx)(n.code,{children:\"grid[m - 1][n - 1]\"}),\")\\u3002 \\u5728\\u4E00\\u6B65\\u4E2D\\uFF0C\\u673A\\u5668\\u4EBA\\u53EA\\u80FD\\u5411\\u4E0B\\u6216\\u5411\\u53F3\\u79FB\\u52A8\\u4E00\\u4E2A\\u5355\\u5143\\u683C\\u3002\"]}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u7ED9\\u5B9A\\u6574\\u6570 \",(0,e.jsx)(n.code,{children:\"m\"}),\" \\u548C \",(0,e.jsx)(n.code,{children:\"n\"}),\"\\uFF0C\\u786E\\u5B9A\\u673A\\u5668\\u4EBA\\u53EF\\u4EE5\\u5230\\u8FBE\\u53F3\\u4E0B\\u89D2\\u7684\\u4E0D\\u540C\\u7684\\u8DEF\\u5F84\\u6570\\u91CF\\u3002\"]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"m: number\"}),\": \\u4E00\\u4E2A\\u6574\\u6570\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"n: number\"}),\": \\u4E00\\u4E2A\\u6574\\u6570\"]}),`\n`]}),`\n`,(0,e.jsx)(l,{testCases:s}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u7ED3\\u679C\\u4E0D\\u4F1A\\u8D85\\u8FC7 2^31\"}),`\n`,(0,e.jsxs)(n.li,{children:[\"1 <= \",(0,e.jsx)(n.code,{children:\"m\"}),\", \",(0,e.jsx)(n.code,{children:\"n\"}),\" <= 100\"]}),`\n`]})]})}function M(t={}){let{wrapper:n}=t.components||{};return n?(0,e.jsx)(n,Object.assign({},t,{children:(0,e.jsx)(u,t)})):u(t)}var C=M;return w(X);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来计算机器人移动在 m x n 网格中的不同路径", + "title": "网格中的不同路径" + }, + "solution": "var Component=(()=>{var p=Object.create;var c=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var x=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),D=(r,e)=>{for(var l in e)c(r,l,{get:e[l],enumerable:!0})},h=(r,e,l,t)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let o of w(e))!b.call(r,o)&&o!==l&&c(r,o,{get:()=>e[o],enumerable:!(t=f(e,o))||t.enumerable});return r};var y=(r,e,l)=>(l=r!=null?p(g(r)):{},h(e||!r||!r.__esModule?c(l,\"default\",{value:r,enumerable:!0}):l,r)),C=r=>h(c({},\"__esModule\",{value:!0}),r);var a=x((B,d)=>{d.exports=_jsx_runtime});var _={};D(_,{default:()=>P});var n=y(a());var i=MDXCodeBlock;var m=`export default function gridDistinctPaths(m: number, n: number): number {\n // Create a 2D DP table (d) to store the number of unique paths reaching each cell.\n // Initialize all cells to 1, representing 1 path (straight down or right from the top/left edge).\n const d = new Array(m).fill(0).map(() => new Array(n).fill(1));\n\n // Iterate through the table (excluding the first row and column since they already have 1 path).\n for (let col = 1; col < m; col++) {\n for (let row = 1; row < n; row++) {\n // The number of unique paths reaching this cell (col, row) is the sum of:\n // - Paths reaching the cell above (col-1, row) - only one possible move (down).\n // - Paths reaching the cell to the left (col, row-1) - only one possible move (right).\n d[col][row] = d[col - 1][row] + d[col][row - 1];\n }\n }\n\n // The final element (d[m-1][n-1]) represents the total number of unique paths reaching the bottom-right corner.\n return d[m - 1][n - 1];\n}\n`;var s=`export default function gridDistinctPaths(m: number, n: number): number {\n // Create a memoization table to store previously calculated results (optional for top-down approach)\n const memo = new Array(m).fill(null).map(() => new Array(n).fill(null));\n\n // Recursive helper function to calculate the number of paths from a specific cell\n function helper(row: number, col: number): number {\n // Base cases:\n if (row === m - 1 && col === n - 1) return 1; // Reached the destination (bottom-right) - 1 path\n if (row >= m || col >= n) return 0; // Outside the grid - no paths possible\n\n // Check if the value has already been calculated and stored in the memo table\n if (memo[row][col] !== null) {\n return memo[row][col];\n }\n\n // Calculate the number of paths by combining paths from below and to the right\n const pathsDown = helper(row + 1, col);\n const pathsRight = helper(row, col + 1);\n\n // Memoize the result for future use\n memo[row][col] = pathsDown + pathsRight;\n\n return memo[row][col];\n }\n\n // Call the helper function to start from the top-left corner\n return helper(0, 0);\n}\n`;function u(r){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u81EA\\u5E95\\u5411\\u4E0A\\u52A8\\u6001\\u89C4\\u5212\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8BE5\\u95EE\\u9898\\u8981\\u6C42\\u627E\\u5230\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"m x n\"}),\" \\u7EF4\\u7F51\\u683C\\u4ECE\\u5DE6\\u4E0A\\u89D2\\u5230\\u53F3\\u4E0B\\u89D2\\u7684\\u4E0D\\u540C\\u7684\\u8DEF\\u5F84\\u6570\\u91CF\\u3002\\u5728\\u4EFB\\u4F55\\u65F6\\u5019\\uFF0C\\u79FB\\u52A8\\u90FD\\u4EC5\\u9650\\u4E8E\\u5411\\u4E0B\\u6216\\u5411\\u53F3\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u65B9\\u6CD5\\u4F7F\\u7528\\u81EA\\u5E95\\u5411\\u4E0A\\u7684\\u52A8\\u6001\\u89C4\\u5212\\u6765\\u9AD8\\u6548\\u5730\\u89E3\\u51B3\\u95EE\\u9898\\u3002\\u5176\\u76F4\\u89C9\\u662F\\uFF0C\\u5230\\u8FBE\\u7F51\\u683C\\u4E2D\\u7279\\u5B9A\\u5355\\u5143\\u683C\\u7684\\u8DEF\\u5F84\\u6570\\u91CF\\u662F\\u5230\\u8FBE\\u5176\\u6B63\\u4E0A\\u65B9\\u5355\\u5143\\u683C\\u7684\\u8DEF\\u5F84\\u6570\\u91CF\\u4E0E\\u5176\\u5DE6\\u4FA7\\u5355\\u5143\\u683C\\u7684\\u8DEF\\u5F84\\u6570\\u91CF\\u4E4B\\u548C\\u3002\\u8FD9\\u662F\\u56E0\\u4E3A\\u5230\\u8FBE\\u5F53\\u524D\\u5355\\u5143\\u683C\\u7684\\u552F\\u4E00\\u6709\\u6548\\u79FB\\u52A8\\u662F\\u4ECE\\u4E0A\\u65B9\\u6216\\u4ECE\\u5DE6\\u4FA7\\u3002\\u4F7F\\u7528\\u4E00\\u4E2A\\u4E8C\\u7EF4\\u8868\\u6765\\u5B58\\u50A8\\u5230\\u8FBE\\u6BCF\\u4E2A\\u5355\\u5143\\u683C\\u7684\\u8DEF\\u5F84\\u6570\\u91CF\\uFF0C\\u907F\\u514D\\u4E86\\u5197\\u4F59\\u8BA1\\u7B97\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u901A\\u8FC7\\u8FED\\u4EE3\\u5730\\u5728\\u8868\\u4E2D\\u6784\\u5EFA\\u89E3\\u51B3\\u65B9\\u6848\\uFF0C\\u6D88\\u9664\\u4E86\\u4E0D\\u5FC5\\u8981\\u7684\\u9012\\u5F52\\u548C\\u91CD\\u53E0\\u7684\\u5B50\\u95EE\\u9898\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u5927\\u5C0F\\u4E3A \",(0,n.jsx)(e.code,{children:\"m x n\"}),\" \\u7684\\u4E8C\\u7EF4\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"d\"}),\"\\uFF0C\\u6240\\u6709\\u5355\\u5143\\u683C\\u90FD\\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"1\"}),\"\\u3002\\u8FD9\\u8868\\u793A\\u5230\\u8FBE\\u7B2C\\u4E00\\u884C\\u6216\\u7B2C\\u4E00\\u5217\\u7684\\u4EFB\\u4F55\\u5355\\u5143\\u683C\\u53EA\\u6709\\u4E00\\u79CD\\u65B9\\u6CD5\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u7B2C\\u4E8C\\u884C\\u548C\\u7B2C\\u4E8C\\u5217\\u5F00\\u59CB\\u904D\\u5386\\u7F51\\u683C\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u5355\\u5143\\u683C \",(0,n.jsx)(e.code,{children:\"(col, row)\"}),\"\\uFF0C\\u5C06\\u5230\\u8FBE\\u8BE5\\u5355\\u5143\\u683C\\u7684\\u8DEF\\u5F84\\u6570\\u91CF\\u8BA1\\u7B97\\u4E3A\\u5230\\u8FBE\\u5176\\u4E0A\\u65B9\\u5355\\u5143\\u683C (\",(0,n.jsx)(e.code,{children:\"d[col-1][row]\"}),\") \\u7684\\u8DEF\\u5F84\\u6570\\u91CF\\u4E0E\\u5230\\u8FBE\\u5176\\u5DE6\\u4FA7\\u5355\\u5143\\u683C (\",(0,n.jsx)(e.code,{children:\"d[col][row-1]\"}),\") \\u7684\\u8DEF\\u5F84\\u6570\\u91CF\\u4E4B\\u548C\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u7EE7\\u7EED\\u6B64\\u8FC7\\u7A0B\\uFF0C\\u76F4\\u5230\\u6240\\u6709\\u5355\\u5143\\u683C\\u90FD\\u88AB\\u586B\\u5145\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE\\u53F3\\u4E0B\\u89D2\\u5355\\u5143\\u683C \",(0,n.jsx)(e.code,{children:\"d[m-1][n-1]\"}),\" \\u7684\\u503C\\uFF0C\\u8BE5\\u503C\\u8868\\u793A\\u4ECE\\u5DE6\\u4E0A\\u89D2\\u5230\\u53F3\\u4E0B\\u89D2\\u7684\\u552F\\u4E00\\u8DEF\\u5F84\\u603B\\u6570\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(i,{children:m}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m.n)\"}),\"\\u3002\\u7F51\\u683C\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5355\\u5143\\u683C\\u90FD\\u4F1A\\u88AB\\u5904\\u7406\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m.n)\"}),\"\\u3002\\u4F7F\\u7528\\u4E00\\u4E2A\\u5927\\u5C0F\\u4E3A \",(0,n.jsx)(e.code,{children:\"m x n\"}),\" \\u7684\\u4E8C\\u7EF4\\u6570\\u7EC4\\u6765\\u5B58\\u50A8\\u6BCF\\u4E2A\\u5355\\u5143\\u683C\\u7684\\u552F\\u4E00\\u8DEF\\u5F84\\u6570\\u91CF\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u81EA\\u9876\\u5411\\u4E0B\\u52A8\\u6001\\u89C4\\u5212\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u4F7F\\u7528\\u5E26\\u5907\\u5FD8\\u5F55\\u7684\\u81EA\\u9876\\u5411\\u4E0B\\u52A8\\u6001\\u89C4\\u5212\\u6765\\u907F\\u514D\\u5197\\u4F59\\u8BA1\\u7B97\\u3002\\u9012\\u5F52\\u51FD\\u6570\\u901A\\u8FC7\\u5C06\\u76F4\\u63A5\\u4E0B\\u65B9\\u5355\\u5143\\u683C\\u548C\\u76F4\\u63A5\\u53F3\\u4FA7\\u5355\\u5143\\u683C\\u7684\\u8DEF\\u5F84\\u76F8\\u52A0\\u6765\\u8BA1\\u7B97\\u4ECE\\u7ED9\\u5B9A\\u5355\\u5143\\u683C\\u5230\\u76EE\\u7684\\u5730\\u7684\\u8DEF\\u5F84\\u6570\\u91CF\\u3002\\u5907\\u5FD8\\u5F55\\u8868\\u5B58\\u50A8\\u5148\\u524D\\u8BA1\\u7B97\\u7684\\u5355\\u5143\\u683C\\u7684\\u7ED3\\u679C\\uFF0C\\u786E\\u4FDD\\u6BCF\\u4E2A\\u5B50\\u95EE\\u9898\\u53EA\\u89E3\\u51B3\\u4E00\\u6B21\\u3002\\u8FD9\\u6D88\\u9664\\u4E86\\u4E0D\\u5FC5\\u8981\\u7684\\u91CD\\u590D\\u5DE5\\u4F5C\\uFF0C\\u4F18\\u5316\\u4E86\\u89E3\\u51B3\\u65B9\\u6848\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u6709\\u6548\\u5730\\u5C06\\u95EE\\u9898\\u5206\\u89E3\\u4E3A\\u91CD\\u53E0\\u7684\\u5B50\\u95EE\\u9898\\uFF0C\\u540C\\u65F6\\u5B58\\u50A8\\u4E2D\\u95F4\\u7ED3\\u679C\\u4EE5\\u51CF\\u5C11\\u603B\\u8BA1\\u7B97\\u65F6\\u95F4\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521B\\u5EFA\\u4E00\\u4E2A\\u5927\\u5C0F\\u4E3A \",(0,n.jsx)(e.code,{children:\"m x n\"}),\" \\u7684\\u5907\\u5FD8\\u5F55\\u8868 \",(0,n.jsx)(e.code,{children:\"memo\"}),\"\\uFF0C\\u5E76\\u5C06\\u5176\\u521D\\u59CB\\u5316\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u4EE5\\u5B58\\u50A8\\u5B50\\u95EE\\u9898\\u7684\\u7ED3\\u679C\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u9012\\u5F52\\u8F85\\u52A9\\u51FD\\u6570 \",(0,n.jsx)(e.code,{children:\"helper(row, col)\"}),\"\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5F53\\u524D\\u5355\\u5143\\u683C\\u662F\\u53F3\\u4E0B\\u89D2 (\",(0,n.jsx)(e.code,{children:\"row === m-1\"}),\" \\u4E14 \",(0,n.jsx)(e.code,{children:\"col === n-1\"}),\")\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"1\"}),\"\\uFF0C\\u56E0\\u4E3A\\u5230\\u8FBE\\u76EE\\u7684\\u5730\\u53EA\\u6709\\u4E00\\u6761\\u8DEF\\u5F84\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5F53\\u524D\\u5355\\u5143\\u683C\\u5728\\u7F51\\u683C\\u4E4B\\u5916 (\",(0,n.jsx)(e.code,{children:\"row >= m\"}),\" \\u6216 \",(0,n.jsx)(e.code,{children:\"col >= n\"}),\")\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u56E0\\u4E3A\\u4E0D\\u53EF\\u80FD\\u6709\\u8DEF\\u5F84\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5F53\\u524D\\u5355\\u5143\\u683C\\u7684\\u7ED3\\u679C\\u5DF2\\u5B58\\u50A8\\u5728 \",(0,n.jsx)(e.code,{children:\"memo[row][col]\"}),\" \\u4E2D\\uFF0C\\u5219\\u8FD4\\u56DE\\u5B58\\u50A8\\u7684\\u503C\\u4EE5\\u907F\\u514D\\u5197\\u4F59\\u8BA1\\u7B97\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u8DEF\\u5F84\\u6570\\u91CF\\u8BA1\\u7B97\\u4E3A\\u6765\\u81EA\\u4E0B\\u65B9\\u5355\\u5143\\u683C (\",(0,n.jsx)(e.code,{children:\"helper(row+1, col)\"}),\") \\u548C\\u53F3\\u4FA7\\u5355\\u5143\\u683C (\",(0,n.jsx)(e.code,{children:\"helper(row, col+1)\"}),\") \\u7684\\u8DEF\\u5F84\\u4E4B\\u548C\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u8BA1\\u7B97\\u7ED3\\u679C\\u5B58\\u50A8\\u5728 \",(0,n.jsx)(e.code,{children:\"memo[row][col]\"}),\" \\u4E2D\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u4E3A\\u5DE6\\u4E0A\\u89D2\\u8C03\\u7528 \",(0,n.jsx)(e.code,{children:\"helper(0, 0)\"}),\" \\u6765\\u5F00\\u59CB\\u8BA1\\u7B97\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u4ECE\\u9012\\u5F52\\u8C03\\u7528\\u4E2D\\u8FD4\\u56DE\\u7ED3\\u679C\\uFF0C\\u8BE5\\u7ED3\\u679C\\u8868\\u793A\\u4ECE\\u5DE6\\u4E0A\\u89D2\\u5230\\u53F3\\u4E0B\\u89D2\\u7684\\u8DEF\\u5F84\\u603B\\u6570\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(i,{children:s}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m.n)\"}),\"\\u3002\\u7531\\u4E8E\\u5907\\u5FD8\\u5F55\\uFF0C\\u6BCF\\u4E2A\\u5355\\u5143\\u683C\\u6700\\u591A\\u8BA1\\u7B97\\u4E00\\u6B21\\uFF0C\\u603B\\u5171\\u6709 \",(0,n.jsx)(e.code,{children:\"m.n\"}),\" \\u4E2A\\u5B50\\u95EE\\u9898\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m.n)\"}),\"\\u3002\\u5907\\u5FD8\\u5F55\\u8868\\u9700\\u8981 \",(0,n.jsx)(e.code,{children:\"m.n\"}),\" \\u7684\\u7A7A\\u95F4\\uFF0C\\u5E76\\u4E14\\u9012\\u5F52\\u5806\\u6808\\u5728\\u6700\\u574F\\u7684\\u60C5\\u51B5\\u4E0B\\u53EF\\u4EE5\\u589E\\u957F\\u5230 \",(0,n.jsx)(e.code,{children:\"m + n\"}),\" \\u5C42\\u3002\"]}),`\n`]})]})}function v(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(u,r)})):u(r)}var P=v;return C(_);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/grid-find-word/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/grid-find-word/locales/zh-CN.json new file mode 100644 index 000000000..7e636d51e --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/grid-find-word/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var g=Object.create;var o=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var b=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),w=(n,e)=>{for(var r in e)o(n,r,{get:e[r],enumerable:!0})},c=(n,e,r,d)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of p(e))!f.call(n,i)&&i!==r&&o(n,i,{get:()=>e[i],enumerable:!(d=m(e,i))||d.enumerable});return n};var j=(n,e,r)=>(r=n!=null?g(x(n)):{},c(e||!n||!n.__esModule?o(r,\"default\",{value:n,enumerable:!0}):r,n)),T=n=>c(o({},\"__esModule\",{value:!0}),n);var a=b((E,l)=>{l.exports=_jsx_runtime});var X={};w(X,{default:()=>D,frontmatter:()=>M});var t=j(a());var h=MDXTestExamples;var s=[{input:[[\"grid\",[[\"a\",\"b\",\"c\",\"e\"],[\"s\",\"f\",\"c\",\"t\"],[\"a\",\"d\",\"e\",\"e\"]]],[\"target\",\"tee\"]],output:!0,explanation:\"The word 'tee' can be formed starting from the cell (1, 3).\"},{input:[[\"grid\",[[\"a\",\"b\"],[\"c\",\"d\"]]],[\"target\",\"abcd\"]],output:!1,explanation:\"The word 'abcd' cannot be formed. There's no way to move from 'b' to 'c' as required by the word.\"},{input:[[\"grid\",[[\"h\",\"e\",\"l\",\"l\",\"o\"],[\"w\",\"o\",\"r\",\"l\",\"d\"]]],[\"target\",\"hello\"]],output:!0,explanation:\"The word 'hello' is found in the first row of the grid.\"}];var M={title:\"\\u5728\\u7F51\\u683C\\u4E2D\\u67E5\\u627E\\u5355\\u8BCD\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u68C0\\u67E5\\u5355\\u8BCD\\u5728\\u7F51\\u683C\\u4E2D\\u662F\\u5426\\u5B58\\u5728\"};function u(n){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},n.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u5C3A\\u5BF8\\u4E3A \",(0,t.jsx)(e.code,{children:\"m x n\"}),\" \\u7684\\u5B57\\u7B26\\u7F51\\u683C\\uFF0C\\u786E\\u5B9A\\u662F\\u5426\\u53EF\\u4EE5\\u901A\\u8FC7\\u8FDE\\u63A5\\u7F51\\u683C\\u4E2D\\u76F8\\u90BB\\u7684\\u5B57\\u7B26\\u6765\\u5F62\\u6210\\u6307\\u5B9A\\u7684\\u5355\\u8BCD\\u3002\"]}),`\n`,(0,t.jsx)(e.p,{children:\"\\u5355\\u8BCD\\u53EF\\u4EE5\\u901A\\u8FC7\\u904D\\u5386\\u76F8\\u90BB\\u7684\\u5355\\u5143\\u683C\\u6765\\u5F62\\u6210\\uFF0C\\u5176\\u4E2D\\u76F8\\u90BB\\u7684\\u5355\\u5143\\u683C\\u662F\\u5F7C\\u6B64\\u76F4\\u63A5\\u76F8\\u90BB\\u7684\\uFF0C\\u65E0\\u8BBA\\u662F\\u6C34\\u5E73\\u8FD8\\u662F\\u5782\\u76F4\\u3002\\u7F51\\u683C\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5355\\u5143\\u683C\\u53EA\\u80FD\\u4F7F\\u7528\\u4E00\\u6B21\\u6765\\u5F62\\u6210\\u5355\\u8BCD\\u3002\"}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.code,{children:\"grid: string[][]\"}),\": \\u4E00\\u4E2A\\u5927\\u5C0F\\u4E3A \",(0,t.jsx)(e.code,{children:\"m x n\"}),\" \\u7684\\u4E8C\\u7EF4\\u6570\\u7EC4\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u5143\\u7D20\\u90FD\\u662F\\u4E00\\u4E2A\\u5C0F\\u5199\\u82F1\\u6587\\u5B57\\u6BCD\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.code,{children:\"target: string\"}),\": \\u8981\\u5728\\u7F51\\u683C\\u4E2D\\u641C\\u7D22\\u7684\\u5B57\\u7B26\\u4E32\"]}),`\n`]}),`\n`,(0,t.jsx)(h,{testCases:s}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[\"1 <= \",(0,t.jsx)(e.code,{children:\"grid.length\"}),\", \",(0,t.jsx)(e.code,{children:\"grid[i].length\"}),\" <= 6\"]}),`\n`,(0,t.jsxs)(e.li,{children:[\"1 <= \",(0,t.jsx)(e.code,{children:\"target.length\"}),\" <= 15\"]}),`\n`,(0,t.jsxs)(e.li,{children:[\"\\u4E24\\u4E2A \",(0,t.jsx)(e.code,{children:\"grid\"}),\" \\u548C \",(0,t.jsx)(e.code,{children:\"target\"}),\" \\u90FD\\u53EA\\u5305\\u542B\\u5C0F\\u5199\\u82F1\\u6587\\u5B57\\u6BCD\"]}),`\n`]})]})}function C(n={}){let{wrapper:e}=n.components||{};return e?(0,t.jsx)(e,Object.assign({},n,{children:(0,t.jsx)(u,n)})):u(n)}var D=C;return T(X);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来检查单词在网格中是否存在", + "title": "在网格中查找单词" + }, + "solution": "var Component=(()=>{var u=Object.create;var o=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var w=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),x=(n,e)=>{for(var t in e)o(n,t,{get:e[t],enumerable:!0})},i=(n,e,t,l)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let c of m(e))!b.call(n,c)&&c!==t&&o(n,c,{get:()=>e[c],enumerable:!(l=g(e,c))||l.enumerable});return n};var k=(n,e,t)=>(t=n!=null?u(p(n)):{},i(e||!n||!n.__esModule?o(t,\"default\",{value:n,enumerable:!0}):t,n)),O=n=>i(o({},\"__esModule\",{value:!0}),n);var h=w((D,d)=>{d.exports=_jsx_runtime});var S={};x(S,{default:()=>C});var r=k(h());var s=MDXCodeBlock;var f=`export default function exist(grid: string[][], target: string): boolean {\n const rows = grid.length; // Number of rows in the grid\n const cols = grid[0].length; // Number of columns in the grid\n\n function backtrack(row: number, col: number, suffix: string): boolean {\n // Step 1: Check if we've matched the entire target word\n if (suffix.length === 0) {\n return true;\n }\n\n // Step 2: Check the boundaries and if the current cell matches the first character of the suffix\n if (\n row < 0 || // Out of bounds (top)\n row === rows || // Out of bounds (bottom)\n col < 0 || // Out of bounds (left)\n col === cols || // Out of bounds (right)\n grid[row][col] !== suffix.charAt(0) // Current cell doesn't match the suffix character\n ) {\n return false;\n }\n\n // Step 3: Explore the neighbors in DFS\n let ret = false;\n // Mark the path before the next exploration\n const temp = grid[row][col];\n grid[row][col] = '#'; // Mark the current cell as visited\n\n const directions = [\n [0, 1], // Move right\n [1, 0], // Move down\n [0, -1], // Move left\n [-1, 0], // Move up\n ];\n\n // Explore all possible directions\n for (let [rowOffset, colOffset] of directions) {\n ret = backtrack(row + rowOffset, col + colOffset, suffix.slice(1)); // Recursively check the next cell\n if (ret) break; // If found, break out of the loop\n }\n\n // Step 4: Clean up and return the result\n grid[row][col] = temp; // Restore the current cell's value\n return ret; // Return whether we found the target word\n }\n\n // Iterate through each cell in the grid\n for (let row = 0; row < rows; row++) {\n for (let col = 0; col < cols; col++) {\n if (backtrack(row, col, target)) return true; // Start backtracking from each cell\n }\n }\n return false; // If no match is found, return false\n}\n`;function a(n){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},n.components);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u56DE\\u6EAF\\u6CD5\"}),`\n`,(0,r.jsxs)(e.p,{children:[\"\\u8BE5\\u95EE\\u9898\\u8981\\u6C42\\u5224\\u65AD\\u7ED9\\u5B9A\\u7684 \",(0,r.jsx)(e.code,{children:\"target\"}),\" \\u5355\\u8BCD\\u662F\\u5426\\u5B58\\u5728\\u4E8E\\u5B57\\u7B26\\u7684\\u4E8C\\u7EF4\\u7F51\\u683C\\u4E2D\\u3002\\u8BE5\\u5355\\u8BCD\\u53EF\\u4EE5\\u7531\\u7F51\\u683C\\u4E2D\\u8FDE\\u7EED\\u76F8\\u90BB\\u7684\\u5355\\u5143\\u683C\\u6784\\u6210\\uFF0C\\u53EF\\u4EE5\\u4E0A\\u4E0B\\u5DE6\\u53F3\\u79FB\\u52A8\\u3002\\u4E00\\u4E2A\\u5355\\u5143\\u683C\\u4E0D\\u80FD\\u5728\\u540C\\u4E00\\u4E2A\\u5355\\u8BCD\\u6784\\u9020\\u4E2D\\u91CD\\u590D\\u4F7F\\u7528\\u3002\"]}),`\n`,(0,r.jsxs)(e.p,{children:[\"\\u8BE5\\u65B9\\u6CD5\\u4F7F\\u7528\\u56DE\\u6EAF\\u6CD5\\u548C\\u6DF1\\u5EA6\\u4F18\\u5148\\u641C\\u7D22\\uFF08DFS\\uFF09\\u6765\\u63A2\\u7D22\\u4ECE\\u7F51\\u683C\\u4E2D\\u6BCF\\u4E2A\\u5355\\u5143\\u683C\\u5F00\\u59CB\\u7684\\u6240\\u6709\\u53EF\\u80FD\\u8DEF\\u5F84\\u3002\\u5728\\u6BCF\\u4E00\\u6B65\\uFF0C\\u7B97\\u6CD5\\u68C0\\u67E5\\u5F53\\u524D\\u5355\\u5143\\u683C\\u662F\\u5426\\u4E0E \",(0,r.jsx)(e.code,{children:\"target\"}),\" \\u7684\\u4E0B\\u4E00\\u4E2A\\u5B57\\u7B26\\u5339\\u914D\\u3002\\u5982\\u679C\\u53D1\\u751F\\u4E0D\\u5339\\u914D\\u6216\\u5355\\u5143\\u683C\\u8D85\\u51FA\\u8FB9\\u754C\\uFF0C\\u5219\\u653E\\u5F03\\u8BE5\\u8DEF\\u5F84\\u3002\\u4E3A\\u4E86\\u786E\\u4FDD\\u4E0D\\u91CD\\u590D\\u8BBF\\u95EE\\u5355\\u5143\\u683C\\uFF0C\\u5728 DFS \\u63A2\\u7D22\\u671F\\u95F4\\uFF0C\\u5B83\\u88AB\\u4E34\\u65F6\\u6807\\u8BB0\\u4E3A\\u5DF2\\u8BBF\\u95EE\\u3002\\u5728\\u63A2\\u7D22\\u5B8C\\u6240\\u6709\\u65B9\\u5411\\u540E\\uFF0C\\u5355\\u5143\\u683C\\u7684\\u503C\\u88AB\\u6062\\u590D\\u4EE5\\u4F7F\\u5176\\u4ED6\\u8DEF\\u5F84\\u53EF\\u4EE5\\u4F7F\\u7528\\u5B83\\u3002\"]}),`\n`,(0,r.jsx)(e.p,{children:\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u7CFB\\u7EDF\\u5730\\u63A2\\u7D22\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u8DEF\\u5F84\\uFF0C\\u540C\\u65F6\\u5C3D\\u65E9\\u4FEE\\u526A\\u65E0\\u6548\\u8DEF\\u5F84\\uFF0C\\u4F18\\u5316\\u641C\\u7D22\\u8FC7\\u7A0B\\u3002\"}),`\n`,(0,r.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,r.jsxs)(e.ol,{children:[`\n`,(0,r.jsx)(e.li,{children:\"\\u68C0\\u7D22\\u7F51\\u683C\\u4E2D\\u7684\\u884C\\u6570\\u548C\\u5217\\u6570\\u3002\"}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u9012\\u5F52\\u7684 \",(0,r.jsx)(e.code,{children:\"backtrack\"}),\" \\u51FD\\u6570\\uFF1A\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,r.jsx)(e.code,{children:\"suffix\"}),\" \\u4E3A\\u7A7A\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,r.jsx)(e.code,{children:\"true\"}),\"\\uFF0C\\u56E0\\u4E3A\\u6574\\u4E2A\\u5355\\u8BCD\\u5DF2\\u5339\\u914D\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u5F53\\u524D\\u5355\\u5143\\u683C\\u662F\\u5426\\u8D85\\u51FA\\u8FB9\\u754C\\uFF0C\\u6216\\u8005\\u5B83\\u662F\\u5426\\u4E0E \",(0,r.jsx)(e.code,{children:\"suffix\"}),\" \\u7684\\u7B2C\\u4E00\\u4E2A\\u5B57\\u7B26\\u4E0D\\u5339\\u914D\\u3002\\u5982\\u679C\\u662F\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,r.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u6682\\u65F6\\u5C06\\u5176\\u503C\\u66F4\\u6539\\u4E3A \",(0,r.jsx)(e.code,{children:\"'#'\"}),\" \\u6765\\u6807\\u8BB0\\u5F53\\u524D\\u5355\\u5143\\u683C\\u4E3A\\u5DF2\\u8BBF\\u95EE\\u3002\"]}),`\n`,(0,r.jsx)(e.li,{children:\"\\u5B9A\\u4E49\\u56DB\\u4E2A\\u53EF\\u80FD\\u8981\\u63A2\\u7D22\\u7684\\u65B9\\u5411\\uFF1A\\u53F3\\u3001\\u4E0B\\u3001\\u5DE6\\u548C\\u4E0A\\u3002\"}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u8FD9\\u4E9B\\u65B9\\u5411\\uFF0C\\u5E76\\u4F7F\\u7528\\u5269\\u4F59\\u7684 \",(0,r.jsx)(e.code,{children:\"suffix\"}),\" \\u9012\\u5F52\\u8C03\\u7528\\u76F8\\u90BB\\u5355\\u5143\\u683C\\u7684 \",(0,r.jsx)(e.code,{children:\"backtrack\"}),\" \\u51FD\\u6570\\u3002\"]}),`\n`,(0,r.jsx)(e.li,{children:\"\\u5728\\u63A2\\u7D22\\u5B8C\\u6240\\u6709\\u65B9\\u5411\\u540E\\uFF0C\\u6062\\u590D\\u5355\\u5143\\u683C\\u7684\\u539F\\u59CB\\u503C\\u3002\"}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u4EFB\\u4F55\\u65B9\\u5411\\u5BFC\\u81F4\\u6210\\u529F\\u5339\\u914D\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,r.jsx)(e.code,{children:\"true\"}),\"\\uFF1B\\u5426\\u5219\\uFF0C\\u8FD4\\u56DE \",(0,r.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u7F51\\u683C\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5355\\u5143\\u683C\\uFF1A\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u4ECE\\u5F53\\u524D\\u5355\\u5143\\u683C\\u5F00\\u59CB\\uFF0C\\u4F7F\\u7528\\u5B8C\\u6574\\u7684 \",(0,r.jsx)(e.code,{children:\"target\"}),\" \\u5B57\\u7B26\\u4E32\\u8C03\\u7528 \",(0,r.jsx)(e.code,{children:\"backtrack\"}),\" \\u51FD\\u6570\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u8BE5\\u51FD\\u6570\\u8FD4\\u56DE \",(0,r.jsx)(e.code,{children:\"true\"}),\"\\uFF0C\\u5219\\u8BE5\\u5355\\u8BCD\\u5B58\\u5728\\u4E8E\\u7F51\\u683C\\u4E2D\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u6CA1\\u6709\\u8D77\\u59CB\\u5355\\u5143\\u683C\\u5BFC\\u81F4\\u5339\\u914D\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,r.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,r.jsx)(s,{children:f}),`\n`,(0,r.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsxs)(e.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m.n.3\",(0,r.jsx)(\"sup\",{children:\"l\"}),\")\"]}),\"\\u3002\\u7F51\\u683C\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5355\\u5143\\u683C (\",(0,r.jsx)(e.code,{children:\"m.n\"}),\") \\u90FD\\u53EF\\u4EE5\\u542F\\u52A8\\u641C\\u7D22\\uFF0C\\u5E76\\u4E14\\u5BF9\\u4E8E\\u5355\\u8BCD\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5B57\\u7B26 (\",(0,r.jsx)(e.code,{children:\"l\"}),\")\\uFF0C\\u6700\\u591A\\u63A2\\u7D22 3 \\u4E2A\\u65B9\\u5411\\uFF08\\u56E0\\u4E3A\\u6211\\u4EEC\\u4E0D\\u4F1A\\u56DE\\u5230\\u6211\\u4EEC\\u6765\\u7684\\u5730\\u65B9\\uFF09\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(l)\"}),\"\\u3002\\u9012\\u5F52\\u5806\\u6808\\u6DF1\\u5EA6\\u4E0E\\u5355\\u8BCD\\u7684\\u957F\\u5EA6 (\",(0,r.jsx)(e.code,{children:\"l\"}),\") \\u6210\\u6B63\\u6BD4\\u3002\"]}),`\n`]})]})}function v(n={}){let{wrapper:e}=n.components||{};return e?(0,r.jsx)(e,Object.assign({},n,{children:(0,r.jsx)(a,n)})):a(n)}var C=v;return O(S);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/grid-find-words/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/grid-find-words/locales/zh-CN.json new file mode 100644 index 000000000..8d6c0b60f --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/grid-find-words/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var m=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var g=(d,e)=>()=>(e||d((e={exports:{}}).exports,e),e.exports),w=(d,e)=>{for(var c in e)i(d,c,{get:e[c],enumerable:!0})},l=(d,e,c,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of x(e))!u.call(d,r)&&r!==c&&i(d,r,{get:()=>e[r],enumerable:!(o=p(e,r))||o.enumerable});return d};var j=(d,e,c)=>(c=d!=null?m(b(d)):{},l(e||!d||!d.__esModule?i(c,\"default\",{value:d,enumerable:!0}):c,d)),_=d=>l(i({},\"__esModule\",{value:!0}),d);var a=g((X,t)=>{t.exports=_jsx_runtime});var C={};w(C,{default:()=>M,frontmatter:()=>T});var n=j(a());var h=MDXTestExamples;var s=[{input:[[\"grid\",[[\"e\",\"e\",\"d\",\"f\",\"a\",\"e\"],[\"b\",\"f\",\"f\",\"b\",\"a\",\"a\"],[\"c\",\"e\",\"f\",\"e\",\"e\",\"d\"],[\"d\",\"d\",\"c\",\"f\",\"c\",\"d\"],[\"a\",\"e\",\"f\",\"e\",\"d\",\"d\"],[\"f\",\"f\",\"e\",\"b\",\"d\",\"c\"]]],[\"words\",[\"acd\",\"cbbc\",\"fb\",\"efdc\"]]],output:[\"fb\"],explanation:\"The word 'fb' can be formed from adjacent cells on the grid, while others cannot.\"},{input:[[\"grid\",[[\"a\",\"b\",\"c\"],[\"s\",\"f\",\"c\"],[\"d\",\"a\",\"f\"]]],[\"words\",[\"abc\",\"bcd\",\"cfa\",\"sfa\"]]],output:[\"abc\",\"cfa\",\"sfa\"],explanation:\"The words 'abc' and 'cfa' can be formed from adjacent cells on the grid.\"},{input:[[\"grid\",[[\"x\",\"y\",\"z\"],[\"a\",\"b\",\"c\"],[\"d\",\"e\",\"f\"]]],[\"words\",[\"xyz\",\"abc\",\"def\",\"xzy\"]]],output:[\"xyz\",\"abc\",\"def\"],explanation:\"The words 'xyz', 'abc', and 'def' can be formed from adjacent cells on the grid.\"}];var T={title:\"\\u5728\\u7F51\\u683C\\u4E2D\\u67E5\\u627E\\u5355\\u8BCD\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u7528\\u4E8E\\u67E5\\u627E\\u7F51\\u683C\\u4E2D\\u5B58\\u5728\\u7684\\u6240\\u6709\\u5355\\u8BCD\"};function f(d){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},d.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u5B57\\u7B26\\u7F51\\u683C\",(0,n.jsx)(e.code,{children:\"grid\"}),\"\\uFF0C\\u5176\\u5C3A\\u5BF8\\u4E3A\",(0,n.jsx)(e.code,{children:\"m x n\"}),\"\\uFF0C\\u4EE5\\u53CA\\u4E00\\u4E2A\\u5B57\\u7B26\\u4E32\\u5217\\u8868\",(0,n.jsx)(e.code,{children:\"words\"}),\"\\uFF0C\\u627E\\u5230\\u7F51\\u683C\\u4E2D\\u5B58\\u5728\\u7684\\u6240\\u6709\\u5355\\u8BCD\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u53EF\\u4EE5\\u901A\\u8FC7\\u904D\\u5386\\u76F8\\u90BB\\u7684\\u5355\\u5143\\u683C\\u6765\\u5F62\\u6210\\u5355\\u8BCD\\uFF0C\\u5176\\u4E2D\\u76F8\\u90BB\\u7684\\u5355\\u5143\\u683C\\u662F\\u5F7C\\u6B64\\u76F4\\u63A5\\u76F8\\u90BB\\u7684\\uFF0C\\u65E0\\u8BBA\\u662F\\u6C34\\u5E73\\u8FD8\\u662F\\u5782\\u76F4\\u3002\\u7F51\\u683C\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5355\\u5143\\u683C\\u53EA\\u80FD\\u4F7F\\u7528\\u4E00\\u6B21\\u6765\\u5F62\\u6210\\u5355\\u8BCD\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u7ED3\\u679C\\u53EF\\u4EE5\\u6309\\u4EFB\\u4F55\\u987A\\u5E8F\\u8FD4\\u56DE\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"grid: string[][]\"}),\": \\u5927\\u5C0F\\u4E3A\",(0,n.jsx)(e.code,{children:\"m x n\"}),\"\\u7684\\u4E8C\\u7EF4\\u6570\\u7EC4\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u5143\\u7D20\\u90FD\\u662F\\u5C0F\\u5199\\u82F1\\u6587\\u5B57\\u6BCD\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"words: string[]\"}),\": \\u8981\\u5728\\u7F51\\u683C\\u4E2D\\u641C\\u7D22\\u7684\\u5B57\\u7B26\\u4E32\\u5217\\u8868\"]}),`\n`]}),`\n`,(0,n.jsx)(h,{testCases:s}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.code,{children:\"m == grid.length\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.code,{children:\"n = grid[i].length\"})}),`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"m\"}),\", \",(0,n.jsx)(e.code,{children:\"n\"}),\" <= 12\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"words.length\"}),\" <= 1000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"words[i].length\"}),\" <= 10\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4EC5\\u7531\\u5C0F\\u5199\\u82F1\\u6587\\u5B57\\u6BCD\\u7EC4\\u6210\",(0,n.jsx)(e.code,{children:\"grid\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"words[i]\"})]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"words\"}),\"\\u5217\\u8868\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5355\\u8BCD\\u90FD\\u662F\\u552F\\u4E00\\u7684\"]}),`\n`]})]})}function z(d={}){let{wrapper:e}=d.components||{};return e?(0,n.jsx)(e,Object.assign({},d,{children:(0,n.jsx)(f,d)})):f(d)}var M=z;return _(C);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,用于查找网格中存在的所有单词", + "title": "在网格中查找单词" + }, + "solution": "var Component=(()=>{var u=Object.create;var t=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var m=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),k=(n,e)=>{for(var o in e)t(n,o,{get:e[o],enumerable:!0})},d=(n,e,o,l)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of f(e))!b.call(n,i)&&i!==o&&t(n,i,{get:()=>e[i],enumerable:!(l=g(e,i))||l.enumerable});return n};var N=(n,e,o)=>(o=n!=null?u(p(n)):{},d(e||!n||!n.__esModule?t(o,\"default\",{value:n,enumerable:!0}):o,n)),x=n=>d(t({},\"__esModule\",{value:!0}),n);var h=m((_,c)=>{c.exports=_jsx_runtime});var T={};k(T,{default:()=>O});var r=N(h());var s=MDXCodeBlock;var a=`class TrieNode {\n // Map to hold child nodes\n children: Map = new Map();\n // To store the word at the end of the Trie path\n word: string = '';\n\n constructor() {}\n}\n\n// Helper function to perform backtracking on the grid\nfunction backtracking(\n row: number,\n col: number,\n board: string[][],\n parent: TrieNode,\n result: string[],\n) {\n const letter = board[row][col];\n const currNode = parent.children.get(letter)!;\n\n // Check if the current node represents a word\n if (currNode.word !== '') {\n result.push(currNode.word);\n currNode.word = ''; // Prevent duplicate entries\n }\n\n // Mark the current cell as visited\n board[row][col] = '#';\n\n // Explore neighboring cells: up, right, down, left\n const rowOffset = [-1, 0, 1, 0];\n const colOffset = [0, 1, 0, -1];\n for (let i = 0; i < 4; i++) {\n const newRow = row + rowOffset[i];\n const newCol = col + colOffset[i];\n if (\n newRow < 0 ||\n newRow >= board.length ||\n newCol < 0 ||\n newCol >= board[0].length\n ) {\n continue;\n }\n if (currNode.children.has(board[newRow][newCol])) {\n backtracking(newRow, newCol, board, currNode, result);\n }\n }\n\n // Restore the original letter in the board\n board[row][col] = letter;\n\n // Optimization: remove leaf nodes\n if (currNode.children.size === 0) {\n parent.children.delete(letter);\n }\n}\n\n// Main function to find words in the grid\nexport default function findWordsInGrid(\n grid: string[][],\n words: string[],\n): string[] {\n // Step 1: Construct the Trie\n const root = new TrieNode();\n for (const word of words) {\n let node = root;\n for (const letter of word) {\n if (!node.children.has(letter)) {\n node.children.set(letter, new TrieNode());\n }\n node = node.children.get(letter)!;\n }\n node.word = word; // Store words in Trie\n }\n\n const result: string[] = [];\n\n // Step 2: Backtracking starting from each cell in the grid\n for (let row = 0; row < grid.length; row++) {\n for (let col = 0; col < grid[row].length; col++) {\n if (root.children.has(grid[row][col])) {\n backtracking(row, col, grid, root, result);\n }\n }\n }\n\n return result;\n}\n`;function w(n){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},n.components);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u56DE\\u6EAF\\u548C\\u5B57\\u5178\\u6811\"}),`\n`,(0,r.jsxs)(e.p,{children:[\"\\u8BE5\\u4EFB\\u52A1\\u662F\\u4ECE\\u7ED9\\u5B9A\\u7684\\u5217\\u8868 (\",(0,r.jsx)(e.code,{children:\"words\"}),\") \\u4E2D\\u627E\\u5230\\u5B58\\u5728\\u4E8E 2D \\u7F51\\u683C\\u4E2D\\u7684\\u6240\\u6709\\u5355\\u8BCD\\u3002\\u5355\\u8BCD\\u53EF\\u4EE5\\u901A\\u8FC7\\u4E0A\\u4E0B\\u5DE6\\u53F3\\u79FB\\u52A8\\u7684\\u76F8\\u90BB\\u5355\\u5143\\u683C\\u987A\\u5E8F\\u5F62\\u6210\\u3002\\u6BCF\\u4E2A\\u5355\\u5143\\u683C\\u6BCF\\u4E2A\\u5355\\u8BCD\\u53EA\\u80FD\\u4F7F\\u7528\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,r.jsx)(e.p,{children:\"\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u5B57\\u5178\\u6811\\uFF08\\u524D\\u7F00\\u6811\\uFF09\\u7ED3\\u5408\\u56DE\\u6EAF\\u6765\\u5B9E\\u73B0\\u9AD8\\u6548\\u7684\\u5355\\u8BCD\\u67E5\\u627E\\u548C\\u9A8C\\u8BC1\\u3002\\u5B57\\u5178\\u6811\\u5141\\u8BB8\\u5FEB\\u901F\\u524D\\u7F00\\u5339\\u914D\\uFF0C\\u4F7F\\u7B97\\u6CD5\\u80FD\\u591F\\u5C3D\\u65E9\\u653E\\u5F03\\u65E0\\u6548\\u8DEF\\u5F84\\u3002\\u5217\\u8868\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5355\\u8BCD\\u90FD\\u5B58\\u50A8\\u5728\\u5B57\\u5178\\u6811\\u4E2D\\uFF0C\\u6BCF\\u6761\\u8DEF\\u5F84\\u4EE3\\u8868\\u4E00\\u4E2A\\u53EF\\u80FD\\u7684\\u5355\\u8BCD\\u3002\\u5728\\u56DE\\u6EAF\\u671F\\u95F4\\uFF0C\\u7B97\\u6CD5\\u4ECE\\u6BCF\\u4E2A\\u7F51\\u683C\\u5355\\u5143\\u683C\\u5F00\\u59CB\\u63A2\\u7D22\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u8DEF\\u5F84\\uFF0C\\u5E76\\u5BF9\\u7167\\u5B57\\u5178\\u6811\\u8FDB\\u884C\\u68C0\\u67E5\\u4EE5\\u9A8C\\u8BC1\\u6709\\u6548\\u524D\\u7F00\\u3002\\u5F53\\u5B57\\u5178\\u6811\\u4E2D\\u5339\\u914D\\u5230\\u5B8C\\u6574\\u7684\\u5355\\u8BCD\\u65F6\\uFF0C\\u5C31\\u4F1A\\u8BB0\\u5F55\\u5355\\u8BCD\\u3002\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u6700\\u5927\\u9650\\u5EA6\\u5730\\u51CF\\u5C11\\u4E86\\u5197\\u4F59\\u68C0\\u67E5\\uFF0C\\u5E76\\u6709\\u6548\\u5730\\u4FEE\\u526A\\u4E86\\u65E0\\u6548\\u8DEF\\u5F84\\uFF0C\\u4E0E\\u86EE\\u529B\\u65B9\\u6CD5\\u76F8\\u6BD4\\uFF0C\\u663E\\u8457\\u63D0\\u9AD8\\u4E86\\u6027\\u80FD\\u3002\"}),`\n`,(0,r.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,r.jsxs)(e.ol,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u6784\\u5EFA\\u4E00\\u4E2A\\u5B57\\u5178\\u6811\\u6765\\u5B58\\u50A8\\u7ED9\\u5B9A\\u7684 \",(0,r.jsx)(e.code,{children:\"words\"}),\":\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"\\u4F7F\\u7528\\u6839\\u8282\\u70B9\\u521D\\u59CB\\u5316\\u5B57\\u5178\\u6811\\u3002\"}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E \",(0,r.jsx)(e.code,{children:\"words\"}),\" \\u4E2D\\u7684\\u6BCF\\u4E2A\\u5355\\u8BCD\\uFF0C\\u904D\\u5386\\u5B57\\u5178\\u6811\\uFF0C\\u5982\\u679C\\u4E0D\\u5B58\\u5728\\uFF0C\\u5219\\u4E3A\\u6BCF\\u4E2A\\u5B57\\u7B26\\u6DFB\\u52A0\\u4E00\\u4E2A\\u65B0\\u8282\\u70B9\\u3002\"]}),`\n`,(0,r.jsx)(e.li,{children:\"\\u901A\\u8FC7\\u5C06\\u5355\\u8BCD\\u5B58\\u50A8\\u5728\\u76F8\\u5E94\\u7684\\u8282\\u70B9\\u4E2D\\u6765\\u6807\\u8BB0\\u5B57\\u5178\\u6811\\u4E2D\\u6BCF\\u4E2A\\u5355\\u8BCD\\u7684\\u7ED3\\u5C3E\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A \",(0,r.jsx)(e.code,{children:\"backtracking\"}),\" \\u51FD\\u6570\\u6765\\u63A2\\u7D22\\u7F51\\u683C\\u4E2D\\u7684\\u8DEF\\u5F84:\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"\\u68C0\\u67E5\\u5B57\\u5178\\u6811\\u4E2D\\u7684\\u5F53\\u524D\\u8282\\u70B9\\u662F\\u5426\\u4EE3\\u8868\\u4E00\\u4E2A\\u5B8C\\u6574\\u7684\\u5355\\u8BCD\\u3002\\u5982\\u679C\\u662F\\uFF0C\\u5C06\\u8BE5\\u5355\\u8BCD\\u6DFB\\u52A0\\u5230\\u7ED3\\u679C\\u5217\\u8868\\u4E2D\\uFF0C\\u5E76\\u5C06\\u5176\\u6807\\u8BB0\\u4E3A\\u5DF2\\u4F7F\\u7528\\u4EE5\\u907F\\u514D\\u91CD\\u590D\\u3002\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u6682\\u65F6\\u5C06\\u5F53\\u524D\\u7F51\\u683C\\u5355\\u5143\\u683C\\u6807\\u8BB0\\u4E3A\\u5DF2\\u8BBF\\u95EE\\uFF0C\\u65B9\\u6CD5\\u662F\\u66F4\\u6539\\u5176\\u503C\\u3002\"}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u63A2\\u7D22\\u6240\\u6709\\u76F8\\u90BB\\u5355\\u5143\\u683C\\uFF08\\u4E0A\\u3001\\u4E0B\\u3001\\u5DE6\\u3001\\u53F3\\uFF09\\uFF0C\\u5982\\u679C\\u5B57\\u5178\\u6811\\u4E2D\\u5B58\\u5728\\u76F8\\u5E94\\u7684\\u5B57\\u7B26\\uFF0C\\u5219\\u9012\\u5F52\\u8C03\\u7528 \",(0,r.jsx)(e.code,{children:\"backtracking\"}),\" \\u51FD\\u6570\\u3002\"]}),`\n`,(0,r.jsx)(e.li,{children:\"\\u5728\\u63A2\\u7D22\\u5B8C\\u6240\\u6709\\u90BB\\u5C45\\u540E\\uFF0C\\u6062\\u590D\\u7F51\\u683C\\u5355\\u5143\\u683C\\u7684\\u503C\\u3002\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u5982\\u679C\\u6CA1\\u6709\\u8FDB\\u4E00\\u6B65\\u7684\\u8DEF\\u5F84\\uFF0C\\u5219\\u4ECE\\u5B57\\u5178\\u6811\\u4E2D\\u5220\\u9664\\u53F6\\u8282\\u70B9\\u4EE5\\u8FDB\\u884C\\u4F18\\u5316\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u7F51\\u683C\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5355\\u5143\\u683C:\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"\\u5982\\u679C\\u5355\\u5143\\u683C\\u7684\\u5B57\\u7B26\\u4F5C\\u4E3A\\u5B57\\u5178\\u6811\\u4E2D\\u6839\\u8282\\u70B9\\u7684\\u5B50\\u8282\\u70B9\\u5B58\\u5728\\uFF0C\\u5219\\u4ECE\\u8BE5\\u5355\\u5143\\u683C\\u542F\\u52A8\\u56DE\\u6EAF\\u641C\\u7D22\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,r.jsx)(e.li,{children:\"\\u8FD4\\u56DE\\u5339\\u914D\\u7684\\u5355\\u8BCD\\u5217\\u8868\\u3002\"}),`\n`]}),`\n`,(0,r.jsx)(s,{children:a}),`\n`,(0,r.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsxs)(e.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m.n.4.3\",(0,r.jsx)(\"sup\",{children:\"l-1\"}),\")\"]}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u904D\\u5386\\u6240\\u6709 \",(0,r.jsx)(e.code,{children:\"m.n\"}),\" \\u4E2A\\u5355\\u5143\\u683C\\uFF0C\\u5728\\u6700\\u574F\\u7684\\u60C5\\u51B5\\u4E0B\\uFF0C\\u6BCF\\u4E2A\\u5355\\u5143\\u683C\\u6700\\u591A\\u63A2\\u7D22 4.3\",(0,r.jsx)(\"sup\",{children:\"l-1\"}),\" \\u6761\\u8DEF\\u5F84\\u3002\\u5F53\\u6240\\u6709\\u8DEF\\u5F84\\u90FD\\u6709\\u6548\\u65F6\\uFF0C\\u5C31\\u4F1A\\u53D1\\u751F\\u8FD9\\u79CD\\u60C5\\u51B5\\uFF0C\\u4F8B\\u5982\\u4E00\\u4E2A\\u7531\\u76F8\\u540C\\u5B57\\u6BCD\\u586B\\u5145\\u7684\\u68CB\\u76D8\\u548C\\u4E00\\u4E2A\\u5305\\u542B\\u5355\\u4E2A\\u957F\\u5355\\u8BCD\\u7684\\u5B57\\u5178\\u3002\\u50CF\\u4ECE\\u5B57\\u5178\\u6811\\u4E2D\\u5220\\u9664\\u5339\\u914D\\u8282\\u70B9\\u8FD9\\u6837\\u7684\\u4F18\\u5316\\u53EF\\u4EE5\\u5728\\u627E\\u5230\\u6240\\u6709\\u5355\\u8BCD\\u540E\\u51CF\\u5C11\\u56DE\\u6EAF\\u6210\\u672C\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(l)\"}),\"\\uFF0C\\u5176\\u4E2D \",(0,r.jsx)(e.code,{children:\"l\"}),\" \\u662F\\u5B57\\u5178\\u4E2D\\u5B57\\u6BCD\\u7684\\u603B\\u6570\\u3002\\u5B57\\u5178\\u6811\\u4F7F\\u7528 \",(0,r.jsx)(e.code,{children:\"l\"}),\" \\u7A7A\\u95F4\\uFF0C\\u5982\\u679C\\u5355\\u8BCD\\u4E5F\\u88AB\\u5B58\\u50A8\\uFF0C\\u5219\\u4F7F\\u7528 \",(0,r.jsx)(e.code,{children:\"2.l\"}),\" \\u7A7A\\u95F4\\u3002\\u5728\\u6700\\u574F\\u7684\\u60C5\\u51B5\\u4E0B\\uFF0C\\u7531\\u4E8E\\u6CA1\\u6709\\u5171\\u4EAB\\u524D\\u7F00\\uFF0C\\u6BCF\\u4E2A\\u5B57\\u6BCD\\u90FD\\u6709\\u81EA\\u5DF1\\u7684\\u8282\\u70B9\\u3002\"]}),`\n`]})]})}function M(n={}){let{wrapper:e}=n.components||{};return e?(0,r.jsx)(e,Object.assign({},n,{children:(0,r.jsx)(w,n)})):w(n)}var O=M;return x(T);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/heap-sort/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/heap-sort/locales/zh-CN.json new file mode 100644 index 000000000..578a29736 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/heap-sort/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var l=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var g=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports),j=(r,n)=>{for(var t in n)l(r,t,{get:n[t],enumerable:!0})},c=(r,n,t,a)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let i of m(n))!u.call(r,i)&&i!==t&&l(r,i,{get:()=>n[i],enumerable:!(a=d(n,i))||a.enumerable});return r};var f=(r,n,t)=>(t=r!=null?p(x(r)):{},c(n||!r||!r.__esModule?l(t,\"default\",{value:r,enumerable:!0}):t,r)),_=r=>c(l({},\"__esModule\",{value:!0}),r);var h=g((b,s)=>{s.exports=_jsx_runtime});var M={};j(M,{default:()=>y,frontmatter:()=>w});var e=f(h()),w={title:\"\\u5806\\u6392\\u5E8F\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u6267\\u884C\\u5806\\u6392\\u5E8F\\u7684\\u51FD\\u6570\"};function o(r){let n=Object.assign({p:\"p\",h2:\"h2\",pre:\"pre\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\",img:\"img\"},r.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.p,{children:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u6267\\u884C\\u5806\\u6392\\u5E8F\\u7684\\u51FD\\u6570\\u3002\\u8BE5\\u51FD\\u6570\\u5E94\\u63A5\\u6536\\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4\\uFF0C\\u5E76\\u8FD4\\u56DE\\u4E00\\u4E2A\\u6309\\u5347\\u5E8F\\u6392\\u5E8F\\u7684\\u6574\\u6570\\u6570\\u7EC4\\u3002\\u8F93\\u5165\\u6570\\u7EC4\\u5C06\\u5C31\\u5730\\u4FEE\\u6539\\u3002\"}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u4F8B\\u5B50\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-js\",children:`heapSort([9, 3, 6, 2, 1, 11]); // [1, 2, 3, 6, 9, 11]\nheapSort([12, 16, 14, 1, 2, 3]); // [1, 2, 3, 12, 14, 16]\n`})}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u56DE\\u987E\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5806\\u6392\\u5E8F\\u662F\\u4E00\\u79CD\\u57FA\\u4E8E\\u6BD4\\u8F83\\u7684\\u6392\\u5E8F\\u7B97\\u6CD5\\uFF0C\\u5B83\\u8FED\\u4EE3\\u5730\\u5C06\\u672A\\u6392\\u5E8F\\u7684\\u6570\\u7EC4\\u6784\\u5EFA\\u6210\\u4E00\\u4E2A\\u6700\\u5927\\u5806\\u6570\\u636E\\u7ED3\\u6784\\uFF0C\\u4EE5\\u8BC6\\u522B\\u6700\\u5927\\u5143\\u7D20\\uFF0C\\u5E76\\u9010\\u6B65\\u5C06\\u5176\\u4EA4\\u6362\\u5230\\u672A\\u6392\\u5E8F\\u6570\\u7EC4\\u7684\\u672B\\u5C3E\\uFF0C\\u4ECE\\u800C\\u6784\\u5EFA\\u4E00\\u4E2A\\u5DF2\\u6392\\u5E8F\\u7684\\u6570\\u7EC4\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u6700\\u5927\\u5806\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u8981\\u7406\\u89E3\\u5806\\u6392\\u5E8F\\uFF0C\\u6211\\u4EEC\\u9700\\u8981\\u9996\\u5148\\u7406\\u89E3\\u5806\\u6570\\u636E\\u7ED3\\u6784\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u4E8C\\u53C9\\u5806\\u662F\\u4E00\\u4E2A\\u90E8\\u5206\\u6392\\u5E8F\\u7684\\u5B8C\\u6574\\u4E8C\\u53C9\\u6811\\uFF0C\\u5B83\\u6EE1\\u8DB3\\u5806\\u5C5E\\u6027\\uFF0C\\u7C7B\\u4F3C\\u4E8E\\u4E8C\\u53C9\\u641C\\u7D22\\u6811\\uFF0C\\u4F46\\u5177\\u6709\\u4E0D\\u540C\\u7684\\u6392\\u5E8F\\u65B9\\u5F0F\\u3002\"}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5806\\u5C5E\\u6027 = \\u7236\\u8282\\u70B9\\u548C\\u5B50\\u8282\\u70B9\\u4E4B\\u95F4\\u7684\\u7279\\u5B9A\\u5173\\u7CFB\\uFF0C\\u5B83\\u6307\\u5B9A\\u4E86\\u5B83\\u4EEC\\u7684\\u987A\\u5E8F\\u3002\\u4E00\\u4E2A\\u4F8B\\u5B50\\u662F\\u6700\\u5927\\u5806\\u5C5E\\u6027\\uFF0C\\u5B83\\u6307\\u5B9A\\u6240\\u6709\\u7236\\u8282\\u70B9\\u5FC5\\u987B >= \\u5176\\u5B50\\u8282\\u70B9\\u3002\\u540C\\u4E00\\u7EA7\\u522B\\u7684\\u5B50\\u8282\\u70B9\\u4E4B\\u95F4\\u7684\\u987A\\u5E8F\\u65E0\\u5173\\u7D27\\u8981\\u3002\\u56E0\\u6B64\\uFF0C\\u6700\\u5927\\u7684\\u8282\\u70B9\\u603B\\u662F\\u5728\\u9876\\u90E8\\uFF0C\\u6700\\u5C0F\\u7684\\u8282\\u70B9\\u5728\\u5E95\\u90E8\\u3002\\u540C\\u4E00\\u7EA7\\u522B\\u7684\\u8282\\u70B9\\u662F\\u65E0\\u5E8F\\u7684\\uFF1A\",(0,e.jsx)(n.img,{src:\"/img/questions/heap-sort/max-heap-property.png\",alt:\"\\u6700\\u5927\\u5806\\u56FE\\u793A\"})]}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5B8C\\u6574\\u4E8C\\u53C9\\u6811 = \\u6811\\u7684\\u6240\\u6709\\u7EA7\\u522B\\u90FD\\u5DF2\\u5B8C\\u5168\\u586B\\u5145\\u3002\\u5982\\u679C\\u6700\\u540E\\u4E00\\u5C42\\u90E8\\u5206\\u586B\\u5145\\uFF0C\\u5219\\u9996\\u5148\\u4ECE\\u5DE6\\u5230\\u53F3\\u586B\\u5145\\u3002\"}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5806\\u7ECF\\u5E38\\u5B9E\\u73B0\\u4E3A\\u6570\\u7EC4\\u3002\\u6211\\u4EEC\\u53EF\\u4EE5\\u4F7F\\u7528\\u4EE5\\u4E0B\\u516C\\u5F0F\\u6765\\u8BA1\\u7B97\\u5806\\u7684\\u6570\\u7EC4\\u8868\\u793A\\u5F62\\u5F0F\\u4E2D\\u7236\\u8282\\u70B9\\u3001\\u5DE6\\u5B50\\u8282\\u70B9\\u548C\\u53F3\\u5B50\\u8282\\u70B9\\u7684\\u7D22\\u5F15\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5DE6\\u5B50\\u8282\\u70B9\\u7D22\\u5F15 = 2 * parentIdx + 1\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u53F3\\u5B50\\u8282\\u70B9\\u7D22\\u5F15 = 2 * parentIdx + 2\"}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,e.jsx)(\"img\",{alt:\"\\u6700\\u5927\\u5806\\u6570\\u7EC4\\u8868\\u793A\",className:\"mx-auto w-full max-w-5xl\",src:\"/img/questions/heap-sort/max-heap-array-representation.png\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5806\\u6392\\u5E8F\\u7684\\u5DE5\\u4F5C\\u539F\\u7406\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5806\\u6392\\u5E8F\\u672C\\u8D28\\u4E0A\\u901A\\u8FC7\\u4EE5\\u4E0B\\u6B65\\u9AA4\\u5DE5\\u4F5C\\uFF1A\"}),`\n`,(0,e.jsx)(\"img\",{alt:\"\\u5806\\u6392\\u5E8F\\u6B65\\u9AA4\",className:\"mx-auto w-full max-w-5xl\",src:\"/img/questions/heap-sort/heap-sort-steps.png\"})]})}function q(r={}){let{wrapper:n}=r.components||{};return n?(0,e.jsx)(n,Object.assign({},r,{children:(0,e.jsx)(o,r)})):o(r)}var y=q;return _(M);})();\n;return Component;", + "info": { + "excerpt": "实现一个执行堆排序的函数", + "title": "堆排序" + }, + "solution": "var Component=(()=>{var g=Object.create;var a=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var I=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var C=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),w=(t,e)=>{for(var i in e)a(t,i,{get:e[i],enumerable:!0})},d=(t,e,i,h)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let n of m(e))!y.call(t,n)&&n!==i&&a(t,n,{get:()=>e[n],enumerable:!(h=u(e,n))||h.enumerable});return t};var z=(t,e,i)=>(i=t!=null?g(I(t)):{},d(e||!t||!t.__esModule?a(i,\"default\",{value:t,enumerable:!0}):i,t)),b=t=>d(a({},\"__esModule\",{value:!0}),t);var o=C((A,s)=>{s.exports=_jsx_runtime});var B={};w(B,{default:()=>v});var r=z(o());var l=MDXCodeBlock;var p=`/**\n * @param {Array} arr The input integer array to be sorted.\n * @return {Array}\n */\nexport default function heapSort(arr) {\n // Begin by building a max heap.\n const size = arr.length;\n for (let i = Math.floor(size / 2 - 1); i >= 0; i--) {\n // Start with the index of the last parent node.\n // heapify: Swaps parent with child as long as child is larger than parent.\n heapify(arr, size, i);\n }\n\n // Iterate through the heap backwards, swapping the last element of the heap with the max element (the root of a max heap).\n // Max elements swapped to the end constitute the sorted part of the array (ignored in the next iteration by \"i--\").\n for (let i = size - 1; i >= 0; i--) {\n [arr[0], arr[i]] = [arr[i], arr[0]];\n\n // Build a max heap again in preparation for the swap in the next iteration.\n heapify(arr, i, 0);\n }\n\n return arr;\n}\n\nfunction heapify(arr, size, parentIdx) {\n let largest = parentIdx; // Initiate largest value's index with parent index.\n const leftChildIdx = 2 * parentIdx + 1; // Calculate index of left child.\n const rightChildIdx = 2 * parentIdx + 2; // Calculate index of right child.\n // Set \\`largest\\` to index with highest value between parent, left and right child.\n // See if left child of parent exists and is larger than parent.\n if (leftChildIdx < size && arr[leftChildIdx] > arr[largest]) {\n largest = leftChildIdx;\n }\n // See if right child of parent exists and is larger than parent.\n if (rightChildIdx < size && arr[rightChildIdx] > arr[largest]) {\n largest = rightChildIdx;\n }\n // If \\`largest\\` is not the current parent, swap positions with the current parent.\n if (largest !== parentIdx) {\n [arr[parentIdx], arr[largest]] = [arr[largest], arr[parentIdx]];\n // Continue to recursively heapify the affected subtree.\n heapify(arr, size, largest);\n }\n}\n`;var c=`export default function heapSort(arr: Array): Array {\n // Begin by building a max heap.\n const size = arr.length;\n for (let i = Math.floor(size / 2 - 1); i >= 0; i--) {\n // Start with the index of the last parent node.\n // heapify: Swaps parent with child as long as child is larger than parent.\n heapify(arr, size, i);\n }\n\n // Iterate through the heap backwards, swapping the last element of the heap with the max element (the root of a max heap).\n // Max elements swapped to the end constitute the sorted part of the array (ignored in the next iteration by \"i--\").\n for (let i = size - 1; i >= 0; i--) {\n [arr[0], arr[i]] = [arr[i], arr[0]];\n\n // Build a max heap again in preparation for the swap in the next iteration.\n heapify(arr, i, 0);\n }\n\n return arr;\n}\n\nfunction heapify(arr: Array, size: number, parentIdx: number) {\n let largest = parentIdx; // Initiate largest value's index with parent index.\n const leftChildIdx = 2 * parentIdx + 1; // Calculate index of left child.\n const rightChildIdx = 2 * parentIdx + 2; // Calculate index of right child.\n // Set \\`largest\\` to index with highest value between parent, left and right child.\n // See if left child of parent exists and is larger than parent.\n if (leftChildIdx < size && arr[leftChildIdx] > arr[largest]) {\n largest = leftChildIdx;\n }\n // See if right child of parent exists and is larger than parent.\n if (rightChildIdx < size && arr[rightChildIdx] > arr[largest]) {\n largest = rightChildIdx;\n }\n // If \\`largest\\` is not the current parent, swap positions with the current parent.\n if (largest !== parentIdx) {\n [arr[parentIdx], arr[largest]] = [arr[largest], arr[parentIdx]];\n // Continue to recursively heapify the affected subtree.\n heapify(arr, size, largest);\n }\n}\n`;var f=`function heapifyMin(arr, size, parentIdx) {\n let smallest = parentIdx; // initiate smallest value's index with parent index\n const leftChildIdx = 2 * parentIdx + 1; // calculate index of left child\n const rightChildIdx = 2 * parentIdx + 2; // calculate index of right child\n // set 'smallest' to index with lowest value between parent, left and right child\n if (leftChildIdx < size && arr[leftChildIdx] < arr[smallest]) {\n smallest = leftChildIdx;\n }\n if (rightChildIdx < size && arr[rightChildIdx] < arr[smallest]) {\n smallest = rightChildIdx;\n }\n // if 'smallest' is not the current parent, swap positions with the current parent\n if (smallest !== parentIdx) {\n [arr[parentIdx], arr[smallest]] = [arr[smallest], arr[parentIdx]];\n // continue to recursively heapify the affected subtree\n heapifyMin(arr, size, smallest);\n }\n}\n`;function x(t){let e=Object.assign({p:\"p\",h2:\"h2\",ul:\"ul\",li:\"li\",code:\"code\",pre:\"pre\",h3:\"h3\",ol:\"ol\"},t.components);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e.p,{children:\"\\u5806\\u6392\\u5E8F\\u662F\\u4E00\\u79CD\\u539F\\u5730\\u3001\\u57FA\\u4E8E\\u6BD4\\u8F83\\u7684\\u7B97\\u6CD5\\uFF0C\\u5BF9\\u4E8E\\u5927\\u578B\\u6570\\u7EC4\\u6548\\u679C\\u5F88\\u597D\\uFF0C\\u56E0\\u4E3A\\u5B83\\u5177\\u6709 O(nlog(n)) \\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u3002\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u5B83\\u4E5F\\u4E0D\\u9700\\u8981\\u4EFB\\u4F55\\u989D\\u5916\\u7684\\u5185\\u5B58\\u7A7A\\u95F4\\u6765\\u5BF9\\u6570\\u636E\\u8FDB\\u884C\\u6392\\u5E8F\\uFF0C\\u56E0\\u4E3A\\u5B83\\u662F\\u4E00\\u79CD\\u539F\\u5730\\u6392\\u5E8F\\u7B97\\u6CD5\\u3002\\u4F46\\u662F\\uFF0C\\u5B83\\u4E0D\\u662F\\u4E00\\u79CD\\u7A33\\u5B9A\\u7684\\u6392\\u5E8F\\uFF0C\\u8FD9\\u610F\\u5473\\u7740\\u5177\\u6709\\u76F8\\u540C\\u503C\\u7684\\u5143\\u7D20\\u7684\\u987A\\u5E8F\\u53EF\\u80FD\\u4E0D\\u4F1A\\u88AB\\u4FDD\\u7559\\u3002\"}),`\n`,(0,r.jsx)(e.h2,{children:\"\\u6F84\\u6E05\\u95EE\\u9898\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u5982\\u679C\\u672A\\u6307\\u5B9A\\uFF1A\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"\\u6570\\u636E\\u5E94\\u8BE5\\u6309\\u5347\\u5E8F\\u8FD8\\u662F\\u964D\\u5E8F\\u6392\\u5E8F\\uFF1F\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u5E94\\u8BE5\\u5BF9\\u6570\\u636E\\u8FDB\\u884C\\u539F\\u5730\\u6392\\u5E8F\\uFF0C\\u8FD8\\u662F\\u53EF\\u4EE5\\u4F7F\\u7528\\u989D\\u5916\\u7684\\u6570\\u636E\\u7ED3\\u6784\\uFF1F\"}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u6211\\u4EEC\\u9700\\u8981\\u5904\\u7406\\u4EC0\\u4E48\\u6837\\u7684\\u8F93\\u5165\\uFF1F\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"\\u5B83\\u53EA\\u662F\\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4\\uFF0C\\u8FD8\\u662F\\u6211\\u4EEC\\u5E94\\u8BE5\\u5904\\u7406\\u5176\\u4ED6\\u6570\\u636E\\u7C7B\\u578B\\uFF1F\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u662F\\u5426\\u5B58\\u5728\\u5927\\u91CF\\u91CD\\u590D\\u5143\\u7D20\\uFF1F\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u5E94\\u8BE5\\u5982\\u4F55\\u5904\\u7406\\u8D1F\\u6570\\uFF1F\"}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,r.jsx)(e.h2,{children:\"\\u89E3\\u51B3\\u65B9\\u6848\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u6CE8\\u610F\\uFF1A\\u6B64\\u95EE\\u9898\\u5904\\u7406\\u7684\\u662F\\u539F\\u5730\\u6392\\u5E8F\\uFF0C\\u7528\\u4E8E\\u5347\\u5E8F\\u8F93\\u51FA\\u3002\\u8BF7\\u53C2\\u9605\\u4E0B\\u9762\\u7684\\u201C\\u6CE8\\u91CA\\u201D\\u90E8\\u5206\\uFF0C\\u4E86\\u89E3\\u5982\\u4F55\\u5904\\u7406\\u5176\\u4ED6\\u60C5\\u51B5\\u3002\"}),`\n`,(0,r.jsx)(l,{languages:{jsx:p,tsx:c}}),`\n`,(0,r.jsx)(e.h2,{children:\"\\u8FB9\\u7F18\\u60C5\\u51B5\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"\\u975E\\u6574\\u6570\\u5143\\u7D20\\u8F93\\u5165\\uFF1A\\u5982\\u679C\\u8F93\\u5165\\u6570\\u7EC4\\u5305\\u542B\\u4E0D\\u540C\\u6570\\u636E\\u7C7B\\u578B\\u7684\\u5143\\u7D20\\uFF0C\\u60A8\\u53EF\\u80FD\\u9700\\u8981\\u8FD4\\u56DE\\u4E00\\u4E2A\\u9519\\u8BEF\\uFF0C\\u5C3D\\u529B\\u8FDB\\u884C\\u6392\\u5E8F\\uFF0C\\u4F8B\\u5982\\uFF0C\\u4EC5\\u5BF9\\u8F93\\u5165\\u6570\\u636E\\u7684\\u5B50\\u96C6\\u8FDB\\u884C\\u6392\\u5E8F\\uFF0C\\u751A\\u81F3\\u4E3A\\u975E\\u6574\\u6570\\u5B9A\\u4E49\\u81EA\\u5B9A\\u4E49\\u6BD4\\u8F83\\u51FD\\u6570\\u3002\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u5355\\u4E2A\\u5143\\u7D20/\\u7A7A\\u8F93\\u5165\\uFF1A\\u8FD4\\u56DE\\u539F\\u59CB\\u6570\\u636E\\u7ED3\\u6784\\u3001\\u5F15\\u53D1\\u9519\\u8BEF\\u6216\\u9610\\u660E\\u6240\\u9700\\u5904\\u7406\\u65B9\\u5F0F\\u3002\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u5DF2\\u6392\\u5E8F\\u7684\\u8F93\\u5165\\uFF1A\\u60A8\\u53EF\\u80FD\\u9700\\u8981\\u68C0\\u6D4B\\u6392\\u5E8F\\u5E76\\u539F\\u6837\\u8FD4\\u56DE\\u8F93\\u5165\\u3002\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u65E0\\u6548\\u8F93\\u5165\\uFF1A\\u5982\\u679C\\u8F93\\u5165\\u4E0D\\u662F\\u6570\\u7EC4\\uFF0C\\u8BF7\\u8003\\u8651\\u629B\\u51FA\\u9519\\u8BEF\\u3002\"}),`\n`]}),`\n`,(0,r.jsx)(e.h2,{children:\"\\u6CE8\\u91CA\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u8981\\u6C42\\u6309\\u964D\\u5E8F\\u6392\\u5E8F\\uFF1A\\u66F4\\u6539 \",(0,r.jsx)(e.code,{children:\"heapify()\"}),\" \\u51FD\\u6570\\u4E2D\\u7684\\u6BD4\\u8F83\\u8FD0\\u7B97\\u7B26\\uFF0C\\u4EE5\\u4FBF\\u6784\\u5EFA\\u6700\\u5C0F\\u5806\\u800C\\u4E0D\\u662F\\u6700\\u5927\\u5806\\uFF0C\\u7136\\u540E\\u5728 \",(0,r.jsx)(e.code,{children:\"heapSort\"}),\" \\u4E2D\\u7167\\u5E38\\u4F7F\\u7528\\u5B83\\uFF1A\"]}),`\n`]}),`\n`,(0,r.jsx)(l,{children:f}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"\\u5982\\u679C\\u8981\\u6C42\\u4F7F\\u7528\\u989D\\u5916\\u7684\\u6570\\u636E\\u7ED3\\u6784\\u6216\\u7F16\\u5199\\u7EAF\\u51FD\\u6570\\u800C\\u4E0D\\u662F\\u5BF9\\u6570\\u636E\\u8FDB\\u884C\\u539F\\u5730\\u6392\\u5E8F\\uFF0C\\u8BF7\\u521B\\u5EFA\\u6570\\u7EC4\\u7684\\u526F\\u672C\\u5E76\\u8FD4\\u56DE\\u5DF2\\u6392\\u5E8F\\u6570\\u7EC4\\u7684\\u6D45\\u5C42\\u526F\\u672C\\uFF1A\"}),`\n`]}),`\n`,(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:\"language-js\",children:`function heapSort(arr) {\n const result = arr.slice(0);\n const size = arr.length;\n for (let i = Math.floor(size / 2 - 1); i >= 0; i--) {\n heapify(result, size, i);\n }\n for (let i = size - 1; i >= 0; i--) {\n [result[0], result[i]] = [result[i], result[0]];\n heapify(result, i, 0);\n }\n return result;\n}\n`})}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u60A8\\u60F3\\u77E5\\u9053\\u4E3A\\u4EC0\\u4E48 \",(0,r.jsx)(e.code,{children:\"Math.floor(size / 2 - 1)\"}),\" \\u80FD\\u591F\\u8BA1\\u7B97\\u6700\\u540E\\u4E00\\u4E2A\\u7236\\u8282\\u70B9\\u7684\\u7D22\\u5F15\\uFF0C\\u90A3\\u662F\\u56E0\\u4E3A\\u5728\\u5B8C\\u5168\\u4E8C\\u53C9\\u6811\\u4E2D\\uFF0C\\u7236\\u8282\\u70B9\\u7684\\u6570\\u91CF\\u7B49\\u4E8E Math.floor(size / 2)\\u3002\\u672B\\u5C3E\\u7684 -1 \\u662F\\u5FC5\\u9700\\u7684\\uFF0C\\u56E0\\u4E3A\\u6570\\u7EC4\\u4E2D\\u7684\\u7D22\\u5F15\\u4ECE 0 \\u5F00\\u59CB\\uFF0C\\u800C\\u4E0D\\u662F 1\\u3002\"]}),`\n`]}),`\n`,(0,r.jsx)(e.h2,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u8BA9\\u6211\\u4EEC\\u5206\\u6790\\u4E00\\u4E0B\\u7B97\\u6CD5\\u7684\\u65F6\\u95F4\\u548C\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u3002\"}),`\n`,(0,r.jsx)(e.h3,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u5806\\u6392\\u5E8F\\u7684\\u6700\\u4F73\\u3001\\u5E73\\u5747\\u548C\\u6700\\u574F\\u60C5\\u51B5\\u4E0B\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(nlog n)\\u3002 \\u65E0\\u8BBA\\u5143\\u7D20\\u662F\\u5426\\u5DF2\\u6392\\u5E8F\\uFF0C\\u8BE5\\u7B97\\u6CD5\\u90FD\\u5C06\\u59CB\\u7EC8\\u9700\\u8981 O(nlog(n)) \\u65F6\\u95F4\\u624D\\u80FD\\u5B8C\\u6210\\u3002 \\u9664\\u975E\\u60A8\\u68C0\\u6D4B\\u5230\\u5DF2\\u6392\\u5E8F\\u7684\\u6570\\u7EC4\\u5E76\\u7ACB\\u5373\\u8FD4\\u56DE\\u5B83\\u4EEC\\u4EE5\\u83B7\\u5F97\\u6700\\u4F73\\u60C5\\u51B5\\u4E0B\\u7684 O(n) \\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF08\\u5BF9\\u4E8E\\u5B8C\\u5168\\u6392\\u5E8F\\u7684\\u6570\\u7EC4\\uFF09\\uFF0C\\u5426\\u5219\\u8FD9\\u662F\\u51C6\\u786E\\u7684\\u3002\"}),`\n`,(0,r.jsxs)(e.p,{children:[\"\\u8981\\u7406\\u89E3\\u5806\\u6392\\u5E8F\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF0C\\u7406\\u89E3 \",(0,r.jsx)(e.code,{children:\"heapify()\"}),\" \\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u81F3\\u5173\\u91CD\\u8981\\u3002 \\u5728 \",(0,r.jsx)(e.code,{children:\"heapify()\"}),\" \\u4E2D\\uFF0C\\u6211\\u4EEC\\u4ECE\\u4E0A\\u5230\\u4E0B\\u904D\\u5386\\u6811\\uFF0C\\u8FD9\\u610F\\u5473\\u7740\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E0E\\u4E8C\\u53C9\\u6811\\u7684\\u9AD8\\u5EA6\\u6210\\u6B63\\u6BD4\\uFF0C\\u5BF9\\u4E8E\\u5927\\u5C0F\\u4E3A n \\u7684\\u6811\\uFF0C\\u9AD8\\u5EA6\\u6700\\u591A\\u4E3A O(log(n))\\u3002 \\u56E0\\u6B64\\uFF0C\",(0,r.jsx)(e.code,{children:\"heapify()\"}),\" \\u51FD\\u6570\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(log(n))\\u3002\"]}),`\n`,(0,r.jsx)(e.p,{children:\"\\u5806\\u6392\\u5E8F\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(nlog(n))\\uFF0C\\u56E0\\u4E3A\\u8BE5\\u7B97\\u6CD5\\u6709 2 \\u4E2A\\u6B65\\u9AA4\\uFF1A\\u6784\\u5EFA\\u5806\\uFF0C\\u7136\\u540E\\u5BF9\\u6570\\u636E\\u8FDB\\u884C\\u6392\\u5E8F\\u3002\"}),`\n`,(0,r.jsxs)(e.ol,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u6784\\u5EFA\\u5806\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(n)\\uFF0C\\u56E0\\u4E3A \",(0,r.jsx)(e.code,{children:\"heapify()\"}),\" \\u65B9\\u6CD5\\u662F\\u4ECE\\u6700\\u540E\\u4E00\\u4E2A\\u8282\\u70B9\\u5F00\\u59CB\\uFF0C\\u4EE5\\u6811\\u6839\\u7ED3\\u675F\\uFF0C\\u5411\\u540E\\u4E3A\\u6BCF\\u4E2A\\u7236\\u8282\\u70B9\\u8C03\\u7528\\u3002 \\u5E73\\u5747\\u800C\\u8A00\\uFF0C\\u8FD9\\u53EF\\u4EE5\\u5728 O(n) \\u65F6\\u6700\\u4F73\\u5730\\u5B8C\\u6210\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5BF9\\u6570\\u636E\\u8FDB\\u884C\\u6392\\u5E8F\\u65F6\\uFF0C\\u6211\\u4EEC\\u8C03\\u7528 \",(0,r.jsx)(e.code,{children:\"heapify()\"}),\" \\u65B9\\u6CD5 n-1 \\u6B21\\u4EE5\\u7EF4\\u62A4\\u6570\\u7EC4\\u672A\\u6392\\u5E8F\\u90E8\\u5206\\u7684\\u5806\\u5C5E\\u6027\\u3002 \\u56E0\\u6B64\\uFF0C\\u603B\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(nlog(n))\\u3002\"]}),`\n`]}),`\n`,(0,r.jsx)(e.p,{children:\"\\u5806\\u6392\\u5E8F\\u7684\\u603B\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u662F\\u6BCF\\u4E2A\\u6B65\\u9AA4\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u7684\\u603B\\u548C\\uFF0C\\u5373 O(n) + O(nlog(n)) = O(nlog(n))\\u3002\"}),`\n`,(0,r.jsx)(e.h3,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u5806\\u6392\\u5E8F\\u7684\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(1)\\uFF0C\\u56E0\\u4E3A\\u5B83\\u8FDB\\u884C\\u539F\\u5730\\u6392\\u5E8F\\uFF0C\\u4E0D\\u9700\\u8981\\u4E0E\\u8F93\\u5165\\u5927\\u5C0F\\u6210\\u6BD4\\u4F8B\\u7684\\u989D\\u5916\\u5B58\\u50A8\\u7A7A\\u95F4\\u3002\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u4F46\\u662F\\uFF0C\\u5982\\u679C\\u4F7F\\u7528\\u9012\\u5F52\\u51FD\\u6570\\u8C03\\u7528\\u6765\\u5B9E\\u73B0\\u8BE5\\u7B97\\u6CD5\\uFF0C\\u5219\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u5C06\\u4E3A O(n)\\uFF0C\\u8FD9\\u9700\\u8981\\u989D\\u5916\\u7684\\u5185\\u5B58\\u7A7A\\u95F4\\u6765\\u5B58\\u50A8\\u51FD\\u6570\\u8C03\\u7528\\u5806\\u6808\\u3002\"})]})}function j(t={}){let{wrapper:e}=t.components||{};return e?(0,r.jsx)(e,Object.assign({},t,{children:(0,r.jsx)(x,t)})):x(t)}var v=j;return b(B);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/heap/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/heap/locales/zh-CN.json new file mode 100644 index 000000000..3a22b4921 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/heap/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var s=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var m=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),g=(n,e)=>{for(var a in e)i(n,a,{get:e[a],enumerable:!0})},l=(n,e,a,t)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let c of x(e))!f.call(n,c)&&c!==a&&i(n,c,{get:()=>e[c],enumerable:!(t=p(e,c))||t.enumerable});return n};var j=(n,e,a)=>(a=n!=null?s(u(n)):{},l(e||!n||!n.__esModule?i(a,\"default\",{value:n,enumerable:!0}):a,n)),y=n=>l(i({},\"__esModule\",{value:!0}),n);var o=m((b,d)=>{d.exports=_jsx_runtime});var H={};g(H,{default:()=>w,frontmatter:()=>M});var r=j(o()),M={title:\"\\u5806\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u5305\\u542B\\u57FA\\u672C\\u5806\\u64CD\\u4F5C\\u7684\\u5806\\u6570\\u636E\\u7ED3\\u6784\"};function h(n){let e=Object.assign({p:\"p\",ul:\"ul\",li:\"li\",code:\"code\",h2:\"h2\",pre:\"pre\"},n.components);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e.p,{children:\"\\u7528 JavaScript \\u5B9E\\u73B0\\u4E00\\u4E2A\\u5806\\u6570\\u636E\\u7ED3\\u6784\\uFF0C\\u5B83\\u652F\\u6301\\u4EE5\\u4E0B\\u64CD\\u4F5C\\uFF1A\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"new Heap(array)\"}),\": \\u521B\\u5EFA\\u4E00\\u4E2A Heap \\u7C7B\\u7684\\u5B9E\\u4F8B\\uFF0C\\u7528 \",(0,r.jsx)(e.code,{children:\"array\"}),\" \\u521D\\u59CB\\u5316\\u5E76\\u5806\\u5316\\u5B83\\u4EE5\\u5F62\\u6210\\u521D\\u59CB\\u7684\\u5806\\u7ED3\\u6784\\u3002\\u5B83\\u8FD8\\u521D\\u59CB\\u5316\\u7EF4\\u62A4\\u5806\\u5C5E\\u6027\\u6240\\u9700\\u7684\\u4EFB\\u4F55\\u5185\\u90E8\\u7ED3\\u6784\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"heapify(array)\"}),\": \\u4ECE\\u65E0\\u5E8F\\u6570\\u7EC4\\u6784\\u9020\\u5806\\uFF0C\\u5728\\u6240\\u6709\\u5143\\u7D20\\u4E2D\\u5EFA\\u7ACB\\u6700\\u5927\\u5806\\u5C5E\\u6027\\u3002\\u8FD9\\u662F\\u4F5C\\u4E3A\\u6784\\u9020\\u51FD\\u6570\\u7684\\u4E00\\u90E8\\u5206\\u6267\\u884C\\u7684\\uFF0C\\u6216\\u8005\\u53EF\\u4EE5\\u662F\\u4E00\\u4E2A\\u5355\\u72EC\\u7684\\u65B9\\u6CD5\\uFF0C\\u7528\\u4E8E\\u91CD\\u7F6E\\u548C\\u91CD\\u5EFA\\u5806\\u3002\\u6240\\u9700\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\\uFF0C\\u5176\\u4E2D n \\u662F\\u6570\\u7EC4\\u4E2D\\u7684\\u5143\\u7D20\\u6570\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"insert(value)\"}),\": \\u5C06\\u4E00\\u4E2A\\u65B0\\u503C\\u6DFB\\u52A0\\u5230\\u5806\\u4E2D\\uFF0C\\u4FDD\\u6301\\u6700\\u5927\\u5806\\u5C5E\\u6027\\u3002\\u6240\\u9700\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(log n)\\uFF0C\\u5176\\u4E2D n \\u662F\\u63D2\\u5165\\u540E\\u5806\\u4E2D\\u7684\\u5143\\u7D20\\u6570\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"delete()\"}),\": \\u4ECE\\u5806\\u4E2D\\u5220\\u9664\\u5E76\\u8FD4\\u56DE\\u6700\\u5927\\u503C\\uFF0C\\u5728\\u5220\\u9664\\u540E\\u4FDD\\u6301\\u6700\\u5927\\u5806\\u5C5E\\u6027\\u3002\\u6240\\u9700\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(log n)\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:\"findMax()\"}),\": \\u8FD4\\u56DE\\u5806\\u4E2D\\u7684\\u6700\\u5927\\u503C\\uFF0C\\u800C\\u4E0D\\u5220\\u9664\\u5B83\\u3002\\u6240\\u9700\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\\u3002\"]}),`\n`]}),`\n`,(0,r.jsx)(e.h2,{children:\"\\u4F8B\\u5B50\"}),`\n`,(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:\"language-js\",children:`const heap = new Heap();\nheap.insert(20);\nheap.insert(15);\nheap.insert(30);\nheap.findMax(); // 30\nheap.insert(10);\nheap.delete(); // 30\nheap.findMax(); // 20\n\nconst array = [5, 3, 17, 10, 84, 19, 6, 22, 9];\nconst newHeap = new Heap(array);\nnewHeap.findMax(); // 84\n`})})]})}function _(n={}){let{wrapper:e}=n.components||{};return e?(0,r.jsx)(e,Object.assign({},n,{children:(0,r.jsx)(h,n)})):h(n)}var w=_;return y(H);})();\n;return Component;", + "info": { + "excerpt": "实现一个包含基本堆操作的堆数据结构", + "title": "堆" + }, + "solution": "var Component=(()=>{var v=Object.create;var l=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var y=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),w=(i,e)=>{for(var a in e)l(i,a,{get:e[a],enumerable:!0})},s=(i,e,a,r)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let n of x(e))!m.call(i,n)&&n!==a&&l(i,n,{get:()=>e[n],enumerable:!(r=g(e,n))||r.enumerable});return i};var T=(i,e,a)=>(a=i!=null?v(f(i)):{},s(e||!i||!i.__esModule?l(a,\"default\",{value:i,enumerable:!0}):a,i)),I=i=>s(l({},\"__esModule\",{value:!0}),i);var d=y((D,h)=>{h.exports=_jsx_runtime});var C={};w(C,{default:()=>_});var t=T(d());var u=MDXCodeBlock;var o=`export default class Heap {\n constructor(array = []) {\n this.values = [];\n if (array.length > 0) {\n this.heapify(array);\n }\n }\n\n /**\n * Constructs the initial heap structure with a given \\`array\\`.\n * @param {Array} array The initial array.\n */\n heapify(array) {\n this.values = [];\n array.forEach((element) => this.insert(element));\n }\n\n /**\n * Adds an item into the heap.\n * @param {*} item The item to be added into the heap.\n */\n insert(value) {\n this.values.push(value);\n let index = this.values.length - 1;\n let parentIndex = Math.floor((index - 1) / 2);\n\n // Move up the newly added value until the heap property is restored.\n while (index > 0 && this.values[parentIndex] < this.values[index]) {\n [this.values[parentIndex], this.values[index]] = [\n this.values[index],\n this.values[parentIndex],\n ];\n index = parentIndex;\n parentIndex = Math.floor((index - 1) / 2);\n }\n }\n\n /**\n * Removes the top of the heap / maximum element.\n * @return {*} The element removed.\n */\n delete() {\n if (this.values.length === 0) {\n return undefined;\n }\n const max = this.values[0];\n const last = this.values.pop();\n if (this.values.length === 0) {\n return max;\n }\n\n this.values[0] = last;\n let index = 0;\n\n // Restore heap property by moving down the root value.\n while (true) {\n const left = 2 * index + 1;\n const right = 2 * index + 2;\n let largest = index;\n\n // If left child exists and is larger than the current largest, replace largest with value of left child.\n if (\n left < this.values.length &&\n this.values[left] > this.values[largest]\n ) {\n largest = left;\n }\n\n // If right child exists and is larger than the current largest, replace largest with value of right child.\n if (\n right < this.values.length &&\n this.values[right] > this.values[largest]\n ) {\n largest = right;\n }\n\n if (largest === index) {\n break; // The current root is already the largest, heap property is satisfied.\n }\n\n // Swap the position such that the largest value is above \\`index\\`, following the heap property.\n [this.values[index], this.values[largest]] = [\n this.values[largest],\n this.values[index],\n ];\n index = largest;\n }\n\n return max;\n }\n\n /**\n * Returns the value of the maximum element.\n * @return {number} The maximum element.\n */\n findMax() {\n return this.values.length > 0 ? this.values[0] : undefined;\n }\n}\n`;var c=`export default class Heap {\n values: T[];\n\n constructor(array: T[] = []) {\n this.values = [];\n if (array.length > 0) {\n this.heapify(array);\n }\n }\n\n /**\n * Constructs the initial heap structure with a given \\`array\\`.\n * @param array The initial array to be used for the heap.\n */\n heapify(array: T[]): void {\n this.values = [];\n array.forEach((element) => this.insert(element));\n }\n\n /**\n * Adds an item to the heap.\n * @param value The item to be added into the heap.\n */\n insert(value: T): void {\n this.values.push(value);\n let index = this.values.length - 1;\n let parentIndex = Math.floor((index - 1) / 2);\n\n // Move up the newly added value until the heap property is restored.\n while (index > 0 && this.values[parentIndex] < this.values[index]) {\n [this.values[parentIndex], this.values[index]] = [\n this.values[index],\n this.values[parentIndex],\n ];\n index = parentIndex;\n parentIndex = Math.floor((index - 1) / 2);\n }\n }\n\n /**\n * Removes the top of the heap / maximum element.\n * @return The element removed, or undefined if the heap is empty.\n */\n delete(): T | undefined {\n if (this.values.length === 0) {\n return undefined;\n }\n const max = this.values[0];\n const last = this.values.pop();\n if (this.values.length > 0 && last !== undefined) {\n this.values[0] = last;\n let index = 0;\n\n // Restore heap property by moving down the root value.\n while (true) {\n const left = 2 * index + 1;\n const right = 2 * index + 2;\n let largest = index;\n\n // If left child exists and is larger than the current largest, replace largest with value of left child.\n if (\n left < this.values.length &&\n this.values[left] > this.values[largest]\n ) {\n largest = left;\n }\n\n // If right child exists and is larger than the current largest, replace largest with value of right child.\n if (\n right < this.values.length &&\n this.values[right] > this.values[largest]\n ) {\n largest = right;\n }\n\n if (largest === index) {\n break; // The current root is already the largest, heap property is satisfied.\n }\n\n // Swap the position such that the largest value is above \\`index\\`, following the heap property.\n [this.values[index], this.values[largest]] = [\n this.values[largest],\n this.values[index],\n ];\n index = largest;\n }\n }\n return max;\n }\n\n /**\n * Returns the value of the maximum element.\n * @return The maximum element.\n */\n findMax(): T | undefined {\n return this.values.length > 0 ? this.values[0] : undefined;\n }\n}\n`;function p(i){let e=Object.assign({h2:\"h2\",p:\"p\",h3:\"h3\",ul:\"ul\",li:\"li\",code:\"code\",img:\"img\"},i.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(e.h2,{children:\"\\u89E3\\u51B3\\u65B9\\u6848\"}),`\n`,(0,t.jsx)(e.p,{children:\"\\u5806\\u662F\\u4E00\\u79CD\\u7279\\u6B8A\\u7684\\u57FA\\u4E8E\\u6811\\u7684\\u6570\\u636E\\u7ED3\\u6784\\uFF0C\\u5B83\\u6EE1\\u8DB3\\u5806\\u5C5E\\u6027\\uFF0C\\u5176\\u4E2D\\u5728\\u6700\\u5927\\u5806\\u4E2D\\uFF0C\\u6BCF\\u4E2A\\u7236\\u8282\\u70B9\\u90FD\\u5927\\u4E8E\\u6216\\u7B49\\u4E8E\\u5176\\u5B50\\u8282\\u70B9\\u7684\\u503C\\u3002\\u6B64\\u5C5E\\u6027\\u4F7F\\u5806\\u6210\\u4E3A\\u5B9E\\u73B0\\u4F18\\u5148\\u7EA7\\u961F\\u5217\\u7684\\u7406\\u60F3\\u9009\\u62E9\\uFF0C\\u5728\\u4F18\\u5148\\u7EA7\\u961F\\u5217\\u4E2D\\uFF0C\\u9700\\u8981\\u5FEB\\u901F\\u8BBF\\u95EE\\u6700\\u9AD8\\uFF08\\u6216\\u6700\\u4F4E\\uFF09\\u4F18\\u5148\\u7EA7\\u5143\\u7D20\\u3002\"}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u64CD\\u4F5C\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.code,{children:\"heapify(array)\"}),\"\\uFF1A\\u4ECE\\u65E0\\u5E8F\\u6570\\u7EC4\\u6784\\u9020\\u5806\\u3002\\u8FD9\\u662F\\u901A\\u8FC7\\u5BF9\\u6570\\u7EC4\\u7684\\u540E\\u534A\\u90E8\\u5206\\u6267\\u884C\\u4E00\\u7CFB\\u5217\\u63D2\\u5165\\u64CD\\u4F5C\\u6765\\u5B8C\\u6210\\u7684\\uFF0C\\u4EE5\\u5C31\\u5730\\u6784\\u5EFA\\u5806\\u3002\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.code,{children:\"insert(value)\"}),\"\\uFF1A\\u5411\\u5806\\u4E2D\\u6DFB\\u52A0\\u4E00\\u4E2A\\u65B0\\u5143\\u7D20\\u3002\\u8FD9\\u6D89\\u53CA\\u5C06\\u5143\\u7D20\\u9644\\u52A0\\u5230\\u6570\\u7EC4\\u7684\\u672B\\u5C3E\\uFF08\\u8868\\u793A\\u5806\\uFF09\\uFF0C\\u7136\\u540E\\u5411\\u4E0A\\u79FB\\u52A8\\u65B0\\u6DFB\\u52A0\\u7684\\u5143\\u7D20\\uFF0C\\u76F4\\u5230\\u6062\\u590D\\u5806\\u5C5E\\u6027\\uFF08\\u5982\\u679C\\u5B83\\u88AB\\u8FDD\\u53CD\\uFF09\\u3002\"]}),`\n`]}),`\n`,(0,t.jsx)(e.p,{children:(0,t.jsx)(e.img,{src:\"/img/questions/heap/insert.png\",alt:\"Insert\"})}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.code,{children:\"delete()\"}),\"\\uFF1A\\u5220\\u9664\\u5806\\u7684\\u6839\\u5143\\u7D20\\uFF0C\\u5373\\u6700\\u5927\\u5806\\u4E2D\\u7684\\u6700\\u5927\\u503C\\u3002\\u5806\\u7684\\u6700\\u540E\\u4E00\\u4E2A\\u5143\\u7D20\\u66FF\\u6362\\u6839\\uFF0C\\u7136\\u540E\\u6162\\u6162\\u5411\\u4E0B\\u79FB\\u52A8\\uFF0C\\u76F4\\u5230\\u6062\\u590D\\u5806\\u5C5E\\u6027\\u3002\"]}),`\n`]}),`\n`,(0,t.jsx)(e.p,{children:(0,t.jsx)(e.img,{src:\"/img/questions/heap/delete.png\",alt:\"Delete\"})}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.code,{children:\"findMax()\"}),\"\\uFF1A\\u8FD4\\u56DE\\u5806\\u7684\\u6839\\u5143\\u7D20\\uFF0C\\u800C\\u4E0D\\u5220\\u9664\\u5B83\\uFF0C\\u4ECE\\u800C\\u63D0\\u4F9B\\u5BF9\\u6700\\u5927\\u503C\\u7684\\u6052\\u5B9A\\u65F6\\u95F4\\u8BBF\\u95EE\\u3002\"]}),`\n`]}),`\n`,(0,t.jsxs)(e.p,{children:[\"\\u7531\\u4E8E\\u64CD\\u4F5C \",(0,t.jsx)(e.code,{children:\"insert\"}),\" \\u548C \",(0,t.jsx)(e.code,{children:\"delete\"}),\" \\u53EF\\u80FD\\u6D89\\u53CA\\u5728\\u5806\\u7684\\u9AD8\\u5EA6\\u4E0A\\u79FB\\u52A8\\u5143\\u7D20\\uFF0C\\u56E0\\u6B64\\u5B83\\u4EEC\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(log n)\\uFF0C\\u5176\\u4E2D n \\u662F\\u5806\\u4E2D\\u5143\\u7D20\\u7684\\u6570\\u91CF\\u3002\",(0,t.jsx)(e.code,{children:\"findMax\"}),\" \\u662F\\u4E00\\u4E2A\\u6052\\u5B9A\\u65F6\\u95F4\\u64CD\\u4F5C\\uFF0CO(1)\\uFF0C\\u56E0\\u4E3A\\u5B83\\u8FD4\\u56DE\\u7B2C\\u4E00\\u4E2A\\u5143\\u7D20\\u3002\",(0,t.jsx)(e.code,{children:\"Heapify\"}),\" \\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(n log(n))\\uFF0C\\u56E0\\u4E3A\\u5B83\\u904D\\u5386\\u6BCF\\u4E2A\\u5143\\u7D20\\u5E76\\u9010\\u4E2A\\u7F13\\u6162\\u5730\\u63D2\\u5165\\u5B83\\u4EEC\\u3002\"]}),`\n`,(0,t.jsx)(e.h2,{children:\"\\u8FB9\\u7F18\\u60C5\\u51B5\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsx)(e.li,{children:\"\\u63D2\\u5165\\u5230\\u7A7A\\u5806\\u4E2D\\u3002\"}),`\n`,(0,t.jsx)(e.li,{children:\"\\u4ECE\\u7A7A\\u5806\\u4E2D\\u5220\\u9664\\u3002\"}),`\n`,(0,t.jsxs)(e.li,{children:[\"\\u5728\\u7A7A\\u5806\\u4E0A\\u8C03\\u7528 \",(0,t.jsx)(e.code,{children:\"findMax\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,t.jsx)(e.h2,{children:\"\\u6280\\u672F\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsx)(e.li,{children:\"\\u9762\\u5411\\u5BF9\\u8C61\\u7F16\\u7A0B\\u3002\"}),`\n`,(0,t.jsx)(e.li,{children:\"\\u6570\\u7EC4\\u64CD\\u4F5C\\u4EE5\\u6A21\\u62DF\\u4E8C\\u53C9\\u6811\\u3002\"}),`\n`,(0,t.jsx)(e.li,{children:\"\\u4E86\\u89E3\\u5BF9\\u6570\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4EE5\\u53CA\\u64CD\\u4F5C\\u5982\\u4F55\\u5F71\\u54CD\\u5B83\\u3002\"}),`\n`]}),`\n`,(0,t.jsx)(e.p,{children:\"\\u6B64\\u5806\\u5B9E\\u73B0\\u4FA7\\u91CD\\u4E8E\\u9AD8\\u6548\\u7684\\u6570\\u636E\\u64CD\\u4F5C\\uFF0C\\u5229\\u7528\\u4E8C\\u53C9\\u6811\\u7684\\u5C5E\\u6027\\u6765\\u786E\\u4FDD\\u5FEB\\u901F\\u8BBF\\u95EE\\u9AD8\\u4F18\\u5148\\u7EA7\\u9879\\u76EE\\uFF0C\\u540C\\u65F6\\u4FDD\\u6301\\u4EE5\\u5BF9\\u6570\\u65F6\\u95F4\\u8FDB\\u884C\\u8C03\\u6574\\u7684\\u80FD\\u529B\\u3002\"}),`\n`,(0,t.jsx)(u,{languages:{jsx:o,tsx:c}})]})}function j(i={}){let{wrapper:e}=i.components||{};return e?(0,t.jsx)(e,Object.assign({},i,{children:(0,t.jsx)(p,i)})):p(i)}var _=j;return I(C);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/insertion-sort/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/insertion-sort/locales/zh-CN.json new file mode 100644 index 000000000..dc11f9c53 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/insertion-sort/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var d=Object.create;var s=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var x=(t,n)=>()=>(n||t((n={exports:{}}).exports,n),n.exports),j=(t,n)=>{for(var i in n)s(t,i,{get:n[i],enumerable:!0})},c=(t,n,i,o)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let r of m(n))!u.call(t,r)&&r!==i&&s(t,r,{get:()=>n[r],enumerable:!(o=h(n,r))||o.enumerable});return t};var _=(t,n,i)=>(i=t!=null?d(g(t)):{},c(n||!t||!t.__esModule?s(i,\"default\",{value:t,enumerable:!0}):i,t)),f=t=>c(s({},\"__esModule\",{value:!0}),t);var a=x((F,p)=>{p.exports=_jsx_runtime});var C={};j(C,{default:()=>M,frontmatter:()=>q});var e=_(a()),q={title:\"\\u63D2\\u5165\\u6392\\u5E8F\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u6267\\u884C\\u63D2\\u5165\\u6392\\u5E8F\\u7684\\u51FD\\u6570\"};function l(t){let n=Object.assign({p:\"p\",img:\"img\",h2:\"h2\",pre:\"pre\",code:\"code\"},t.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.p,{children:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u6267\\u884C\\u63D2\\u5165\\u6392\\u5E8F\\u7684\\u51FD\\u6570\\u3002\\u8BE5\\u51FD\\u6570\\u5E94\\u63A5\\u6536\\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4\\uFF0C\\u5E76\\u8FD4\\u56DE\\u4E00\\u4E2A\\u6309\\u5347\\u5E8F\\u6392\\u5E8F\\u7684\\u6574\\u6570\\u6570\\u7EC4\\u3002\\u8F93\\u5165\\u6570\\u7EC4\\u5C06\\u88AB\\u4FEE\\u6539\\u3002\"}),`\n`,(0,e.jsx)(n.p,{children:(0,e.jsx)(n.img,{src:\"/img/questions/insertion-sort/insertion-sort-input-output.png\",alt:\"\\u63D2\\u5165\\u6392\\u5E8F\\u7684\\u9884\\u671F\\u8F93\\u5165\\u548C\\u8F93\\u51FA\"})}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u4F8B\\u5B50\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-js\",children:`insertionSort([9, 3, 6, 2, 1, 11]); // [1, 2, 3, 6, 9, 11]\ninsertionSort([12, 16, 14, 1, 2, 3]); // [1, 2, 3, 12, 14, 16]\n`})}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u56DE\\u987E\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u63D2\\u5165\\u6392\\u5E8F\\u662F\\u4E00\\u79CD\\u7B80\\u5355\\u7684\\u6392\\u5E8F\\u7B97\\u6CD5\\uFF0C\\u5B83\\u4E00\\u6B21\\u5C06\\u5143\\u7D20\\u4E0E\\u524D\\u4E00\\u4E2A\\u5143\\u7D20\\u8FDB\\u884C\\u6BD4\\u8F83\\uFF0C\\u5C06\\u5B83\\u4EEC\\u201C\\u63D2\\u5165\\u201D\\u5230\\u6B63\\u786E\\u7684\\u4F4D\\u7F6E\\uFF0C\\u5E76\\u9010\\u6B65\\u6784\\u5EFA\\u4E00\\u4E2A\\u5DF2\\u6392\\u5E8F\\u7684\\u6570\\u7EC4\\u3002\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u8BE5\\u7B97\\u6CD5\\u4ECE\\u68C0\\u67E5\\u8F93\\u5165\\u6570\\u7EC4\\u7684\\u7B2C\\u4E8C\\u4E2A\\u5143\\u7D20\\uFF08\\u201C\\u5F53\\u524D\\u201D\\u5143\\u7D20\\uFF09\\u5F00\\u59CB\\uFF0C\\u5E76\\u5C06\\u5176\\u4E0E\\u524D\\u4E00\\u4E2A\\u5143\\u7D20\\uFF08\\u5373\\u7B2C\\u4E00\\u4E2A\\u5143\\u7D20\\uFF09\\u8FDB\\u884C\\u6BD4\\u8F83\\u3002\\u5982\\u679C\\u5F53\\u524D\\u5143\\u7D20\\u8F83\\u5C0F\\uFF0C\\u6211\\u4EEC\\u4EA4\\u6362\\u5B83\\u4EEC\\u7684\\u4F4D\\u7F6E\\uFF08\\u901A\\u8FC7\\u590D\\u5236\\uFF09\\u3002\\u7ED3\\u679C\\u662F\\u524D 2 \\u4E2A\\u5143\\u7D20\\u6309\\u5347\\u5E8F\\u6B63\\u786E\\u6392\\u5E8F\\u3002\"}),`\n`,(0,e.jsx)(n.p,{children:(0,e.jsx)(n.img,{src:\"/img/questions/insertion-sort/insertion-sort-first-iteration.png\",alt:\"\\u63D2\\u5165\\u6392\\u5E8F\\u7B97\\u6CD5\\u7684\\u7B2C\\u4E00\\u6B21\\u8FED\\u4EE3\\u63D2\\u56FE\"})}),`\n`,(0,e.jsx)(n.p,{children:\"\\u7136\\u540E\\uFF0C\\u8BE5\\u7B97\\u6CD5\\u79FB\\u52A8\\u5230\\u8F93\\u5165\\u5217\\u8868\\u4E2D\\u7684\\u4E0B\\u4E00\\u4E2A\\u5143\\u7D20\\uFF0C\\u5E76\\u5C06\\u5176\\u4E0E\\u524D\\u9762\\u7684\\u5143\\u7D20\\uFF08\\u5DF2\\u6309\\u5347\\u5E8F\\u6392\\u5E8F\\uFF09\\u8FDB\\u884C\\u6BD4\\u8F83\\uFF0C\\u4EE5\\u5C06\\u5176\\u63D2\\u5165\\u5230\\u6B63\\u786E\\u7684\\u4F4D\\u7F6E\\u3002\\u7531\\u4E8E\\u524D\\u9762\\u7684\\u5143\\u7D20\\u5DF2\\u7ECF\\u6392\\u5E8F\\uFF0C\\u8BE5\\u7B97\\u6CD5\\u53EA\\u9700\\u8981\\u5C06\\u5F53\\u524D\\u5143\\u7D20\\u4E0E\\u6BCF\\u4E2A\\u524D\\u9762\\u7684\\u5143\\u7D20\\u8FDB\\u884C\\u6BD4\\u8F83\\uFF0C\\u76F4\\u5230\\u5F53\\u524D\\u5143\\u7D20\\u4E0D\\u5C0F\\u4E8E\\u8BE5\\u5143\\u7D20\\u3002\\u7136\\u540E\\u5C06\\u5176\\u63D2\\u5165\\u5230\\u5217\\u8868\\u4E2D\\u7684\\u6B63\\u786E\\u4F4D\\u7F6E\\uFF0C\\u5E76\\u4E14\\u8BE5\\u7B97\\u6CD5\\u79FB\\u52A8\\u5230\\u8F93\\u5165\\u5217\\u8868\\u4E2D\\u7684\\u4E0B\\u4E00\\u4E2A\\u5143\\u7D20\\u3002\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u4F8B\\u5982\\uFF0C\\u4ECE\\u4E0A\\u9762\\u7684\\u4F8B\\u5B50\\u7EE7\\u7EED\\uFF0C\\u8BE5\\u7B97\\u6CD5\\u5C06\\u79FB\\u52A8\\u5230\\u7B2C 3 \\u4E2A\\u5143\\u7D20\\u4F5C\\u4E3A\\u201C\\u5F53\\u524D\\u201D\\u5143\\u7D20\\uFF0C\\u5E76\\u5C06\\u5176\\u4E0E\\u524D\\u9762\\u7684\\u6392\\u5E8F\\u5217\\u8868\\u8FDB\\u884C\\u6BD4\\u8F83\\u3002\\u901A\\u8FC7\\u5411\\u540E\\u904D\\u5386\\u524D\\u9762\\u7684\\u5217\\u8868\\uFF0C\\u5F53\\u524D\\u5143\\u7D20\\u5C06\\u4E0E\\u7B2C 2 \\u4E2A\\u5143\\u7D20\\u9010\\u6B65\\u6BD4\\u8F83\\uFF0C\\u7136\\u540E\\u662F\\u7B2C 1 \\u4E2A\\u5143\\u7D20\\uFF0C\\u76F4\\u5230\\u5B83\\u4E0D\\u518D\\u5C0F\\u4E8E\\u8BE5\\u5143\\u7D20\\u3002\\u7136\\u540E\\u5B83\\u5C06\\u628A\\u81EA\\u5DF1\\u63D2\\u5165\\u5230\\u90A3\\u4E2A\\u4F4D\\u7F6E\\u3002\\u5982\\u679C\\u5B83\\u5C0F\\u4E8E\\u7B2C 2 \\u4E2A\\u548C\\u7B2C 1 \\u4E2A\\u5143\\u7D20\\uFF0C\\u5B83\\u53EA\\u662F\\u4F5C\\u4E3A\\u6700\\u5C0F\\u5143\\u7D20\\u63D2\\u5165\\u5230\\u5217\\u8868\\u7684\\u5F00\\u5934\\u3002\"}),`\n`,(0,e.jsx)(n.p,{children:(0,e.jsx)(n.img,{src:\"/img/questions/insertion-sort/insertion-sort-subsequent-iteration.png\",alt:\"\\u63D2\\u5165\\u6392\\u5E8F\\u7B97\\u6CD5\\u7684\\u540E\\u7EED\\u8FED\\u4EE3\\u63D2\\u56FE\"})})]})}function b(t={}){let{wrapper:n}=t.components||{};return n?(0,e.jsx)(n,Object.assign({},t,{children:(0,e.jsx)(l,t)})):l(t)}var M=b;return f(C);})();\n;return Component;", + "info": { + "excerpt": "实现一个执行插入排序的函数", + "title": "插入排序" + }, + "solution": "var Component=(()=>{var g=Object.create;var l=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var b=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),x=(n,e)=>{for(var t in e)l(n,t,{get:e[t],enumerable:!0})},h=(n,e,t,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of f(e))!v.call(n,i)&&i!==t&&l(n,i,{get:()=>e[i],enumerable:!(o=m(e,i))||o.enumerable});return n};var w=(n,e,t)=>(t=n!=null?g(j(n)):{},h(e||!n||!n.__esModule?l(t,\"default\",{value:n,enumerable:!0}):t,n)),y=n=>h(l({},\"__esModule\",{value:!0}),n);var c=b((D,a)=>{a.exports=_jsx_runtime});var M={};x(M,{default:()=>S});var r=w(c());var s=MDXCodeBlock;var u=`/**\n * @param {Array} arr The input integer array to be sorted.\n * @return {Array}\n */\nexport default function insertionSort(arr) {\n // Iterate through the array, starting with the 2nd element.\n for (let i = 1; i < arr.length; i++) {\n // Store the current value in a variable so it\n // can be shifted to the correct position after the comparisons.\n let currentValue = arr[i];\n\n // Initialize a pointer for the index of the previous element\n // so we can use it to iterate progressively backwards\n // through preceding elements.\n let j = i - 1;\n\n // Keep iterating backwards through preceding elements\n // as long as the previous element is greater than the current value.\n while (j >= 0 && arr[j] > currentValue) {\n // \"Move\" the previous element one position to the right.\n // if it's bigger than currentValue.\n arr[j + 1] = arr[j];\n\n // Decrement the pointer so as to keep comparing with the\n // previous element.\n j--;\n }\n\n // Set the currentValue into its final position.\n arr[j + 1] = currentValue;\n }\n\n // Return the sorted array.\n return arr;\n}\n`;var d=`export default function insertionSort(arr: Array): Array {\n // Iterate through the array, starting with the 2nd element.\n for (let i = 1; i < arr.length; i++) {\n // Store the current value in a variable so it\n // can be shifted to the correct position after the comparisons.\n let currentValue = arr[i];\n\n // Initialize a pointer for the index of the previous element\n // so we can use it to iterate progressively backwards\n // through preceding elements.\n let j = i - 1;\n\n // Keep iterating backwards through preceding elements\n // as long as the previous element is greater than the current value.\n while (j >= 0 && arr[j] > currentValue) {\n // \"Move\" the previous element one position to the right.\n // if it's bigger than currentValue.\n arr[j + 1] = arr[j];\n\n // Decrement the pointer so as to keep comparing with the\n // previous element.\n j--;\n }\n\n // Set the currentValue into its final position.\n arr[j + 1] = currentValue;\n }\n\n // Return the sorted array.\n return arr;\n}\n`;function p(n){let e=Object.assign({p:\"p\",h2:\"h2\",ul:\"ul\",li:\"li\",code:\"code\",pre:\"pre\",h3:\"h3\",strong:\"strong\"},n.components);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e.p,{children:\"\\u63D2\\u5165\\u6392\\u5E8F\\u662F\\u4E00\\u79CD\\u7A33\\u5B9A\\u7684\\u3001\\u539F\\u5730\\u7684\\u3001\\u57FA\\u4E8E\\u6BD4\\u8F83\\u7684\\u7B97\\u6CD5\\uFF0C\\u9002\\u7528\\u4E8E\\u4E2D\\u5C0F\\u578B\\u6570\\u7EC4\\u4EE5\\u53CA\\u90E8\\u5206\\u6392\\u5E8F\\u7684\\u6570\\u7EC4\\u3002\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u5B83\\u53EA\\u9700\\u8981\\u5C11\\u91CF\\u7684\\u5DE5\\u4F5C\\u5C31\\u53EF\\u4EE5\\u5BF9\\u5DF2\\u7ECF\\u90E8\\u5206\\u6392\\u5E8F\\u7684\\u6570\\u7EC4\\u8FDB\\u884C\\u6392\\u5E8F\\u3002\"}),`\n`,(0,r.jsx)(e.h2,{children:\"\\u6F84\\u6E05\\u95EE\\u9898\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u5982\\u679C\\u672A\\u6307\\u5B9A\\uFF1A\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"\\u6570\\u636E\\u5E94\\u8BE5\\u6309\\u5347\\u5E8F\\u8FD8\\u662F\\u964D\\u5E8F\\u6392\\u5E8F\\uFF1F\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u6570\\u636E\\u5E94\\u8BE5\\u5C31\\u5730\\u6392\\u5E8F\\u8FD8\\u662F\\u53EF\\u4EE5\\u4F7F\\u7528\\u5176\\u4ED6\\u6570\\u636E\\u7ED3\\u6784\\uFF1F\"}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u6211\\u4EEC\\u9700\\u8981\\u5904\\u7406\\u4EC0\\u4E48\\u6837\\u7684\\u8F93\\u5165\\uFF1F\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"\\u5B83\\u53EA\\u662F\\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4\\uFF0C\\u8FD8\\u662F\\u6211\\u4EEC\\u5E94\\u8BE5\\u5904\\u7406\\u5176\\u4ED6\\u6570\\u636E\\u7C7B\\u578B\\uFF1F\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u662F\\u5426\\u5B58\\u5728\\u5927\\u91CF\\u91CD\\u590D\\u5143\\u7D20\\uFF1F\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u5E94\\u8BE5\\u5982\\u4F55\\u5904\\u7406\\u8D1F\\u6570\\uFF1F\"}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,r.jsx)(e.h2,{children:\"\\u89E3\\u51B3\\u65B9\\u6848\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u6CE8\\u610F\\uFF1A\\u6B64\\u95EE\\u9898\\u9488\\u5BF9\\u5347\\u5E8F\\u8F93\\u51FA\\u7684\\u5C31\\u5730\\u6392\\u5E8F\\u3002\\u8BF7\\u53C2\\u9605\\u4E0B\\u9762\\u7684\\u201C\\u6CE8\\u91CA\\u201D\\u90E8\\u5206\\uFF0C\\u4E86\\u89E3\\u5982\\u4F55\\u5904\\u7406\\u5176\\u4ED6\\u60C5\\u51B5\\u3002\"}),`\n`,(0,r.jsx)(s,{languages:{jsx:u,tsx:d}}),`\n`,(0,r.jsx)(e.h2,{children:\"\\u8FB9\\u7F18\\u60C5\\u51B5\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"\\u975E\\u6574\\u6570\\u5143\\u7D20\\u8F93\\u5165\\uFF1A\\u5982\\u679C\\u8F93\\u5165\\u6570\\u7EC4\\u5305\\u542B\\u4E0D\\u540C\\u6570\\u636E\\u7C7B\\u578B\\u7684\\u5143\\u7D20\\uFF0C\\u60A8\\u53EF\\u80FD\\u9700\\u8981\\u8FD4\\u56DE\\u4E00\\u4E2A\\u9519\\u8BEF\\uFF0C\\u5C3D\\u529B\\u8FDB\\u884C\\u6392\\u5E8F\\uFF0C\\u4F8B\\u5982\\uFF0C\\u4EC5\\u5BF9\\u8F93\\u5165\\u6570\\u636E\\u7684\\u5B50\\u96C6\\u8FDB\\u884C\\u6392\\u5E8F\\uFF0C\\u751A\\u81F3\\u4E3A\\u975E\\u6574\\u6570\\u5B9A\\u4E49\\u81EA\\u5B9A\\u4E49\\u6BD4\\u8F83\\u51FD\\u6570\\u3002\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u5355\\u4E2A\\u5143\\u7D20/\\u7A7A\\u8F93\\u5165\\uFF1A\\u8FD4\\u56DE\\u539F\\u59CB\\u6570\\u636E\\u7ED3\\u6784\\u3001\\u5F15\\u53D1\\u9519\\u8BEF\\u6216\\u9610\\u660E\\u6240\\u9700\\u5904\\u7406\\u65B9\\u5F0F\\u3002\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u5927\\u8F93\\u5165\\uFF1A\\u60A8\\u53EF\\u80FD\\u9700\\u8981\\u8003\\u8651\\u4F7F\\u7528\\u5176\\u4ED6\\u4F18\\u5316\\uFF0C\\u5982\\u4E8C\\u5206\\u67E5\\u627E\\uFF0C\\u4EE5\\u52A0\\u5FEB\\u63D2\\u5165\\u901F\\u5EA6\\u3002\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u5DF2\\u6392\\u5E8F\\u7684\\u8F93\\u5165\\uFF1A\\u60A8\\u53EF\\u80FD\\u9700\\u8981\\u68C0\\u6D4B\\u6392\\u5E8F\\u5E76\\u4FDD\\u6301\\u8F93\\u5165\\u4E0D\\u53D8\\u3002\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u65E0\\u6548\\u8F93\\u5165\\uFF1A\\u5982\\u679C\\u8F93\\u5165\\u4E0D\\u662F\\u6570\\u7EC4\\uFF0C\\u8BF7\\u8003\\u8651\\u629B\\u51FA\\u9519\\u8BEF\\u3002\"}),`\n`]}),`\n`,(0,r.jsx)(e.h2,{children:\"\\u7B14\\u8BB0\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u8981\\u6C42\\u6309\\u964D\\u5E8F\\u6392\\u5E8F\\uFF1A\\u53EA\\u9700\\u5C06\\u6BD4\\u8F83\\u66F4\\u6539\\u4E3A \",(0,r.jsx)(e.code,{children:\"<\"}),\" \\u800C\\u4E0D\\u662F \",(0,r.jsx)(e.code,{children:\">\"}),\"\\uFF0C\\u5982\\u4E0B\\u6240\\u793A\\uFF1A\"]}),`\n`]}),`\n`,(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:\"language-js\",children:`while (j >= 0 && arr[j] < currentValue)\n`})}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u8981\\u6C42\\u4F7F\\u7528\\u5176\\u4ED6\\u6570\\u636E\\u7ED3\\u6784\\u6216\\u7F16\\u5199\\u7EAF\\u51FD\\u6570\\u800C\\u4E0D\\u662F\\u5C31\\u5730\\u6392\\u5E8F\\u6570\\u636E\\uFF0C\\u8BF7\\u4F7F\\u7528\\u6269\\u5C55\\u8FD0\\u7B97\\u7B26\\u6216 \",(0,r.jsx)(e.code,{children:\"Array.prototype.slice()\"}),\" \\u514B\\u9686\\u8F93\\u5165\\u6570\\u7EC4\\uFF0C\\u5E76\\u5728\\u514B\\u9686\\u7684\\u6570\\u7EC4\\u4E0A\\u8FDB\\u884C\\u6392\\u5E8F\\u3002\"]}),`\n`]}),`\n`,(0,r.jsx)(e.h2,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u8BA9\\u6211\\u4EEC\\u5206\\u6790\\u4E00\\u4E0B\\u7B97\\u6CD5\\u7684\\u65F6\\u95F4\\u548C\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u3002\"}),`\n`,(0,r.jsx)(e.h3,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\"}),`\n`,(0,r.jsxs)(e.p,{children:[\"\\u5BF9\\u4E8E\\u63D2\\u5165\\u6392\\u5E8F\\uFF0C\\u6700\\u4F73\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(n)\\uFF0C\\u6700\\u574F\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(n\",(0,r.jsx)(\"sup\",{children:\"2\"}),\")\\uFF0C\\u5E73\\u5747\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E5F\\u4E3A O(n\",(0,r.jsx)(\"sup\",{children:\"2\"}),\")\\u3002\"]}),`\n`,(0,r.jsxs)(e.p,{children:[\"\\u7531\\u4E8E\\u63D2\\u5165\\u6392\\u5E8F\\u9700\\u8981\\u5D4C\\u5957\\u5FAA\\u73AF\\u7ED3\\u6784\\uFF0C\\u5176\\u4E2D\\u5916\\u5FAA\\u73AF\\u904D\\u5386\\u6570\\u7EC4\\uFF0C\\u5185\\u5FAA\\u73AF\\u904D\\u5386\\u5DF2\\u6392\\u5E8F\\u7684\\u6570\\u7EC4\\u4EE5\\u627E\\u5230\\u63D2\\u5165\\u5F53\\u524D\\u5143\\u7D20\\u7684\\u6B63\\u786E\\u4F4D\\u7F6E\\uFF0C\\u56E0\\u6B64\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u901A\\u5E38\\u4E3AO(n\",(0,r.jsx)(\"sup\",{children:\"2\"}),\")\\uFF0C\\u5982\\u679C\\u4E24\\u4E2A\\u5FAA\\u73AF\\u90FD\\u5B8C\\u5168\\u8FED\\u4EE3\\u3002\\u4E0D\\u540C\\u60C5\\u51B5\\u4E4B\\u95F4\\u7684\\u5DEE\\u5F02\\u53D7\\u5230\\u539F\\u59CB\\u8F93\\u5165\\u6392\\u5E8F\\u7A0B\\u5EA6\\u7684\\u5F71\\u54CD\\uFF0C\\u8FD9\\u4F1A\\u5F71\\u54CD\\u6211\\u4EEC\\u662F\\u5426\\u9700\\u8981\\u5BF9\\u7279\\u5B9A\\u5143\\u7D20\\u8FD0\\u884C\\u5185\\u5FAA\\u73AF\\u3002\"]}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u6700\\u574F\\u60C5\\u51B5\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\"}),\"\\uFF1A\\u5F53\\u8F93\\u5165\\u4EE5\\u5B8C\\u5168\\u76F8\\u53CD\\u7684\\u987A\\u5E8F\\u6392\\u5217\\u65F6\\uFF0C\\u8F93\\u51FA\\u5FC5\\u987B\\u662F\\uFF08\\u4F8B\\u5982\\uFF0C\\u5F53\\u6211\\u4EEC\\u9700\\u8981\\u964D\\u5E8F\\u65F6\\u5347\\u5E8F\\uFF09\\u3002\\u6211\\u4EEC\\u9700\\u8981\\u5BF9\\u6BCF\\u4E2A\\u5143\\u7D20\\u5B8C\\u5168\\u904D\\u5386\\u5916\\u5FAA\\u73AF\\u548C\\u5185\\u5FAA\\u73AF\\uFF0C\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3AO(n\",(0,r.jsx)(\"sup\",{children:\"2\"}),\")\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u6700\\u4F73\\u60C5\\u51B5\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\"}),\"\\uFF1A\\u5F53\\u8F93\\u5165\\u5DF2\\u7ECF\\u6392\\u5E8F\\u6216\\u63A5\\u8FD1\\u6392\\u5E8F\\u65F6\\u3002\\u8FD9\\u610F\\u5473\\u7740\\u5185\\u5FAA\\u73AF\\u4E0D\\u9700\\u8981\\u8FED\\u4EE3\\u592A\\u591A\\u3002\\u5728\\u6700\\u597D\\u7684\\u60C5\\u51B5\\u4E0B\\uFF0C\\u8F93\\u5165\\u6570\\u7EC4\\u5DF2\\u7ECF\\u5B8C\\u5168\\u6392\\u5E8F\\uFF0C\\u6211\\u4EEC\\u53EA\\u8FD0\\u884C\\u5916\\u5FAA\\u73AF\\uFF0C\\u590D\\u6742\\u5EA6\\u4E3AO(n)\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u5E73\\u5747\\u60C5\\u51B5\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\"}),\"\\uFF1A\\u8003\\u8651\\u5230\\u8F93\\u5165\\u6570\\u7EC4\\u968F\\u673A\\u6392\\u5217\\u7684\\u60C5\\u51B5\\uFF0C\\u7B97\\u6CD5\\u7684\\u5185\\u5FAA\\u73AF\\u4ECD\\u7136\\u5FC5\\u987B\\u904D\\u5386\\u6570\\u7EC4\\u7684\\u5DF2\\u6392\\u5E8F\\u90E8\\u5206\\uFF0C\\u4EE5\\u4FBF\\u627E\\u5230\\u63D2\\u5165\\u5F53\\u524D\\u5143\\u7D20\\u7684\\u6B63\\u786E\\u4F4D\\u7F6E\\u3002\"]}),`\n`]}),`\n`,(0,r.jsx)(e.h3,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u63D2\\u5165\\u6392\\u5E8F\\u7684\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u4E3AO(1)\\uFF0C\\u56E0\\u4E3A\\u5B83\\u8FDB\\u884C\\u539F\\u5730\\u6392\\u5E8F\\uFF0C\\u4E0D\\u9700\\u8981\\u4E0E\\u8F93\\u5165\\u5927\\u5C0F\\u6210\\u6BD4\\u4F8B\\u7684\\u989D\\u5916\\u5B58\\u50A8\\u3002\"})]})}function k(n={}){let{wrapper:e}=n.components||{};return e?(0,r.jsx)(e,Object.assign({},n,{children:(0,r.jsx)(p,n)})):p(n)}var S=k;return y(M);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/intervals-combine-overlapping/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/intervals-combine-overlapping/locales/zh-CN.json new file mode 100644 index 000000000..ec89c62ef --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/intervals-combine-overlapping/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var u=Object.create;var l=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var f=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),j=(r,e)=>{for(var t in e)l(r,t,{get:e[t],enumerable:!0})},a=(r,e,t,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of x(e))!v.call(r,i)&&i!==t&&l(r,i,{get:()=>e[i],enumerable:!(o=m(e,i))||o.enumerable});return r};var _=(r,e,t)=>(t=r!=null?u(g(r)):{},a(e||!r||!r.__esModule?l(t,\"default\",{value:r,enumerable:!0}):t,r)),M=r=>a(l({},\"__esModule\",{value:!0}),r);var d=f((E,s)=>{s.exports=_jsx_runtime});var y={};j(y,{default:()=>X,frontmatter:()=>C});var n=_(d());var c=MDXTestExamples;var h=[{input:[[\"intervals\",[[1,5],[6,10],[11,15]]]],output:[[1,5],[6,10],[11,15]],explanation:\"None of the intervals overlap, so they remain the same.\"},{input:[[\"intervals\",[[1,3],[3,5]]]],output:[[1,5]],explanation:\"Intervals [1,3] and [3,5] are considered overlapping and are therefore are merged into [1,5].\"},{input:[[\"intervals\",[[1,5],[2,4],[4,6],[7,8]]]],output:[[1,6],[7,8]],explanation:\"Intervals [1,5], [2,4] and [4,6] are considered overlapping and are therefore merged into [1,6].\"}];var C={title:\"\\u5408\\u5E76\\u91CD\\u53E0\\u533A\\u95F4\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u5408\\u5E76\\u91CD\\u53E0\\u533A\\u95F4\\u7684\\u51FD\\u6570\"};function p(r){let e=Object.assign({p:\"p\",code:\"code\",strong:\"strong\",h3:\"h3\",ul:\"ul\",li:\"li\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\",(0,n.jsx)(e.code,{children:\"intervals\"}),\"\\u6570\\u7EC4\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u533A\\u95F4\\u8868\\u793A\\u4E3A\",(0,n.jsx)(e.code,{children:\"[start, end]\"}),\"\\u3002\\u6BCF\\u5BF9\\u8868\\u793A\\u6570\\u8F74\\u4E0A\\u533A\\u95F4\\u7684\\u5F00\\u59CB\\u548C\\u7ED3\\u675F\\u3002\\u4F8B\\u5982\\uFF0C\",(0,n.jsx)(e.code,{children:\"[1, 3]\"}),\"\\u8868\\u793A\\u4ECE1\\u5F00\\u59CB\\u52303\\u7ED3\\u675F\\u7684\\u533A\\u95F4\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.strong,{children:\"\\u5408\\u5E76\\u6570\\u7EC4\\u4E2D\\u6240\\u6709\\u91CD\\u53E0\\u7684\\u533A\\u95F4\"}),\"\\uFF0C\\u5E76\\u8FD4\\u56DE\\u4E00\\u4E2A\",(0,n.jsx)(e.strong,{children:\"\\u975E\\u91CD\\u53E0\\u533A\\u95F4\"}),\"\\u6570\\u7EC4\\uFF0C\\u8BE5\\u6570\\u7EC4\\u5B8C\\u5168\\u8986\\u76D6\\u8F93\\u5165\\u533A\\u95F4\\u6307\\u5B9A\\u7684\\u8303\\u56F4\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"intervals: Array<[number, number]>\"}),\": \\u6574\\u6570\\u5BF9\\u6570\\u7EC4\"]}),`\n`]}),`\n`,(0,n.jsx)(c,{testCases:h}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"intervals.length\"}),\" <= 100\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"intervals[i].length\"}),\" == 2\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"0 <= \",(0,n.jsx)(e.code,{children:\"start\"}),\" <= \",(0,n.jsx)(e.code,{children:\"end\"}),\" <= 10,000\"]}),`\n`]})]})}function D(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(p,r)})):p(r)}var X=D;return M(y);})();\n;return Component;", + "info": { + "excerpt": "实现一个合并重叠区间的函数", + "title": "合并重叠区间" + }, + "solution": "var Component=(()=>{var u=Object.create;var t=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var I=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),x=(r,e)=>{for(var i in e)t(r,i,{get:e[i],enumerable:!0})},h=(r,e,i,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let l of v(e))!f.call(r,l)&&l!==i&&t(r,l,{get:()=>e[l],enumerable:!(o=g(e,l))||o.enumerable});return r};var C=(r,e,i)=>(i=r!=null?u(b(r)):{},h(e||!r||!r.__esModule?t(i,\"default\",{value:r,enumerable:!0}):i,r)),j=r=>h(t({},\"__esModule\",{value:!0}),r);var c=I((k,a)=>{a.exports=_jsx_runtime});var N={};x(N,{default:()=>D});var n=C(c());var d=MDXCodeBlock;var m=`export default function mergeOverlappingIntervals(\n intervals: number[][],\n): number[][] {\n // Sort the intervals by their starting points\n intervals.sort((a, b) => a[0] - b[0]);\n\n // Initialize an array to hold the merged intervals\n let merged: number[][] = [];\n\n // Iterate through each interval\n for (let interval of intervals) {\n // If the merged list is empty or the current interval does not overlap with the previous, append it\n if (merged.length === 0 || merged[merged.length - 1][1] < interval[0]) {\n merged.push(interval);\n }\n // Otherwise, there is overlap, so merge the current and previous intervals\n else {\n merged[merged.length - 1][1] = Math.max(\n merged[merged.length - 1][1],\n interval[1],\n );\n }\n }\n\n // Return the merged intervals\n return merged;\n}\n`;var s=`const overlap = (a: number[], b: number[]): boolean => {\n return a[0] <= b[1] && b[0] <= a[1];\n};\n\nconst buildGraph = (intervals: number[][]): Map => {\n let graph: Map = new Map();\n // Iterate through each pair of intervals\n for (let i = 0; i < intervals.length; i++) {\n for (let j = i + 1; j < intervals.length; j++) {\n // If intervals overlap, add an edge in the graph\n if (overlap(intervals[i], intervals[j])) {\n if (graph.has(intervals[i])) {\n graph.get(intervals[i])?.push(intervals[j]);\n } else {\n graph.set(intervals[i], [intervals[j]]);\n }\n if (graph.has(intervals[j])) {\n graph.get(intervals[j])?.push(intervals[i]);\n } else {\n graph.set(intervals[j], [intervals[i]]);\n }\n }\n }\n }\n return graph;\n};\n\nconst mergeNodes = (nodes: number[][]): number[] => {\n let minStart: number = Infinity;\n let maxEnd: number = -Infinity;\n // Find the minimum start and maximum end among the nodes\n for (let node of nodes) {\n minStart = Math.min(minStart, node[0]);\n maxEnd = Math.max(maxEnd, node[1]);\n }\n return [minStart, maxEnd];\n};\n\nconst markComponentDFS = (\n start: number[],\n graph: Map,\n nodesInComp: Record,\n compNumber: number,\n visited: Set,\n): void => {\n let stack: number[][] = [start];\n // Perform DFS\n while (stack.length) {\n let node: number[] | undefined = stack.pop();\n if (node && !visited.has(node)) {\n visited.add(node);\n if (nodesInComp[compNumber]) {\n nodesInComp[compNumber].push(node);\n } else {\n nodesInComp[compNumber] = [node];\n }\n // Add all unvisited neighbors to the stack\n if (graph.has(node)) {\n for (let child of graph.get(node) as number[][]) {\n stack.push(child);\n }\n }\n }\n }\n};\n\n// Main function to merge all overlapping intervals\nexport default function mergeOverlappingIntervals(\n intervals: number[][],\n): number[][] {\n // Build the graph\n let graph: Map = buildGraph(intervals);\n let nodesInComp: Record = {};\n let visited: Set = new Set();\n let compNumber: number = 0;\n // Perform DFS to find all connected components\n for (let interval of intervals) {\n if (!visited.has(interval)) {\n markComponentDFS(interval, graph, nodesInComp, compNumber, visited);\n compNumber++;\n }\n }\n let merged: number[][] = [];\n // Merge each connected component\n for (let comp = 0; comp < compNumber; comp++) {\n merged.push(mergeNodes(nodesInComp[comp]));\n }\n return merged;\n}\n`;function p(r){let e=Object.assign({h2:\"h2\",p:\"p\",h3:\"h3\",ol:\"ol\",li:\"li\",code:\"code\",ul:\"ul\",strong:\"strong\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u6392\\u5E8F\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u95EE\\u9898\\u6D89\\u53CA\\u5C06\\u91CD\\u53E0\\u7684\\u533A\\u95F4\\u5408\\u5E76\\u6210\\u4E00\\u4E2A\\u5355\\u4E00\\u7684\\u533A\\u95F4\\uFF0C\\u9488\\u5BF9\\u6BCF\\u4E2A\\u91CD\\u53E0\\u7EC4\\u3002\\u8BE5\\u65B9\\u6CD5\\u4F7F\\u7528\\u6392\\u5E8F\\u6765\\u786E\\u4FDD\\u533A\\u95F4\\u6309\\u5176\\u5F00\\u59CB\\u65F6\\u95F4\\u7684\\u5347\\u5E8F\\u5904\\u7406\\u3002\\u901A\\u8FC7\\u8FED\\u4EE3\\u6392\\u5E8F\\u540E\\u7684\\u533A\\u95F4\\uFF0C\\u53EF\\u4EE5\\u6709\\u6548\\u5730\\u68C0\\u6D4B\\u548C\\u5408\\u5E76\\u91CD\\u53E0\\u90E8\\u5206\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u6309\\u5F00\\u59CB\\u65F6\\u95F4\\u5BF9\\u533A\\u95F4\\u8FDB\\u884C\\u6392\\u5E8F\\uFF0C\\u786E\\u4FDD\\u6240\\u6709\\u6F5C\\u5728\\u7684\\u91CD\\u53E0\\u90E8\\u5206\\u8FDE\\u7EED\\u51FA\\u73B0\\uFF0C\\u4ECE\\u800C\\u51CF\\u5C11\\u4E0D\\u5FC5\\u8981\\u7684\\u6BD4\\u8F83\\u3002\\u5982\\u679C\\u4E0D\\u8FDB\\u884C\\u6392\\u5E8F\\uFF0C\\u66B4\\u529B\\u65B9\\u6CD5\\u5C06\\u6D89\\u53CA\\u5C06\\u6BCF\\u4E2A\\u533A\\u95F4\\u4E0E\\u6240\\u6709\\u5176\\u4ED6\\u533A\\u95F4\\u8FDB\\u884C\\u6BD4\\u8F83\\uFF0C\\u5BFC\\u81F4\\u91CD\\u590D\\u5DE5\\u4F5C\\u548C\\u6548\\u7387\\u4F4E\\u4E0B\\u3002\\u66B4\\u529B\\u65B9\\u6CD5\\u7684\\u74F6\\u9888\\u5728\\u4E8E\\u8FD9\\u4E9B\\u5197\\u4F59\\u7684\\u6BD4\\u8F83\\uFF0C\\u800C\\u6392\\u5E8F\\u6D88\\u9664\\u4E86\\u8FD9\\u4E9B\\u6BD4\\u8F83\\u3002\\u6392\\u5E8F\\u540E\\uFF0C\\u53EA\\u9700\\u904D\\u5386\\u4E00\\u6B21\\u533A\\u95F4\\u5373\\u53EF\\u901A\\u8FC7\\u5C06\\u5F53\\u524D\\u533A\\u95F4\\u4E0E\\u6700\\u540E\\u4E00\\u4E2A\\u5408\\u5E76\\u7684\\u533A\\u95F4\\u8FDB\\u884C\\u6BD4\\u8F83\\u6765\\u5408\\u5E76\\u91CD\\u53E0\\u90E8\\u5206\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u6309\\u6BCF\\u4E2A\\u533A\\u95F4\\u7684\\u8D77\\u59CB\\u70B9\\u5BF9 \",(0,n.jsx)(e.code,{children:\"intervals\"}),\" \\u6570\\u7EC4\\u8FDB\\u884C\\u5347\\u5E8F\\u6392\\u5E8F\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u7A7A\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"merged\"}),\" \\u4EE5\\u5B58\\u50A8\\u5408\\u5E76\\u540E\\u7684\\u533A\\u95F4\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u6392\\u5E8F\\u540E\\u7684\\u6570\\u7EC4\\u4E2D\\u7684\\u6BCF\\u4E2A\\u533A\\u95F4\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"merged\"}),\" \\u6570\\u7EC4\\u4E3A\\u7A7A\\uFF0C\\u6216\\u8005\\u5F53\\u524D\\u533A\\u95F4\\u4E0E \",(0,n.jsx)(e.code,{children:\"merged\"}),\" \\u4E2D\\u7684\\u6700\\u540E\\u4E00\\u4E2A\\u533A\\u95F4\\u4E0D\\u91CD\\u53E0\\uFF0C\\u5219\\u5C06\\u5F53\\u524D\\u533A\\u95F4\\u8FFD\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"merged\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5B58\\u5728\\u91CD\\u53E0\\uFF0C\\u5219\\u5C06 \",(0,n.jsx)(e.code,{children:\"merged\"}),\" \\u4E2D\\u6700\\u540E\\u4E00\\u4E2A\\u533A\\u95F4\\u7684\\u7ED3\\u675F\\u65F6\\u95F4\\u66F4\\u65B0\\u4E3A\\u5176\\u5F53\\u524D\\u7ED3\\u675F\\u65F6\\u95F4\\u548C\\u5F53\\u524D\\u533A\\u95F4\\u7684\\u7ED3\\u675F\\u65F6\\u95F4\\u7684\\u6700\\u5927\\u503C\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE\\u5305\\u542B\\u6240\\u6709\\u5408\\u5E76\\u533A\\u95F4\\u7684 \",(0,n.jsx)(e.code,{children:\"merged\"}),\" \\u6570\\u7EC4\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(d,{children:m}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n log n)\"}),\"\\u3002\\u5BF9\\u533A\\u95F4\\u8FDB\\u884C\\u6392\\u5E8F\\u9700\\u8981 O(n log n)\\uFF0C\\u540E\\u7EED\\u904D\\u5386\\u533A\\u95F4\\u9700\\u8981 O(n)\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u5982\\u679C\\u6CA1\\u6709\\u4EFB\\u4F55\\u533A\\u95F4\\u91CD\\u53E0\\uFF0C\",(0,n.jsx)(e.code,{children:\"merged\"}),\" \\u6570\\u7EC4\\u6700\\u591A\\u53EF\\u4EE5\\u5BB9\\u7EB3\\u6240\\u6709\\u533A\\u95F4\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u8FDE\\u901A\\u5206\\u91CF\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u53EF\\u4EE5\\u4F7F\\u7528\\u56FE\\u8BBA\\u4E2D\\u7684\\u8FDE\\u901A\\u5206\\u91CF\\u7684\\u6982\\u5FF5\\u6765\\u89E3\\u51B3\\u5408\\u5E76\\u91CD\\u53E0\\u533A\\u95F4\\u7684\\u95EE\\u9898\\u3002\\u6BCF\\u4E2A\\u533A\\u95F4\\u88AB\\u89C6\\u4E3A\\u56FE\\u4E2D\\u7684\\u4E00\\u4E2A\\u8282\\u70B9\\uFF0C\\u5982\\u679C\\u4E24\\u4E2A\\u8282\\u70B9\\u5BF9\\u5E94\\u7684\\u533A\\u95F4\\u91CD\\u53E0\\uFF0C\\u5219\\u5728\\u5B83\\u4EEC\\u4E4B\\u95F4\\u521B\\u5EFA\\u4E00\\u6761\\u8FB9\\u3002\\u76EE\\u6807\\u662F\\u8BC6\\u522B\\u8BE5\\u56FE\\u4E2D\\u7684\\u6240\\u6709\\u8FDE\\u901A\\u5206\\u91CF\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u5206\\u91CF\\u4EE3\\u8868\\u4E00\\u7EC4\\u91CD\\u53E0\\u7684\\u533A\\u95F4\\u3002\\u7136\\u540E\\u53EF\\u4EE5\\u5C06\\u6BCF\\u4E2A\\u5206\\u91CF\\u5408\\u5E76\\u6210\\u4E00\\u4E2A\\u5355\\u4E00\\u7684\\u533A\\u95F4\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u901A\\u8FC7\\u6784\\u5EFA\\u8FDE\\u63A5\\u533A\\u95F4\\u7684\\u56FE\\u5E76\\u4F7F\\u7528\\u6DF1\\u5EA6\\u4F18\\u5148\\u641C\\u7D22 (DFS) \\u6765\\u8BC6\\u522B\\u8FDE\\u901A\\u5206\\u91CF\\uFF0C\\u8BE5\\u8FC7\\u7A0B\\u53D8\\u5F97\\u7ED3\\u6784\\u5316\\u5E76\\u907F\\u514D\\u4E86\\u4E0D\\u5FC5\\u8981\\u7684\\u6BD4\\u8F83\\u3002\\u4E00\\u65E6\\u8BC6\\u522B\\u51FA\\u8FD9\\u4E9B\\u5206\\u91CF\\uFF0C\\u5408\\u5E76\\u5B83\\u4EEC\\u5C31\\u53D8\\u5F97\\u5F88\\u7B80\\u5355\\uFF0C\\u56E0\\u4E3A\\u5B83\\u6D89\\u53CA\\u627E\\u5230\\u5206\\u91CF\\u4E2D\\u6240\\u6709\\u533A\\u95F4\\u7684\\u6700\\u5C0F\\u5F00\\u59CB\\u65F6\\u95F4\\u548C\\u6700\\u5927\\u7ED3\\u675F\\u65F6\\u95F4\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u8F85\\u52A9\\u51FD\\u6570 \",(0,n.jsx)(e.code,{children:\"overlap\"}),\"\\uFF0C\\u901A\\u8FC7\\u6BD4\\u8F83\\u4E24\\u4E2A\\u533A\\u95F4\\u7684\\u8D77\\u59CB\\u70B9\\u548C\\u7ED3\\u675F\\u70B9\\u6765\\u68C0\\u67E5\\u5B83\\u4EEC\\u662F\\u5426\\u91CD\\u53E0\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"buildGraph\"}),\" \\u51FD\\u6570\\u6784\\u5EFA\\u4E00\\u4E2A\\u56FE\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u904D\\u5386\\u6240\\u6709\\u533A\\u95F4\\u5BF9\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u4E24\\u4E2A\\u533A\\u95F4\\u91CD\\u53E0\\uFF0C\\u5219\\u5728\\u56FE\\u4E2D\\u7684\\u76F8\\u5E94\\u8282\\u70B9\\u4E4B\\u95F4\\u6DFB\\u52A0\\u4E00\\u6761\\u8FB9\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"mergeNodes\"}),\" \\u51FD\\u6570\\uFF0C\\u901A\\u8FC7\\u627E\\u5230\\u8FDE\\u901A\\u5206\\u91CF\\u4E2D\\u6240\\u6709\\u533A\\u95F4\\u7684\\u6700\\u5C0F\\u5F00\\u59CB\\u70B9\\u548C\\u6700\\u5927\\u7ED3\\u675F\\u70B9\\u6765\\u5408\\u5E76\\u5B83\\u4EEC\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9E\\u73B0 \",(0,n.jsx)(e.code,{children:\"markComponentDFS\"}),\" \\u51FD\\u6570\\u4EE5\\u6267\\u884C DFS\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u4ECE\\u4E00\\u4E2A\\u8282\\u70B9\\u5F00\\u59CB\\uFF0C\\u5C06\\u6240\\u6709\\u8FDE\\u63A5\\u7684\\u8282\\u70B9\\u6807\\u8BB0\\u4E3A\\u540C\\u4E00\\u5206\\u91CF\\u7684\\u4E00\\u90E8\\u5206\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u4F7F\\u7528\\u5806\\u6808\\u9012\\u5F52\\u5730\\u63A2\\u7D22\\u6240\\u6709\\u90BB\\u5C45\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5728\\u4E3B\\u51FD\\u6570\\u4E2D\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"buildGraph\"}),\" \\u6784\\u5EFA\\u533A\\u95F4\\u56FE\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u4F7F\\u7528 DFS \\u8BC6\\u522B\\u6240\\u6709\\u8FDE\\u901A\\u5206\\u91CF\\uFF0C\\u5E76\\u5C06\\u533A\\u95F4\\u5206\\u7EC4\\u6210\\u5206\\u91CF\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"mergeNodes\"}),\" \\u5C06\\u6BCF\\u4E2A\\u5206\\u91CF\\u5408\\u5E76\\u6210\\u4E00\\u4E2A\\u5355\\u4E00\\u7684\\u533A\\u95F4\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8FD4\\u56DE\\u5408\\u5E76\\u540E\\u7684\\u533A\\u95F4\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(d,{children:s}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,n.jsx)(\"sup\",{children:\"2\"}),\")\"]}),\"\\u3002\\u6784\\u5EFA\\u56FE\\u9700\\u8981\\u6BD4\\u8F83\\u6BCF\\u5BF9\\u533A\\u95F4\\uFF0C\\u5BFC\\u81F4 O(n\",(0,n.jsx)(\"sup\",{children:\"2\"}),\") \\u6B21\\u64CD\\u4F5C\\u3002\"]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,n.jsx)(\"sup\",{children:\"2\"}),\")\"]}),\"\\u3002\\u5728\\u6700\\u574F\\u7684\\u60C5\\u51B5\\u4E0B\\uFF0C\\u8BE5\\u56FE\\u6700\\u591A\\u53EF\\u4EE5\\u6709 O(n\",(0,n.jsx)(\"sup\",{children:\"2\"}),\") \\u6761\\u8FB9\\uFF0C\\u5E76\\u4E14 \",(0,n.jsx)(e.code,{children:\"visited\"}),\" \\u96C6\\u5408\\u548C \",(0,n.jsx)(e.code,{children:\"nodesInComp\"}),\" \\u5B58\\u50A8\\u4F1A\\u968F\\u7740\\u533A\\u95F4\\u6570\\u91CF\\u7684\\u589E\\u52A0\\u800C\\u6269\\u5C55\\u3002\"]}),`\n`]}),`\n`]})]})}function O(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(p,r)})):p(r)}var D=O;return j(N);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/intervals-meeting-calendar/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/intervals-meeting-calendar/locales/zh-CN.json new file mode 100644 index 000000000..c92c335e1 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/intervals-meeting-calendar/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var u=Object.create;var l=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var v=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),b=(t,e)=>{for(var i in e)l(t,i,{get:e[i],enumerable:!0})},s=(t,e,i,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of x(e))!g.call(t,r)&&r!==i&&l(t,r,{get:()=>e[r],enumerable:!(o=m(e,r))||o.enumerable});return t};var j=(t,e,i)=>(i=t!=null?u(f(t)):{},s(e||!t||!t.__esModule?l(i,\"default\",{value:t,enumerable:!0}):i,t)),_=t=>s(l({},\"__esModule\",{value:!0}),t);var a=v((k,c)=>{c.exports=_jsx_runtime});var X={};b(X,{default:()=>D,frontmatter:()=>M});var n=j(a());var d=MDXTestExamples;var h=[{input:[[\"intervals\",[[83,99]]]],output:!0,explanation:\"There is only one meeting, so there is no possibility of overlap.\"},{input:[[\"intervals\",[[1,5],[5,10],[10,15]]]],output:!0,explanation:\"The meetings are back-to-back but do not overlap.\"},{input:[[\"intervals\",[[8,10],[1,3],[2,6],[15,18]]]],output:!1,explanation:\"The meetings [1, 3] and [2, 6] overlap, so it is not possible to attend all meetings.\"}];var M={title:\"\\u4F1A\\u8BAE\\u65E5\\u5386\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u68C0\\u67E5\\u662F\\u5426\\u53EF\\u4EE5\\u53C2\\u52A0\\u6240\\u6709\\u4F1A\\u8BAE\"};function p(t){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u4F1A\\u8BAE\\u65F6\\u95F4 \",(0,n.jsx)(e.code,{children:\"intervals\"}),\" \\u6570\\u7EC4\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u5143\\u7D20\\u4EE3\\u8868\\u4E00\\u4E2A\\u4F1A\\u8BAE\\u65F6\\u95F4\\uFF0C\\u683C\\u5F0F\\u4E3A \",(0,n.jsx)(e.code,{children:\"[start, end]\"}),\"\\uFF0C\\u786E\\u5B9A\\u4E00\\u4E2A\\u4EBA\\u662F\\u5426\\u53EF\\u4EE5\\u53C2\\u52A0\\u6240\\u6709\\u4F1A\\u8BAE\\uFF0C\\u800C\\u4F1A\\u8BAE\\u65F6\\u95F4\\u4E4B\\u95F4\\u6CA1\\u6709\\u4EFB\\u4F55\\u91CD\\u53E0\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4E00\\u4E2A\\u6574\\u6570\\u7684\\u4E8C\\u7EF4\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"intervals\"}),\"\\uFF0C\\u5927\\u5C0F\\u4E3A \",(0,n.jsx)(e.code,{children:\"n x 2\"}),\"\\uFF0C\\u5176\\u4E2D \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u662F\\u4F1A\\u8BAE\\u7684\\u6570\\u91CF\\uFF0C\\u6BCF\\u4E2A\\u533A\\u95F4 \",(0,n.jsx)(e.code,{children:\"[start, end]\"}),\" \\u4EE3\\u8868\\u4E00\\u4E2A\\u4F1A\\u8BAE\\uFF0C\\u5F00\\u59CB\\u65F6\\u95F4\\u4E3A start\\uFF0C\\u7ED3\\u675F\\u65F6\\u95F4\\u4E3A end\"]}),`\n`]}),`\n`,(0,n.jsx)(d,{testCases:h}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"0 <= \",(0,n.jsx)(e.code,{children:\"intervals.length\"}),\" <= 1000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"intervals[i].length\"}),\" == 2\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"0 <= \",(0,n.jsx)(e.code,{children:\"start\"}),\" < \",(0,n.jsx)(e.code,{children:\"end\"}),\" <= 1,000,000\"]}),`\n`]})]})}function C(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(p,t)})):p(t)}var D=C;return _(X);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来检查是否可以参加所有会议", + "title": "会议日历" + }, + "solution": "var Component=(()=>{var v=Object.create;var t=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var x=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),O=(r,e)=>{for(var l in e)t(r,l,{get:e[l],enumerable:!0})},c=(r,e,l,a)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of p(e))!b.call(r,i)&&i!==l&&t(r,i,{get:()=>e[i],enumerable:!(a=g(e,i))||a.enumerable});return r};var j=(r,e,l)=>(l=r!=null?v(m(r)):{},c(e||!r||!r.__esModule?t(l,\"default\",{value:r,enumerable:!0}):l,r)),C=r=>c(t({},\"__esModule\",{value:!0}),r);var h=x((X,d)=>{d.exports=_jsx_runtime});var k={};O(k,{default:()=>B});var n=j(h());var o=MDXCodeBlock;var s=`export default function isMeetingCalendarValid(intervals: number[][]): boolean {\n // Sort the intervals based on the start times\n intervals.sort((a, b) => a[0] - b[0]);\n\n // Iterate through the sorted intervals\n for (let i = 0; i < intervals.length - 1; i++) {\n // Check if the end time of the current interval is greater than the start time of the next interval\n if (intervals[i][1] > intervals[i + 1][0]) {\n return false; // If there is an overlap, return false\n }\n }\n\n // If no overlaps are found, return true\n return true;\n}\n`;var u=`export default function isMeetingCalendarValid(intervals: number[][]): boolean {\n const overlap = (interval1: number[], interval2: number[]): boolean => {\n return (\n (interval1[0] >= interval2[0] && interval1[0] < interval2[1]) ||\n (interval2[0] >= interval1[0] && interval2[0] < interval1[1])\n );\n };\n\n // Iterate through each pair of intervals to check for overlaps\n for (let i = 0; i < intervals.length; i++) {\n for (let j = i + 1; j < intervals.length; j++) {\n if (overlap(intervals[i], intervals[j])) {\n return false; // If any overlap is found, return false\n }\n }\n }\n return true; // If no overlaps are found, return true\n}\n`;function f(r){let e=Object.assign({h2:\"h2\",p:\"p\",h3:\"h3\",ol:\"ol\",li:\"li\",code:\"code\",ul:\"ul\",strong:\"strong\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u66B4\\u529B\\u65B9\\u6CD5\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u6734\\u7D20\\u7684\\u65B9\\u6CD5\\u662F\\u901A\\u8FC7\\u9A8C\\u8BC1\\u4E00\\u7EC4\\u95F4\\u9694\\u662F\\u5426\\u53EF\\u4EE5\\u901A\\u8FC7\\u68C0\\u67E5\\u6CA1\\u6709\\u4E24\\u4E2A\\u95F4\\u9694\\u91CD\\u53E0\\u6765\\u5F62\\u6210\\u6709\\u6548\\u7684\\u4F1A\\u8BAE\\u65E5\\u5386\\u3002 \\u5173\\u952E\\u601D\\u60F3\\u662F\\u904D\\u5386\\u6240\\u6709\\u95F4\\u9694\\u5BF9\\u5E76\\u6BD4\\u8F83\\u5B83\\u4EEC\\u7684\\u5F00\\u59CB\\u548C\\u7ED3\\u675F\\u65F6\\u95F4\\u3002 \\u5BF9\\u4E8E\\u6BCF\\u4E00\\u5BF9\\uFF0C\\u91CD\\u53E0\\u662F\\u901A\\u8FC7\\u68C0\\u67E5\\u4E00\\u4E2A\\u95F4\\u9694\\u662F\\u5426\\u5728\\u53E6\\u4E00\\u4E2A\\u95F4\\u9694\\u7ED3\\u675F\\u4E4B\\u524D\\u5F00\\u59CB\\u4EE5\\u53CA\\u53CD\\u4E4B\\u4EA6\\u7136\\u6765\\u786E\\u5B9A\\u7684\\u3002 \\u5982\\u679C\\u68C0\\u6D4B\\u5230\\u4EFB\\u4F55\\u91CD\\u53E0\\uFF0C\\u5219\\u65E5\\u5386\\u88AB\\u8BA4\\u4E3A\\u65E0\\u6548\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u8F85\\u52A9\\u51FD\\u6570 \",(0,n.jsx)(e.code,{children:\"overlap\"}),\"\\uFF0C\\u5B83\\u5C06\\u4E24\\u4E2A\\u95F4\\u9694\\u4F5C\\u4E3A\\u8F93\\u5165\\uFF0C\\u5E76\\u901A\\u8FC7\\u6BD4\\u8F83\\u5B83\\u4EEC\\u7684\\u5F00\\u59CB\\u548C\\u7ED3\\u675F\\u65F6\\u95F4\\u6765\\u68C0\\u67E5\\u5B83\\u4EEC\\u662F\\u5426\\u91CD\\u53E0\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u5D4C\\u5957\\u5FAA\\u73AF\\u904D\\u5386\\u6240\\u6709\\u95F4\\u9694\\u5BF9\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E00\\u5BF9\\u95F4\\u9694\\uFF0C\\u8C03\\u7528 \",(0,n.jsx)(e.code,{children:\"overlap\"}),\" \\u51FD\\u6570\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u51FD\\u6570\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\uFF0C\\u5219\\u7ACB\\u5373\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\uFF0C\\u56E0\\u4E3A\\u8FD9\\u4E9B\\u95F4\\u9694\\u65E0\\u6548\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5728\\u6240\\u6709\\u6BD4\\u8F83\\u4E4B\\u540E\\u672A\\u627E\\u5230\\u91CD\\u53E0\\u7684\\u95F4\\u9694\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(o,{children:u}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,n.jsx)(\"sup\",{children:\"2\"}),\")\"]}),\"\\u3002 \\u8BE5\\u7B97\\u6CD5\\u904D\\u5386\\u6240\\u6709\\u95F4\\u9694\\u5BF9\\uFF0C\\u5BFC\\u81F4 n(n - 1)/2 \\u6B21\\u6BD4\\u8F83\\uFF0C\\u5373 O(n\",(0,n.jsx)(\"sup\",{children:\"2\"}),\")\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002 \\u8BE5\\u7B97\\u6CD5\\u4F7F\\u7528\\u6052\\u5B9A\\u7A7A\\u95F4\\uFF0C\\u56E0\\u4E3A\\u5B83\\u4E0D\\u9700\\u8981\\u4EFB\\u4F55\\u989D\\u5916\\u7684\\u6570\\u636E\\u7ED3\\u6784\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u6392\\u5E8F\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u4F9D\\u8D56\\u4E8E\\u6309\\u5176\\u5F00\\u59CB\\u65F6\\u95F4\\u5BF9\\u95F4\\u9694\\u8FDB\\u884C\\u6392\\u5E8F\\uFF0C\\u4EE5\\u4FDD\\u8BC1\\u91CD\\u53E0\\u7684\\u95F4\\u9694\\u5F7C\\u6B64\\u76F8\\u90BB\\u51FA\\u73B0\\u3002 \\u6392\\u5E8F\\u786E\\u4FDD\\u95F4\\u9694\\u6309\\u5176\\u5F00\\u59CB\\u65F6\\u95F4\\u6309\\u65F6\\u95F4\\u987A\\u5E8F\\u6392\\u5217\\u3002 \\u5982\\u679C\\u4E24\\u4E2A\\u95F4\\u9694\\u91CD\\u53E0\\uFF0C\\u5219\\u8F83\\u65E9\\u95F4\\u9694\\u7684\\u7ED3\\u675F\\u65F6\\u95F4\\u5C06\\u5EF6\\u4F38\\u5230\\u4E0B\\u4E00\\u4E2A\\u95F4\\u9694\\u7684\\u5F00\\u59CB\\u65F6\\u95F4\\u8303\\u56F4\\u5185\\u3002 \\u901A\\u8FC7\\u6309\\u5176\\u5F00\\u59CB\\u65F6\\u95F4\\u7684\\u5347\\u5E8F\\u6392\\u5217\\u95F4\\u9694\\uFF0C\\u53EA\\u9700\\u5C06\\u6BCF\\u4E2A\\u95F4\\u9694\\u4E0E\\u6392\\u5E8F\\u5217\\u8868\\u4E2D\\u7684\\u4E0B\\u4E00\\u4E2A\\u95F4\\u9694\\u8FDB\\u884C\\u6BD4\\u8F83\\u5373\\u53EF\\u68C0\\u6D4B\\u91CD\\u53E0\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u6B64\\u65B9\\u6CD5\\u6D88\\u9664\\u4E86\\u86EE\\u529B\\u65B9\\u6CD5\\u4E2D\\u5B58\\u5728\\u7684\\u4E0D\\u5FC5\\u8981\\u7684\\u6BD4\\u8F83\\u3002 \\u65E0\\u9700\\u6BD4\\u8F83\\u6BCF\\u5BF9\\u95F4\\u9694\\uFF0C\\u53EA\\u9700\\u68C0\\u67E5\\u6392\\u5E8F\\u987A\\u5E8F\\u4E2D\\u76F8\\u90BB\\u7684\\u95F4\\u9694\\uFF0C\\u56E0\\u4E3A\\u5728\\u6392\\u5E8F\\u540E\\uFF0C\\u4EFB\\u4F55\\u91CD\\u53E0\\u7684\\u95F4\\u9694\\u90FD\\u4FDD\\u8BC1\\u662F\\u8FDE\\u7EED\\u7684\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"sort\"}),\" \\u65B9\\u6CD5\\u6309\\u5176\\u5F00\\u59CB\\u65F6\\u95F4\\u6309\\u5347\\u5E8F\\u5BF9\\u95F4\\u9694\\u8FDB\\u884C\\u6392\\u5E8F\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u6392\\u5E8F\\u540E\\u7684\\u95F4\\u9694\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u95F4\\u9694\\uFF0C\\u68C0\\u67E5\\u5176\\u7ED3\\u675F\\u65F6\\u95F4\\u662F\\u5426\\u5927\\u4E8E\\u4E0B\\u4E00\\u4E2A\\u95F4\\u9694\\u7684\\u5F00\\u59CB\\u65F6\\u95F4\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u68C0\\u6D4B\\u5230\\u91CD\\u53E0\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\uFF0C\\u56E0\\u4E3A\\u65E5\\u5386\\u65E0\\u6548\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5FAA\\u73AF\\u5728\\u672A\\u68C0\\u6D4B\\u5230\\u4EFB\\u4F55\\u91CD\\u53E0\\u7684\\u60C5\\u51B5\\u4E0B\\u5B8C\\u6210\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(o,{children:s}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n log n)\"}),\"\\u3002 \\u6392\\u5E8F\\u95F4\\u9694\\u5360\\u636E\\u4E86\\u8FD0\\u884C\\u65F6\\uFF0C\\u9700\\u8981 O(n log n)\\uFF0C\\u800C\\u7EBF\\u6027\\u626B\\u63CF\\u95F4\\u9694\\u9700\\u8981 O(n)\\uFF0C\\u603B\\u5171\\u5F97\\u5230 O(n log n)\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002 \\u8BE5\\u7B97\\u6CD5\\u4F7F\\u7528\\u6052\\u5B9A\\u7A7A\\u95F4\\uFF0C\\u56E0\\u4E3A\\u5B83\\u5C31\\u5730\\u4FEE\\u6539\\u95F4\\u9694\\u6570\\u7EC4\\uFF0C\\u5E76\\u4E14\\u4E0D\\u9700\\u8981\\u989D\\u5916\\u7684\\u6570\\u636E\\u7ED3\\u6784\\u3002\"]}),`\n`]})]})}function I(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(f,r)})):f(r)}var B=I;return C(k);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/intervals-merge-new/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/intervals-merge-new/locales/zh-CN.json new file mode 100644 index 000000000..4e95922f9 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/intervals-merge-new/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var l=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var g=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),f=(t,e)=>{for(var r in e)l(t,r,{get:e[r],enumerable:!0})},s=(t,e,r,a)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of v(e))!w.call(t,i)&&i!==r&&l(t,i,{get:()=>e[i],enumerable:!(a=m(e,i))||a.enumerable});return t};var j=(t,e,r)=>(r=t!=null?p(x(t)):{},s(e||!t||!t.__esModule?l(r,\"default\",{value:t,enumerable:!0}):r,t)),T=t=>s(l({},\"__esModule\",{value:!0}),t);var c=g((I,d)=>{d.exports=_jsx_runtime});var C={};f(C,{default:()=>y,frontmatter:()=>b});var n=j(c());var o=MDXTestExamples;var h=[{input:[[\"intervals\",[[1,2],[3,5],[6,10],[11,12],[13,16]]],[\"newInterval\",[8,15]]],output:[[1,2],[3,5],[6,16]],explanation:\"The new interval [8, 15] overlaps with [6, 10], [11, 12], and [13, 16]. These intervals merge to form [6, 16], and the result is [[1, 2], [3, 5], [6, 16]].\"},{input:[[\"intervals\",[[1,2],[3,4],[5,6],[7,8]]],[\"newInterval\",[2,5]]],output:[[1,6],[7,8]],explanation:\"The new interval [2, 5] overlaps with [1, 2], [3, 4], and [5, 6]. Merging them results in [1, 6].\"},{input:[[\"intervals\",[[2,4],[6,8],[10,12]]],[\"newInterval\",[15,17]]],output:[[2,4],[6,8],[10,12],[15,17]],explanation:\"The new interval [15, 17] does not overlap with any existing intervals and is simply added at the end.\"}];var b={title:\"\\u5408\\u5E76\\u65B0\\u533A\\u95F4\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u5C06\\u4E00\\u4E2A\\u65B0\\u533A\\u95F4\\u63D2\\u5165\\u7ED9\\u5B9A\\u7684\\u533A\\u95F4\\u4E2D\"};function u(t){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u5DF2\\u6392\\u5E8F\\u7684\\u975E\\u91CD\\u53E0\\u533A\\u95F4\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"intervals\"}),\"\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u533A\\u95F4\\u8868\\u793A\\u4E3A \",(0,n.jsx)(e.code,{children:\"[start, end]\"}),\"\\uFF0C\\u5E76\\u6309 \",(0,n.jsx)(e.code,{children:\"start\"}),\" \\u65F6\\u95F4\\u5347\\u5E8F\\u6392\\u5E8F\\uFF0C\\u5C06\\u4E00\\u4E2A\\u65B0\\u533A\\u95F4 \",(0,n.jsx)(e.code,{children:\"[start, end]\"}),\" \\u63D2\\u5165\\u5230\\u6570\\u7EC4\\u4E2D\\u3002\\u786E\\u4FDD\\u7ED3\\u679C\\u6570\\u7EC4\\u4FDD\\u6301\\u6392\\u5E8F\\uFF0C\\u5E76\\u4E14\\u6CA1\\u6709\\u91CD\\u53E0\\u7684\\u533A\\u95F4\\uFF0C\\u5FC5\\u8981\\u65F6\\u901A\\u8FC7\\u5408\\u5E76\\u4EFB\\u4F55\\u91CD\\u53E0\\u7684\\u533A\\u95F4\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"intervals: Array<[number, number]>\"}),\": \\u6574\\u6570\\u5BF9\\u6570\\u7EC4\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"newInterval: [number, number]\"}),\": \\u8868\\u793A \",(0,n.jsx)(e.code,{children:\"[start, end]\"}),\" \\u7684\\u6574\\u6570\\u5BF9\"]}),`\n`]}),`\n`,(0,n.jsx)(o,{testCases:h}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"intervals.length\"}),\" <= 100\"]}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.code,{children:\"intervals[i].length == 2\"})}),`\n`,(0,n.jsxs)(e.li,{children:[\"0 <= \",(0,n.jsx)(e.code,{children:\"start\"}),\" <= \",(0,n.jsx)(e.code,{children:\"end\"}),\" <= 10,000\"]}),`\n`]})]})}function M(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(u,t)})):u(t)}var y=M;return T(C);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,将一个新区间插入给定的区间中", + "title": "合并新区间" + }, + "solution": "var Component=(()=>{var m=Object.create;var t=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty;var I=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),x=(r,e)=>{for(var l in e)t(r,l,{get:e[l],enumerable:!0})},c=(r,e,l,d)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of f(e))!p.call(r,i)&&i!==l&&t(r,i,{get:()=>e[i],enumerable:!(d=u(e,i))||d.enumerable});return r};var b=(r,e,l)=>(l=r!=null?m(w(r)):{},c(e||!r||!r.__esModule?t(l,\"default\",{value:r,enumerable:!0}):l,r)),O=r=>c(t({},\"__esModule\",{value:!0}),r);var o=I((N,a)=>{a.exports=_jsx_runtime});var _={};x(_,{default:()=>C});var n=b(o());var h=MDXCodeBlock;var s=`export default function mergeNewInterval(\n intervals: number[][],\n newInterval: number[],\n): number[][] {\n let n = intervals.length,\n i = 0,\n res = [];\n\n // Case 1: No overlapping before merging intervals\n // Add all intervals that come before the new interval (no overlap)\n while (i < n && intervals[i][1] < newInterval[0]) {\n res.push(intervals[i]);\n i++;\n }\n\n // Case 2: Overlapping and merging intervals\n // Merge all intervals that overlap with the new interval\n while (i < n && newInterval[1] >= intervals[i][0]) {\n newInterval[0] = Math.min(newInterval[0], intervals[i][0]); // Adjust the start of the new interval\n newInterval[1] = Math.max(newInterval[1], intervals[i][1]); // Adjust the end of the new interval\n i++;\n }\n res.push(newInterval); // Add the merged interval to the result\n\n // Case 3: No overlapping after merging newInterval\n // Add all remaining intervals after the new interval\n while (i < n) {\n res.push(intervals[i]);\n i++;\n }\n\n return res;\n}\n`;var v=`export default function mergeNewInterval(\n intervals: number[][],\n newInterval: number[],\n): number[][] {\n // If the intervals array is empty, return a list containing the newInterval\n if (intervals.length === 0) {\n return [newInterval];\n }\n\n let n = intervals.length;\n let target = newInterval[0]; // The start value of the new interval\n let left = 0,\n right = n - 1;\n\n // Binary search to find the position to insert newInterval\n while (left <= right) {\n let mid = Math.floor((left + right) / 2);\n if (intervals[mid][0] < target) {\n left = mid + 1;\n } else {\n right = mid - 1;\n }\n }\n\n // Insert newInterval at the found position\n intervals.splice(left, 0, newInterval);\n\n // Initialize the result array to hold merged intervals\n let res: number[][] = [];\n for (let interval of intervals) {\n // If res is empty or there is no overlap, add the interval to the result\n if (res.length === 0 || res[res.length - 1][1] < interval[0]) {\n res.push(interval);\n // If there is an overlap, merge the intervals by updating the end of the last interval in res\n } else {\n res[res.length - 1][1] = Math.max(res[res.length - 1][1], interval[1]);\n }\n }\n return res; // Return the merged intervals\n}\n`;function g(r){let e=Object.assign({h2:\"h2\",p:\"p\",h3:\"h3\",ol:\"ol\",li:\"li\",code:\"code\",ul:\"ul\",strong:\"strong\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u7EBF\\u6027\\u641C\\u7D22\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u65B9\\u6CD5\\u901A\\u8FC7\\u6267\\u884C\\u4E00\\u6B21\\u7EBF\\u6027\\u626B\\u63CF\\uFF0C\\u5C06\\u4E00\\u4E2A\\u65B0\\u533A\\u95F4\\u5408\\u5E76\\u5230\\u4E00\\u7EC4\\u975E\\u91CD\\u53E0\\u533A\\u95F4\\u4E2D\\u3002\\u533A\\u95F4\\u6839\\u636E\\u5176\\u4E0E\\u65B0\\u533A\\u95F4\\u4E4B\\u95F4\\u7684\\u5173\\u7CFB\\u5206\\u4E3A\\u4E09\\u4E2A\\u4E0D\\u540C\\u7684\\u9636\\u6BB5\\u8FDB\\u884C\\u5904\\u7406\\uFF1A\\u5B8C\\u5168\\u5728\\u65B0\\u533A\\u95F4\\u4E4B\\u524D\\u7684\\u533A\\u95F4\\u3001\\u91CD\\u53E0\\u7684\\u533A\\u95F4\\u548C\\u5B8C\\u5168\\u5728\\u65B0\\u533A\\u95F4\\u4E4B\\u540E\\u7684\\u533A\\u95F4\\u3002\\u7531\\u4E8E\\u8F93\\u5165\\u533A\\u95F4\\u5DF2\\u7ECF\\u6392\\u5E8F\\uFF0C\\u56E0\\u6B64\\u4E0D\\u9700\\u8981\\u6392\\u5E8F\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u4E0D\\u4E0E\\u65B0\\u533A\\u95F4\\u91CD\\u53E0\\u7684\\u533A\\u95F4\\u5C06\\u539F\\u6837\\u6DFB\\u52A0\\u5230\\u7ED3\\u679C\\u4E2D\\u3002\\u4E0E\\u65B0\\u533A\\u95F4\\u91CD\\u53E0\\u7684\\u533A\\u95F4\\u901A\\u8FC7\\u66F4\\u65B0\\u65B0\\u533A\\u95F4\\u7684\\u5F00\\u59CB\\u548C\\u7ED3\\u675F\\u4EE5\\u8986\\u76D6\\u7EC4\\u5408\\u8303\\u56F4\\u6765\\u8FDB\\u884C\\u5408\\u5E76\\u3002\\u5408\\u5E76\\u6240\\u6709\\u91CD\\u53E0\\u533A\\u95F4\\u540E\\uFF0C\\u5C06\\u65B0\\u533A\\u95F4\\u6DFB\\u52A0\\u5230\\u7ED3\\u679C\\u4E2D\\uFF0C\\u7136\\u540E\\u6DFB\\u52A0\\u5269\\u4F59\\u7684\\u533A\\u95F4\\u3002\\u8FD9\\u79CD\\u65B9\\u6CD5\\u786E\\u4FDD\\u6BCF\\u4E2A\\u533A\\u95F4\\u53EA\\u5904\\u7406\\u4E00\\u6B21\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u7A7A\\u7684\\u7ED3\\u679C\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"res\"}),\"\\uFF0C\\u5E76\\u5C06\\u6307\\u9488 \",(0,n.jsx)(e.code,{children:\"i\"}),\" \\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5904\\u7406\\u65B0\\u533A\\u95F4\\u4E4B\\u524D\\u7684\\u533A\\u95F4\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5F53\\u5F53\\u524D\\u533A\\u95F4\\u7684\\u7ED3\\u675F\\u5C0F\\u4E8E\\u65B0\\u533A\\u95F4\\u7684\\u5F00\\u59CB\\u65F6\\uFF0C\\u5C06\\u8BE5\\u533A\\u95F4\\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"res\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4E3A\\u6BCF\\u4E2A\\u6DFB\\u52A0\\u7684\\u533A\\u95F4\\u9012\\u589E\\u6307\\u9488 \",(0,n.jsx)(e.code,{children:\"i\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5904\\u7406\\u91CD\\u53E0\\u533A\\u95F4\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u5F53\\u5F53\\u524D\\u533A\\u95F4\\u7684\\u5F00\\u59CB\\u5C0F\\u4E8E\\u6216\\u7B49\\u4E8E\\u65B0\\u533A\\u95F4\\u7684\\u7ED3\\u675F\\u65F6\\uFF0C\\u901A\\u8FC7\\u66F4\\u65B0\\u65B0\\u533A\\u95F4\\u7684\\u5F00\\u59CB\\u548C\\u7ED3\\u675F\\u6765\\u5408\\u5E76\\u533A\\u95F4\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5408\\u5E76\\u540E\\u9012\\u589E\\u6307\\u9488 \",(0,n.jsx)(e.code,{children:\"i\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u5408\\u5E76\\u540E\\u7684\\u533A\\u95F4\\uFF08\\u65B0\\u533A\\u95F4\\uFF09\\u6DFB\\u52A0\\u5230\\u7ED3\\u679C\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"res\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5904\\u7406\\u65B0\\u533A\\u95F4\\u4E4B\\u540E\\u7684\\u533A\\u95F4\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u5F53\\u524D\\u6307\\u9488\\u4F4D\\u7F6E \",(0,n.jsx)(e.code,{children:\"i\"}),\" \\u5F00\\u59CB\\uFF0C\\u5C06\\u6240\\u6709\\u5269\\u4F59\\u533A\\u95F4\\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"res\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4E3A\\u6BCF\\u4E2A\\u6DFB\\u52A0\\u7684\\u533A\\u95F4\\u9012\\u589E\\u6307\\u9488 \",(0,n.jsx)(e.code,{children:\"i\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE\\u7ED3\\u679C\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"res\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(h,{children:s}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u6BCF\\u4E2A\\u533A\\u95F4\\u53EA\\u5904\\u7406\\u4E00\\u6B21\\uFF0C\\u5BFC\\u81F4\\u7EBF\\u6027\\u8FD0\\u884C\\u65F6\\u957F\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u7ED3\\u679C\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"res\"}),\" \\u5B58\\u50A8\\u6240\\u6709\\u533A\\u95F4\\uFF0C\\u9700\\u8981\\u4E0E\\u8F93\\u5165\\u5927\\u5C0F\\u6210\\u6BD4\\u4F8B\\u7684\\u7A7A\\u95F4\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u4E8C\\u5206\\u67E5\\u627E\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u7ED3\\u5408\\u4E86\\u4E8C\\u5206\\u67E5\\u627E\\u548C\\u5408\\u5E76\\uFF0C\\u4EE5\\u6709\\u6548\\u5730\\u5C06\\u4E00\\u4E2A\\u65B0\\u533A\\u95F4\\u63D2\\u5165\\u5230\\u5DF2\\u6392\\u5E8F\\u7684\\u533A\\u95F4\\u5217\\u8868\\u4E2D\\uFF0C\\u5E76\\u5408\\u5E76\\u4EFB\\u4F55\\u91CD\\u53E0\\u90E8\\u5206\\u3002\\u4E8C\\u5206\\u67E5\\u627E\\u7528\\u4E8E\\u786E\\u5B9A\\u63D2\\u5165\\u65B0\\u533A\\u95F4\\u57FA\\u4E8E\\u5176\\u5F00\\u59CB\\u65F6\\u95F4\\u7684\\u6B63\\u786E\\u4F4D\\u7F6E\\u3002\\u63D2\\u5165\\u540E\\uFF0C\\u53EA\\u9700\\u904D\\u5386\\u4E00\\u6B21\\u533A\\u95F4\\u5373\\u53EF\\u5408\\u5E76\\u91CD\\u53E0\\u533A\\u95F4\\u3002\\u5408\\u5E76\\u8FC7\\u7A0B\\u901A\\u8FC7\\u68C0\\u67E5\\u7ED3\\u679C\\u5217\\u8868\\u4E2D\\u76F8\\u90BB\\u7684\\u533A\\u95F4\\uFF0C\\u786E\\u4FDD\\u5C06\\u91CD\\u53E0\\u533A\\u95F4\\u5408\\u5E76\\u6210\\u4E00\\u4E2A\\u533A\\u95F4\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5904\\u7406 \",(0,n.jsx)(e.code,{children:\"intervals\"}),\" \\u6570\\u7EC4\\u4E3A\\u7A7A\\u7684\\u8FB9\\u7F18\\u60C5\\u51B5\\uFF0C\\u8FD4\\u56DE\\u4EC5\\u5305\\u542B \",(0,n.jsx)(e.code,{children:\"newInterval\"}),\" \\u7684\\u5217\\u8868\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u4E8C\\u5206\\u67E5\\u627E\\u627E\\u5230\\u63D2\\u5165 \",(0,n.jsx)(e.code,{children:\"newInterval\"}),\" \\u7684\\u5408\\u9002\\u4F4D\\u7F6E\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E24\\u4E2A\\u6307\\u9488 \",(0,n.jsx)(e.code,{children:\"left\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"right\"}),\"\\uFF0C\\u4EE5\\u8868\\u793A\\u641C\\u7D22\\u8303\\u56F4\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"newInterval\"}),\" \\u7684\\u5F00\\u59CB\\u503C\\u4E0E\\u5F53\\u524D\\u8303\\u56F4\\u7684\\u4E2D\\u95F4\\u5143\\u7D20\\u8FDB\\u884C\\u6BD4\\u8F83\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8C03\\u6574\\u6307\\u9488\\uFF0C\\u76F4\\u5230\\u627E\\u5230\\u63D2\\u5165 \",(0,n.jsx)(e.code,{children:\"newInterval\"}),\" \\u7684\\u4F4D\\u7F6E\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"splice\"}),\" \\u65B9\\u6CD5\\u5C06 \",(0,n.jsx)(e.code,{children:\"newInterval\"}),\" \\u63D2\\u5165\\u5230\\u786E\\u5B9A\\u7684\\u4F4D\\u7F6E\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u7A7A\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"res\"}),\" \\u4EE5\\u5B58\\u50A8\\u5408\\u5E76\\u540E\\u7684\\u533A\\u95F4\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386 \",(0,n.jsx)(e.code,{children:\"intervals\"}),\" \\u6570\\u7EC4\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"res\"}),\" \\u4E3A\\u7A7A\\uFF0C\\u6216\\u8005\\u5F53\\u524D\\u533A\\u95F4\\u4E0E \",(0,n.jsx)(e.code,{children:\"res\"}),\" \\u4E2D\\u7684\\u6700\\u540E\\u4E00\\u4E2A\\u533A\\u95F4\\u4E0D\\u91CD\\u53E0\\uFF0C\\u5219\\u5C06\\u5F53\\u524D\\u533A\\u95F4\\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"res\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5B58\\u5728\\u91CD\\u53E0\\uFF0C\\u5219\\u901A\\u8FC7\\u5C06 \",(0,n.jsx)(e.code,{children:\"res\"}),\" \\u4E2D\\u6700\\u540E\\u4E00\\u4E2A\\u533A\\u95F4\\u7684\\u7ED3\\u675F\\u66F4\\u65B0\\u4E3A\\u4E24\\u4E2A\\u91CD\\u53E0\\u533A\\u95F4\\u7684\\u6700\\u5927\\u503C\\u6765\\u5408\\u5E76\\u533A\\u95F4\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE\\u5305\\u542B\\u5408\\u5E76\\u533A\\u95F4\\u7684 \",(0,n.jsx)(e.code,{children:\"res\"}),\" \\u6570\\u7EC4\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(h,{children:v}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u4E8C\\u5206\\u67E5\\u627E\\u9700\\u8981 O(log n) \\u65F6\\u95F4\\uFF0C\\u4F46\\u4E0E\\u5408\\u5E76\\u533A\\u95F4\\u6240\\u9700\\u7684 O(n) \\u65F6\\u95F4\\u76F8\\u6BD4\\uFF0C\\u8FD9\\u53EF\\u4EE5\\u5FFD\\u7565\\u4E0D\\u8BA1\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u7ED3\\u679C\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"res\"}),\" \\u9700\\u8981\\u4E0E\\u8F93\\u5165\\u5927\\u5C0F\\u6210\\u6BD4\\u4F8B\\u7684\\u7A7A\\u95F4\\u3002\"]}),`\n`]})]})}function y(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(g,r)})):g(r)}var C=y;return O(_);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/intervals-minimum-meeting-rooms/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/intervals-minimum-meeting-rooms/locales/zh-CN.json new file mode 100644 index 000000000..34842a4e3 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/intervals-minimum-meeting-rooms/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var u=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var v=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),j=(t,e)=>{for(var o in e)i(t,o,{get:e[o],enumerable:!0})},s=(t,e,o,l)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of x(e))!f.call(t,r)&&r!==o&&i(t,r,{get:()=>e[r],enumerable:!(l=p(e,r))||l.enumerable});return t};var y=(t,e,o)=>(o=t!=null?u(g(t)):{},s(e||!t||!t.__esModule?i(o,\"default\",{value:t,enumerable:!0}):o,t)),T=t=>s(i({},\"__esModule\",{value:!0}),t);var c=v((X,a)=>{a.exports=_jsx_runtime});var C={};j(C,{default:()=>M,frontmatter:()=>_});var n=y(c());var d=MDXTestExamples;var h=[{input:[[\"intervals\",[[83,99]]]],output:1,explanation:\"Since there is only one meeting, only one room is required. There is no overlap, so just one room can accommodate the meeting.\"},{input:[[\"intervals\",[[1,5],[2,6],[8,9]]]],output:2,explanation:\"There are two overlapping meetings: [1, 5] and [2, 6]. To accommodate both meetings simultaneously, at least two rooms are needed. The other meeting [8, 9] do not overlap with the earlier ones, so only two rooms are required in total.\"},{input:[[\"intervals\",[[5,10],[10,15],[15,20]]]],output:1,explanation:\"The meetings are back-to-back, meaning they do not overlap. Since the end of one meeting coincides with the start of the next, only one room is sufficient to host all the meetings.\"}];var _={title:\"\\u6240\\u9700\\u6700\\u5C11\\u4F1A\\u8BAE\\u5BA4\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u67E5\\u627E\\u6240\\u9700\\u7684\\u6700\\u5C11\\u4F1A\\u8BAE\\u5BA4\\u6570\\u91CF\"};function m(t){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u4F1A\\u8BAE\\u65F6\\u95F4 \",(0,n.jsx)(e.code,{children:\"intervals\"}),\" \\u6570\\u7EC4\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u95F4\\u9694\\u8868\\u793A\\u4E3A \",(0,n.jsx)(e.code,{children:\"[start, end]\"}),\"\\uFF0C\\u8868\\u793A\\u4F1A\\u8BAE\\u5728 \",(0,n.jsx)(e.code,{children:\"start\"}),\" \\u65F6\\u95F4\\u5F00\\u59CB\\uFF0C\\u5728 \",(0,n.jsx)(e.code,{children:\"end\"}),\" \\u65F6\\u95F4\\u7ED3\\u675F\\uFF0C\\u786E\\u5B9A\\u5BB9\\u7EB3\\u6240\\u6709\\u4F1A\\u8BAE\\u6240\\u9700\\u7684\\u6700\\u5C11\\u4F1A\\u8BAE\\u5BA4\\u6570\\u91CF\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"intervals: Array<[number, number]>\"}),\": \\u6574\\u6570\\u5BF9\\u6570\\u7EC4\"]}),`\n`]}),`\n`,(0,n.jsx)(d,{testCases:h}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"0 <= \",(0,n.jsx)(e.code,{children:\"intervals.length\"}),\" <= 1000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"intervals[i].length\"}),\" == 2\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"0 <= \",(0,n.jsx)(e.code,{children:\"start\"}),\" < \",(0,n.jsx)(e.code,{children:\"end\"}),\" <= 1,000,000\"]}),`\n`]})]})}function w(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(m,t)})):m(t)}var M=w;return T(C);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来查找所需的最少会议室数量", + "title": "所需最少会议室" + }, + "solution": "var Component=(()=>{var g=Object.create;var o=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var v=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var P=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),R=(r,e)=>{for(var t in e)o(r,t,{get:e[t],enumerable:!0})},c=(r,e,t,d)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of p(e))!b.call(r,i)&&i!==t&&o(r,i,{get:()=>e[i],enumerable:!(d=f(e,i))||d.enumerable});return r};var x=(r,e,t)=>(t=r!=null?g(v(r)):{},c(e||!r||!r.__esModule?o(t,\"default\",{value:r,enumerable:!0}):t,r)),M=r=>c(o({},\"__esModule\",{value:!0}),r);var s=P((_,h)=>{h.exports=_jsx_runtime});var k={};R(k,{default:()=>j});var n=x(s());var l=MDXCodeBlock;var a=`export default function minMeetingRoomsNeeded(intervals: number[][]): number {\n // Check for the base case. If there are no intervals, return 0\n if (intervals.length === 0) {\n return 0;\n }\n\n // Separate start and end times into their own arrays\n const start: number[] = new Array(intervals.length);\n const end: number[] = new Array(intervals.length);\n\n for (let i = 0; i < intervals.length; i++) {\n start[i] = intervals[i][0];\n end[i] = intervals[i][1];\n }\n\n // Sort the start and end times\n start.sort((a, b) => a - b);\n end.sort((a, b) => a - b);\n\n // The two pointers in the algorithm: endPointer and startPointer\n let startPointer = 0,\n endPointer = 0;\n\n // Variable to keep track of the maximum number of rooms used\n let usedRooms = 0;\n\n // Iterate over the intervals\n while (startPointer < intervals.length) {\n // If there is a meeting that has ended by the time the meeting at startPointer starts\n if (start[startPointer] >= end[endPointer]) {\n usedRooms -= 1;\n endPointer += 1;\n }\n\n // Regardless of whether a room frees up or not, we allocate a room for the current meeting\n usedRooms += 1;\n startPointer += 1;\n }\n\n return usedRooms;\n}\n`;var m=`// Importing the PriorityQueue from a suitable library\nimport { MinPriorityQueue } from '@datastructures-js/priority-queue';\n\nexport default function minMeetingRoomsNeeded(intervals: number[][]): number {\n // Check for the base case. If there are no intervals, return 0\n if (intervals.length === 0) {\n return 0;\n }\n\n // Min heap to track the end time of meetings\n const allocator = new MinPriorityQueue();\n\n // Sort the intervals by start time\n intervals.sort((a, b) => a[0] - b[0]);\n\n // Add the first meeting's end time to the heap\n allocator.enqueue(intervals[0][1]);\n\n // Iterate over remaining intervals\n for (let i = 1; i < intervals.length; i++) {\n // If the room due to free up the earliest is free, assign that room to this meeting\n if (intervals[i][0] >= allocator.front()) {\n allocator.dequeue();\n }\n\n // Add the current meeting's end time to the heap\n allocator.enqueue(intervals[i][1]);\n }\n\n // The size of the heap tells us the minimum rooms required for all the meetings\n return allocator.size();\n}\n`;function u(r){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u53CC\\u6307\\u9488\\u65B9\\u6CD5\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u901A\\u8FC7\\u5206\\u79BB\\u5E76\\u6392\\u5E8F\\u533A\\u95F4\\u7684\\u5F00\\u59CB\\u548C\\u7ED3\\u675F\\u65F6\\u95F4\\u6765\\u786E\\u5B9A\\u6240\\u9700\\u7684\\u6700\\u5C11\\u4F1A\\u8BAE\\u5BA4\\u6570\\u91CF\\u3002\\u901A\\u8FC7\\u4F7F\\u7528\\u4E24\\u4E2A\\u6307\\u9488\\uFF0C\\u4E00\\u4E2A\\u7528\\u4E8E\",(0,n.jsx)(e.code,{children:\"start\"}),\"\\u65F6\\u95F4\\uFF0C\\u4E00\\u4E2A\\u7528\\u4E8E\",(0,n.jsx)(e.code,{children:\"end\"}),\"\\u65F6\\u95F4\\uFF0C\\u8BE5\\u7B97\\u6CD5\\u6709\\u6548\\u5730\\u8DDF\\u8E2A\\u5E76\\u53D1\\u4F1A\\u8BAE\\u7684\\u6570\\u91CF\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u76F4\\u89C9\\u662F\\uFF0C\\u5F53\\u4F1A\\u8BAE\\u7ED3\\u675F\\u65F6\\uFF0C\\u4F1A\\u8BAE\\u5BA4\\u5C31\\u4F1A\\u7A7A\\u95F2\\uFF0C\\u8FD9\\u7531\",(0,n.jsx)(e.code,{children:\"endPointer\"}),\"\\u8868\\u793A\\u3002\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u4F1A\\u8BAE\\u5F00\\u59CB\\u65F6\\u95F4\\uFF08\",(0,n.jsx)(e.code,{children:\"startPointer\"}),\"\\uFF09\\uFF0C\\u7B97\\u6CD5\\u4F1A\\u68C0\\u67E5\\u4F1A\\u8BAE\\u662F\\u5426\\u53EF\\u4EE5\\u91CD\\u590D\\u4F7F\\u7528\\u4E00\\u4E2A\\u53EF\\u7528\\u7684\\u623F\\u95F4\\uFF08\\u901A\\u8FC7\\u5C06\\u5F00\\u59CB\\u65F6\\u95F4\\u4E0E\\u6700\\u65E9\\u7684\\u7ED3\\u675F\\u65F6\\u95F4\\u8FDB\\u884C\\u6BD4\\u8F83\\uFF09\\u3002\\u5982\\u679C\\u623F\\u95F4\\u7A7A\\u95F2\\uFF0C\\u5219\\u5C06\",(0,n.jsx)(e.code,{children:\"endPointer\"}),\"\\u5411\\u524D\\u79FB\\u52A8\\u4EE5\\u6807\\u8BB0\\u8BE5\\u623F\\u95F4\\u53EF\\u7528\\u3002\\u5426\\u5219\\uFF0C\\u5C06\\u5206\\u914D\\u4E00\\u4E2A\\u65B0\\u623F\\u95F4\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u6B64\\u65B9\\u6CD5\\u907F\\u514D\\u4E86\\u76F4\\u63A5\\u6BD4\\u8F83\\u6240\\u6709\\u533A\\u95F4\\u5BF9\\uFF0C\\u4F7F\\u7528\\u6392\\u5E8F\\u6570\\u7EC4\\u548C\\u4E24\\u4E2A\\u6307\\u9488\\u6765\\u5B9E\\u73B0\\u6700\\u4F73\\u6548\\u7387\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5904\\u7406\\u57FA\\u672C\\u60C5\\u51B5\\uFF0C\\u5982\\u679C\",(0,n.jsx)(e.code,{children:\"intervals\"}),\"\\u6570\\u7EC4\\u4E3A\\u7A7A\\uFF0C\\u5219\\u8FD4\\u56DE\",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521B\\u5EFA\\u4E24\\u4E2A\\u6570\\u7EC4\",(0,n.jsx)(e.code,{children:\"start\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"end\"}),\"\\uFF0C\\u4EE5\\u5B58\\u50A8\\u6BCF\\u4E2A\\u533A\\u95F4\\u7684\\u5F00\\u59CB\\u548C\\u7ED3\\u675F\\u65F6\\u95F4\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u904D\\u5386\",(0,n.jsx)(e.code,{children:\"intervals\"}),\"\\u6570\\u7EC4\\u6765\\u586B\\u5145\",(0,n.jsx)(e.code,{children:\"start\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"end\"}),\"\\u6570\\u7EC4\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u6309\\u5347\\u5E8F\\u5BF9\",(0,n.jsx)(e.code,{children:\"start\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"end\"}),\"\\u6570\\u7EC4\\u8FDB\\u884C\\u6392\\u5E8F\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E24\\u4E2A\\u6307\\u9488\",(0,n.jsx)(e.code,{children:\"startPointer\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"endPointer\"}),\"\\uFF0C\\u5206\\u522B\\u904D\\u5386\",(0,n.jsx)(e.code,{children:\"start\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"end\"}),\"\\u6570\\u7EC4\\u3002\\u6B64\\u5916\\uFF0C\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u53D8\\u91CF\",(0,n.jsx)(e.code,{children:\"usedRooms\"}),\"\\u4EE5\\u8DDF\\u8E2A\\u5F53\\u524D\\u6B63\\u5728\\u4F7F\\u7528\\u7684\\u623F\\u95F4\\u6570\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386\",(0,n.jsx)(e.code,{children:\"start\"}),\"\\u6570\\u7EC4\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5F53\\u524D\\u4F1A\\u8BAE\\u7684\\u5F00\\u59CB\\u65F6\\u95F4\\u5927\\u4E8E\\u6216\\u7B49\\u4E8E\\u6700\\u65E9\\u7684\\u7ED3\\u675F\\u65F6\\u95F4\\uFF08\\u7531\",(0,n.jsx)(e.code,{children:\"end[endPointer]\"}),\"\\u6307\\u793A\\uFF09\\uFF0C\\u5219\\u901A\\u8FC7\\u9012\\u51CF\",(0,n.jsx)(e.code,{children:\"usedRooms\"}),\"\\u5E76\\u5C06\",(0,n.jsx)(e.code,{children:\"endPointer\"}),\"\\u5411\\u524D\\u79FB\\u52A8\\u6765\\u91CA\\u653E\\u4E00\\u4E2A\\u623F\\u95F4\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4E3A\\u5F53\\u524D\\u4F1A\\u8BAE\\u5206\\u914D\\u4E00\\u4E2A\\u623F\\u95F4\\uFF0C\\u65B9\\u6CD5\\u662F\\u9012\\u589E\",(0,n.jsx)(e.code,{children:\"usedRooms\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u79FB\\u52A8\",(0,n.jsx)(e.code,{children:\"startPointer\"}),\"\\u4EE5\\u5904\\u7406\\u4E0B\\u4E00\\u4E2A\\u4F1A\\u8BAE\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE\",(0,n.jsx)(e.code,{children:\"usedRooms\"}),\"\\u7684\\u503C\\uFF0C\\u8BE5\\u503C\\u8868\\u793A\\u5728\\u4EFB\\u4F55\\u65F6\\u5019\\u6240\\u9700\\u7684\\u6700\\u5927\\u623F\\u95F4\\u6570\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(l,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n log n)\"}),\"\\u3002\\u5BF9\",(0,n.jsx)(e.code,{children:\"start\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"end\"}),\"\\u6570\\u7EC4\\u8FDB\\u884C\\u6392\\u5E8F\\u5360\\u636E\\u4E86\\u8FD0\\u884C\\u65F6\\u7684\\u5927\\u90E8\\u5206\\uFF0C\\u800C\\u5904\\u7406\\u533A\\u95F4\\u7684\\u7EBF\\u6027\\u626B\\u63CF\\u9700\\u8981 O(n)\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u4F7F\\u7528\\u4E24\\u4E2A\\u989D\\u5916\\u7684\\u6570\\u7EC4\",(0,n.jsx)(e.code,{children:\"start\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"end\"}),\"\\u6765\\u5B58\\u50A8\\u533A\\u95F4\\u7684\\u5F00\\u59CB\\u548C\\u7ED3\\u675F\\u65F6\\u95F4\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u4F18\\u5148\\u7EA7\\u961F\\u5217\\uFF08\\u6700\\u5C0F\\u5806\\uFF09\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u65B9\\u6CD5\\u4F7F\\u7528\\u6700\\u5C0F\\u5806\\u6765\\u6709\\u6548\\u5730\\u8DDF\\u8E2A\\u6B63\\u5728\\u8FDB\\u884C\\u7684\\u4F1A\\u8BAE\\u7684\\u7ED3\\u675F\\u65F6\\u95F4\\uFF0C\\u786E\\u4FDD\\u6700\\u65E9\\u7ED3\\u675F\\u7684\\u4F1A\\u8BAE\\u59CB\\u7EC8\\u9996\\u5148\\u88AB\\u5904\\u7406\\u3002\\u8FD9\\u5141\\u8BB8\\u786E\\u5B9A\\u5F53\\u65B0\\u4F1A\\u8BAE\\u5F00\\u59CB\\u65F6\\u623F\\u95F4\\u662F\\u5426\\u7A7A\\u95F2\\u3002\\u6309\\u5F00\\u59CB\\u65F6\\u95F4\\u5BF9\\u533A\\u95F4\\u8FDB\\u884C\\u6392\\u5E8F\\u53EF\\u786E\\u4FDD\\u4F1A\\u8BAE\\u6309\\u65F6\\u95F4\\u987A\\u5E8F\\u5904\\u7406\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u4F7F\\u7528\\u6700\\u5C0F\\u5806\\u662F\\u56E0\\u4E3A\\u5B83\\u652F\\u6301\\u9AD8\\u6548\\u5730\\u63D2\\u5165\\u548C\\u63D0\\u53D6\\u6700\\u5C0F\\u5143\\u7D20\\u3002\\u5728\\u4EFB\\u4F55\\u65F6\\u5019\\uFF0C\\u5806\\u90FD\\u5305\\u542B\\u6240\\u6709\\u6D3B\\u52A8\\u4F1A\\u8BAE\\u7684\\u7ED3\\u675F\\u65F6\\u95F4\\u3002\\u5F53\\u4F1A\\u8BAE\\u5F00\\u59CB\\u65F6\\uFF0C\\u5C06\\u5176\\u5F00\\u59CB\\u65F6\\u95F4\\u4E0E\\u5806\\u4E2D\\u6700\\u5C0F\\u7684\\u7ED3\\u675F\\u65F6\\u95F4\\uFF08\\u6700\\u65E9\\u7ED3\\u675F\\u7684\\u4F1A\\u8BAE\\uFF09\\u8FDB\\u884C\\u6BD4\\u8F83\\u3002\\u5982\\u679C\\u65B0\\u4F1A\\u8BAE\\u53EF\\u4EE5\\u91CD\\u590D\\u4F7F\\u7528\\u623F\\u95F4\\uFF08\\u5176\\u5F00\\u59CB\\u65F6\\u95F4\\u5927\\u4E8E\\u6216\\u7B49\\u4E8E\\u6700\\u5C0F\\u7ED3\\u675F\\u65F6\\u95F4\\uFF09\\uFF0C\\u5219\\u4ECE\\u5806\\u4E2D\\u5220\\u9664\\u7ED3\\u675F\\u65F6\\u95F4\\u3002\\u5426\\u5219\\uFF0C\\u5C06\\u5206\\u914D\\u4E00\\u4E2A\\u65B0\\u623F\\u95F4\\uFF0C\\u5E76\\u5C06\\u4F1A\\u8BAE\\u7684\\u7ED3\\u675F\\u65F6\\u95F4\\u6DFB\\u52A0\\u5230\\u5806\\u4E2D\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5904\\u7406\\u57FA\\u672C\\u60C5\\u51B5\\uFF0C\\u5982\\u679C\",(0,n.jsx)(e.code,{children:\"intervals\"}),\"\\u6570\\u7EC4\\u4E3A\\u7A7A\\uFF0C\\u5219\\u8FD4\\u56DE\",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u6309\\u4F1A\\u8BAE\\u7684\\u5F00\\u59CB\\u65F6\\u95F4\\u5BF9\",(0,n.jsx)(e.code,{children:\"intervals\"}),\"\\u6570\\u7EC4\\u8FDB\\u884C\\u5347\\u5E8F\\u6392\\u5E8F\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u6700\\u5C0F\\u5806\\uFF08\",(0,n.jsx)(e.code,{children:\"allocator\"}),\"\\uFF09\\u4EE5\\u5B58\\u50A8\\u5F53\\u524D\\u5360\\u7528\\u623F\\u95F4\\u7684\\u4F1A\\u8BAE\\u7684\\u7ED3\\u675F\\u65F6\\u95F4\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5C06\\u7B2C\\u4E00\\u4E2A\\u4F1A\\u8BAE\\u7684\\u7ED3\\u675F\\u65F6\\u95F4\\u6DFB\\u52A0\\u5230\\u5806\\u4E2D\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u5269\\u4F59\\u7684\\u533A\\u95F4\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u5F53\\u524D\\u4F1A\\u8BAE\\u7684\\u5F00\\u59CB\\u65F6\\u95F4\\u5927\\u4E8E\\u6216\\u7B49\\u4E8E\\u5806\\u4E2D\\u6700\\u5C0F\\u7684\\u7ED3\\u675F\\u65F6\\u95F4\\uFF0C\\u5219\\u4ECE\\u5806\\u4E2D\\u5220\\u9664\\u6700\\u5C0F\\u7684\\u7ED3\\u675F\\u65F6\\u95F4\\uFF08\\u8868\\u793A\\u4E00\\u4E2A\\u623F\\u95F4\\u5DF2\\u91CA\\u653E\\uFF09\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5C06\\u5F53\\u524D\\u4F1A\\u8BAE\\u7684\\u7ED3\\u675F\\u65F6\\u95F4\\u6DFB\\u52A0\\u5230\\u5806\\u4E2D\\uFF0C\\u4E3A\\u5176\\u5206\\u914D\\u4E00\\u4E2A\\u623F\\u95F4\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5904\\u7406\\u5B8C\\u6240\\u6709\\u533A\\u95F4\\u540E\\uFF0C\\u5806\\u7684\\u5927\\u5C0F\\u8868\\u793A\\u6240\\u9700\\u7684\\u6700\\u5C0F\\u623F\\u95F4\\u6570\\uFF0C\\u56E0\\u4E3A\\u5806\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5143\\u7D20\\u5BF9\\u5E94\\u4E8E\\u5F53\\u524D\\u6D3B\\u52A8\\u7684\\u4F1A\\u8BAE\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8FD4\\u56DE\\u5806\\u7684\\u5927\\u5C0F\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(l,{children:m}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n log n)\"}),\"\\u3002\\u5BF9\\u533A\\u95F4\\u8FDB\\u884C\\u6392\\u5E8F\\u9700\\u8981 O(n log n)\\uFF0C\\u5E76\\u4E14\\u5806\\u4E2D\\u7684\\u6BCF\\u4E2A\\u63D2\\u5165\\u548C\\u5220\\u9664\\u64CD\\u4F5C\\u90FD\\u9700\\u8981 O(log n)\\uFF0C\\u5BFC\\u81F4\\u6240\\u6709\\u533A\\u95F4\\u7684\\u5806\\u64CD\\u4F5C\\u4E3A O(n log n)\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u6700\\u5C0F\\u5806\\u5728\\u6700\\u574F\\u60C5\\u51B5\\u4E0B\\u6700\\u591A\\u53EF\\u4EE5\\u5305\\u542B\",(0,n.jsx)(e.code,{children:\"n\"}),\"\\u4E2A\\u5143\\u7D20\\u3002\"]}),`\n`]})]})}function w(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(u,r)})):u(r)}var j=w;return M(k);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/linked-list-combine-k-sorted/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/linked-list-combine-k-sorted/locales/zh-CN.json new file mode 100644 index 000000000..a9c7aec87 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/linked-list-combine-k-sorted/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var u=Object.create;var s=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var L=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),_=(t,e)=>{for(var i in e)s(t,i,{get:e[i],enumerable:!0})},o=(t,e,i,r)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let l of x(e))!f.call(t,l)&&l!==i&&s(t,l,{get:()=>e[l],enumerable:!(r=m(e,l))||r.enumerable});return t};var j=(t,e,i)=>(i=t!=null?u(g(t)):{},o(e||!t||!t.__esModule?s(i,\"default\",{value:t,enumerable:!0}):i,t)),N=t=>o(s({},\"__esModule\",{value:!0}),t);var d=L((D,c)=>{c.exports=_jsx_runtime});var y={};_(y,{default:()=>w,frontmatter:()=>M});var n=j(d());var a=MDXTestExamples;var h=[{input:[[\"lists\",[[10,20,30],[5,15,25],[2,12,22]]]],output:[2,5,10,12,15,20,22,25,30],explanation:\"The lists are combined into a single sorted list with elements in increasing order.\"},{input:[[\"lists\",[[1],[3],[2]]]],output:[1,2,3],explanation:\"Each list contains a single element, so they are combined into a sorted list.\"},{input:[[\"lists\",[[1,2,3],[4,5,6],[7,8,9]]]],output:[1,2,3,4,5,6,7,8,9],explanation:\"All lists are already in ascending order and combined directly.\"}];var M={title:\"\\u94FE\\u8868\\u5408\\u5E76 K \\u4E2A\\u5DF2\\u6392\\u5E8F\\u5217\\u8868\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u5408\\u5E76 k \\u4E2A\\u5DF2\\u6392\\u5E8F\\u94FE\\u8868\\u7684\\u51FD\\u6570\"};function p(t){let e=Object.assign({p:\"p\",a:\"a\",code:\"code\",strong:\"strong\",pre:\"pre\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A \",(0,n.jsx)(e.a,{href:\"https://en.wikipedia.org/wiki/Linked_list\",children:\"\\u94FE\\u8868\"}),\" \\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"lists\"}),\"\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u94FE\\u8868\\u7684\\u8282\\u70B9\\u503C\\u90FD\\u6309\",(0,n.jsx)(e.strong,{children:\"\\u5347\\u5E8F\"}),\"\\u6392\\u5217\\uFF0C\\u5C06\\u6240\\u6709\\u8FD9\\u4E9B\\u94FE\\u8868\\u5408\\u5E76\\u6210\\u4E00\\u4E2A\\u5DF2\\u6392\\u5E8F\\u7684\\u94FE\\u8868\\uFF0C\\u5E76\\u8FD4\\u56DE\\u5408\\u5E76\\u540E\\u94FE\\u8868\\u7684\\u5934\\u8282\\u70B9\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u94FE\\u8868\\u7531\\u4E00\\u7CFB\\u5217 \",(0,n.jsx)(e.code,{children:\"ListNode\"}),\" \\u8868\\u793A\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u8282\\u70B9\\u6307\\u5411\\u5E8F\\u5217\\u4E2D\\u7684\\u4E0B\\u4E00\\u4E2A\\u8282\\u70B9\\uFF0C\\u5982\\u679C\\u5B83\\u662F\\u6700\\u540E\\u4E00\\u4E2A\\u8282\\u70B9\\uFF0C\\u5219\\u6307\\u5411 \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"ListNode\"}),\" \\u5177\\u6709\\u4EE5\\u4E0B\\u63A5\\u53E3\\uFF1A\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-ts\",children:`interface ListNode {\n val: number;\n next: ListNode | null;\n}\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"lists: ListNode[]\"}),\": \\u94FE\\u8868\\u5934\\u8282\\u70B9\\u6570\\u7EC4\\u3002\\u793A\\u4F8B\\u5C06\\u6BCF\\u4E2A\\u94FE\\u8868\\u663E\\u793A\\u4E3A\\u5217\\u8868\\u4E2D\\u7684\\u503C\\u6570\\u7EC4\"]}),`\n`]}),`\n`,(0,n.jsx)(a,{testCases:h}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"lists.length\"}),\" <= 100\"]}),`\n`,(0,n.jsx)(e.li,{children:\"0 <= \\u6BCF\\u5217\\u8868\\u7684\\u8282\\u70B9\\u6570 <= 100\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"-10,000 <= \",(0,n.jsx)(e.code,{children:\"ListNode.val\"}),\" <= 10,000\"]}),`\n`]})]})}function k(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(p,t)})):p(t)}var w=k;return N(y);})();\n;return Component;", + "info": { + "excerpt": "实现一个合并 k 个已排序链表的函数", + "title": "链表合并 K 个已排序列表" + }, + "solution": "var Component=(()=>{var p=Object.create;var o=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var v=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),k=(i,e)=>{for(var l in e)o(i,l,{get:e[l],enumerable:!0})},c=(i,e,l,r)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let t of f(e))!g.call(i,t)&&t!==l&&o(i,t,{get:()=>e[t],enumerable:!(r=b(e,t))||r.enumerable});return i};var L=(i,e,l)=>(l=i!=null?p(x(i)):{},c(e||!i||!i.__esModule?o(l,\"default\",{value:i,enumerable:!0}):l,i)),N=i=>c(o({},\"__esModule\",{value:!0}),i);var s=v((_,h)=>{h.exports=_jsx_runtime});var O={};k(O,{default:()=>M});var n=L(s());var d=MDXCodeBlock;var a=`interface ListNode {\n val: number;\n next: ListNode | null;\n}\n\nexport default function linkedListCombineKSorted(\n lists: (ListNode | null)[],\n): ListNode | null {\n let amount: number = lists.length; // Number of lists to combine\n let interval: number = 1; // Interval for merging lists in pairs\n\n // Continue combining in pairs, doubling the interval each time\n while (interval < amount) {\n // Merge lists in pairs\n for (let i = 0; i < amount - interval; i += interval * 2) {\n lists[i] = merge2Lists(lists[i], lists[i + interval]);\n }\n interval *= 2; // Double the interval\n }\n\n return amount > 0 ? lists[0] : null; // Return the combined list or null if there are no lists\n}\n\n// Helper function to combine two sorted linked lists\nfunction merge2Lists(\n l1: ListNode | null,\n l2: ListNode | null,\n): ListNode | null {\n let head: ListNode = { val: 0, next: null }; // Dummy node to simplify the combining process\n let point: ListNode = head; // Pointer to build the new combined list\n\n // Merge the two lists while both are non-empty\n while (l1 && l2) {\n if (l1.val <= l2.val) {\n point.next = l1; // Link the smaller node in the first list to the combined list\n l1 = l1.next; // Move to the next node in the first list\n } else {\n point.next = l2; // Link the smaller node in the second list to the combined list\n l2 = l1; // Move to the next node in the second list\n l1 = point.next.next; // Correct the next pointer of l1\n }\n point = point.next; // Move to the next node in the combined list\n }\n\n // If one of the lists is empty, link the remaining nodes from the other list\n if (!l1) {\n point.next = l2;\n } else {\n point.next = l1;\n }\n\n return head.next; // Return the head of the combined list, skipping the dummy node\n}\n`;var m=`interface ListNode {\n val: number;\n next: ListNode | null;\n}\n\nexport default function linkedListCombineKSorted(\n lists: (ListNode | null)[],\n): ListNode | null {\n // Array to hold all node values from the linked lists\n let nodes: number[] = [];\n\n // Create a dummy node to serve as the starting point for the combined list\n let dummy: ListNode = { val: 0, next: null };\n let combinedHead: ListNode = dummy; // Head node to build the new combined list\n\n // Traverse each linked list in the input array\n lists.forEach((l) => {\n // Traverse the current linked list\n while (l) {\n // Collect all node values in the array\n nodes.push(l.val);\n l = l.next; // Move to the next node in the current list\n }\n });\n\n // Sort the collected node values in ascending order\n nodes\n .sort((a, b) => a - b)\n .forEach((n) => {\n // Create a new node with the sorted value and link it to the combined list\n combinedHead.next = { val: n, next: null };\n combinedHead = combinedHead.next; // Move the pointer to the newly added node\n });\n\n // Return the combined list, skipping the dummy node\n return dummy.next;\n}\n`;function u(i){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},i.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u66B4\\u529B\\u89E3\\u6CD5\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u79CD\\u6734\\u7D20\\u7684\\u65B9\\u6CD5\\u662F\\u5C06\\u6240\\u6709\",(0,n.jsx)(e.code,{children:\"k\"}),\"\\u4E2A\\u94FE\\u8868\\u4E2D\\u7684\\u6240\\u6709\\u503C\\u63D0\\u53D6\\u5230\\u4E00\\u4E2A\\u6570\\u7EC4\\u4E2D\\uFF0C\\u5BF9\\u5B83\\u4EEC\\u8FDB\\u884C\\u6392\\u5E8F\\uFF0C\\u7136\\u540E\\u4ECE\\u6392\\u5E8F\\u540E\\u7684\\u6570\\u7EC4\\u4E2D\\u91CD\\u5EFA\\u4E00\\u4E2A\\u65B0\\u7684\\u6392\\u5E8F\\u94FE\\u8868\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521B\\u5EFA\\u4E00\\u4E2A\\u7A7A\\u6570\\u7EC4\",(0,n.jsx)(e.code,{children:\"nodes\"}),\"\\uFF0C\\u7528\\u4E8E\\u5B58\\u50A8\\u94FE\\u8868\\u4E2D\\u6240\\u6709\\u8282\\u70B9\\u7684\\u503C\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u521B\\u5EFA\\u4E00\\u4E2A\\u865A\\u62DF\\u8282\\u70B9\\uFF0C\\u4F5C\\u4E3A\\u6784\\u5EFA\\u65B0\\u94FE\\u8868\\u7684\\u8D77\\u70B9\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386\",(0,n.jsx)(e.code,{children:\"lists\"}),\"\\u6570\\u7EC4\\u4E2D\\u7684\\u6BCF\\u4E2A\\u94FE\\u8868\\u3002\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u904D\\u5386\\u5F53\\u524D\\u94FE\\u8868\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u6BCF\\u4E2A\\u8282\\u70B9\\u7684\\u503C\\u8FFD\\u52A0\\u5230\",(0,n.jsx)(e.code,{children:\"nodes\"}),\"\\u6570\\u7EC4\\u4E2D\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u6309\\u5347\\u5E8F\\u5BF9\",(0,n.jsx)(e.code,{children:\"nodes\"}),\"\\u6570\\u7EC4\\u8FDB\\u884C\\u6392\\u5E8F\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u6392\\u5E8F\\u540E\\u7684\",(0,n.jsx)(e.code,{children:\"nodes\"}),\"\\u6570\\u7EC4\\u3002\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u4E3A\\u6BCF\\u4E2A\\u503C\\u521B\\u5EFA\\u4E00\\u4E2A\\u65B0\\u8282\\u70B9\\uFF0C\\u5E76\\u5C06\\u5176\\u94FE\\u63A5\\u5230\\u7EC4\\u5408\\u94FE\\u8868\\u4E2D\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5C06\\u6307\\u9488\\u79FB\\u52A8\\u5230\\u65B0\\u6DFB\\u52A0\\u7684\\u8282\\u70B9\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8FD4\\u56DE\\u7EC4\\u5408\\u94FE\\u8868\\uFF0C\\u8DF3\\u8FC7\\u865A\\u62DF\\u8282\\u70B9\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(d,{children:m}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n log n)\"}),\"\\u3002\\u63D0\\u53D6\\u503C\\u9700\\u8981 O(n)\\uFF0C\\u5176\\u4E2D\",(0,n.jsx)(e.code,{children:\"n\"}),\"\\u662F\\u6240\\u6709\",(0,n.jsx)(e.code,{children:\"k\"}),\"\\u4E2A\\u94FE\\u8868\\u4E2D\\u8282\\u70B9\\u7684\\u603B\\u6570\\u3002\\u5BF9\\u6570\\u7EC4\\u8FDB\\u884C\\u6392\\u5E8F\\u9700\\u8981 O(n log n)\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u4F7F\\u7528\\u989D\\u5916\\u7684\\u7A7A\\u95F4\\u6765\\u5B58\\u50A8\\u5927\\u5C0F\\u4E3A\",(0,n.jsx)(e.code,{children:\"n\"}),\"\\u7684\",(0,n.jsx)(e.code,{children:\"nodes\"}),\"\\u6570\\u7EC4\\u548C\\u65B0\\u7684\\u94FE\\u8868\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u5206\\u6CBB\\u6CD5\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5206\\u6CBB\\u6CD5\\u4E0D\\u662F\\u5C1D\\u8BD5\\u4E00\\u6B65\\u5408\\u5E76\\u6240\\u6709\",(0,n.jsx)(e.code,{children:\"k\"}),\"\\u4E2A\\u5217\\u8868\\uFF0C\\u800C\\u662F\\u5C06\\u95EE\\u9898\\u5206\\u89E3\\u6210\\u66F4\\u5C0F\\u7684\\u90E8\\u5206\\u3002\\u76F8\\u90BB\\u7684\\u5217\\u8868\\u6210\\u5BF9\\u5408\\u5E76\\uFF0C\\u5728\\u6BCF\\u4E00\\u8F6E\\u4E2D\\u5C06\\u5217\\u8868\\u7684\\u6570\\u91CF\\u51CF\\u5C11\\u4E00\\u534A\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8FD9\\u4E2A\\u8FC7\\u7A0B\\u53EF\\u4EE5\\u88AB\\u53EF\\u89C6\\u5316\\u4E3A\\u6784\\u5EFA\\u4E00\\u4E2A\\u4E8C\\u53C9\\u6811\\u3002\\u5728\\u5E95\\u5C42\\uFF0C\",(0,n.jsx)(e.code,{children:\"k\"}),\"\\u4E2A\\u5217\\u8868\\u4E2D\\u7684\\u6BCF\\u4E00\\u4E2A\\u90FD\\u88AB\\u89C6\\u4E3A\\u4E00\\u4E2A\\u5355\\u72EC\\u7684\\u8282\\u70B9\\u3002\\u5728\\u4E0B\\u4E00\\u5C42\\uFF0C\\u76F8\\u90BB\\u7684\\u5217\\u8868\\u5BF9\\u88AB\\u5408\\u5E76\\u4EE5\\u5F62\\u6210\",(0,n.jsx)(e.code,{children:\"k/2\"}),\"\\u4E2A\\u5408\\u5E76\\u5217\\u8868\\u3002\\u8FD9\\u79CD\\u914D\\u5BF9\\u548C\\u5408\\u5E76\\u4E00\\u76F4\\u6301\\u7EED\\u5230\\u53EA\\u5269\\u4E0B\\u4E00\\u4E2A\\u5217\\u8868\\uFF0C\\u5F62\\u6210\\u6811\\u7684\\u6839\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u6BCF\\u6B21\\u6210\\u5BF9\\u5408\\u5E76\\u64CD\\u4F5C\\u90FD\\u4F1A\\u5904\\u7406\\u88AB\\u5408\\u5E76\\u7684\\u4E24\\u4E2A\\u5217\\u8868\\u4E2D\\u7684\\u6240\\u6709\\u8282\\u70B9\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\\u4E0D\\u4F1A\\u8FDB\\u884C\\u989D\\u5916\\u7684\\u6BD4\\u8F83\\uFF0C\\u4ECE\\u800C\\u5229\\u7528\\u4E86\\u5217\\u8868\\u7684\\u6392\\u5E8F\\u987A\\u5E8F\\u3002\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5408\\u5E76\\u8FC7\\u7A0B\\u4E2D\\u7684\\u5C42\\u6570\\u5BF9\\u5E94\\u4E8E\\u4E8C\\u53C9\\u6811\\u7684\\u9AD8\\u5EA6\\uFF0C\\u8BE5\\u9AD8\\u5EA6\\u4E0E\",(0,n.jsx)(e.code,{children:\"log k\"}),\"\\u6210\\u6B63\\u6BD4\\u3002\\u4E0E\\u66B4\\u529B\\u89E3\\u6CD5\\u76F8\\u6BD4\\uFF0C\\u8FD9\\u79CD\\u5206\\u5C42\\u51CF\\u5C11\\u663E\\u8457\\u51CF\\u5C11\\u4E86\\u6BD4\\u8F83\\u6B21\\u6570\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\",(0,n.jsx)(e.code,{children:\"amount\"}),\"\\u521D\\u59CB\\u5316\\u4E3A\\u8981\\u5408\\u5E76\\u7684\\u94FE\\u8868\\u6570\\u91CF\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\",(0,n.jsx)(e.code,{children:\"interval\"}),\"\\u8BBE\\u7F6E\\u4E3A 1\\uFF0C\\u8868\\u793A\\u6210\\u5BF9\\u5408\\u5E76\\u7684\\u8DDD\\u79BB\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5F53\",(0,n.jsx)(e.code,{children:\"interval\"}),\"\\u5C0F\\u4E8E\",(0,n.jsx)(e.code,{children:\"amount\"}),\"\\u65F6\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386\",(0,n.jsx)(e.code,{children:\"lists\"}),\"\\u6570\\u7EC4\\uFF0C\\u5408\\u5E76\\u76F8\\u9694\",(0,n.jsx)(e.code,{children:\"interval\"}),\"\\u7684\\u94FE\\u8868\\u5BF9\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5C06\\u6BCF\\u5BF9\\u4E2D\\u7684\\u7B2C\\u4E00\\u4E2A\\u5217\\u8868\\u66FF\\u6362\\u4E3A\\u5408\\u5E76\\u7ED3\\u679C\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\",(0,n.jsx)(e.code,{children:\"interval\"}),\"\\u52A0\\u500D\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\",(0,n.jsx)(e.code,{children:\"amount\"}),\"\\u5927\\u4E8E 0\\uFF0C\\u5219\\u8FD4\\u56DE\",(0,n.jsx)(e.code,{children:\"lists\"}),\"\\u6570\\u7EC4\\u4E2D\\u7684\\u7B2C\\u4E00\\u4E2A\\u5217\\u8868\\uFF1B\\u5426\\u5219\\uFF0C\\u8FD4\\u56DE\",(0,n.jsx)(e.code,{children:\"null\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8F85\\u52A9\\u51FD\\u6570\",(0,n.jsx)(e.code,{children:\"merge2Lists\"}),\"\\u6267\\u884C\\u4E24\\u4E2A\\u5DF2\\u6392\\u5E8F\\u94FE\\u8868\\u7684\\u5408\\u5E76\\uFF1A\"]}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u865A\\u62DF\\u8282\\u70B9\\u548C\\u4E00\\u4E2A\\u6307\\u9488\\u6765\\u6784\\u5EFA\\u65B0\\u7684\\u7EC4\\u5408\\u5217\\u8868\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u4E24\\u4E2A\\u8F93\\u5165\\u5217\\u8868\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u6BD4\\u8F83\\u4E24\\u4E2A\\u5217\\u8868\\u7684\\u5F53\\u524D\\u8282\\u70B9\\uFF0C\\u5E76\\u5C06\\u8F83\\u5C0F\\u7684\\u8282\\u70B9\\u9644\\u52A0\\u5230\\u7EC4\\u5408\\u5217\\u8868\\u4E2D\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u79FB\\u52A8\\u5230\\u8F83\\u5C0F\\u8282\\u70B9\\u6240\\u5728\\u7684\\u5217\\u8868\\u4E2D\\u7684\\u4E0B\\u4E00\\u4E2A\\u8282\\u70B9\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5C06\\u975E\\u7A7A\\u5217\\u8868\\u4E2D\\u5269\\u4F59\\u7684\\u4EFB\\u4F55\\u8282\\u70B9\\u9644\\u52A0\\u5230\\u7EC4\\u5408\\u5217\\u8868\\u4E2D\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8FD4\\u56DE\\u7EC4\\u5408\\u5217\\u8868\\uFF0C\\u8DF3\\u8FC7\\u865A\\u62DF\\u8282\\u70B9\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(d,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n log k)\"}),\"\\u3002\\u4E24\\u4E2A\\u5217\\u8868\\u7684\\u6BCF\\u6B21\\u5408\\u5E76\\u64CD\\u4F5C\\u4E3A O(n)\\uFF0C\\u5176\\u4E2D\",(0,n.jsx)(e.code,{children:\"n\"}),\"\\u662F\\u4E24\\u4E2A\\u5217\\u8868\\u4E2D\\u8282\\u70B9\\u7684\\u603B\\u6570\\u3002\\u5408\\u5E76\\u5C42\\u6570\\u4E3A O(log k)\\uFF0C\\u5176\\u4E2D\",(0,n.jsx)(e.code,{children:\"k\"}),\"\\u662F\\u5217\\u8868\\u7684\\u6570\\u91CF\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u5408\\u5E76\\u8FC7\\u7A0B\\u662F\\u5C31\\u5730\\u6267\\u884C\\u7684\\uFF0C\\u4E0D\\u9700\\u8981\\u989D\\u5916\\u7684\\u7A7A\\u95F4\\u3002\"]}),`\n`]})]})}function w(i={}){let{wrapper:e}=i.components||{};return e?(0,n.jsx)(e,Object.assign({},i,{children:(0,n.jsx)(u,i)})):u(i)}var M=w;return N(O);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/linked-list-combine-two-sorted/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/linked-list-combine-two-sorted/locales/zh-CN.json new file mode 100644 index 000000000..8c4de9179 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/linked-list-combine-two-sorted/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var u=Object.create;var l=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var L=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),N=(t,e)=>{for(var i in e)l(t,i,{get:e[i],enumerable:!0})},o=(t,e,i,r)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let s of x(e))!f.call(t,s)&&s!==i&&l(t,s,{get:()=>e[s],enumerable:!(r=m(e,s))||r.enumerable});return t};var _=(t,e,i)=>(i=t!=null?u(g(t)):{},o(e||!t||!t.__esModule?l(i,\"default\",{value:t,enumerable:!0}):i,t)),j=t=>o(l({},\"__esModule\",{value:!0}),t);var c=L((D,d)=>{d.exports=_jsx_runtime});var A={};N(A,{default:()=>w,frontmatter:()=>b});var n=_(c());var a=MDXTestExamples;var h=[{input:[[\"listA\",[-3,-1,9,10]],[\"listB\",[-10,3,4,6,9]]],output:[-10,-3,-1,3,4,6,9,9,10],explanation:\"Combining the sorted lists [-3, -1, 9, 10] and [-10, 3, 4, 6, 9] results in a single sorted list [-10, -3, -1, 3, 4, 6, 9, 9, 10].\"},{input:[[\"listA\",[1,2,4]],[\"listB\",[1,3,4]]],output:[1,1,2,3,4,4],explanation:\"Combining the sorted lists [1, 2, 4] and [1, 3, 4] results in a single sorted list [1, 1, 2, 3, 4, 4].\"},{input:[[\"listA\",[]],[\"listB\",[0]]],output:[0],explanation:\"Combining the empty list [] with the sorted list [0] results in the list [0].\"}];var b={title:\"\\u94FE\\u8868\\u5408\\u5E76\\u4E24\\u4E2A\\u5DF2\\u6392\\u5E8F\\u7684\\u5217\\u8868\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u5408\\u5E76\\u4E24\\u4E2A\\u5DF2\\u6392\\u5E8F\\u7684\\u94FE\\u8868\"};function p(t){let e=Object.assign({p:\"p\",a:\"a\",code:\"code\",strong:\"strong\",pre:\"pre\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\",(0,n.jsx)(e.a,{href:\"https://en.wikipedia.org/wiki/Linked_list\",children:\"\\u94FE\\u8868\"}),\"\\u6570\\u7EC4\",(0,n.jsx)(e.code,{children:\"lists\"}),\"\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u94FE\\u8868\\u7684\\u8282\\u70B9\\u503C\\u6309\",(0,n.jsx)(e.strong,{children:\"\\u5347\\u5E8F\"}),\"\\u6392\\u5217\\uFF0C\\u5C06\\u6240\\u6709\\u8FD9\\u4E9B\\u94FE\\u8868\\u5408\\u5E76\\u6210\\u4E00\\u4E2A\\u5DF2\\u6392\\u5E8F\\u7684\\u94FE\\u8868\\uFF0C\\u5E76\\u8FD4\\u56DE\\u5408\\u5E76\\u540E\\u94FE\\u8868\\u7684\\u5934\\u8282\\u70B9\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u94FE\\u8868\\u7531\\u4E00\\u7CFB\\u5217\",(0,n.jsx)(e.code,{children:\"ListNode\"}),\"\\u8868\\u793A\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u8282\\u70B9\\u6307\\u5411\\u5E8F\\u5217\\u4E2D\\u7684\\u4E0B\\u4E00\\u4E2A\\u8282\\u70B9\\uFF0C\\u5982\\u679C\\u5B83\\u662F\\u6700\\u540E\\u4E00\\u4E2A\\u8282\\u70B9\\uFF0C\\u5219\\u6307\\u5411\",(0,n.jsx)(e.code,{children:\"null\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A\",(0,n.jsx)(e.code,{children:\"ListNode\"}),\"\\u5177\\u6709\\u4EE5\\u4E0B\\u63A5\\u53E3\\uFF1A\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-ts\",children:`interface ListNode {\n val: number;\n next: ListNode | null;\n}\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"listA: ListNode\"}),\": \\u7B2C\\u4E00\\u4E2A\\u94FE\\u8868\\u7684\\u5934\\u8282\\u70B9\\u3002\\u793A\\u4F8B\\u5C06\\u6BCF\\u4E2A\\u94FE\\u8868\\u663E\\u793A\\u4E3A\\u5217\\u8868\\u4E2D\\u7684\\u503C\\u6570\\u7EC4\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"listB: ListNode\"}),\": \\u7B2C\\u4E8C\\u4E2A\\u94FE\\u8868\\u7684\\u5934\\u8282\\u70B9\\u3002\\u793A\\u4F8B\\u5C06\\u6BCF\\u4E2A\\u94FE\\u8868\\u663E\\u793A\\u4E3A\\u5217\\u8868\\u4E2D\\u7684\\u503C\\u6570\\u7EC4\"]}),`\n`]}),`\n`,(0,n.jsx)(a,{testCases:h}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"1 <= \\u8282\\u70B9\\u6570 <= 50\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"-100 <= \",(0,n.jsx)(e.code,{children:\"ListNode.val\"}),\" <= 100\"]}),`\n`]})]})}function M(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(p,t)})):p(t)}var w=M;return j(A);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来合并两个已排序的链表", + "title": "链表合并两个已排序的列表" + }, + "solution": "var Component=(()=>{var B=Object.create;var d=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var v=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var b=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),p=(i,e)=>{for(var n in e)d(i,n,{get:e[n],enumerable:!0})},c=(i,e,n,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let t of x(e))!f.call(i,t)&&t!==n&&d(i,t,{get:()=>e[t],enumerable:!(o=A(e,t))||o.enumerable});return i};var L=(i,e,n)=>(n=i!=null?B(v(i)):{},c(e||!i||!i.__esModule?d(n,\"default\",{value:i,enumerable:!0}):n,i)),g=i=>c(d({},\"__esModule\",{value:!0}),i);var h=b((M,r)=>{r.exports=_jsx_runtime});var w={};p(w,{default:()=>j});var l=L(h());var s=MDXCodeBlock;var u=`interface ListNode {\n val: number;\n next: ListNode | null;\n}\n\nexport default function linkedListCombineTwoSorted(\n listA: ListNode | null,\n listB: ListNode | null,\n): ListNode | null {\n // Dummy node to act as the previous node to the head of the combined list\n let dummy: ListNode = { val: -1, next: null };\n\n // Pointer to the last node in the combined list, initially set to dummy\n let prev: ListNode = dummy;\n\n // Iterate while both listA and listB are not null\n while (listA !== null && listB !== null) {\n // Compare the values of listA and listB nodes\n if (listA.val <= listB.val) {\n // If listA node is smaller or equal, add it to the combined list\n prev.next = listA;\n listA = listA.next; // Move to the next node in listA\n } else {\n // If listB node is smaller, add it to the combined list\n prev.next = listB;\n listB = listB.next; // Move to the next node in listB\n }\n // Move prev to the next node in the combined list\n prev = prev.next!;\n }\n\n // At least one of listA and listB can still have nodes, add the remaining nodes to the combined list\n if (listA !== null) {\n prev.next = listA;\n } else {\n prev.next = listB;\n }\n\n // The combined list is next to the dummy node\n return dummy.next;\n}\n`;var a=`interface ListNode {\n val: number;\n next: ListNode | null;\n}\n\nexport default function linkedListCombineTwoSorted(\n listA: ListNode | null,\n listB: ListNode | null,\n): ListNode | null {\n // If listA is null, return listB because the combined list is just listB\n if (listA === null) {\n return listB;\n }\n\n // If listB is null, return listA because the combined list is just listA\n if (listB === null) {\n return listA;\n }\n\n // If listA's value is less than listB's value\n if (listA.val < listB.val) {\n // Recursively combine listA.next and listB, and set the next of listA to the combined list\n listA.next = linkedListCombineTwoSorted(listA.next, listB);\n // Return listA as the head of the combined list\n return listA;\n }\n\n // If listB's value is less than or equal to listA's value\n // Recursively combine listA and listB.next, and set the next of listB to the combined list\n listB.next = linkedListCombineTwoSorted(listA, listB.next);\n\n // Return listB as the head of the combined list\n return listB;\n}\n`;function m(i){let e=Object.assign({h2:\"h2\",p:\"p\",h3:\"h3\",ol:\"ol\",li:\"li\",code:\"code\",ul:\"ul\",strong:\"strong\"},i.components);return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u8FED\\u4EE3\\u65B9\\u6CD5\"}),`\n`,(0,l.jsx)(e.p,{children:\"\\u5408\\u5E76\\u4E24\\u4E2A\\u5DF2\\u6392\\u5E8F\\u94FE\\u8868\\u7684\\u8FED\\u4EE3\\u65B9\\u6CD5\\u4FA7\\u91CD\\u4E8E\\u901A\\u8FC7\\u4F7F\\u7528\\u8F93\\u5165\\u5217\\u8868\\u7684\\u5DF2\\u6392\\u5E8F\\u7279\\u6027\\u6765\\u4FDD\\u6301\\u6548\\u7387\\u3002\\u8BE5\\u7B56\\u7565\\u5305\\u62EC\\u540C\\u65F6\\u904D\\u5386\\u4E24\\u4E2A\\u5217\\u8868\\uFF0C\\u6BD4\\u8F83\\u5B83\\u4EEC\\u7684\\u5F53\\u524D\\u8282\\u70B9\\uFF0C\\u5E76\\u9010\\u4E2A\\u6784\\u5EFA\\u7EC4\\u5408\\u5217\\u8868\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\\u5408\\u5E76\\u540E\\u7684\\u5217\\u8868\\u4FDD\\u6301\\u6392\\u5E8F\\uFF0C\\u800C\\u65E0\\u9700\\u989D\\u5916\\u7684\\u6392\\u5E8F\\u6B65\\u9AA4\\u3002\"}),`\n`,(0,l.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,l.jsxs)(e.ol,{children:[`\n`,(0,l.jsxs)(e.li,{children:[\"\\u521B\\u5EFA\\u4E00\\u4E2A\\u5E26\\u6709\\u5360\\u4F4D\\u7B26\\u503C\\u7684 \",(0,l.jsx)(e.code,{children:\"dummy\"}),\" \\u8282\\u70B9\\uFF0C\\u5E76\\u5C06 \",(0,l.jsx)(e.code,{children:\"prev\"}),\" \\u8BBE\\u7F6E\\u4E3A\\u6307\\u5411 \",(0,l.jsx)(e.code,{children:\"dummy\"}),\"\\u3002\"]}),`\n`,(0,l.jsxs)(e.li,{children:[\"\\u5F53 \",(0,l.jsx)(e.code,{children:\"listA\"}),\" \\u548C \",(0,l.jsx)(e.code,{children:\"listB\"}),\" \\u90FD\\u4E0D\\u4E3A \",(0,l.jsx)(e.code,{children:\"null\"}),\" \\u65F6\\uFF1A\",`\n`,(0,l.jsxs)(e.ol,{children:[`\n`,(0,l.jsxs)(e.li,{children:[\"\\u6BD4\\u8F83 \",(0,l.jsx)(e.code,{children:\"listA\"}),\" \\u548C \",(0,l.jsx)(e.code,{children:\"listB\"}),\" \\u7684\\u5F53\\u524D\\u8282\\u70B9\\u3002\"]}),`\n`,(0,l.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u66F4\\u65B0 \",(0,l.jsx)(e.code,{children:\"prev.next\"}),\" \\u5C06\\u8F83\\u5C0F\\u7684\\u8282\\u70B9\\u9644\\u52A0\\u5230\\u5408\\u5E76\\u5217\\u8868\\u4E2D\\u3002\"]}),`\n`,(0,l.jsx)(e.li,{children:\"\\u79FB\\u52A8\\u8F83\\u5C0F\\u8282\\u70B9\\u6240\\u5728\\u5217\\u8868\\u7684\\u6307\\u9488\\u5230\\u5176\\u4E0B\\u4E00\\u4E2A\\u8282\\u70B9\\u3002\"}),`\n`,(0,l.jsxs)(e.li,{children:[\"\\u66F4\\u65B0 \",(0,l.jsx)(e.code,{children:\"prev\"}),\" \\u4EE5\\u6307\\u5411\\u5408\\u5E76\\u5217\\u8868\\u4E2D\\u7684\\u6700\\u540E\\u4E00\\u4E2A\\u8282\\u70B9\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,l.jsxs)(e.li,{children:[\"\\u9000\\u51FA\\u5FAA\\u73AF\\u540E\\uFF0C\\u5C06 \",(0,l.jsx)(e.code,{children:\"listA\"}),\" \\u6216 \",(0,l.jsx)(e.code,{children:\"listB\"}),\"\\uFF08\\u65E0\\u8BBA\\u54EA\\u4E2A\\u4E0D\\u4E3A \",(0,l.jsx)(e.code,{children:\"null\"}),\"\\uFF09\\u7684\\u5269\\u4F59\\u8282\\u70B9\\u9644\\u52A0\\u5230\\u5408\\u5E76\\u5217\\u8868\\u4E2D\\u3002\"]}),`\n`,(0,l.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE \",(0,l.jsx)(e.code,{children:\"dummy.next\"}),\"\\uFF0C\\u5B83\\u6307\\u5411\\u5408\\u5E76\\u5217\\u8868\\u7684\\u5934\\u90E8\\u3002\"]}),`\n`]}),`\n`,(0,l.jsx)(s,{children:u}),`\n`,(0,l.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,l.jsxs)(e.ul,{children:[`\n`,(0,l.jsxs)(e.li,{children:[(0,l.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m + n)\"}),\"\\u3002\\u4E24\\u4E2A\\u5217\\u8868\\u4E2D\\u7684\\u6BCF\\u4E2A\\u8282\\u70B9\\u90FD\\u53EA\\u5904\\u7406\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,l.jsxs)(e.li,{children:[(0,l.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u4EC5\\u4F7F\\u7528\\u6052\\u5B9A\\u7684\\u989D\\u5916\\u7A7A\\u95F4\\u3002\"]}),`\n`]}),`\n`,(0,l.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u9012\\u5F52\\u65B9\\u6CD5\"}),`\n`,(0,l.jsx)(e.p,{children:\"\\u5408\\u5E76\\u4E24\\u4E2A\\u5DF2\\u6392\\u5E8F\\u94FE\\u8868\\u7684\\u9012\\u5F52\\u65B9\\u6CD5\\u4F9D\\u8D56\\u4E8E\\u4F7F\\u7528\\u9012\\u5F52\\u6765\\u7B80\\u5316\\u7EC4\\u5408\\u5217\\u8868\\u7684\\u8FC7\\u7A0B\\u3002\\u8BE5\\u7B56\\u7565\\u5305\\u62EC\\u6BD4\\u8F83\\u4E24\\u4E2A\\u5217\\u8868\\u7684\\u5F53\\u524D\\u8282\\u70B9\\uFF0C\\u5E76\\u8FDB\\u884C\\u9012\\u5F52\\u8C03\\u7528\\u4EE5\\u5408\\u5E76\\u5217\\u8868\\u7684\\u5176\\u4F59\\u90E8\\u5206\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\\u5408\\u5E76\\u5217\\u8868\\u5728\\u8C03\\u7528\\u9012\\u5F52\\u65F6\\u4EE5\\u6392\\u5E8F\\u987A\\u5E8F\\u6784\\u5EFA\\u3002\"}),`\n`,(0,l.jsxs)(e.p,{children:[\"\\u5728\\u6BCF\\u4E00\\u6B65\\u4E2D\\uFF0C\\u7B97\\u6CD5\\u90FD\\u4F1A\\u6BD4\\u8F83 \",(0,l.jsx)(e.code,{children:\"listA\"}),\" \\u548C \",(0,l.jsx)(e.code,{children:\"listB\"}),\" \\u7684\\u5F53\\u524D\\u8282\\u70B9\\u3002\\u9009\\u62E9\\u4E24\\u4E2A\\u8282\\u70B9\\u4E2D\\u8F83\\u5C0F\\u7684\\u8282\\u70B9\\u4F5C\\u4E3A\\u5408\\u5E76\\u5217\\u8868\\u7684\\u5934\\u90E8\\u3002\\u6B64\\u8FC7\\u7A0B\\u5C06\\u5BF9\\u5217\\u8868\\u4E2D\\u5269\\u4F59\\u7684\\u8282\\u70B9\\u9012\\u5F52\\u91CD\\u590D\\u3002\"]}),`\n`,(0,l.jsxs)(e.p,{children:[\"\\u5F53 \",(0,l.jsx)(e.code,{children:\"listA\"}),\" \\u6216 \",(0,l.jsx)(e.code,{children:\"listB\"}),\" \\u53D8\\u4E3A \",(0,l.jsx)(e.code,{children:\"null\"}),\" \\u65F6\\uFF0C\\u9012\\u5F52\\u7EC8\\u6B62\\u3002\\u6B64\\u65F6\\uFF0C\\u975E \",(0,l.jsx)(e.code,{children:\"null\"}),\" \\u5217\\u8868\\u5C06\\u9644\\u52A0\\u5230\\u5408\\u5E76\\u5217\\u8868\\u4E2D\\uFF0C\\u56E0\\u4E3A\\u5B83\\u5DF2\\u7ECF\\u6392\\u5E8F\\u3002\"]}),`\n`,(0,l.jsx)(e.p,{children:\"\\u9012\\u5F52\\u65B9\\u6CD5\\u901A\\u8FC7\\u4E00\\u6B21\\u5904\\u7406\\u4E00\\u4E2A\\u8282\\u70B9\\uFF0C\\u6709\\u6548\\u5730\\u51CF\\u5C0F\\u4E86\\u6BCF\\u4E00\\u6B65\\u7684\\u95EE\\u9898\\u89C4\\u6A21\\u3002\\u6BCF\\u4E2A\\u8282\\u70B9\\u53EA\\u5904\\u7406\\u4E00\\u6B21\\uFF0C\\u786E\\u4FDD\\u7B97\\u6CD5\\u76F8\\u5BF9\\u4E8E\\u8282\\u70B9\\u603B\\u6570\\u662F\\u7EBF\\u6027\\u7684\\u3002\"}),`\n`,(0,l.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,l.jsxs)(e.ol,{children:[`\n`,(0,l.jsxs)(e.li,{children:[\"\\u68C0\\u67E5 \",(0,l.jsx)(e.code,{children:\"listA\"}),\" \\u662F\\u5426\\u4E3A \",(0,l.jsx)(e.code,{children:\"null\"}),\"\\u3002\\u5982\\u679C\\u662F\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,l.jsx)(e.code,{children:\"listB\"}),\" \\u4F5C\\u4E3A\\u5408\\u5E76\\u5217\\u8868\\u3002\"]}),`\n`,(0,l.jsxs)(e.li,{children:[\"\\u68C0\\u67E5 \",(0,l.jsx)(e.code,{children:\"listB\"}),\" \\u662F\\u5426\\u4E3A \",(0,l.jsx)(e.code,{children:\"null\"}),\"\\u3002\\u5982\\u679C\\u662F\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,l.jsx)(e.code,{children:\"listA\"}),\" \\u4F5C\\u4E3A\\u5408\\u5E76\\u5217\\u8868\\u3002\"]}),`\n`,(0,l.jsxs)(e.li,{children:[\"\\u6BD4\\u8F83 \",(0,l.jsx)(e.code,{children:\"listA\"}),\" \\u548C \",(0,l.jsx)(e.code,{children:\"listB\"}),\" \\u4E2D\\u5F53\\u524D\\u8282\\u70B9\\u7684\\u503C\\u3002\",`\n`,(0,l.jsxs)(e.ol,{children:[`\n`,(0,l.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,l.jsx)(e.code,{children:\"listA.val\"}),\" \\u5C0F\\u4E8E \",(0,l.jsx)(e.code,{children:\"listB.val\"}),\"\\uFF1A\",`\n`,(0,l.jsxs)(e.ul,{children:[`\n`,(0,l.jsxs)(e.li,{children:[\"\\u5C06 \",(0,l.jsx)(e.code,{children:\"listA.next\"}),\" \\u8BBE\\u7F6E\\u4E3A\\u9012\\u5F52\\u5408\\u5E76 \",(0,l.jsx)(e.code,{children:\"listA.next\"}),\" \\u548C \",(0,l.jsx)(e.code,{children:\"listB\"}),\" \\u7684\\u7ED3\\u679C\\u3002\"]}),`\n`,(0,l.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE \",(0,l.jsx)(e.code,{children:\"listA\"}),\" \\u4F5C\\u4E3A\\u5408\\u5E76\\u5217\\u8868\\u7684\\u5934\\u90E8\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,l.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,l.jsx)(e.code,{children:\"listB.val\"}),\" \\u5C0F\\u4E8E\\u6216\\u7B49\\u4E8E \",(0,l.jsx)(e.code,{children:\"listA.val\"}),\"\\uFF1A\",`\n`,(0,l.jsxs)(e.ul,{children:[`\n`,(0,l.jsxs)(e.li,{children:[\"\\u5C06 \",(0,l.jsx)(e.code,{children:\"listB.next\"}),\" \\u8BBE\\u7F6E\\u4E3A\\u9012\\u5F52\\u5408\\u5E76 \",(0,l.jsx)(e.code,{children:\"listA\"}),\" \\u548C \",(0,l.jsx)(e.code,{children:\"listB.next\"}),\" \\u7684\\u7ED3\\u679C\\u3002\"]}),`\n`,(0,l.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE \",(0,l.jsx)(e.code,{children:\"listB\"}),\" \\u4F5C\\u4E3A\\u5408\\u5E76\\u5217\\u8868\\u7684\\u5934\\u90E8\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,l.jsx)(s,{children:a}),`\n`,(0,l.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,l.jsxs)(e.ul,{children:[`\n`,(0,l.jsxs)(e.li,{children:[(0,l.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m + n)\"}),\"\\u3002\\u4E24\\u4E2A\\u5217\\u8868\\u4E2D\\u7684\\u6BCF\\u4E2A\\u8282\\u70B9\\u90FD\\u53EA\\u8BBF\\u95EE\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,l.jsxs)(e.li,{children:[(0,l.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m + n)\"}),\"\\u3002\\u9012\\u5F52\\u6DF1\\u5EA6\\u53D6\\u51B3\\u4E8E\\u8282\\u70B9\\u7684\\u603B\\u6570\\uFF0C\\u8FD9\\u4F1A\\u5BFC\\u81F4\\u989D\\u5916\\u7684\\u5806\\u6808\\u7A7A\\u95F4\\uFF0C\\u4E0E \",(0,l.jsx)(e.code,{children:\"m + n\"}),\" \\u6210\\u6B63\\u6BD4\\u3002\"]}),`\n`]})]})}function C(i={}){let{wrapper:e}=i.components||{};return e?(0,l.jsx)(e,Object.assign({},i,{children:(0,l.jsx)(m,i)})):m(i)}var j=C;return g(w);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/linked-list-delete-nth-from-end/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/linked-list-delete-nth-from-end/locales/zh-CN.json new file mode 100644 index 000000000..b98e0ecc8 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/linked-list-delete-nth-from-end/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var r=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var L=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),N=(t,e)=>{for(var i in e)r(t,i,{get:e[i],enumerable:!0})},o=(t,e,i,s)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let l of x(e))!g.call(t,l)&&l!==i&&r(t,l,{get:()=>e[l],enumerable:!(s=m(e,l))||s.enumerable});return t};var _=(t,e,i)=>(i=t!=null?p(f(t)):{},o(e||!t||!t.__esModule?r(i,\"default\",{value:t,enumerable:!0}):i,t)),j=t=>o(r({},\"__esModule\",{value:!0}),t);var c=L((X,d)=>{d.exports=_jsx_runtime});var w={};N(w,{default:()=>b,frontmatter:()=>T});var n=_(c());var h=MDXTestExamples;var a=[{input:[[\"list\",[1,2,3,4,5,6]],[\"n\",3]],output:[1,2,3,5,6],explanation:\"The 3rd node from the end is 4. Deleting it results in the list [1, 2, 3, 5, 6].\"},{input:[[\"list\",[8]],[\"n\",1]],output:[],explanation:\"The list contains only one node, which is the 1st from the end. Deleting it results in an empty list.\"},{input:[[\"list\",[9,7]],[\"n\",1]],output:[9],explanation:\"The 1st node from the end is 7. Deleting it results in the list [9].\"}];var T={title:\"\\u5220\\u9664\\u94FE\\u8868\\u5012\\u6570\\u7B2C N \\u4E2A\\u8282\\u70B9\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u7528\\u4E8E\\u5220\\u9664\\u94FE\\u8868\\u5012\\u6570\\u7B2C n \\u4E2A\\u8282\\u70B9\"};function u(t){let e=Object.assign({p:\"p\",a:\"a\",code:\"code\",pre:\"pre\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A \",(0,n.jsx)(e.a,{href:\"https://en.wikipedia.org/wiki/Linked_list\",children:\"\\u94FE\\u8868\"}),\" \\u7684\\u5934\\u8282\\u70B9\\uFF0C\\u5220\\u9664\\u94FE\\u8868\\u4E2D\\u5012\\u6570\\u7B2C \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u4E2A\\u8282\\u70B9\\uFF0C\\u5E76\\u8FD4\\u56DE\\u66F4\\u65B0\\u540E\\u7684\\u5934\\u8282\\u70B9\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u94FE\\u8868\\u7531\\u4E00\\u7CFB\\u5217 \",(0,n.jsx)(e.code,{children:\"ListNode\"}),\" \\u8868\\u793A\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u8282\\u70B9\\u6307\\u5411\\u5E8F\\u5217\\u4E2D\\u7684\\u4E0B\\u4E00\\u4E2A\\u8282\\u70B9\\uFF0C\\u5982\\u679C\\u5B83\\u662F\\u6700\\u540E\\u4E00\\u4E2A\\u8282\\u70B9\\uFF0C\\u5219\\u6307\\u5411 \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"ListNode\"}),\" \\u5177\\u6709\\u4EE5\\u4E0B\\u63A5\\u53E3\\uFF1A\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-ts\",children:`interface ListNode {\n val: number;\n next: ListNode | null;\n}\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"head: ListNode\"}),\": \\u94FE\\u8868\\u7684\\u5934\\u8282\\u70B9\\u3002\\u793A\\u4F8B\\u5C06\\u6BCF\\u4E2A\\u94FE\\u8868\\u663E\\u793A\\u4E3A\\u5217\\u8868\\u4E2D\\u7684\\u503C\\u6570\\u7EC4\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"n: number\"}),\": \\u4E00\\u4E2A\\u6574\\u6570\\uFF0C\\u8868\\u793A\\u8981\\u5220\\u9664\\u7684\\u8282\\u70B9\\u7684\\u4F4D\\u7F6E\\uFF08\\u4ECE\\u672B\\u5C3E\\u5F00\\u59CB\\uFF09\"]}),`\n`]}),`\n`,(0,n.jsx)(h,{testCases:a}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"1 <= \\u8282\\u70B9\\u6570 <= 1000\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"ListNode.val\"}),\" <= 1000\"]}),`\n`]})]})}function M(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(u,t)})):u(t)}var b=M;return j(w);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,用于删除链表倒数第 n 个节点", + "title": "删除链表倒数第 N 个节点" + }, + "solution": "var Component=(()=>{var a=Object.create;var l=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var N=(d,e)=>()=>(e||d((e={exports:{}}).exports,e),e.exports),b=(d,e)=>{for(var i in e)l(d,i,{get:e[i],enumerable:!0})},o=(d,e,i,c)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let t of p(e))!y.call(d,t)&&t!==i&&l(d,t,{get:()=>e[t],enumerable:!(c=x(e,t))||c.enumerable});return d};var L=(d,e,i)=>(i=d!=null?a(g(d)):{},o(e||!d||!d.__esModule?l(i,\"default\",{value:d,enumerable:!0}):i,d)),v=d=>o(l({},\"__esModule\",{value:!0}),d);var s=N((M,h)=>{h.exports=_jsx_runtime});var _={};b(_,{default:()=>C});var n=L(s());var r=MDXCodeBlock;var f=`interface ListNode {\n val: number;\n next: ListNode | null;\n}\n\nexport default function deleteNthNodeFromEnd(\n head: ListNode | null,\n n: number,\n): ListNode | null {\n // Create a dummy node that points to the head of the list\n let dummy: ListNode = { val: 0, next: head };\n\n // Initialize a variable to keep track of the length of the list\n let length: number = 0;\n let first: ListNode | null = head;\n\n // Traverse the list to calculate its length\n while (first !== null) {\n length++;\n first = first.next;\n }\n\n // Calculate the position of the node just before the node to be removed\n length -= n;\n first = dummy;\n\n // Traverse to the node just before the node to be removed\n while (length > 0) {\n length--;\n first = first.next!;\n }\n\n // Remove the nth node from the end\n first.next = first.next!.next;\n\n // Return the modified list, starting from the node after the dummy\n return dummy.next;\n}\n`;var m=`interface ListNode {\n val: number;\n next: ListNode | null;\n}\n\nexport default function removeNthFromEnd(\n head: ListNode | null,\n n: number,\n): ListNode | null {\n // Create a dummy node that points to the head of the list\n const dummy: ListNode = { val: 0, next: head };\n\n // Initialize two pointers, both starting at the dummy node\n let first: ListNode | null = dummy;\n let second: ListNode | null = dummy;\n\n // Advance the first pointer so that there is a gap of n nodes between the first and second pointers\n for (let i = 0; i <= n; i++) {\n if (first !== null) {\n first = first.next;\n }\n }\n\n // Move both pointers until the first pointer reaches the end of the list\n // This maintains the gap between the two pointers\n while (first !== null) {\n first = first.next;\n second = second!.next;\n }\n\n // Remove the nth node from the end by skipping the node after the second pointer\n if (second !== null && second.next !== null) {\n second.next = second.next.next;\n }\n\n // Return the head of the modified list, which is the node after the dummy node\n return dummy.next;\n}\n`;function u(d){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},d.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u4E24\\u904D\\u626B\\u63CF\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5220\\u9664\\u94FE\\u8868\\u4E2D\\u5012\\u6570\\u7B2C \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u4E2A\\u8282\\u70B9\\u7684\\u4E24\\u904D\\u626B\\u63CF\\u65B9\\u6CD5\\u5C06\\u95EE\\u9898\\u5206\\u89E3\\u4E3A\\u4E24\\u4E2A\\u6E05\\u6670\\u7684\\u6B65\\u9AA4\\u3002\\u7B2C\\u4E00\\u904D\\u786E\\u5B9A\\u94FE\\u8868\\u7684\\u603B\\u957F\\u5EA6\\uFF0C\\u7B2C\\u4E8C\\u904D\\u786E\\u5B9A\\u5E76\\u5220\\u9664\\u76EE\\u6807\\u8282\\u70B9\\u3002\\u4F7F\\u7528\\u865A\\u62DF\\u8282\\u70B9\\u7B80\\u5316\\u4E86\\u8FB9\\u7F18\\u60C5\\u51B5\\uFF0C\\u4F8B\\u5982\\u5F53\\u9700\\u8981\\u5220\\u9664\\u5217\\u8868\\u7684\\u5934\\u8282\\u70B9\\u65F6\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u901A\\u8FC7\\u5728\\u7B2C\\u4E00\\u904D\\u626B\\u63CF\\u4E2D\\u904D\\u5386\\u5217\\u8868\\uFF0C\\u53EF\\u4EE5\\u8BA1\\u7B97\\u51FA\\u94FE\\u8868\\u7684\\u603B\\u957F\\u5EA6\\u3002\\u6B64\\u6B65\\u9AA4\\u786E\\u4FDD\\u53EF\\u4EE5\\u4ECE\\u5217\\u8868\\u7684\\u5F00\\u5934\\u8BA1\\u7B97\\u51FA\\u5012\\u6570\\u7B2C \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u4E2A\\u8282\\u70B9\\u7684\\u4F4D\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"(length - n)\"}),\"\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u4F7F\\u7528\\u8BA1\\u7B97\\u51FA\\u7684\\u4F4D\\u7F6E\\uFF0C\\u7B2C\\u4E8C\\u904D\\u626B\\u63CF\\u5728\\u76EE\\u6807\\u8282\\u70B9\\u7684\\u524D\\u4E00\\u4E2A\\u8282\\u70B9\\u5904\\u505C\\u6B62\\u3002\\u8FD9\\u81F3\\u5173\\u91CD\\u8981\\uFF0C\\u56E0\\u4E3A\\u5220\\u9664\\u94FE\\u8868\\u4E2D\\u7684\\u8282\\u70B9\\u9700\\u8981\\u8BBF\\u95EE\\u524D\\u4E00\\u4E2A\\u8282\\u70B9\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u5728\\u5217\\u8868\\u7684\\u5F00\\u5934\\u6DFB\\u52A0\\u4E00\\u4E2A\\u865A\\u62DF\\u8282\\u70B9\\uFF0C\\u4EE5\\u5904\\u7406\\u9700\\u8981\\u5220\\u9664\\u5934\\u8282\\u70B9\\u7684\\u60C5\\u51B5\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\\u903B\\u8F91\\u5728\\u5217\\u8868\\u4E2D\\u7684\\u8282\\u70B9\\u4F4D\\u7F6E\\u65E0\\u5173\\u7D27\\u8981\\u3002\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u65E6\\u627E\\u5230\\u76EE\\u6807\\u8282\\u70B9\\u7684\\u524D\\u4E00\\u4E2A\\u8282\\u70B9\\uFF0C\\u901A\\u8FC7\\u66F4\\u65B0\\u5176\\u524D\\u9A71\\u8282\\u70B9\\u7684 \",(0,n.jsx)(e.code,{children:\"next\"}),\" \\u6307\\u9488\\u6765\\u7ED5\\u8FC7\\u76EE\\u6807\\u8282\\u70B9\\u3002\\u6B64\\u64CD\\u4F5C\\u786E\\u4FDD\\u5728\\u5220\\u9664\\u540E\\u5217\\u8868\\u4FDD\\u6301\\u5B8C\\u6574\\u5E76\\u6B63\\u786E\\u94FE\\u63A5\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u7B80\\u5355\\u660E\\u4E86\\uFF0C\\u786E\\u4FDD\\u5728\\u6700\\u5927\\u9650\\u5EA6\\u5730\\u51CF\\u5C11\\u590D\\u6742\\u6027\\u7684\\u540C\\u65F6\\u6709\\u6548\\u5730\\u89E3\\u51B3\\u95EE\\u9898\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521B\\u5EFA\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"dummy\"}),\" \\u8282\\u70B9\\uFF0C\\u5176 \",(0,n.jsx)(e.code,{children:\"next\"}),\" \\u6307\\u9488\\u8BBE\\u7F6E\\u4E3A\\u5217\\u8868\\u7684\\u5934\\u8282\\u70B9\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u53D8\\u91CF \",(0,n.jsx)(e.code,{children:\"length\"}),\" \\u521D\\u59CB\\u5316\\u4E3A 0\\uFF0C\\u5E76\\u5C06 \",(0,n.jsx)(e.code,{children:\"first\"}),\" \\u8BBE\\u7F6E\\u4E3A\\u5217\\u8868\\u7684\\u5934\\u8282\\u70B9\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u5217\\u8868\\u4EE5\\u8BA1\\u7B97\\u603B\\u957F\\u5EA6\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u9047\\u5230\\u6BCF\\u4E2A\\u8282\\u70B9\\u65F6\\uFF0C\\u9012\\u589E \",(0,n.jsx)(e.code,{children:\"length\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"first\"}),\" \\u79FB\\u52A8\\u5230\\u4E0B\\u4E00\\u4E2A\\u8282\\u70B9\\uFF0C\\u76F4\\u5230\\u5230\\u8FBE\\u5217\\u8868\\u7684\\u672B\\u5C3E\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE \",(0,n.jsx)(e.code,{children:\"length\"}),\" \\u4E2D\\u51CF\\u53BB \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u4EE5\\u8BA1\\u7B97\\u76EE\\u6807\\u8282\\u70B9\\u524D\\u4E00\\u4E2A\\u8282\\u70B9\\u7684\\u4F4D\\u7F6E\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"first\"}),\" \\u91CD\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"dummy\"}),\" \\u8282\\u70B9\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u518D\\u6B21\\u904D\\u5386\\u5217\\u8868\\uFF0C\\u76F4\\u5230\\u5230\\u8FBE\\u76EE\\u6807\\u8282\\u70B9\\u7684\\u524D\\u4E00\\u4E2A\\u8282\\u70B9\\u7684\\u4F4D\\u7F6E\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5728\\u6BCF\\u4E00\\u6B65\\u4E2D\\u9012\\u51CF \",(0,n.jsx)(e.code,{children:\"length\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"first\"}),\" \\u79FB\\u52A8\\u5230\\u4E0B\\u4E00\\u4E2A\\u8282\\u70B9\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u66F4\\u65B0 \",(0,n.jsx)(e.code,{children:\"first\"}),\" \\u7684 \",(0,n.jsx)(e.code,{children:\"next\"}),\" \\u6307\\u9488\\uFF0C\\u4F7F\\u5176\\u6307\\u5411 \",(0,n.jsx)(e.code,{children:\"first.next.next\"}),\"\\uFF0C\\u4ECE\\u800C\\u7ED5\\u8FC7\\u76EE\\u6807\\u8282\\u70B9\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"dummy.next\"}),\" \\u4F5C\\u4E3A\\u4FEE\\u6539\\u540E\\u5217\\u8868\\u7684\\u5934\\u8282\\u70B9\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(r,{children:f}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u5217\\u8868\\u88AB\\u904D\\u5386\\u4E24\\u6B21\\uFF0C\\u4E00\\u6B21\\u7528\\u4E8E\\u8BA1\\u7B97\\u5176\\u957F\\u5EA6\\uFF0C\\u4E00\\u6B21\\u7528\\u4E8E\\u5B9A\\u4F4D\\u76EE\\u6807\\u8282\\u70B9\\u7684\\u524D\\u9A71\\u8282\\u70B9\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u4F7F\\u7528\\u6052\\u5B9A\\u91CF\\u7684\\u989D\\u5916\\u7A7A\\u95F4\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u4E00\\u904D\\u626B\\u63CF\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4ECE\\u94FE\\u8868\\u4E2D\\u5220\\u9664\\u5012\\u6570\\u7B2C \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u4E2A\\u8282\\u70B9\\u7684\\u4E00\\u904D\\u626B\\u63CF\\u65B9\\u6CD5\\u901A\\u8FC7\\u4F7F\\u7528\\u4E24\\u4E2A\\u6307\\u9488\\u6765\\u4F18\\u5316\\u904D\\u5386\\u3002\\u6B64\\u65B9\\u6CD5\\u4E0D\\u662F\\u8BA1\\u7B97\\u5217\\u8868\\u7684\\u603B\\u957F\\u5EA6\\uFF0C\\u800C\\u662F\\u786E\\u4FDD\\u4E24\\u4E2A\\u6307\\u9488\\u5728\\u5355\\u4E2A\\u8FED\\u4EE3\\u4E2D\\u904D\\u5386\\u5217\\u8868\\uFF0C\\u4ECE\\u800C\\u4FDD\\u6301\\u5B83\\u4EEC\\u4E4B\\u95F4\\u7684\\u56FA\\u5B9A\\u95F4\\u9699\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8BE5\\u7B97\\u6CD5\\u4F7F\\u7528\\u4E24\\u4E2A\\u6307\\u9488 \",(0,n.jsx)(e.code,{children:\"first\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"second\"}),\"\\uFF0C\\u90FD\\u4ECE \",(0,n.jsx)(e.code,{children:\"dummy\"}),\" \\u8282\\u70B9\\u5F00\\u59CB\\u3002\\u901A\\u8FC7\\u5C06 \",(0,n.jsx)(e.code,{children:\"first\"}),\" \\u6307\\u9488\\u63A8\\u8FDB \",(0,n.jsx)(e.code,{children:\"n + 1\"}),\" \\u6B65\\uFF0C\\u5728 \",(0,n.jsx)(e.code,{children:\"first\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"second\"}),\" \\u4E4B\\u95F4\\u521B\\u5EFA\\u4E86 \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u4E2A\\u8282\\u70B9\\u7684\\u95F4\\u9699\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u65E6\\u5EFA\\u7ACB\\u4E86\\u95F4\\u9699\\uFF0C\\u4E24\\u4E2A\\u6307\\u9488\\u540C\\u65F6\\u79FB\\u52A8\\uFF0C\\u76F4\\u5230 \",(0,n.jsx)(e.code,{children:\"first\"}),\" \\u5230\\u8FBE\\u5217\\u8868\\u7684\\u672B\\u5C3E\\u3002\\u6B64\\u65F6\\uFF0C\",(0,n.jsx)(e.code,{children:\"second\"}),\" \\u6307\\u9488\\u4F4D\\u4E8E\\u8981\\u5220\\u9664\\u7684\\u8282\\u70B9\\u7684\\u524D\\u9762\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"second\"}),\" \\u6307\\u9488\\uFF0C\\u901A\\u8FC7\\u5C06 \",(0,n.jsx)(e.code,{children:\"second.next\"}),\" \\u66F4\\u65B0\\u4E3A \",(0,n.jsx)(e.code,{children:\"second.next.next\"}),\" \\u6765\\u8DF3\\u8FC7\\u76EE\\u6807\\u8282\\u70B9\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\\u5728\\u5220\\u9664\\u540E\\u5217\\u8868\\u4FDD\\u6301\\u5B8C\\u6574\\u5E76\\u6B63\\u786E\\u94FE\\u63A5\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5728\\u5217\\u8868\\u7684\\u5F00\\u5934\\u6DFB\\u52A0\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"dummy\"}),\" \\u8282\\u70B9\\uFF0C\\u4EE5\\u5904\\u7406\\u9700\\u8981\\u5220\\u9664\\u5934\\u8282\\u70B9\\u7684\\u60C5\\u51B5\\u3002\\u8FD9\\u6D88\\u9664\\u4E86\\u5BF9\\u7279\\u6B8A\\u5904\\u7406\\u8FB9\\u7F18\\u60C5\\u51B5\\u7684\\u9700\\u6C42\\uFF0C\\u5E76\\u7B80\\u5316\\u4E86\\u903B\\u8F91\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8FD9\\u79CD\\u5355\\u7A0B\\u65B9\\u6CD5\\u662F\\u6709\\u6548\\u7684\\uFF0C\\u56E0\\u4E3A\\u5B83\\u6700\\u5927\\u9650\\u5EA6\\u5730\\u51CF\\u5C11\\u4E86\\u8FED\\u4EE3\\u6B21\\u6570\\u5E76\\u4FDD\\u6301\\u7EBF\\u6027\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521B\\u5EFA\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"dummy\"}),\" \\u8282\\u70B9\\uFF0C\\u5176 \",(0,n.jsx)(e.code,{children:\"next\"}),\" \\u6307\\u9488\\u8BBE\\u7F6E\\u4E3A\\u5217\\u8868\\u7684\\u5934\\u90E8\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E24\\u4E2A\\u6307\\u9488 \",(0,n.jsx)(e.code,{children:\"first\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"second\"}),\"\\uFF0C\\u90FD\\u6307\\u5411 \",(0,n.jsx)(e.code,{children:\"dummy\"}),\" \\u8282\\u70B9\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"first\"}),\" \\u6307\\u9488\\u63A8\\u8FDB \",(0,n.jsx)(e.code,{children:\"n + 1\"}),\" \\u6B65\\uFF0C\\u5728 \",(0,n.jsx)(e.code,{children:\"first\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"second\"}),\" \\u4E4B\\u95F4\\u521B\\u5EFA \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u4E2A\\u8282\\u70B9\\u7684\\u95F4\\u9699\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"first\"}),\" \\u4E0D\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u5219\\u5728\\u6BCF\\u4E00\\u6B65\\u5C06\\u5176\\u79FB\\u52A8\\u5230\\u4E0B\\u4E00\\u4E2A\\u8282\\u70B9\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u6BCF\\u6B21\\u79FB\\u52A8 \",(0,n.jsx)(e.code,{children:\"first\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"second\"}),\" \\u6307\\u9488\\u4E00\\u6B65\\uFF0C\\u76F4\\u5230 \",(0,n.jsx)(e.code,{children:\"first\"}),\" \\u5230\\u8FBE\\u5217\\u8868\\u7684\\u672B\\u5C3E\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"first\"}),\" \\u79FB\\u52A8\\u5230 \",(0,n.jsx)(e.code,{children:\"first.next\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"second\"}),\" \\u79FB\\u52A8\\u5230 \",(0,n.jsx)(e.code,{children:\"second.next\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u5C06 \",(0,n.jsx)(e.code,{children:\"second.next\"}),\" \\u66F4\\u65B0\\u4E3A \",(0,n.jsx)(e.code,{children:\"second.next.next\"}),\"\\uFF0C\\u4ECE\\u672B\\u5C3E\\u5220\\u9664\\u7B2C \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u4E2A\\u8282\\u70B9\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"dummy.next\"}),\"\\uFF0C\\u5B83\\u6307\\u5411\\u4FEE\\u6539\\u540E\\u7684\\u5217\\u8868\\u7684\\u5934\\u90E8\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(r,{children:m}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u5217\\u8868\\u904D\\u5386\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u4F7F\\u7528\\u6052\\u5B9A\\u7684\\u989D\\u5916\\u7A7A\\u95F4\\u3002\"]}),`\n`]})]})}function w(d={}){let{wrapper:e}=d.components||{};return e?(0,n.jsx)(e,Object.assign({},d,{children:(0,n.jsx)(u,d)})):u(d)}var C=w;return v(_);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/linked-list-detect-cycle/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/linked-list-detect-cycle/locales/zh-CN.json new file mode 100644 index 000000000..3118ffc45 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/linked-list-detect-cycle/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var s=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var T=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),g=(n,e)=>{for(var i in e)s(n,i,{get:e[i],enumerable:!0})},c=(n,e,i,l)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let o of f(e))!k.call(n,o)&&o!==i&&s(n,o,{get:()=>e[o],enumerable:!(l=m(e,o))||l.enumerable});return n};var w=(n,e,i)=>(i=n!=null?p(x(n)):{},c(e||!n||!n.__esModule?s(i,\"default\",{value:n,enumerable:!0}):i,n)),y=n=>c(s({},\"__esModule\",{value:!0}),n);var a=T((M,r)=>{r.exports=_jsx_runtime});var v={};g(v,{default:()=>j,frontmatter:()=>L});var t=w(a());var d=MDXTestExamples;var h=[{input:[[\"list\",[1,2,3]],[\"pos\",0]],output:!0,explanation:\"The linked list is constructed from the array [1, 2, 3] with the pos = 0, which means the last node (value 3) connects back to the 0th node (value 1). The structure of the linked list is: 1 -> 2 -> 3 -> (back to 1). This forms a cycle starting from node 1. Hence, the output is true.\"},{input:[[\"list\",[1]],[\"pos\",-1]],output:!1,explanation:\"The linked list has only one node with the value 1. The pos = -1 indicates that the last node does not connect to any other node. The structure of the linked list is: 1 -> null. Since the list terminates with null and does not loop back to any earlier node, it does not contain a cycle. Hence, the output is false.\"},{input:[[\"list\",[3,2,0,-4]],[\"pos\",1]],output:!0,explanation:\"The linked list is constructed from the array [3, 2, 0, -4] with the pos = 1, which means the last node (value -4) connects back to the 1st node (value 2). The structure of the linked list is: 3 -> 2 -> 0 -> -4 -> (back to 2). This forms a cycle starting at node 2. Hence, the output is true.\"}];var L={title:\"\\u94FE\\u8868\\u68C0\\u6D4B\\u73AF\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u68C0\\u6D4B\\u94FE\\u8868\\u4E2D\\u662F\\u5426\\u6709\\u73AF\"};function u(n){let e=Object.assign({p:\"p\",a:\"a\",code:\"code\",pre:\"pre\",h3:\"h3\",ul:\"ul\",li:\"li\"},n.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\",(0,t.jsx)(e.a,{href:\"https://en.wikipedia.org/wiki/Linked_list\",children:\"\\u94FE\\u8868\"}),\"\\u7684\\u5934\\u8282\\u70B9\\uFF0C\\u786E\\u5B9A\\u8BE5\\u94FE\\u8868\\u662F\\u5426\\u5305\\u542B\\u73AF\\u3002\\u5982\\u679C\\u94FE\\u8868\\u5305\\u542B\\u73AF\\uFF0C\\u5219\\u8FD4\\u56DE\",(0,t.jsx)(e.code,{children:\"true\"}),\"\\uFF1B\\u5426\\u5219\\uFF0C\\u8FD4\\u56DE\",(0,t.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`,(0,t.jsx)(e.p,{children:\"\\u5982\\u679C\\u5B58\\u5728\\u4E00\\u4E2A\\u8282\\u70B9\\u53EF\\u4EE5\\u901A\\u8FC7\\u8FDE\\u7EED\\u8DDF\\u968F\\u4E0B\\u4E00\\u4E2A\\u6307\\u9488\\u88AB\\u91CD\\u65B0\\u8BBF\\u95EE\\uFF0C\\u5219\\u94FE\\u8868\\u5177\\u6709\\u73AF\\u3002\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"\\u94FE\\u8868\\u7531\\u4E00\\u7CFB\\u5217\",(0,t.jsx)(e.code,{children:\"ListNode\"}),\"\\u8868\\u793A\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u8282\\u70B9\\u6307\\u5411\\u5E8F\\u5217\\u4E2D\\u7684\\u4E0B\\u4E00\\u4E2A\\u8282\\u70B9\\uFF0C\\u5982\\u679C\\u5B83\\u662F\\u6700\\u540E\\u4E00\\u4E2A\\u8282\\u70B9\\uFF0C\\u5219\\u6307\\u5411\",(0,t.jsx)(e.code,{children:\"null\"}),\"\\u3002\"]}),`\n`,(0,t.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A\",(0,t.jsx)(e.code,{children:\"ListNode\"}),\"\\u5177\\u6709\\u4EE5\\u4E0B\\u63A5\\u53E3\\uFF1A\"]}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-ts\",children:`interface ListNode {\n val: number;\n next: ListNode | null;\n}\n`})}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.code,{children:\"head: ListNode\"}),\": \\u94FE\\u8868\\u7684\\u5934\\u8282\\u70B9\\u3002\\u793A\\u4F8B\\u5C06\\u6BCF\\u4E2A\\u94FE\\u8868\\u663E\\u793A\\u4E3A\\u5217\\u8868\\u4E2D\\u7684\\u503C\\u6570\\u7EC4\"]}),`\n`]}),`\n`,(0,t.jsx)(d,{testCases:h}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsx)(e.li,{children:\"0 <= \\u8282\\u70B9\\u6570 <= 1000\"}),`\n`,(0,t.jsxs)(e.li,{children:[\"-1000 <= \",(0,t.jsx)(e.code,{children:\"ListNode.val\"}),\" <= 1000\"]}),`\n`]})]})}function _(n={}){let{wrapper:e}=n.components||{};return e?(0,t.jsx)(e,Object.assign({},n,{children:(0,t.jsx)(u,n)})):u(n)}var j=_;return y(v);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来检测链表中是否有环", + "title": "链表检测环" + }, + "solution": "var Component=(()=>{var p=Object.create;var i=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var m=(l,e)=>()=>(e||l((e={exports:{}}).exports,e),e.exports),L=(l,e)=>{for(var d in e)i(l,d,{get:e[d],enumerable:!0})},o=(l,e,d,r)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let c of x(e))!S.call(l,c)&&c!==d&&i(l,c,{get:()=>e[c],enumerable:!(r=w(e,c))||r.enumerable});return l};var b=(l,e,d)=>(d=l!=null?p(y(l)):{},o(e||!l||!l.__esModule?i(d,\"default\",{value:l,enumerable:!0}):d,l)),g=l=>o(i({},\"__esModule\",{value:!0}),l);var s=m((M,h)=>{h.exports=_jsx_runtime});var O={};L(O,{default:()=>N});var n=b(s());var t=MDXCodeBlock;var a=`interface ListNode {\n val: number;\n next: ListNode | null;\n}\n\nexport default function linkedListDetectCycle(head: ListNode | null): boolean {\n // Create a Set to track nodes that have been visited\n const nodesSeen = new Set();\n // Start with the head of the linked list\n let current = head;\n\n // Traverse the linked list\n while (current !== null) {\n // If the current node has been seen before, a cycle is present\n if (nodesSeen.has(current)) {\n return true;\n }\n\n // Add the current node to the Set of seen nodes\n nodesSeen.add(current);\n\n // Move to the next node in the linked list\n current = current.next;\n }\n\n // If the end of the list is reached without finding a cycle, return false\n return false;\n}\n`;var u=`interface ListNode {\n val: number;\n next: ListNode | null;\n}\n\nexport default function linkedListDetectCycle(head: ListNode | null): boolean {\n // If the list is empty or has only one node without a cycle, return false\n if (head === null) {\n return false;\n }\n\n // Initialize two pointers: slow and fast\n // Slow pointer advances by one step at a time\n let slow: ListNode | null = head;\n // Fast pointer advances by two steps at a time\n let fast: ListNode | null = head.next;\n\n // Traverse the list\n while (fast !== null && fast.next !== null) {\n // Move slow pointer by one step\n if (slow === null) {\n // This check is for TypeScript to satisfy non-null assertions\n return false;\n }\n slow = slow.next;\n\n // Move fast pointer by two steps\n fast = fast.next.next;\n\n // If slow and fast pointers meet, a cycle is detected\n if (slow === fast) {\n return true;\n }\n }\n\n // If fast pointer reaches the end of the list, no cycle exists\n return false;\n}\n`;function f(l){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},l.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528 Set\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"Set\"}),\" \\u68C0\\u6D4B\\u94FE\\u8868\\u4E2D\\u5FAA\\u73AF\\u7684\\u65B9\\u6CD5\\u5229\\u7528\\u4E86\\u5FAA\\u73AF\\u4F1A\\u5BFC\\u81F4\\u5BF9\\u67D0\\u4E9B\\u8282\\u70B9\\u7684\\u91CD\\u590D\\u904D\\u5386\\u7684\\u7279\\u6027\\u3002\\u901A\\u8FC7\\u5C06\\u8BBF\\u95EE\\u8FC7\\u7684\\u8282\\u70B9\\u5B58\\u50A8\\u5728 \",(0,n.jsx)(e.code,{children:\"Set\"}),\" \\u4E2D\\uFF0C\\u8BE5\\u7B97\\u6CD5\\u53EF\\u4EE5\\u6709\\u6548\\u5730\\u68C0\\u67E5\\u4E00\\u4E2A\\u8282\\u70B9\\u662F\\u5426\\u5DF2\\u7ECF\\u88AB\\u8BBF\\u95EE\\u8FC7\\u3002\\u5982\\u679C\\u4E00\\u4E2A\\u8282\\u70B9\\u88AB\\u518D\\u6B21\\u8BBF\\u95EE\\uFF0C\\u5219\\u5B58\\u5728\\u5FAA\\u73AF\\u3002\\u5426\\u5219\\uFF0C\\u5982\\u679C\\u904D\\u5386\\u5230\\u8FBE\\u5217\\u8868\\u7684\\u672B\\u5C3E\\uFF0C\\u5219\\u4E0D\\u5B58\\u5728\\u5FAA\\u73AF\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:\"Set\"}),\" \\u63D0\\u4F9B\\u4E86\\u4E00\\u79CD\\u6709\\u6548\\u7684\\u65B9\\u5F0F\\u6765\\u5B58\\u50A8\\u548C\\u68C0\\u67E5\\u8282\\u70B9\\u662F\\u5426\\u5B58\\u5728\\u3002\\u5728 \",(0,n.jsx)(e.code,{children:\"Set\"}),\" \\u4E2D\\u63D2\\u5165\\u548C\\u67E5\\u627E\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(1)\\uFF0C\\u8FD9\\u4F7F\\u5F97\\u5B83\\u975E\\u5E38\\u9002\\u5408\\u8FD9\\u9879\\u4EFB\\u52A1\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5728\\u904D\\u5386\\u8FC7\\u7A0B\\u4E2D\\uFF0C\\u6BCF\\u4E2A\\u8282\\u70B9\\u90FD\\u4F1A\\u88AB\\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"Set\"}),\" \\u4E2D\\u3002\\u5982\\u679C\\u9047\\u5230\\u4E00\\u4E2A\\u5DF2\\u7ECF\\u5B58\\u5728\\u4E8E \",(0,n.jsx)(e.code,{children:\"Set\"}),\" \\u4E2D\\u7684\\u8282\\u70B9\\uFF0C\\u8FD9\\u610F\\u5473\\u7740\\u5217\\u8868\\u5DF2\\u7ECF\\u5FAA\\u73AF\\u56DE\\u5230\\u4E86\\u4E4B\\u524D\\u8BBF\\u95EE\\u8FC7\\u7684\\u8282\\u70B9\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u4E00\\u65E6\\u68C0\\u6D4B\\u5230\\u5FAA\\u73AF\\uFF08\\u627E\\u5230\\u91CD\\u590D\\u7684\\u8282\\u70B9\\uFF09\\uFF0C\\u904D\\u5386\\u5C31\\u4F1A\\u505C\\u6B62\\uFF0C\\u786E\\u4FDD\\u7B97\\u6CD5\\u7684\\u6548\\u7387\\u3002\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5982\\u679C\\u5230\\u8FBE\\u5217\\u8868\\u7684\\u672B\\u5C3E (\",(0,n.jsx)(e.code,{children:\"null\"}),\") \\u4E14\\u6CA1\\u6709\\u9047\\u5230\\u91CD\\u590D\\u7684\\u8282\\u70B9\\uFF0C\\u5219\\u786E\\u8BA4\\u5217\\u8868\\u4E2D\\u6CA1\\u6709\\u5FAA\\u73AF\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u5F88\\u7B80\\u5355\\uFF0C\\u5E76\\u4E14\\u4F7F\\u7528\\u989D\\u5916\\u7684\\u7A7A\\u95F4\\u6765\\u8DDF\\u8E2A\\u8BBF\\u95EE\\u8FC7\\u7684\\u8282\\u70B9\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521B\\u5EFA\\u4E00\\u4E2A\\u540D\\u4E3A \",(0,n.jsx)(e.code,{children:\"nodesSeen\"}),\" \\u7684 \",(0,n.jsx)(e.code,{children:\"Set\"}),\"\\uFF0C\\u7528\\u4E8E\\u5B58\\u50A8\\u5DF2\\u8BBF\\u95EE\\u7684\\u8282\\u70B9\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u53D8\\u91CF \",(0,n.jsx)(e.code,{children:\"current\"}),\"\\uFF0C\\u4F7F\\u5176\\u6307\\u5411\\u94FE\\u8868\\u7684\\u5934\\u90E8\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"while\"}),\" \\u5FAA\\u73AF\\u904D\\u5386\\u5217\\u8868\\uFF0C\\u76F4\\u5230 \",(0,n.jsx)(e.code,{children:\"current\"}),\" \\u53D8\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5 \",(0,n.jsx)(e.code,{children:\"current\"}),\" \\u662F\\u5426\\u5DF2\\u7ECF\\u5728 \",(0,n.jsx)(e.code,{children:\"nodesSeen\"}),\" \\u4E2D\\u3002\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u4E3A \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\uFF0C\\u56E0\\u4E3A\\u68C0\\u6D4B\\u5230\\u5FAA\\u73AF\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"current\"}),\" \\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"nodesSeen\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"current\"}),\" \\u79FB\\u52A8\\u5230\\u5217\\u8868\\u4E2D\\u7684\\u4E0B\\u4E00\\u4E2A\\u8282\\u70B9\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5FAA\\u73AF\\u7ED3\\u675F\\u800C\\u672A\\u68C0\\u6D4B\\u5230\\u5FAA\\u73AF\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(t,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u5217\\u8868\\u4E2D\\u7684\\u6BCF\\u4E2A\\u8282\\u70B9\\u90FD\\u4F1A\\u88AB\\u8BBF\\u95EE\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\",(0,n.jsx)(e.code,{children:\"Set\"}),\" \\u6700\\u591A\\u5B58\\u50A8 \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u4E2A\\u8282\\u70B9\\uFF08\\u5728\\u6CA1\\u6709\\u5FAA\\u73AF\\u7684\\u6700\\u574F\\u60C5\\u51B5\\u4E0B\\uFF09\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528 Floyd \\u5FAA\\u73AF\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"Floyd \\u5FAA\\u73AF\\u68C0\\u6D4B\\u7B97\\u6CD5\\uFF0C\\u4E5F\\u79F0\\u4E3A\\u201C\\u9F9F\\u5154\\u8D5B\\u8DD1\\u201D\\u7B97\\u6CD5\\uFF0C\\u662F\\u4E00\\u79CD\\u7528\\u4E8E\\u68C0\\u6D4B\\u94FE\\u8868\\u4E2D\\u5FAA\\u73AF\\u7684\\u6709\\u6548\\u65B9\\u6CD5\\u3002\\u8BE5\\u7B97\\u6CD5\\u4F7F\\u7528\\u4E24\\u4E2A\\u6307\\u9488\\uFF0C\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"slow\"}),\" \\u6307\\u9488\\u548C\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"fast\"}),\" \\u6307\\u9488\\uFF0C\\u5B83\\u4EEC\\u4EE5\\u4E0D\\u540C\\u7684\\u901F\\u5EA6\\u904D\\u5386\\u5217\\u8868\\u3002\\u5982\\u679C\\u5B58\\u5728\\u5FAA\\u73AF\\uFF0C\\u8FD9\\u4E24\\u4E2A\\u6307\\u9488\\u6700\\u7EC8\\u4F1A\\u76F8\\u9047\\u3002\\u5426\\u5219\\uFF0C\",(0,n.jsx)(e.code,{children:\"fast\"}),\" \\u6307\\u9488\\u5C06\\u5230\\u8FBE\\u5217\\u8868\\u7684\\u672B\\u5C3E\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:\"slow\"}),\" \\u6307\\u9488\\u4E00\\u6B21\\u79FB\\u52A8\\u4E00\\u6B65\\uFF0C\\u800C \",(0,n.jsx)(e.code,{children:\"fast\"}),\" \\u6307\\u9488\\u4E00\\u6B21\\u79FB\\u52A8\\u4E24\\u6B65\\u3002\\u8FD9\\u79CD\\u901F\\u5EA6\\u5DEE\\u5F02\\u786E\\u4FDD\\u5982\\u679C\\u5B58\\u5728\\u5FAA\\u73AF\\uFF0C\",(0,n.jsx)(e.code,{children:\"fast\"}),\" \\u6307\\u9488\\u6700\\u7EC8\\u4F1A\\u8FFD\\u4E0A \",(0,n.jsx)(e.code,{children:\"slow\"}),\" \\u6307\\u9488\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5982\\u679C\\u4E24\\u4E2A\\u6307\\u9488\\u5728\\u904D\\u5386\\u8FC7\\u7A0B\\u4E2D\\u76F8\\u9047\\uFF0C\\u5219\\u786E\\u8BA4\\u5B58\\u5728\\u5FAA\\u73AF\\u3002\\u8FD9\\u662F\\u56E0\\u4E3A \",(0,n.jsx)(e.code,{children:\"fast\"}),\" \\u6307\\u9488\\u7ED5\\u7740\\u5FAA\\u73AF\\u8F6C\\u4E86\\u4E00\\u5708\\u5E76\\u8FFD\\u4E0A\\u4E86 \",(0,n.jsx)(e.code,{children:\"slow\"}),\" \\u6307\\u9488\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"fast\"}),\" \\u6307\\u9488\\u5230\\u8FBE\\u5217\\u8868\\u7684\\u672B\\u5C3E (\",(0,n.jsx)(e.code,{children:\"null\"}),\")\\uFF0C\\u5219\\u8868\\u793A\\u5217\\u8868\\u4E2D\\u6CA1\\u6709\\u5FAA\\u73AF\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\\u8BE5\\u7B97\\u6CD5\\u5BF9\\u975E\\u5FAA\\u73AF\\u5217\\u8868\\u7684\\u6709\\u6548\\u7EC8\\u6B62\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u7B97\\u6CD5\\u5728\\u7EBF\\u6027\\u65F6\\u95F4\\u5185\\u8FD0\\u884C\\u5E76\\u4F7F\\u7528\\u6052\\u5B9A\\u7A7A\\u95F4\\uFF0C\\u4F7F\\u5176\\u6210\\u4E3A\\u68C0\\u6D4B\\u94FE\\u8868\\u4E2D\\u5FAA\\u73AF\\u7684\\u6700\\u4F73\\u9009\\u62E9\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u94FE\\u8868\\u7684\\u5934\\u662F\\u5426\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\u3002\\u5982\\u679C\\u4E3A\\u771F\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\uFF0C\\u56E0\\u4E3A\\u7A7A\\u94FE\\u8868\\u4E0D\\u80FD\\u6709\\u73AF\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E24\\u4E2A\\u6307\\u9488\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"slow\"}),\" \\u6307\\u9488\\u8BBE\\u7F6E\\u4E3A\\u94FE\\u8868\\u7684\\u5934\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"fast\"}),\" \\u6307\\u9488\\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"head.next\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"while\"}),\" \\u5FAA\\u73AF\\u904D\\u5386\\u94FE\\u8868\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5 \",(0,n.jsx)(e.code,{children:\"fast\"}),\" \\u6216 \",(0,n.jsx)(e.code,{children:\"fast.next\"}),\" \\u662F\\u5426\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\u3002\\u5982\\u679C\\u4E3A\\u771F\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\uFF0C\\u56E0\\u4E3A\\u6CA1\\u6709\\u73AF\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"slow\"}),\" \\u6307\\u9488\\u5411\\u524D\\u79FB\\u52A8\\u4E00\\u6B65 (\",(0,n.jsx)(e.code,{children:\"slow = slow.next\"}),\")\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"fast\"}),\" \\u6307\\u9488\\u5411\\u524D\\u79FB\\u52A8\\u4E24\\u6B65 (\",(0,n.jsx)(e.code,{children:\"fast = fast.next.next\"}),\")\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5 \",(0,n.jsx)(e.code,{children:\"slow\"}),\" \\u6307\\u9488\\u662F\\u5426\\u7B49\\u4E8E \",(0,n.jsx)(e.code,{children:\"fast\"}),\" \\u6307\\u9488\\u3002\\u5982\\u679C\\u4E3A\\u771F\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\uFF0C\\u56E0\\u4E3A\\u68C0\\u6D4B\\u5230\\u73AF\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5FAA\\u73AF\\u5728\\u6307\\u9488\\u672A\\u76F8\\u9047\\u7684\\u60C5\\u51B5\\u4E0B\\u7ED3\\u675F\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\uFF0C\\u56E0\\u4E3A\\u4E0D\\u5B58\\u5728\\u73AF\\u3002\"]}),`\n`]}),`\n`,(0,n.jsxs)(t,{children:[\" \",u,\" \"]}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u6BCF\\u4E2A\\u6307\\u9488\\u6700\\u591A\\u904D\\u5386\\u5217\\u8868\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u4EC5\\u4F7F\\u7528\\u4E24\\u4E2A\\u6307\\u9488\\uFF0C\\u4E0E\\u5217\\u8868\\u7684\\u5927\\u5C0F\\u65E0\\u5173\\u3002\"]}),`\n`]})]})}function C(l={}){let{wrapper:e}=l.components||{};return e?(0,n.jsx)(e,Object.assign({},l,{children:(0,n.jsx)(f,l)})):f(l)}var N=C;return g(O);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/linked-list-rearrange/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/linked-list-rearrange/locales/zh-CN.json new file mode 100644 index 000000000..7d3f8b6af --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/linked-list-rearrange/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var u=Object.create;var l=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var _=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),g=(t,e)=>{for(var i in e)l(t,i,{get:e[i],enumerable:!0})},c=(t,e,i,d)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of m(e))!f.call(t,r)&&r!==i&&l(t,r,{get:()=>e[r],enumerable:!(d=L(e,r))||d.enumerable});return t};var j=(t,e,i)=>(i=t!=null?u(x(t)):{},c(e||!t||!t.__esModule?l(i,\"default\",{value:t,enumerable:!0}):i,t)),N=t=>c(l({},\"__esModule\",{value:!0}),t);var s=_((X,o)=>{o.exports=_jsx_runtime});var C={};g(C,{default:()=>T,frontmatter:()=>w});var n=j(s());var a=MDXTestExamples;var h=[{input:[[\"list\",[9,9,10,7,10,6,4,2,3,1]]],output:[9,1,9,3,10,2,7,4,10,6],explanation:\"The list is reordered to alternate between the start and end of the list.\"},{input:[[\"list\",[1,2,3,4,5,6]]],output:[1,6,2,5,3,4],explanation:\"The list is reordered to alternate between the start and end of the list.\"}];var w={title:\"\\u91CD\\u6392\\u94FE\\u8868\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u91CD\\u65B0\\u6392\\u5217\\u94FE\\u8868\\u4E2D\\u7684\\u8282\\u70B9\"};function p(t){let e=Object.assign({p:\"p\",a:\"a\",code:\"code\",pre:\"pre\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\",(0,n.jsx)(e.a,{href:\"https://en.wikipedia.org/wiki/Linked_list\",children:\"\\u94FE\\u8868\"}),\"\\u7684\\u5934\\u8282\\u70B9\",(0,n.jsx)(e.code,{children:\"head\"}),\"\\uFF0C\\u91CD\\u65B0\\u6392\\u5217\\u5217\\u8868\\uFF0C\\u4F7F\\u5217\\u8868\\u4ECE\\u5934\\u8282\\u70B9\\u548C\\u5C3E\\u8282\\u70B9\\u4EA4\\u66FF\\u51FA\\u73B0\\u3002\\u91CD\\u65B0\\u6392\\u5E8F\\u5E94\\u8BE5\\u901A\\u8FC7\\u91CD\\u65B0\\u6392\\u5217\\u8282\\u70B9\\u672C\\u8EAB\\u6765\\u6267\\u884C\\uFF0C\\u800C\\u65E0\\u9700\\u4FEE\\u6539\\u5B58\\u50A8\\u5728\\u8282\\u70B9\\u4E2D\\u7684\\u503C\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u539F\\u59CB\\u7ED3\\u6784\\u5982\\u4E0B\\uFF1A\"}),`\n`,(0,n.jsx)(e.p,{children:(0,n.jsx)(e.code,{children:\"L0 \\u2192 L1 \\u2192 ... \\u2192 Ln-1 \\u2192 Ln\"})}),`\n`,(0,n.jsx)(e.p,{children:\"\\u5C06\\u5217\\u8868\\u91CD\\u65B0\\u7EC4\\u7EC7\\u6210\\u4EE5\\u4E0B\\u7ED3\\u6784\\uFF1A\"}),`\n`,(0,n.jsx)(e.p,{children:(0,n.jsx)(e.code,{children:\"L0 \\u2192 Ln \\u2192 L1 \\u2192 Ln-1 \\u2192 L2 \\u2192 Ln-2 \\u2192 \\u2026\"})}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u94FE\\u8868\\u7531\\u4E00\\u7CFB\\u5217\",(0,n.jsx)(e.code,{children:\"ListNode\"}),\"\\u8868\\u793A\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u8282\\u70B9\\u6307\\u5411\\u5E8F\\u5217\\u4E2D\\u7684\\u4E0B\\u4E00\\u4E2A\\u8282\\u70B9\\uFF0C\\u5982\\u679C\\u5B83\\u662F\\u6700\\u540E\\u4E00\\u4E2A\\u8282\\u70B9\\uFF0C\\u5219\\u6307\\u5411\",(0,n.jsx)(e.code,{children:\"null\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A\",(0,n.jsx)(e.code,{children:\"ListNode\"}),\"\\u5177\\u6709\\u4EE5\\u4E0B\\u63A5\\u53E3\\uFF1A\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-ts\",children:`interface ListNode {\n val: number;\n next: ListNode | null;\n}\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"head: ListNode\"}),\": \\u94FE\\u8868\\u7684\\u5934\\u8282\\u70B9\\u3002\\u793A\\u4F8B\\u5C06\\u6BCF\\u4E2A\\u94FE\\u8868\\u663E\\u793A\\u4E3A\\u5217\\u8868\\u4E2D\\u7684\\u503C\\u6570\\u7EC4\"]}),`\n`]}),`\n`,(0,n.jsx)(a,{testCases:h}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"1 <= \\u8282\\u70B9\\u6570 <= 1000\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"ListNode.val\"}),\" <= 1000\"]}),`\n`]})]})}function M(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(p,t)})):p(t)}var T=M;return N(C);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来重新排列链表中的节点", + "title": "重排链表" + }, + "solution": "var Component=(()=>{var f=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var w=(l,e)=>()=>(e||l((e={exports:{}}).exports,e),e.exports),v=(l,e)=>{for(var d in e)i(l,d,{get:e[d],enumerable:!0})},o=(l,e,d,r)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let c of m(e))!L.call(l,c)&&c!==d&&i(l,c,{get:()=>e[c],enumerable:!(r=p(e,c))||r.enumerable});return l};var g=(l,e,d)=>(d=l!=null?f(x(l)):{},o(e||!l||!l.__esModule?i(d,\"default\",{value:l,enumerable:!0}):d,l)),N=l=>o(i({},\"__esModule\",{value:!0}),l);var h=w((O,t)=>{t.exports=_jsx_runtime});var k={};v(k,{default:()=>M});var n=g(h());var s=MDXCodeBlock;var u=`interface ListNode {\n val: number;\n next: ListNode | null;\n}\n\nexport default function rearrangeLinkedList(head: ListNode | null): void {\n if (head === null) {\n return;\n }\n\n let slow: ListNode | null = head;\n let fast: ListNode | null = head;\n\n // Locate the middle node of the linked list\n // For example, in the list 1->2->3->4->5->6, the middle is 4\n while (fast !== null && fast.next !== null) {\n slow = slow!.next;\n fast = fast.next.next;\n }\n\n // Reverse the second half of the list\n // Transform 1->2->3->4->5->6 into 1->2->3->4 and 6->5->4 (reversed in-place)\n let prev: ListNode | null = null;\n let curr: ListNode | null = slow;\n while (curr !== null) {\n const tmp: ListNode | null = curr.next;\n curr.next = prev;\n prev = curr;\n curr = tmp;\n }\n\n // Merge the two halves of the list\n // Combine 1->2->3->4 and 6->5->4 into 1->6->2->5->3->4\n let first: ListNode | null = head;\n let second: ListNode | null = prev;\n while (second !== null && second.next !== null) {\n const tmp1: ListNode | null = first!.next;\n first!.next = second;\n first = tmp1;\n\n const tmp2: ListNode | null = second.next;\n second.next = first;\n second = tmp2;\n }\n}\n`;function a(l){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},l.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u5408\\u5E76\\u5217\\u8868\\u4E0E\\u53CD\\u5411\\u5B50\\u5217\\u8868\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u95EE\\u9898\\u6D89\\u53CA\\u91CD\\u65B0\\u6392\\u5217\\u94FE\\u8868\\uFF0C\\u4F7F\\u5F97\\u8282\\u70B9\\u5728\\u5217\\u8868\\u7684\\u524D\\u534A\\u90E8\\u5206\\u548C\\u540E\\u534A\\u90E8\\u5206\\u4E4B\\u95F4\\u4EA4\\u66FF\\u3002\\u8FD9\\u79CD\\u65B9\\u6CD5\\u4F7F\\u7528\\u4E09\\u4E2A\\u5173\\u952E\\u6B65\\u9AA4\\u7684\\u7EC4\\u5408\\uFF1A\\u5B9A\\u4F4D\\u5217\\u8868\\u7684\\u4E2D\\u95F4\\u4F4D\\u7F6E\\uFF0C\\u53CD\\u8F6C\\u5217\\u8868\\u7684\\u540E\\u534A\\u90E8\\u5206\\uFF0C\\u4EE5\\u53CA\\u5408\\u5E76\\u8FD9\\u4E24\\u4E2A\\u90E8\\u5206\\u3002\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u94FE\\u8868\\u7684\\u4E2D\\u95F4\\u4F4D\\u7F6E\\u4F7F\\u7528\\u53CC\\u6307\\u9488\\u6280\\u672F\\u786E\\u5B9A\\u3002\",(0,n.jsx)(e.code,{children:\"slow\"}),\"\\u6307\\u9488\\u4E00\\u6B21\\u79FB\\u52A8\\u4E00\\u6B65\\uFF0C\\u800C\",(0,n.jsx)(e.code,{children:\"fast\"}),\"\\u6307\\u9488\\u79FB\\u52A8\\u4E24\\u6B65\\u3002\\u5F53\",(0,n.jsx)(e.code,{children:\"fast\"}),\"\\u6307\\u9488\\u5230\\u8FBE\\u672B\\u5C3E\\u65F6\\uFF0C\",(0,n.jsx)(e.code,{children:\"slow\"}),\"\\u6307\\u9488\\u4F4D\\u4E8E\\u4E2D\\u95F4\\u4F4D\\u7F6E\\u3002\\u8FD9\\u4F1A\\u5C06\\u5217\\u8868\\u5206\\u6210\\u4E24\\u534A\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u5217\\u8868\\u7684\\u540E\\u534A\\u90E8\\u5206\\u5C31\\u5730\\u53CD\\u8F6C\\u3002\\u8FD9\\u4F1A\\u5C06\\u94FE\\u8868\\u8F6C\\u6362\\u4E3A\\u4E24\\u90E8\\u5206\\uFF1A\\u524D\\u534A\\u90E8\\u5206\\u6309\\u539F\\u59CB\\u987A\\u5E8F\\u6392\\u5217\\uFF0C\\u540E\\u534A\\u90E8\\u5206\\u6309\\u53CD\\u5411\\u987A\\u5E8F\\u6392\\u5217\\u3002\\u53CD\\u8F6C\\u662F\\u4E3A\\u4E86\\u65B9\\u4FBF\\u4EA4\\u66FF\\u5408\\u5E76\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u901A\\u8FC7\\u4EA4\\u66FF\\u9009\\u62E9\\u6765\\u81EA\\u524D\\u534A\\u90E8\\u5206\\u548C\\u53CD\\u5411\\u540E\\u534A\\u90E8\\u5206\\u7684\\u8282\\u70B9\\u6765\\u5408\\u5E76\\u8FD9\\u4E24\\u534A\\u3002\\u8FD9\\u4F1A\\u4EE5\\u6240\\u9700\\u7684\\u4EA4\\u66FF\\u6A21\\u5F0F\\u91CD\\u65B0\\u6392\\u5217\\u5217\\u8868\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u5728\\u7EBF\\u6027\\u65F6\\u95F4\\u5185\\u6709\\u6548\\u5730\\u89E3\\u51B3\\u4E86\\u95EE\\u9898\\uFF0C\\u5E76\\u4F7F\\u7528\\u6052\\u5B9A\\u7A7A\\u95F4\\u6765\\u91CD\\u65B0\\u6392\\u5E8F\\u8282\\u70B9\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\",(0,n.jsx)(e.code,{children:\"head\"}),\"\\u662F\\u5426\\u4E3A\",(0,n.jsx)(e.code,{children:\"null\"}),\"\\u3002\\u5982\\u679C\\u4E3A\\u771F\\uFF0C\\u5219\\u7ACB\\u5373\\u8FD4\\u56DE\\uFF0C\\u56E0\\u4E3A\\u6CA1\\u6709\\u4EC0\\u4E48\\u53EF\\u91CD\\u65B0\\u6392\\u5217\\u7684\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E24\\u4E2A\\u6307\\u9488\",(0,n.jsx)(e.code,{children:\"slow\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"fast\"}),\"\\uFF0C\\u90FD\\u8BBE\\u7F6E\\u4E3A\\u94FE\\u8868\\u7684\",(0,n.jsx)(e.code,{children:\"head\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4F4D\\u5217\\u8868\\u7684\\u4E2D\\u95F4\\u4F4D\\u7F6E\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u6BCF\\u6B21\\u79FB\\u52A8\",(0,n.jsx)(e.code,{children:\"slow\"}),\"\\u4E00\\u6B65\\uFF0C\",(0,n.jsx)(e.code,{children:\"fast\"}),\"\\u4E24\\u6B65\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5F53\",(0,n.jsx)(e.code,{children:\"fast\"}),\"\\u4E3A\",(0,n.jsx)(e.code,{children:\"null\"}),\"\\u6216\",(0,n.jsx)(e.code,{children:\"fast.next\"}),\"\\u4E3A\",(0,n.jsx)(e.code,{children:\"null\"}),\"\\u65F6\\u505C\\u6B62\\u3002\",(0,n.jsx)(e.code,{children:\"slow\"}),\"\\u6307\\u9488\\u73B0\\u5728\\u5C06\\u6307\\u5411\\u4E2D\\u95F4\\u8282\\u70B9\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u53CD\\u8F6C\\u5217\\u8868\\u7684\\u540E\\u534A\\u90E8\\u5206\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\",(0,n.jsx)(e.code,{children:\"prev\"}),\"\\u521D\\u59CB\\u5316\\u4E3A\",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u5C06\",(0,n.jsx)(e.code,{children:\"curr\"}),\"\\u521D\\u59CB\\u5316\\u4E3A\",(0,n.jsx)(e.code,{children:\"slow\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\",(0,n.jsx)(e.code,{children:\"slow\"}),\"\\u904D\\u5386\\u5217\\u8868\\u5230\\u672B\\u5C3E\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u4E0B\\u4E00\\u4E2A\\u8282\\u70B9\\u5B58\\u50A8\\u5728\\u4E34\\u65F6\\u53D8\\u91CF\",(0,n.jsx)(e.code,{children:\"tmp\"}),\"\\u4E2D\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\",(0,n.jsx)(e.code,{children:\"curr.next\"}),\"\\u66F4\\u65B0\\u4E3A\\u6307\\u5411\",(0,n.jsx)(e.code,{children:\"prev\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\",(0,n.jsx)(e.code,{children:\"prev\"}),\"\\u79FB\\u52A8\\u5230\",(0,n.jsx)(e.code,{children:\"curr\"}),\"\\uFF0C\\u5C06\",(0,n.jsx)(e.code,{children:\"curr\"}),\"\\u79FB\\u52A8\\u5230\",(0,n.jsx)(e.code,{children:\"tmp\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5408\\u5E76\\u5217\\u8868\\u7684\\u4E24\\u534A\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\",(0,n.jsx)(e.code,{children:\"first\"}),\"\\u521D\\u59CB\\u5316\\u4E3A\\u5217\\u8868\\u7684\",(0,n.jsx)(e.code,{children:\"head\"}),\"\\uFF0C\\u5C06\",(0,n.jsx)(e.code,{children:\"second\"}),\"\\u521D\\u59CB\\u5316\\u4E3A\",(0,n.jsx)(e.code,{children:\"prev\"}),\"\\uFF08\\u53CD\\u5411\\u540E\\u534A\\u90E8\\u5206\\u7684\\u5934\\uFF09\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4EA4\\u66FF\\u94FE\\u63A5\\u6765\\u81EA\",(0,n.jsx)(e.code,{children:\"first\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"second\"}),\"\\u7684\\u8282\\u70B9\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\",(0,n.jsx)(e.code,{children:\"first\"}),\"\\u7684\\u4E0B\\u4E00\\u4E2A\\u8282\\u70B9\\u5B58\\u50A8\\u5728\",(0,n.jsx)(e.code,{children:\"tmp1\"}),\"\\u4E2D\\uFF0C\\u5C06\",(0,n.jsx)(e.code,{children:\"second\"}),\"\\u7684\\u4E0B\\u4E00\\u4E2A\\u8282\\u70B9\\u5B58\\u50A8\\u5728\",(0,n.jsx)(e.code,{children:\"tmp2\"}),\"\\u4E2D\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\",(0,n.jsx)(e.code,{children:\"first.next\"}),\"\\u66F4\\u65B0\\u4E3A\\u6307\\u5411\",(0,n.jsx)(e.code,{children:\"second\"}),\"\\uFF0C\\u5C06\",(0,n.jsx)(e.code,{children:\"second.next\"}),\"\\u66F4\\u65B0\\u4E3A\\u6307\\u5411\",(0,n.jsx)(e.code,{children:\"tmp1\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\",(0,n.jsx)(e.code,{children:\"first\"}),\"\\u79FB\\u52A8\\u5230\",(0,n.jsx)(e.code,{children:\"tmp1\"}),\"\\uFF0C\\u5C06\",(0,n.jsx)(e.code,{children:\"second\"}),\"\\u79FB\\u52A8\\u5230\",(0,n.jsx)(e.code,{children:\"tmp2\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(s,{children:[\" \",u,\" \"]}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u5728\\u4E09\\u4E2A\\u6B65\\u9AA4\\u4E2D\\uFF0C\\u6BCF\\u4E2A\\u8282\\u70B9\\u90FD\\u4F1A\\u88AB\\u8BBF\\u95EE\\u4E00\\u6B21\\uFF1A\\u627E\\u5230\\u4E2D\\u95F4\\u4F4D\\u7F6E\\u3001\\u53CD\\u8F6C\\u540E\\u534A\\u90E8\\u5206\\u548C\\u5408\\u5E76\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u4F7F\\u7528\\u6052\\u5B9A\\u91CF\\u7684\\u989D\\u5916\\u7A7A\\u95F4\\u3002\"]}),`\n`]})]})}function _(l={}){let{wrapper:e}=l.components||{};return e?(0,n.jsx)(e,Object.assign({},l,{children:(0,n.jsx)(a,l)})):a(l)}var M=_;return N(k);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/linked-list-reversal/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/linked-list-reversal/locales/zh-CN.json new file mode 100644 index 000000000..45a76dea1 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/linked-list-reversal/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var u=Object.create;var r=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var _=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),g=(t,e)=>{for(var i in e)r(t,i,{get:e[i],enumerable:!0})},d=(t,e,i,s)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let l of x(e))!L.call(t,l)&&l!==i&&r(t,l,{get:()=>e[l],enumerable:!(s=m(e,l))||s.enumerable});return t};var j=(t,e,i)=>(i=t!=null?u(f(t)):{},d(e||!t||!t.__esModule?r(i,\"default\",{value:t,enumerable:!0}):i,t)),N=t=>d(r({},\"__esModule\",{value:!0}),t);var o=_((D,c)=>{c.exports=_jsx_runtime});var w={};g(w,{default:()=>v,frontmatter:()=>M});var n=j(o());var a=MDXTestExamples;var h=[{input:[[\"list\",[1,2,3,4,5]]],output:[5,4,3,2,1],explanation:\"The input list [1, 2, 3, 4, 5] creates a linked list that, when reversed, produces [5, 4, 3, 2, 1].\"},{input:[[\"list\",[]]],output:[],explanation:\"The input list is empty, so the reversed linked list is also empty.\"}];var M={title:\"\\u94FE\\u8868\\u53CD\\u8F6C\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u53CD\\u8F6C\\u94FE\\u8868\\u7684\\u51FD\\u6570\"};function p(t){let e=Object.assign({p:\"p\",a:\"a\",code:\"code\",pre:\"pre\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\",(0,n.jsx)(e.a,{href:\"https://en.wikipedia.org/wiki/Linked_list\",children:\"\\u94FE\\u8868\"}),\"\\u7684\\u5934\\u8282\\u70B9\\uFF0C\\u53CD\\u8F6C\\u94FE\\u8868\\u5E76\\u8FD4\\u56DE\\u53CD\\u8F6C\\u540E\\u94FE\\u8868\\u7684\\u65B0\\u5934\\u8282\\u70B9\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u94FE\\u8868\\u7531\\u4E00\\u7CFB\\u5217\",(0,n.jsx)(e.code,{children:\"ListNode\"}),\"\\u8868\\u793A\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u8282\\u70B9\\u6307\\u5411\\u5E8F\\u5217\\u4E2D\\u7684\\u4E0B\\u4E00\\u4E2A\\u8282\\u70B9\\uFF0C\\u5982\\u679C\\u5B83\\u662F\\u6700\\u540E\\u4E00\\u4E2A\\u8282\\u70B9\\uFF0C\\u5219\\u6307\\u5411\",(0,n.jsx)(e.code,{children:\"null\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A\",(0,n.jsx)(e.code,{children:\"ListNode\"}),\"\\u5177\\u6709\\u4EE5\\u4E0B\\u63A5\\u53E3\\uFF1A\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-ts\",children:`interface ListNode {\n val: number;\n next: ListNode | null;\n}\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"head: ListNode\"}),\": \\u94FE\\u8868\\u7684\\u5934\\u8282\\u70B9\\u3002\\u793A\\u4F8B\\u5C06\\u6BCF\\u4E2A\\u94FE\\u8868\\u663E\\u793A\\u4E3A\\u5217\\u8868\\u4E2D\\u7684\\u503C\\u6570\\u7EC4\"]}),`\n`]}),`\n`,(0,n.jsx)(a,{testCases:h}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"1 <= \\u8282\\u70B9\\u6570 <= 1000\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"-1000 <= \",(0,n.jsx)(e.code,{children:\"ListNode.val\"}),\" <= 1000\"]}),`\n`]})]})}function T(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(p,t)})):p(t)}var v=T;return N(w);})();\n;return Component;", + "info": { + "excerpt": "实现一个反转链表的函数", + "title": "链表反转" + }, + "solution": "var Component=(()=>{var x=Object.create;var c=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var g=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),N=(r,e)=>{for(var d in e)c(r,d,{get:e[d],enumerable:!0})},t=(r,e,d,h)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let l of L(e))!m.call(r,l)&&l!==d&&c(r,l,{get:()=>e[l],enumerable:!(h=v(e,l))||h.enumerable});return r};var k=(r,e,d)=>(d=r!=null?x(f(r)):{},t(e||!r||!r.__esModule?c(d,\"default\",{value:r,enumerable:!0}):d,r)),O=r=>t(c({},\"__esModule\",{value:!0}),r);var s=g((B,o)=>{o.exports=_jsx_runtime});var M={};N(M,{default:()=>w});var n=k(s());var i=MDXCodeBlock;var u=`interface ListNode {\n val: number;\n next: ListNode | null;\n}\n\nexport default function reverseLinkedList(\n head: ListNode | null,\n): ListNode | null {\n // Initialize pointers\n let prev: ListNode | null = null; // Previous node, initially null\n let curr: ListNode | null = head; // Current node, starts with head\n\n // Iterate over the linked list\n while (curr !== null) {\n // Temporarily store the next node\n const nextTemp: ListNode | null = curr.next;\n\n // Reverse the current node's pointer\n curr.next = prev;\n\n // Move prev and curr one step forward\n prev = curr;\n curr = nextTemp;\n }\n\n // Return the new head of the reversed list\n return prev;\n}\n`;var a=`interface ListNode {\n val: number;\n next: ListNode | null;\n}\n\nexport default function reverseLinkedList(\n head: ListNode | null,\n): ListNode | null {\n // Base case: if the list is empty or has only one node, return the head\n if (head === null || head.next === null) {\n return head;\n }\n\n // Recursive case: reverse the rest of the list\n const p: ListNode | null = reverseLinkedList(head.next);\n\n // Set the next node's next reference to the current node\n head.next.next = head;\n\n // Set the current node's next reference to null\n head.next = null;\n\n // Return the new head of the reversed list\n return p;\n}\n`;function p(r){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u8FED\\u4EE3\\u65B9\\u6CD5\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u53CD\\u8F6C\\u94FE\\u8868\\u6D89\\u53CA\\u7FFB\\u8F6C\\u6240\\u6709\\u8282\\u70B9\\u7684 \",(0,n.jsx)(e.code,{children:\"next\"}),\" \\u6307\\u9488\\uFF0C\\u4F7F\\u5176\\u6307\\u5411\\u524D\\u4E00\\u4E2A\\u8282\\u70B9\\u800C\\u4E0D\\u662F\\u4E0B\\u4E00\\u4E2A\\u8282\\u70B9\\u3002\\u8FED\\u4EE3\\u65B9\\u6CD5\\u4F7F\\u7528\\u4E24\\u4E2A\\u6307\\u9488 \",(0,n.jsx)(e.code,{children:\"prev\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"curr\"}),\" \\u5206\\u522B\\u8DDF\\u8E2A\\u524D\\u4E00\\u4E2A\\u8282\\u70B9\\u548C\\u5F53\\u524D\\u8282\\u70B9\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\\u5217\\u8868\\u5728\\u539F\\u5730\\u53CD\\u8F6C\\uFF0C\\u800C\\u65E0\\u9700\\u989D\\u5916\\u7684\\u5185\\u5B58\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u6BCF\\u4E2A\\u8282\\u70B9\\u7684 \",(0,n.jsx)(e.code,{children:\"next\"}),\" \\u6307\\u9488\\u88AB\\u53CD\\u8F6C\\u4EE5\\u6307\\u5411\\u524D\\u4E00\\u4E2A\\u8282\\u70B9\\u3002\\u6B64\\u64CD\\u4F5C\\u5BF9\\u5217\\u8868\\u4E2D\\u7684\\u6240\\u6709\\u8282\\u70B9\\u8FDB\\u884C\\u8FED\\u4EE3\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:\"curr\"}),\" \\u6307\\u9488\\u4ECE\\u5934\\u5230\\u5C3E\\u904D\\u5386\\u5217\\u8868\\uFF0C\\u800C \",(0,n.jsx)(e.code,{children:\"prev\"}),\" \\u6307\\u9488\\u6EDE\\u540E\\uFF0C\\u9010\\u6B65\\u6784\\u5EFA\\u5217\\u8868\\u7684\\u53CD\\u8F6C\\u90E8\\u5206\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u901A\\u8FC7\\u4EC5\\u4F7F\\u7528\\u51E0\\u4E2A\\u6307\\u9488 (\",(0,n.jsx)(e.code,{children:\"prev\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"curr\"}),\" \\u548C\\u4E00\\u4E2A\\u7528\\u4E8E\\u4E0B\\u4E00\\u4E2A\\u8282\\u70B9\\u7684\\u4E34\\u65F6\\u6307\\u9488)\\uFF0C\\u8BE5\\u7B97\\u6CD5\\u5B9E\\u73B0\\u4E86\\u53CD\\u8F6C\\uFF0C\\u800C\\u65E0\\u9700\\u4E3A\\u65B0\\u5217\\u8868\\u5206\\u914D\\u989D\\u5916\\u7684\\u7A7A\\u95F4\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5F53 \",(0,n.jsx)(e.code,{children:\"curr\"}),\" \\u6307\\u9488\\u53D8\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\" \\u65F6\\uFF0C\\u8BE5\\u8FC7\\u7A0B\\u7ED3\\u675F\\uFF0C\\u8FD9\\u8868\\u660E\\u6240\\u6709\\u8282\\u70B9\\u90FD\\u5DF2\\u88AB\\u53CD\\u8F6C\\u3002\\u6B64\\u65F6\\uFF0C\",(0,n.jsx)(e.code,{children:\"prev\"}),\" \\u6307\\u9488\\u6307\\u5411\\u53CD\\u8F6C\\u5217\\u8868\\u7684\\u65B0\\u5934\\u90E8\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u5728\\u7EBF\\u6027\\u65F6\\u95F4\\u5185\\u6709\\u6548\\u5730\\u53CD\\u8F6C\\u5217\\u8868\\uFF0C\\u540C\\u65F6\\u4FDD\\u6301\\u6052\\u5B9A\\u7684\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E24\\u4E2A\\u6307\\u9488\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"prev\"}),\" \\u521D\\u59CB\\u5316\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u8868\\u793A\\u524D\\u4E00\\u4E2A\\u8282\\u70B9\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"curr\"}),\" \\u521D\\u59CB\\u5316\\u4E3A \",(0,n.jsx)(e.code,{children:\"head\"}),\"\\uFF0C\\u8868\\u793A\\u5F53\\u524D\\u8282\\u70B9\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5F53 \",(0,n.jsx)(e.code,{children:\"curr\"}),\" \\u4E0D\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\" \\u65F6\\uFF0C\\u904D\\u5386\\u5217\\u8868\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u4E0B\\u4E00\\u4E2A\\u8282\\u70B9\\u5B58\\u50A8\\u5728\\u4E34\\u65F6\\u53D8\\u91CF \",(0,n.jsx)(e.code,{children:\"nextTemp\"}),\" (\",(0,n.jsx)(e.code,{children:\"curr.next\"}),\") \\u4E2D\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u53CD\\u8F6C\\u5F53\\u524D\\u8282\\u70B9\\u7684 \",(0,n.jsx)(e.code,{children:\"next\"}),\" \\u6307\\u9488 (\",(0,n.jsx)(e.code,{children:\"curr.next = prev\"}),\")\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"prev\"}),\" \\u6307\\u9488\\u79FB\\u52A8\\u5230\\u5F53\\u524D\\u8282\\u70B9 (\",(0,n.jsx)(e.code,{children:\"prev = curr\"}),\")\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"curr\"}),\" \\u6307\\u9488\\u79FB\\u52A8\\u5230\\u4E0B\\u4E00\\u4E2A\\u8282\\u70B9 (\",(0,n.jsx)(e.code,{children:\"curr = nextTemp\"}),\")\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5FAA\\u73AF\\u7ED3\\u675F\\u540E\\uFF0C\",(0,n.jsx)(e.code,{children:\"prev\"}),\" \\u6307\\u9488\\u5C06\\u6307\\u5411\\u53CD\\u8F6C\\u5217\\u8868\\u7684\\u65B0\\u5934\\u90E8\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"prev\"}),\" \\u4F5C\\u4E3A\\u65B0\\u5934\\u90E8\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(i,{children:u}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u5217\\u8868\\u4E2D\\u7684\\u6BCF\\u4E2A\\u8282\\u70B9\\u90FD\\u4F1A\\u88AB\\u8BBF\\u95EE\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u4F7F\\u7528\\u6052\\u5B9A\\u91CF\\u7684\\u989D\\u5916\\u7A7A\\u95F4\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u9012\\u5F52\\u65B9\\u6CD5\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u9012\\u5F52\\u5730\\u53CD\\u8F6C\\u94FE\\u8868\\u6D89\\u53CA\\u5C06\\u95EE\\u9898\\u5206\\u89E3\\u4E3A\\u66F4\\u5C0F\\u7684\\u5B50\\u95EE\\u9898\\uFF0C\\u9996\\u5148\\u53CD\\u8F6C\\u5217\\u8868\\u7684\\u5C3E\\u90E8\\uFF0C\\u5E76\\u5728\\u9012\\u5F52\\u8C03\\u7528\\u65F6\\u8C03\\u6574\\u6307\\u9488\\u3002\\u5173\\u952E\\u662F\\u5728\\u9012\\u5F52\\u6CBF\\u8C03\\u7528\\u5806\\u6808\\u5411\\u4E0A\\u4F20\\u64AD\\u65F6\\uFF0C\\u4E00\\u6B21\\u4E00\\u6B65\\u5730\\u53CD\\u8F6C\\u8282\\u70B9\\u7684 \",(0,n.jsx)(e.code,{children:\"next\"}),\" \\u6307\\u9488\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8BE5\\u95EE\\u9898\\u88AB\\u5206\\u89E3\\u4E3A\\u53CD\\u8F6C\\u4ECE\\u7B2C\\u4E8C\\u4E2A\\u8282\\u70B9\\u5F00\\u59CB\\u7684\\u5B50\\u5217\\u8868 (\",(0,n.jsx)(e.code,{children:\"head.next\"}),\")\\u3002\\u57FA\\u672C\\u60C5\\u51B5\\u53D1\\u751F\\u5728\\u5217\\u8868\\u4E3A\\u7A7A\\u6216\\u53EA\\u6709\\u4E00\\u4E2A\\u8282\\u70B9\\u65F6\\uFF0C\\u5728\\u8FD9\\u79CD\\u60C5\\u51B5\\u4E0B\\uFF0C\\u53CD\\u8F6C\\u5B8C\\u6210\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5728\\u6BCF\\u6B21\\u9012\\u5F52\\u8C03\\u7528\\u671F\\u95F4\\uFF0C\\u540E\\u7EED\\u8282\\u70B9\\u7684 \",(0,n.jsx)(e.code,{children:\"next\"}),\" \\u6307\\u9488\\u88AB\\u66F4\\u65B0\\u4EE5\\u6307\\u56DE\\u5F53\\u524D\\u8282\\u70B9 (\",(0,n.jsx)(e.code,{children:\"head\"}),\")\\u3002\\u8FD9\\u4F1A\\u53CD\\u8F6C\\u6BCF\\u4E2A\\u8282\\u70B9\\u7684 \",(0,n.jsx)(e.code,{children:\"next\"}),\" \\u6307\\u9488\\u7684\\u65B9\\u5411\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u9012\\u5F52\\u8C03\\u7528\\u8FD4\\u56DE\\u53CD\\u8F6C\\u5B50\\u5217\\u8868\\u7684\\u65B0\\u5934\\u90E8\\uFF0C\\u8BE5\\u5934\\u90E8\\u4F20\\u64AD\\u56DE\\u9876\\u5C42\\u8C03\\u7528\\u8005\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\\u8FD4\\u56DE\\u53CD\\u8F6C\\u5217\\u8868\\u7684\\u6700\\u7EC8\\u5934\\u90E8\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u7B97\\u6CD5\\u76F4\\u63A5\\u5728\\u5217\\u8868\\u7684\\u8282\\u70B9\\u4E0A\\u8FD0\\u884C\\uFF0C\\u800C\\u65E0\\u9700\\u4E3A\\u65B0\\u5217\\u8868\\u6216\\u8F85\\u52A9\\u6570\\u636E\\u7ED3\\u6784\\u5206\\u914D\\u989D\\u5916\\u7684\\u7A7A\\u95F4\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u57FA\\u672C\\u60C5\\u51B5\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"head\"}),\" \\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\" \\u6216 \",(0,n.jsx)(e.code,{children:\"head.next\"}),\" \\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"head\"}),\" \\u4F5C\\u4E3A\\u53CD\\u8F6C\\u540E\\u7684\\u5217\\u8868\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u9012\\u5F52\\u8C03\\u7528 \",(0,n.jsx)(e.code,{children:\"reverseLinkedList\"}),\"\\uFF0C\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"head.next\"}),\" \\u53CD\\u8F6C\\u5217\\u8868\\u7684\\u5176\\u4F59\\u90E8\\u5206\\u3002\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u7ED3\\u679C\\u5B58\\u50A8\\u5728\\u53D8\\u91CF \",(0,n.jsx)(e.code,{children:\"p\"}),\" \\u4E2D\\uFF0C\\u5B83\\u8868\\u793A\\u53CD\\u8F6C\\u5217\\u8868\\u7684\\u65B0\\u5934\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8C03\\u6574\\u6307\\u9488\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"head.next.next\"}),\" \\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"head\"}),\"\\uFF0C\\u53CD\\u8F6C\\u5F53\\u524D\\u8282\\u70B9\\u7684 \",(0,n.jsx)(e.code,{children:\"next\"}),\" \\u6307\\u9488\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"head.next\"}),\" \\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF0C\\u4EE5\\u65AD\\u5F00\\u5F53\\u524D\\u8282\\u70B9\\u4E0E\\u539F\\u59CB\\u5217\\u8868\\u7ED3\\u6784\\u7684\\u8FDE\\u63A5\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"p\"}),\" \\u4F5C\\u4E3A\\u53CD\\u8F6C\\u5217\\u8868\\u7684\\u65B0\\u5934\\u3002\"]}),`\n`]}),`\n`,(0,n.jsxs)(i,{children:[\" \",a,\" \"]}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u5728\\u9012\\u5F52\\u671F\\u95F4\\uFF0C\\u6BCF\\u4E2A\\u8282\\u70B9\\u53EA\\u8BBF\\u95EE\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u9012\\u5F52\\u6DF1\\u5EA6\\u4E0E\\u5217\\u8868\\u7684\\u5927\\u5C0F\\u6210\\u6B63\\u6BD4\\uFF0C\\u9700\\u8981\\u989D\\u5916\\u7684\\u5806\\u6808\\u7A7A\\u95F4\\u3002\"]}),`\n`]})]})}function _(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(p,r)})):p(r)}var w=_;return O(M);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/linked-list/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/linked-list/locales/zh-CN.json new file mode 100644 index 000000000..0c6a7ed19 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/linked-list/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var a=Object.create;var c=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var p=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),x=(i,e)=>{for(var l in e)c(i,l,{get:e[l],enumerable:!0})},t=(i,e,l,r)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let d of k(e))!g.call(i,d)&&d!==l&&c(i,d,{get:()=>e[d],enumerable:!(r=u(e,d))||r.enumerable});return i};var j=(i,e,l)=>(l=i!=null?a(m(i)):{},t(e||!i||!i.__esModule?c(l,\"default\",{value:i,enumerable:!0}):l,i)),f=i=>t(c({},\"__esModule\",{value:!0}),i);var s=p((w,o)=>{o.exports=_jsx_runtime});var y={};x(y,{default:()=>_,frontmatter:()=>v});var n=j(s()),v={title:\"\\u94FE\\u8868\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u5305\\u542B\\u5E38\\u89C1\\u94FE\\u8868\\u65B9\\u6CD5\\u7684\\u94FE\\u8868\\u6570\\u636E\\u7ED3\\u6784\"};function h(i){let e=Object.assign({p:\"p\",ul:\"ul\",li:\"li\",code:\"code\",h2:\"h2\",pre:\"pre\"},i.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.p,{children:\"\\u5728 JavaScript \\u4E2D\\u5B9E\\u73B0\\u4E00\\u4E2A\\u94FE\\u8868\\u6570\\u636E\\u7ED3\\u6784\\uFF0C\\u5176\\u4E2D\\u5305\\u542B\\u4EE5\\u4E0B\\u64CD\\u4F5C\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"new LinkedList()\"}),\"\\uFF1A\\u521B\\u5EFA\\u4E00\\u4E2A\\u4E0D\\u5305\\u542B\\u4EFB\\u4F55\\u9879\\u76EE\\u7684 \",(0,n.jsx)(e.code,{children:\"LinkedList\"}),\" \\u7C7B\\u7684\\u5B9E\\u4F8B\\u3002\\u6784\\u9020\\u51FD\\u6570\\u4E0D\\u63A5\\u53D7\\u4EFB\\u4F55\\u53C2\\u6570\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"get()\"}),\"\\uFF1A\\u63A5\\u53D7\\u4E00\\u4E2A\\u6574\\u6570\\u53C2\\u6570 \",(0,n.jsx)(e.code,{children:\"i\"}),\"\\uFF0C\\u4EE5\\u8FD4\\u56DE\\u7B2C \",(0,n.jsx)(e.code,{children:\"i\"}),\" \\u4E2A\\u8282\\u70B9\\u7684\\u503C\\u3002\\u5982\\u679C\\u7D22\\u5F15\\u8D85\\u51FA\\u8303\\u56F4\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"undefined\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"insertHead()\"}),\"\\uFF1A\\u63A5\\u53D7\\u4E00\\u4E2A\\u53C2\\u6570 \",(0,n.jsx)(e.code,{children:\"value\"}),\"\\uFF0C\\u5E76\\u5C06 \",(0,n.jsx)(e.code,{children:\"value\"}),\" \\u63D2\\u5165\\u5230\\u5217\\u8868\\u7684\\u5934\\u90E8\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"insertTail()\"}),\"\\uFF1A\\u63A5\\u53D7\\u4E00\\u4E2A\\u53C2\\u6570 \",(0,n.jsx)(e.code,{children:\"value\"}),\"\\uFF0C\\u5E76\\u5C06 \",(0,n.jsx)(e.code,{children:\"value\"}),\" \\u63D2\\u5165\\u5230\\u5217\\u8868\\u7684\\u5C3E\\u90E8\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"remove()\"}),\"\\uFF1A\\u63A5\\u53D7\\u4E00\\u4E2A\\u6574\\u6570\\u53C2\\u6570 \",(0,n.jsx)(e.code,{children:\"i\"}),\"\\uFF0C\\u5E76\\u5220\\u9664\\u7B2C \",(0,n.jsx)(e.code,{children:\"i\"}),\" \\u4E2A\\u7D22\\u5F15\\u5904\\u7684\\u9879\\u76EE\\uFF0C\\u540C\\u65F6\\u8FD4\\u56DE\\u5176\\u503C\\u3002\\u5982\\u679C\\u7D22\\u5F15\\u8D85\\u51FA\\u8303\\u56F4\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"undefined\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"toArray()\"}),\"\\uFF1A\\u8FD4\\u56DE\\u4E00\\u4E2A\\u6570\\u7EC4\\uFF0C\\u5176\\u4E2D\\u5305\\u542B\\u94FE\\u8868\\u4E2D\\u4ECE\\u5934\\uFF08\\u6570\\u7EC4\\u4E2D\\u7684\\u7B2C\\u4E00\\u4E2A\\u5143\\u7D20\\uFF09\\u5230\\u5C3E\\uFF08\\u6570\\u7EC4\\u4E2D\\u7684\\u6700\\u540E\\u4E00\\u4E2A\\u5143\\u7D20\\uFF09\\u7684\\u6240\\u6709\\u9879\\u76EE\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"length()\"}),\"\\uFF1A\\u8FD4\\u56DE\\u94FE\\u8868\\u4E2D\\u7684\\u5143\\u7D20\\u6570\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"\\u4F8B\\u5B50\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`const linkedlist = new LinkedList();\nlinkedlist.toArray(); // []\nlinkedlist.insertTail(1);\nlinkedlist.insertHead(2);\nlinkedlist.toArray(); // [2, 1]\nlinkedlist.insertTail(3);\nlinkedlist.toArray(); // [2, 1, 3]\nlinkedlist.length(); // 3\nlinkedlist.get(1); // 1\nlinkedlist.get(2); // 3\nlinkedlist.remove(1); // 1\nlinkedlist.toArray(); // [2, 3]\n`})})]})}function L(i={}){let{wrapper:e}=i.components||{};return e?(0,n.jsx)(e,Object.assign({},i,{children:(0,n.jsx)(h,i)})):h(i)}var _=L;return f(y);})();\n;return Component;", + "info": { + "excerpt": "实现一个包含常见链表方法的链表数据结构", + "title": "链表" + }, + "solution": "var Component=(()=>{var x=Object.create;var l=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty;var T=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),k=(n,e)=>{for(var i in e)l(n,i,{get:e[i],enumerable:!0})},h=(n,e,i,d)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of m(e))!p.call(n,r)&&r!==i&&l(n,r,{get:()=>e[r],enumerable:!(d=v(e,r))||d.enumerable});return n};var b=(n,e,i)=>(i=n!=null?x(g(n)):{},h(e||!n||!n.__esModule?l(i,\"default\",{value:n,enumerable:!0}):i,n)),w=n=>h(l({},\"__esModule\",{value:!0}),n);var u=T((L,o)=>{o.exports=_jsx_runtime});var A={};k(A,{default:()=>N});var t=b(u());var a=MDXCodeBlock;var c=`class Node {\n constructor(value, next = null) {\n this.value = value;\n this.next = next;\n }\n}\n\nexport default class LinkedList {\n constructor() {\n this.head = null;\n this.tail = null;\n }\n\n /**\n * Adds an item to the head of the linked list.\n * @param {*} value The item to be added to the head of the list.\n */\n insertHead(value) {\n const node = new Node(value, this.head);\n if (this.head == null) {\n this.tail = node;\n }\n this.head = node;\n }\n\n /**\n * Adds an item to the tail of the linked list.\n * @param {*} value The item to be added to the tail of the list.\n */\n insertTail(value) {\n const node = new Node(value);\n if (this.tail == null) {\n this.head = node;\n } else {\n this.tail.next = node;\n }\n this.tail = node;\n }\n\n /**\n * Remove the item in the given index and return its value or \\`undefined\\` if index is out of bound.\n * @param {number} i The index of the item to be removed.\n * @return {*} The value of the item in index i if it exists, \\`undefined\\` otherwise.\n */\n remove(i) {\n // To remove index 0, we have to replace the value of head, if it exists.\n if (i === 0 && this.head != null) {\n let value = this.head.value;\n this.head = this.head.next;\n if (this.head == null) {\n this.tail = null;\n } // If there is no node left in the linked list, replace tail with null as well.\n return value;\n }\n\n let curr = this.head; // Set a pointer to the first node of the linked list.\n // Point the pointer to the next node for i-1 times to reach index i-1.\n for (let j = 1; j < i; j++) {\n if (curr == null || curr.next == null) {\n return undefined;\n } // Return \\`undefined\\` if linked list ends before reaching index i.\n\n curr = curr.next; // Change the current pointer to the next one.\n }\n\n if (curr == null || curr.next == null) {\n return undefined;\n }\n\n let value = curr.next.value; // Save the value of the node in index i.\n curr.next = curr.next.next;\n\n // If curr.next, which is to be removed, is the last node in the linked list, update tail to the previous node (curr).\n this.tail = curr.next == null ? curr : this.tail;\n\n return value; // Return the value of the node in index i.\n }\n\n /**\n * Return the value of the item in the given index or \\`undefined\\` if index is out of bound.\n * @param {number} i The index of the value of the item to be returned.\n * @return {*} The value of the item in index i if it exists, \\`undefined\\` otherwise.\n */\n get(i) {\n let curr = this.head; // Set a pointer to the first node of the linked list.\n // Point the pointer to the next node for i times to reach index i.\n for (let j = 0; j < i; j++) {\n if (curr == null) {\n return undefined;\n } // Return \\`undefined\\` if linked list ends before reaching index i.\n\n curr = curr.next; // Change the current pointer to the next one.\n }\n\n let value = curr != null ? curr.value : undefined;\n return value; // Return the value of the node in index i.\n }\n\n /**\n * Return an array containing all the values of the items in the linked list from head to tail.\n * @return {*} The array of all the values in the linked list from head to tail.\n */\n toArray() {\n const array = [];\n let curr = this.head; // Set a pointer to the first node of the linked list.\n\n // Continue to traverse through the linked list until it reaches the tail (null).\n while (curr != null) {\n array.push(curr.value);\n curr = curr.next; // Change the current pointer to the next one.\n }\n\n return array;\n }\n\n /**\n * Return the length / number of elements in the linked list.\n * @return {*} Length of the linked list.\n */\n length() {\n let length = 0;\n let curr = this.head;\n\n while (curr) {\n length += 1;\n curr = curr.next;\n }\n\n return length;\n }\n}\n`;var s=`class Node {\n value: any;\n next: Node | null;\n\n constructor(value: any, next: Node | null = null) {\n this.value = value;\n this.next = next;\n }\n}\n\nexport default class LinkedList {\n head: Node | null;\n tail: Node | null;\n\n constructor() {\n this.head = null;\n this.tail = null;\n }\n\n /**\n * Adds an item to the head of the linked list.\n * @param {*} value The item to be added to the head of the list.\n */\n insertHead(value: T): void {\n const node = new Node(value, this.head);\n if (this.head == null) {\n this.tail = node;\n }\n this.head = node;\n }\n\n /**\n * Adds an item to the tail of the linked list.\n * @param {*} value The item to be added to the tail of the list.\n */\n insertTail(value: T): void {\n const node = new Node(value);\n if (this.tail == null) {\n this.head = node;\n } else {\n this.tail.next = node;\n }\n this.tail = node;\n }\n\n /**\n * Remove the item in the given index and return its value or \\`undefined\\` if index is out of bound.\n * @param {number} i The index of the item to be removed.\n * @return {*} The value of the item in index i if it exists, \\`undefined\\` otherwise.\n */\n remove(i: number): T | undefined {\n // To remove index 0, we have to replace the value of head, if it exists.\n if (i === 0 && this.head != null) {\n let value = this.head.value;\n this.head = this.head.next;\n if (this.head == null) {\n this.tail = null;\n } // If there is no node left in the linked list, replace tail with null as well.\n return value;\n }\n\n let curr: Node | null = this.head; // Set a pointer to the first node of the linked list.\n // Point the pointer to the next node for i-1 times to reach index i-1.\n for (let j = 1; j < i; j++) {\n if (curr == null || curr.next == null) {\n return undefined;\n } // Return \\`undefined\\` if linked list ends before reaching index i.\n\n curr = curr.next; // Change the current pointer to the next one.\n }\n\n if (curr == null || curr.next == null) {\n return undefined;\n }\n\n let value = curr.next.value; // Save the value of the node in index i.\n curr.next = curr.next.next;\n\n // If curr.next, which is to be removed, is the last node in the linked list, update tail to the previous node (curr).\n this.tail = curr.next == null ? curr : this.tail;\n\n return value; // Return the value of the node in index i.\n }\n\n /**\n * Return the value of the item in the given index or \\`undefined\\` if index is out of bound.\n * @param {number} i The index of the value of the item to be returned.\n * @return {*} The value of the item in index i if it exists, \\`undefined\\` otherwise.\n */\n get(i: number): T | undefined {\n let curr: Node | null = this.head; // Set a pointer to the first node of the linked list.\n // Point the pointer to the next node for i times to reach index i.\n for (let j = 0; j < i; j++) {\n if (curr == null) {\n return undefined;\n } // Return \\`undefined\\` if linked list ends before reaching index i.\n\n curr = curr.next;\n }\n\n let value = curr != null ? curr.value : undefined;\n return value; // Return the value of the node in index i.\n }\n\n /**\n * Return an array containing all the values of the items in the linked list from head to tail.\n * @return {*} The array of all the values in the linked list from head to tail.\n */\n toArray(): Array {\n const array: Array = [];\n let curr: Node | null = this.head; // Set a pointer to the first node of the linked list.\n\n // Continue to traverse through the linked list until it reaches the tail (null).\n while (curr != null) {\n array.push(curr.value);\n curr = curr.next; // Change the current pointer to the next one.\n }\n\n return array;\n }\n\n /**\n * Return the length / number of elements in the linked list.\n * @return {*} Length of the linked list.\n */\n length(): number {\n let length = 0;\n let curr = this.head;\n\n while (curr) {\n length += 1;\n curr = curr.next;\n }\n\n return length;\n }\n}\n`;function f(n){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",img:\"img\",ul:\"ul\",li:\"li\",strong:\"strong\"},n.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(e.h2,{children:\"\\u89E3\\u51B3\\u65B9\\u6848\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"\\u94FE\\u8868\\u662F\\u8FDE\\u63A5\\u8282\\u70B9\\u7684\\u94FE\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u8282\\u70B9\\u5305\\u542B\\u4E00\\u4E2A \",(0,t.jsx)(e.code,{children:\"value\"}),\" \\u548C\\u4E00\\u4E2A\\u5BF9 \",(0,t.jsx)(e.code,{children:\"next\"}),\" \\u8282\\u70B9\\u7684\\u5F15\\u7528\\u3002\\u6BCF\\u4E2A\\u8282\\u70B9\\u4E2D\\u7684 \",(0,t.jsx)(e.code,{children:\"next\"}),\" \\u5F62\\u6210\\u4E86\\u5236\\u4F5C\\u94FE\\u8868\\u6240\\u9700\\u7684\\u94FE\\u63A5\\u3002\"]}),`\n`,(0,t.jsxs)(e.p,{children:[\"\\u5728 \",(0,t.jsx)(e.code,{children:\"LinkedList\"}),\" \\u7C7B\\u4E2D\\uFF0C\",(0,t.jsx)(e.code,{children:\"head\"}),\" \\u548C \",(0,t.jsx)(e.code,{children:\"tail\"}),\" \\u7528\\u4E8E\\u6307\\u793A\\u5217\\u8868\\u7684\\u5F00\\u59CB\\u548C\\u7ED3\\u675F\\u3002\\u867D\\u7136\\u4EC5\\u4F7F\\u7528 \",(0,t.jsx)(e.code,{children:\"head\"}),\" \\u662F\\u53EF\\u80FD\\u7684\\uFF0C\\u4F46\\u7EF4\\u62A4\\u4E00\\u4E2A \",(0,t.jsx)(e.code,{children:\"tail\"}),\" \\u6307\\u9488\\u53EF\\u4EE5\\u63D0\\u9AD8 \",(0,t.jsx)(e.code,{children:\"insertTail()\"}),\" \\u7B49\\u64CD\\u4F5C\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF0C\\u5E76\\u5B9E\\u73B0\\u9AD8\\u6548\\u7684\\u7528\\u4F8B\\uFF0C\\u4F8B\\u5982\\u5B9E\\u73B0\\u961F\\u5217\\u3002\"]}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u63D2\\u5165\"}),`\n`,(0,t.jsxs)(e.p,{children:[(0,t.jsx)(e.code,{children:\"insertHead()\"}),\" \\u548C \",(0,t.jsx)(e.code,{children:\"insertTail()\"}),\" \\u6D89\\u53CA\\u66F4\\u65B0\\u5217\\u8868\\u7684 \",(0,t.jsx)(e.code,{children:\"head\"}),\" \\u6216 \",(0,t.jsx)(e.code,{children:\"tail\"}),\" \\u4EE5\\u6307\\u5411\\u4E00\\u4E2A\\u65B0\\u8282\\u70B9\\u3002\"]}),`\n`,(0,t.jsx)(e.p,{children:(0,t.jsx)(e.img,{src:\"/img/questions/linked-list/insert-head.png\",alt:\"Insert Head\"})}),`\n`,(0,t.jsx)(e.p,{children:(0,t.jsx)(e.img,{src:\"/img/questions/linked-list/insert-tail.png\",alt:\"Insert Tail\"})}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u5220\\u9664\"}),`\n`,(0,t.jsxs)(e.p,{children:[(0,t.jsx)(e.code,{children:\"remove()\"}),\" \\u4FEE\\u6539\\u8282\\u70B9 \",(0,t.jsx)(e.code,{children:\"i-1\"}),\" \\u7684 \",(0,t.jsx)(e.code,{children:\"next\"}),\" \\u5F15\\u7528\\u4EE5\\u6307\\u5411\\u8282\\u70B9 \",(0,t.jsx)(e.code,{children:\"i+1\"}),\"\\uFF0C\\u4ECE\\u800C\\u6709\\u6548\\u5730\\u4ECE\\u5217\\u8868\\u4E2D\\u5220\\u9664\\u8282\\u70B9 \",(0,t.jsx)(e.code,{children:\"i\"}),\"\\u3002\\u5982\\u679C\\u5220\\u9664\\u7684\\u8282\\u70B9\\u4F4D\\u4E8E\\u5934\\u90E8\\u6216\\u5C3E\\u90E8\\uFF0C\\u5219 \",(0,t.jsx)(e.code,{children:\"head\"}),\" \\u6216 \",(0,t.jsx)(e.code,{children:\"tail\"}),\" \\u6307\\u9488\\u4E5F\\u4F1A\\u76F8\\u5E94\\u5730\\u66F4\\u65B0\\u3002\"]}),`\n`,(0,t.jsx)(e.p,{children:(0,t.jsx)(e.img,{src:\"/img/questions/linked-list/remove.png\",alt:\"Remove\"})}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u83B7\\u53D6\\u548C toArray\"}),`\n`,(0,t.jsxs)(e.p,{children:[(0,t.jsx)(e.code,{children:\"get()\"}),\" \\u548C \",(0,t.jsx)(e.code,{children:\"toArray()\"}),\" \\u4ECE \",(0,t.jsx)(e.code,{children:\"head\"}),\" \\u8282\\u70B9\\u904D\\u5386\\u5217\\u8868\\u3002\",(0,t.jsx)(e.code,{children:\"get()\"}),\" \\u5728\\u6307\\u5B9A\\u7684\\u7D22\\u5F15\\u5904\\u505C\\u6B62\\uFF0C\\u800C \",(0,t.jsx)(e.code,{children:\"toArray()\"}),\" \\u7EE7\\u7EED\\u5230 \",(0,t.jsx)(e.code,{children:\"tail\"}),\"\\uFF0C\\u6536\\u96C6\\u6240\\u6709\\u503C\\u3002\"]}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u957F\\u5EA6\"}),`\n`,(0,t.jsxs)(e.p,{children:[(0,t.jsx)(e.code,{children:\"length()\"}),\" \\u904D\\u5386\\u6574\\u4E2A\\u94FE\\u8868\\u4EE5\\u8BA1\\u7B97\\u5143\\u7D20\\u7684\\u6570\\u91CF\\u3002\\u6216\\u8005\\uFF0C\\u53EF\\u4EE5\\u7EF4\\u62A4\\u4E00\\u4E2A\\u957F\\u5EA6\\u53D8\\u91CF\\u6765\\u8DDF\\u8E2A\\u6BCF\\u6B21\\u63D2\\u5165/\\u5220\\u9664\\u8282\\u70B9\\u65F6\\u94FE\\u8868\\u7684\\u957F\\u5EA6\\u3002\"]}),`\n`,(0,t.jsx)(a,{languages:{jsx:c,tsx:s}}),`\n`,(0,t.jsx)(e.h2,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,t.jsx)(e.p,{children:\"\\u8BA9\\u6211\\u4EEC\\u5206\\u6790\\u4E00\\u4E0B\\u7B97\\u6CD5\\u7684\\u65F6\\u95F4\\u548C\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u3002\"}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.code,{children:\"insertHead()\"}),\" \\u548C \",(0,t.jsx)(e.code,{children:\"insertTail()\"}),\"\\uFF1AO(1)\\uFF0C\\u56E0\\u4E3A\\u6211\\u4EEC\\u53EF\\u4EE5\\u7ACB\\u5373\\u8BBF\\u95EE \",(0,t.jsx)(e.code,{children:\"head\"}),\" \\u548C \",(0,t.jsx)(e.code,{children:\"tail\"}),\"\\u3002\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.code,{children:\"get()\"}),\"\\u3001\",(0,t.jsx)(e.code,{children:\"remove()\"}),\"\\u3001\",(0,t.jsx)(e.code,{children:\"toArray()\"}),\"\\uFF1AO(n)\\uFF0C\\u56E0\\u4E3A\\u6700\\u574F\\u7684\\u60C5\\u51B5\\u662F\\u904D\\u5386\\u6574\\u4E2A\\u94FE\\u8868\\u4EE5\\u641C\\u7D22 \",(0,t.jsx)(e.code,{children:\"get()\"}),\" \\u548C \",(0,t.jsx)(e.code,{children:\"remove()\"}),\" \\u7684\\u7279\\u5B9A\\u7D22\\u5F15\\u3002\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.code,{children:\"length()\"}),\"\\uFF1AO(n)\\uFF0C\\u5982\\u679C\\u904D\\u5386\\u6574\\u4E2A\\u6570\\u7EC4\\u6765\\u8BA1\\u7B97\\u957F\\u5EA6\\uFF0CO(1) \\u5982\\u679C\\u7EF4\\u62A4\\u4E00\\u4E2A\\u957F\\u5EA6\\u53D8\\u91CF\\u3002\"]}),`\n`]}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsx)(e.li,{children:\"\\u6240\\u6709\\u65B9\\u6CD5\\u90FD\\u9700\\u8981 O(1) \\u7A7A\\u95F4\\uFF0C\\u56E0\\u4E3A\\u6CA1\\u6709\\u521B\\u5EFA\\u968F\\u8F93\\u5165\\u5927\\u5C0F\\u589E\\u957F\\u7684\\u989D\\u5916\\u6570\\u636E\\u7ED3\\u6784\\u3002\"}),`\n`]}),`\n`,(0,t.jsx)(e.h2,{children:\"\\u8FB9\\u7F18\\u60C5\\u51B5\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:\"\\u7A7A\\u5217\\u8868\"}),\"\\uFF1A\\u5728\\u7A7A\\u5217\\u8868\\u4E0A\\u64CD\\u4F5C\\u65F6\\uFF0C\",(0,t.jsx)(e.code,{children:\"insertHead()\"}),\" \\u548C \",(0,t.jsx)(e.code,{children:\"insertTail()\"}),\" \\u5FC5\\u987B\\u540C\\u65F6\\u8BBE\\u7F6E \",(0,t.jsx)(e.code,{children:\"head\"}),\" \\u548C \",(0,t.jsx)(e.code,{children:\"tail\"}),\"\\u3002\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:\"\\u65E0\\u6548\\u7D22\\u5F15\"}),\"\\uFF1A\\u5728 \",(0,t.jsx)(e.code,{children:\"get()\"}),\" \\u548C \",(0,t.jsx)(e.code,{children:\"remove()\"}),\" \\u4E2D\\uFF0C\\u5FC5\\u987B\\u59A5\\u5584\\u5904\\u7406\\u5C0F\\u4E8E 0 \\u6216\\u5927\\u4E8E\\u6216\\u7B49\\u4E8E\\u5217\\u8868\\u957F\\u5EA6\\u7684\\u7D22\\u5F15\\u503C\\u3002 \\u4E00\\u79CD\\u5E38\\u89C1\\u7684\\u65B9\\u6CD5\\u662F\\u8FD4\\u56DE \",(0,t.jsx)(e.code,{children:\"undefined\"}),\"\\uFF0C\\u5982\\u672C\\u95EE\\u9898\\u4E2D\\u6240\\u4F7F\\u7528\\u3002\"]}),`\n`]}),`\n`,(0,t.jsx)(e.h2,{children:\"\\u6280\\u672F\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsx)(e.li,{children:\"\\u9762\\u5411\\u5BF9\\u8C61\\u7F16\\u7A0B\\u3002\"}),`\n`]})]})}function R(n={}){let{wrapper:e}=n.components||{};return e?(0,t.jsx)(e,Object.assign({},n,{children:(0,t.jsx)(f,n)})):f(n)}var N=R;return w(A);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/list.zh-CN.json b/apps/web/src/__generated__/questions/algo/list.zh-CN.json new file mode 100644 index 000000000..e83fe77ad --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/list.zh-CN.json @@ -0,0 +1,3164 @@ +[ + { + "info": { + "excerpt": "实现一个函数来确定一个字符串是否包含平衡的括号", + "title": "平衡括号" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722729600, + "difficulty": "easy", + "duration": 25, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/array-balanced-brackets", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "array-balanced-brackets", + "subtitle": null, + "topics": [ + "array", + "stack" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来检查数组中是否有任何重复的数字", + "title": "查找数组中的重复项" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718409600, + "difficulty": "easy", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/array-find-duplicate", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "array-find-duplicate", + "subtitle": null, + "topics": [ + "array" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来查找已排序数组中缺失的元素", + "title": "查找序列中缺失的数字" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718928000, + "difficulty": "easy", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/array-find-missing-number-in-sequence", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "array-find-missing-number-in-sequence", + "subtitle": null, + "topics": [ + "array" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来查找具有最大乘积的子数组", + "title": "连续数组中的最大乘积" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718236800, + "difficulty": "medium", + "duration": 30, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/array-maximum-product-contiguous", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "array-maximum-product-contiguous", + "subtitle": null, + "topics": [ + "array" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来查找具有最大和的子数组", + "title": "连续数组中的最大和" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718841600, + "difficulty": "medium", + "duration": 25, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/array-maximum-sum-contiguous", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "array-maximum-sum-contiguous", + "subtitle": null, + "topics": [ + "array" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来确定整数数组中最常见的元素", + "title": "最常见的元素" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1724889600, + "difficulty": "medium", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/array-most-common-elements", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "array-most-common-elements", + "subtitle": null, + "topics": [ + "array", + "heap" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,找到数组中除当前元素之外的所有元素的乘积。", + "title": "数组的乘积,不包含当前元素" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718496000, + "difficulty": "medium", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/array-product-excluding-current", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "array-product-excluding-current", + "subtitle": null, + "topics": [ + "array" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来确定数组的末端是否可达", + "title": "数组末端可达" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1720828800, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/array-reachable-end", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "array-reachable-end", + "subtitle": null, + "topics": [ + "array", + "dynamic-programming", + "greedy" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,在旋转排序数组中查找一个整数", + "title": "在旋转数组中查找元素" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718928000, + "difficulty": "medium", + "duration": 30, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/array-rotated-find", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "array-rotated-find", + "subtitle": null, + "topics": [ + "array", + "binary-search" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,找到旋转排序数组中的最小元素", + "title": "旋转排序数组中的最小元素" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718928000, + "difficulty": "medium", + "duration": 25, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/array-smallest-in-rotated", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "array-smallest-in-rotated", + "subtitle": null, + "topics": [ + "array", + "binary-search" + ] + } + }, + { + "info": { + "excerpt": "实现一个对数字数组执行二分查找的函数", + "title": "二分查找" + }, + "metadata": { + "access": "standard", + "author": null, + "companies": [], + "created": 1671667200, + "difficulty": "medium", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-search", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [ + "selection-sort", + "quick-sort", + "merge-sort", + "depth-first-search", + "breadth-first-search" + ], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "binary-search", + "subtitle": null, + "topics": [ + "binary-search", + "sorting" + ] + } + }, + { + "info": { + "excerpt": "实现一个二叉搜索树数据结构,包括基本的 BST 操作", + "title": "二叉搜索树" + }, + "metadata": { + "access": "standard", + "author": null, + "companies": [], + "created": 1745539200, + "difficulty": "medium", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-search-tree", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [ + "heap", + "binary-search" + ], + "slug": "binary-search-tree", + "subtitle": null, + "topics": [ + "binary-tree", + "binary-search-tree", + "tree" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,用于查找 BST 中第 k 个最小的节点", + "title": "二叉搜索树第 K 小的元素" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1724284800, + "difficulty": "medium", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-search-tree-kth-smallest", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "binary-search-tree-kth-smallest", + "subtitle": null, + "topics": [ + "binary-tree", + "binary-search-tree", + "tree" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,以找到二叉搜索树中的 LCA", + "title": "二叉搜索树的最低公共祖先" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1724284800, + "difficulty": "medium", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-search-tree-lowest-common-ancestor", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "binary-search-tree-lowest-common-ancestor", + "subtitle": null, + "topics": [ + "binary-tree", + "binary-search-tree", + "tree" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来验证二叉树是否为有效的二叉搜索树", + "title": "验证二叉搜索树" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1724284800, + "difficulty": "medium", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-search-tree-validate", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "binary-search-tree-validate", + "subtitle": null, + "topics": [ + "binary-tree", + "binary-search-tree", + "tree" + ] + } + }, + { + "info": { + "excerpt": "实现一个二叉树数据结构,包括基本操作", + "title": "二叉树" + }, + "metadata": { + "access": "standard", + "author": null, + "companies": [], + "created": 1716422400, + "difficulty": "medium", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-tree", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [ + "binary-search-tree", + "binary-search" + ], + "slug": "binary-tree", + "subtitle": null, + "topics": [ + "binary-tree", + "tree" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来确定两个二叉树是否相等", + "title": "二叉树相等" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1723161600, + "difficulty": "easy", + "duration": 25, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-tree-equal", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "binary-tree-equal", + "subtitle": null, + "topics": [ + "binary-tree", + "tree" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来翻转二叉树中的节点", + "title": "翻转二叉树" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1723766400, + "difficulty": "easy", + "duration": 20, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-tree-flip", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "binary-tree-flip", + "subtitle": null, + "topics": [ + "binary-tree", + "tree" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来查找二叉树的层序遍历", + "title": "二叉树层序遍历" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1723161600, + "difficulty": "medium", + "duration": 25, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-tree-level-order-traversal", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "binary-tree-level-order-traversal", + "subtitle": null, + "topics": [ + "binary-tree", + "tree" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来查找二叉树的最大深度", + "title": "二叉树的最大深度" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1723161600, + "difficulty": "easy", + "duration": 20, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-tree-maximum-depth", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "binary-tree-maximum-depth", + "subtitle": null, + "topics": [ + "binary-tree", + "tree", + "dfs" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,以找到二叉树路径中节点的最大总和", + "title": "二叉树最大路径和" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1724112000, + "difficulty": "hard", + "duration": 40, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-tree-maximum-total-path", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "binary-tree-maximum-total-path", + "subtitle": null, + "topics": [ + "binary-tree", + "tree", + "dfs" + ] + } + }, + { + "info": { + "excerpt": "实现一个从先序和中序遍历构造二叉树的函数", + "title": "通过先序和中序遍历重建二叉树" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1724889600, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-tree-rebuilding-from-traversals", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "binary-tree-rebuilding-from-traversals", + "subtitle": null, + "topics": [ + "binary-tree", + "tree" + ] + } + }, + { + "info": { + "excerpt": "实现一个序列化和反序列化二叉树的函数", + "title": "二叉树序列化和反序列化" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1724889600, + "difficulty": "hard", + "duration": 20, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-tree-serialization-deserialization", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "binary-tree-serialization-deserialization", + "subtitle": null, + "topics": [ + "binary-tree", + "tree", + "dfs" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来检查一个二叉树是否是另一个二叉树的子树", + "title": "二叉树子树" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1723852800, + "difficulty": "easy", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-tree-subtree", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "binary-tree-subtree", + "subtitle": null, + "topics": [ + "binary-tree", + "tree" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,用于查找从 0 到 n 的设置位数量", + "title": "位计数" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718928000, + "difficulty": "easy", + "duration": 25, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/bit-counting", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "bit-counting", + "subtitle": null, + "topics": [ + "binary" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来翻转给定数字中的位顺序", + "title": "位翻转" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718928000, + "difficulty": "easy", + "duration": 25, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/bit-reversal", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "bit-reversal", + "subtitle": null, + "topics": [ + "binary" + ] + } + }, + { + "info": { + "excerpt": "实现一个广度优先搜索算法,该算法以广度优先的方式遍历有向图", + "title": "广度优先搜索" + }, + "metadata": { + "access": "free", + "author": null, + "companies": [], + "created": 1679788800, + "difficulty": "medium", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/breadth-first-search", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [ + "depth-first-search" + ], + "slug": "breadth-first-search", + "subtitle": null, + "topics": [ + "bfs" + ] + } + }, + { + "info": { + "excerpt": "实现一个执行冒泡排序的函数", + "title": "冒泡排序" + }, + "metadata": { + "access": "standard", + "author": null, + "companies": [], + "created": 1745539200, + "difficulty": "easy", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/bubble-sort", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [ + "quick-sort" + ], + "published": true, + "ranking": 100, + "similarQuestions": [ + "insertion-sort", + "selection-sort" + ], + "slug": "bubble-sort", + "subtitle": null, + "topics": [ + "sorting" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,返回组成给定金额所需的最少硬币数", + "title": "找零所需的最少硬币数" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1733616000, + "difficulty": "medium", + "duration": 40, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/coin-change", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "coin-change", + "subtitle": null, + "topics": [ + "dynamic-programming" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来计算总和为目标值的组合", + "title": "目标和的组合" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1720310400, + "difficulty": "medium", + "duration": 40, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/combinations-target-sum", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "combinations-target-sum", + "subtitle": null, + "topics": [ + "dynamic-programming" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来查找给定整数的二进制表示中的设置位", + "title": "计算二进制数中的设置位" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718928000, + "difficulty": "easy", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/count-ones-in-binary", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "count-ones-in-binary", + "subtitle": null, + "topics": [ + "binary" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,用于检查在给定先决条件的情况下是否可以完成所有课程", + "title": "课程依赖" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1721260800, + "difficulty": "medium", + "duration": 40, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/course-dependency", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "course-dependency", + "subtitle": null, + "topics": [ + "graph", + "topological-sort", + "dfs" + ] + } + }, + { + "info": { + "excerpt": "实现一个深度优先搜索算法,以深度优先的方式遍历有向图", + "title": "深度优先搜索" + }, + "metadata": { + "access": "free", + "author": null, + "companies": [], + "created": 1671667200, + "difficulty": "medium", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/depth-first-search", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [ + "breadth-first-search" + ], + "slug": "depth-first-search", + "subtitle": null, + "topics": [ + "dfs" + ] + } + }, + { + "info": { + "excerpt": "实现 Dijkstra 算法,以找到图中从源顶点开始的最短路径,该图表示为邻接表。", + "title": "Dijkstra 算法" + }, + "metadata": { + "access": "free", + "author": null, + "companies": [], + "created": 1745539200, + "difficulty": "medium", + "duration": 20, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/dijkstra", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [ + "depth-first-search" + ], + "slug": "dijkstra", + "subtitle": null, + "topics": [ + "dfs", + "graph" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,以确定需要移除的最小数量,以获得不重叠的区间", + "title": "不相交的区间" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722384000, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/disjoint-intervals", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "disjoint-intervals", + "subtitle": null, + "topics": [ + "intervals", + "greedy" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来验证并返回外星语言的字母表顺序", + "title": "外星语言" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722384000, + "difficulty": "hard", + "duration": 55, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/extraterrestrial-language", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "extraterrestrial-language", + "subtitle": null, + "topics": [ + "graph", + "topological-sort" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,深度克隆一个连通的无向图", + "title": "图的克隆" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1721260800, + "difficulty": "medium", + "duration": 50, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/graph-clone", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "graph-clone", + "subtitle": null, + "topics": [ + "graph", + "dfs" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来计算图中连通分量的数量", + "title": "图计算连通分量" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1721779200, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/graph-count-connected-components", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "graph-count-connected-components", + "subtitle": null, + "topics": [ + "graph", + "dfs" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来确定一个图是否为有效的树", + "title": "图是否为树" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1721779200, + "difficulty": "medium", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/graph-is-tree", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "graph-is-tree", + "subtitle": null, + "topics": [ + "graph", + "dfs" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来计算二维二进制网格中不同的岛屿数量", + "title": "计算网格中的岛屿数量" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1721001600, + "difficulty": "medium", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/grid-count-islands", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "grid-count-islands", + "subtitle": null, + "topics": [ + "matrix", + "dfs" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来计算机器人移动在 m x n 网格中的不同路径", + "title": "网格中的不同路径" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1720742400, + "difficulty": "medium", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/grid-distinct-paths", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "grid-distinct-paths", + "subtitle": null, + "topics": [ + "dynamic-programming" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来检查单词在网格中是否存在", + "title": "在网格中查找单词" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722729600, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/grid-find-word", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "grid-find-word", + "subtitle": null, + "topics": [ + "matrix", + "dfs" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,用于查找网格中存在的所有单词", + "title": "在网格中查找单词" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1724976000, + "difficulty": "hard", + "duration": 40, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/grid-find-words", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "grid-find-words", + "subtitle": null, + "topics": [ + "matrix", + "tree", + "trie" + ] + } + }, + { + "info": { + "excerpt": "实现一个包含基本堆操作的堆数据结构", + "title": "堆" + }, + "metadata": { + "access": "standard", + "author": null, + "companies": [], + "created": 1745539200, + "difficulty": "hard", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/heap", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [ + "heap-sort" + ], + "published": true, + "ranking": 100, + "similarQuestions": [ + "binary-search-tree" + ], + "slug": "heap", + "subtitle": null, + "topics": [ + "heap" + ] + } + }, + { + "info": { + "excerpt": "实现一个执行堆排序的函数", + "title": "堆排序" + }, + "metadata": { + "access": "free", + "author": null, + "companies": [], + "created": 1673395200, + "difficulty": "medium", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/heap-sort", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [ + "quick-sort" + ], + "published": true, + "ranking": 100, + "similarQuestions": [ + "selection-sort" + ], + "slug": "heap-sort", + "subtitle": null, + "topics": [ + "heap", + "sorting" + ] + } + }, + { + "info": { + "excerpt": "实现一个执行插入排序的函数", + "title": "插入排序" + }, + "metadata": { + "access": "free", + "author": null, + "companies": [], + "created": 1671667200, + "difficulty": "easy", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/insertion-sort", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [ + "quick-sort" + ], + "published": true, + "ranking": 100, + "similarQuestions": [ + "selection-sort" + ], + "slug": "insertion-sort", + "subtitle": null, + "topics": [ + "sorting" + ] + } + }, + { + "info": { + "excerpt": "实现一个合并重叠区间的函数", + "title": "合并重叠区间" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722384000, + "difficulty": "medium", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/intervals-combine-overlapping", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "intervals-combine-overlapping", + "subtitle": null, + "topics": [ + "intervals", + "sorting", + "dfs" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来检查是否可以参加所有会议", + "title": "会议日历" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1721779200, + "difficulty": "easy", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/intervals-meeting-calendar", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "intervals-meeting-calendar", + "subtitle": null, + "topics": [ + "intervals", + "sorting" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,将一个新区间插入给定的区间中", + "title": "合并新区间" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722384000, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/intervals-merge-new", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "intervals-merge-new", + "subtitle": null, + "topics": [ + "binary-search", + "intervals", + "sorting" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来查找所需的最少会议室数量", + "title": "所需最少会议室" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722038400, + "difficulty": "medium", + "duration": 55, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/intervals-minimum-meeting-rooms", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "intervals-minimum-meeting-rooms", + "subtitle": null, + "topics": [ + "heap", + "intervals" + ] + } + }, + { + "info": { + "excerpt": "实现一个包含常见链表方法的链表数据结构", + "title": "链表" + }, + "metadata": { + "access": "free", + "author": null, + "companies": [], + "created": 1745539200, + "difficulty": "medium", + "duration": 20, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/linked-list", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [ + "stack", + "queue" + ], + "slug": "linked-list", + "subtitle": null, + "topics": [ + "linked-list" + ] + } + }, + { + "info": { + "excerpt": "实现一个合并 k 个已排序链表的函数", + "title": "链表合并 K 个已排序列表" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722297600, + "difficulty": "hard", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/linked-list-combine-k-sorted", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "linked-list-combine-k-sorted", + "subtitle": null, + "topics": [ + "linked-list", + "heap" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来合并两个已排序的链表", + "title": "链表合并两个已排序的列表" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722038400, + "difficulty": "easy", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/linked-list-combine-two-sorted", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "linked-list-combine-two-sorted", + "subtitle": null, + "topics": [ + "linked-list" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,用于删除链表倒数第 n 个节点", + "title": "删除链表倒数第 N 个节点" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722297600, + "difficulty": "medium", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/linked-list-delete-nth-from-end", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "linked-list-delete-nth-from-end", + "subtitle": null, + "topics": [ + "linked-list" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来检测链表中是否有环", + "title": "链表检测环" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718928000, + "difficulty": "easy", + "duration": 30, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/linked-list-detect-cycle", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "linked-list-detect-cycle", + "subtitle": null, + "topics": [ + "linked-list" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来重新排列链表中的节点", + "title": "重排链表" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722297600, + "difficulty": "medium", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/linked-list-rearrange", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "linked-list-rearrange", + "subtitle": null, + "topics": [ + "linked-list" + ] + } + }, + { + "info": { + "excerpt": "实现一个反转链表的函数", + "title": "链表反转" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722038400, + "difficulty": "easy", + "duration": 25, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/linked-list-reversal", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "linked-list-reversal", + "subtitle": null, + "topics": [ + "linked-list" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来查找两个字符串中最长的公共子序列", + "title": "最长公共子序列" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1719705600, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/longest-common-subsequence", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "longest-common-subsequence", + "subtitle": null, + "topics": [ + "array", + "dynamic-programming" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来查找最长连续数字序列的长度", + "title": "最长连续数字序列" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1721606400, + "difficulty": "medium", + "duration": 40, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/longest-consecutive-number-sequence", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "longest-consecutive-number-sequence", + "subtitle": null, + "topics": [ + "array" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来查找最长递增子序列的长度", + "title": "最长递增子序列" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1733616000, + "difficulty": "medium", + "duration": 40, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/longest-increasing-subsequence", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "longest-increasing-subsequence", + "subtitle": null, + "topics": [ + "array", + "binary-search", + "greedy" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来查找具有唯一字符的最长子串的长度", + "title": "最长不重复子串" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1723161600, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/longest-non-repeating-substring", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "longest-non-repeating-substring", + "subtitle": null, + "topics": [ + "string" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来查找最长回文子串", + "title": "查找最长回文子串" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1723161600, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/longest-palindromic-substring", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "longest-palindromic-substring", + "subtitle": null, + "topics": [ + "string" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,在最多进行 k 次替换后,找到最长的统一子串", + "title": "替换后最长重复子串" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1723161600, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/longest-repeating-substring-after-replacements", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "longest-repeating-substring-after-replacements", + "subtitle": null, + "topics": [ + "string", + "binary-search" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,将给定的矩阵旋转 90 度", + "title": "矩阵旋转" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722038400, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/matrix-rotation", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "matrix-rotation", + "subtitle": null, + "topics": [ + "matrix" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,以螺旋顺序遍历矩阵", + "title": "矩阵螺旋遍历" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": null, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/matrix-spiral-traversal", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "matrix-spiral-traversal", + "subtitle": null, + "topics": [ + "matrix" + ] + } + }, + { + "info": { + "excerpt": "实现一个将矩阵的行和列设置为零的函数", + "title": "矩阵置零" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722038400, + "difficulty": "medium", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/matrix-zeroing", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "matrix-zeroing", + "subtitle": null, + "topics": [ + "matrix" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,用于查找墙壁数组中两个墙壁之间的最大蓄水体积", + "title": "墙壁之间的最大蓄水" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718236800, + "difficulty": "medium", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/maximum-water-between-walls", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "maximum-water-between-walls", + "subtitle": null, + "topics": [ + "array" + ] + } + }, + { + "info": { + "excerpt": "实现一个执行递归归并排序的函数", + "title": "归并排序" + }, + "metadata": { + "access": "free", + "author": null, + "companies": [], + "created": 1671667200, + "difficulty": "medium", + "duration": 20, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/merge-sort", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [ + "quick-sort" + ], + "slug": "merge-sort", + "subtitle": null, + "topics": [ + "sorting" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,找到在不惊动警察的情况下抢劫的最大金额", + "title": "邻里盗窃" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1720828800, + "difficulty": "medium", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/neighborhood-theft", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "neighborhood-theft", + "subtitle": null, + "topics": [ + "array", + "dynamic-programming" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,用于在环形房屋中找到在不惊动警察的情况下抢劫的最大金额", + "title": "邻里盗窃(环形)" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1720828800, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/neighborhood-theft-circular", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "neighborhood-theft-circular", + "subtitle": null, + "topics": [ + "array", + "dynamic-programming" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来查找动态整数流的中位数", + "title": "数字流的中位数" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1724976000, + "difficulty": "hard", + "duration": 55, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/number-stream-median", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "number-stream-median", + "subtitle": null, + "topics": [ + "heap" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,返回可以流向两个大洋的单元格", + "title": "海洋流动" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1721088000, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/ocean-flow", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "ocean-flow", + "subtitle": null, + "topics": [ + "graph", + "dfs", + "bfs" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,通过买入和卖出股票一次来找到可实现的最大利润", + "title": "最佳股票交易" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718582400, + "difficulty": "easy", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/optimal-stock-trading", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "optimal-stock-trading", + "subtitle": null, + "topics": [ + "array", + "greedy" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,用于查找整数数组中两个相加等于目标整数的数字", + "title": "Pair sum" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718236800, + "difficulty": "easy", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/pair-sum", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "pair-sum", + "subtitle": null, + "topics": [ + "array" + ] + } + }, + { + "info": { + "excerpt": "实现一个包含常见队列方法的队列数据结构", + "title": "队列" + }, + "metadata": { + "access": "free", + "author": "yangshun", + "companies": [], + "created": 1670457600, + "difficulty": "medium", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/queue", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [ + "stack" + ], + "slug": "queue", + "subtitle": null, + "topics": [ + "queue" + ] + } + }, + { + "info": { + "excerpt": "实现一个执行递归快速排序的函数", + "title": "快速排序" + }, + "metadata": { + "access": "free", + "author": null, + "companies": [], + "created": 1671667200, + "difficulty": "medium", + "duration": 20, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/quick-sort", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [ + "merge-sort" + ], + "slug": "quick-sort", + "subtitle": null, + "topics": [ + "sorting" + ] + } + }, + { + "info": { + "excerpt": "实现一个执行选择排序的函数", + "title": "选择排序" + }, + "metadata": { + "access": "standard", + "author": null, + "companies": [], + "created": 1671667200, + "difficulty": "easy", + "duration": 10, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/selection-sort", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [ + "quick-sort" + ], + "published": true, + "ranking": 100, + "similarQuestions": [ + "insertion-sort" + ], + "slug": "selection-sort", + "subtitle": null, + "topics": [ + "sorting" + ] + } + }, + { + "info": { + "excerpt": "实现一个包含常见栈方法的栈数据结构", + "title": "栈" + }, + "metadata": { + "access": "free", + "author": "yangshun", + "companies": [ + "amazon" + ], + "created": 1670025600, + "difficulty": "easy", + "duration": 10, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/stack", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [ + "queue" + ], + "published": true, + "ranking": 100, + "similarQuestions": [ + "queue" + ], + "slug": "stack", + "subtitle": null, + "topics": [ + "stack" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,找到到达楼梯顶部的不同方式的数量", + "title": "爬楼梯组合" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1719187200, + "difficulty": "easy", + "duration": 20, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/staircase-climbing-combinations", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "staircase-climbing-combinations", + "subtitle": null, + "topics": [ + "dynamic-programming" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来确定两个字符串是否互为异位词", + "title": "字符串异位词" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722729600, + "difficulty": "easy", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/string-anagram", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "string-anagram", + "subtitle": null, + "topics": [ + "string" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,将字符串数组分组为异位词", + "title": "字符串异位词分组" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [ + "amazon" + ], + "created": 1723161600, + "difficulty": "medium", + "duration": 40, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/string-anagram-groups", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "string-anagram-groups", + "subtitle": null, + "topics": [ + "string" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来计算解码数字字符串的方法", + "title": "解码消息" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1720742400, + "difficulty": "medium", + "duration": 40, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/string-decode-message", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "string-decode-message", + "subtitle": null, + "topics": [ + "string", + "dynamic-programming" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来确定一个字符串是否是回文", + "title": "字符串回文" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722729600, + "difficulty": "easy", + "duration": 25, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/string-palindrome", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "string-palindrome", + "subtitle": null, + "topics": [ + "string" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来计算字符串中所有回文子串的数量", + "title": "回文子串" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1723161600, + "difficulty": "medium", + "duration": 40, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/string-palindromic-substrings", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "string-palindromic-substrings", + "subtitle": null, + "topics": [ + "string" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来检查一个字符串是否可以由字典中的单词组成", + "title": "单词分割" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1720310400, + "difficulty": "medium", + "duration": 40, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/string-segment-words", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "string-segment-words", + "subtitle": null, + "topics": [ + "string", + "dynamic-programming", + "graph" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,返回包含来自另一个字符串的所有字符(包括重复字符)的字符串的最小子字符串", + "title": "包含字符的最短子字符串" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1723161600, + "difficulty": "hard", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/string-shortest-substring-containing-characters", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "string-shortest-substring-containing-characters", + "subtitle": null, + "topics": [ + "string" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,无需使用 + 和 - 运算符即可找到两个整数的和", + "title": "无加法求和" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718928000, + "difficulty": "medium", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/sum-without-addition", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "sum-without-addition", + "subtitle": null, + "topics": [ + "binary" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,用于查找具有冷却时间的任务的最小间隔", + "title": "任务协调" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1725408000, + "difficulty": "medium", + "duration": 40, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/task-coordination", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "task-coordination", + "subtitle": null, + "topics": [ + "greedy", + "heap" + ] + } + }, + { + "info": { + "excerpt": "实现一个执行拓扑排序的函数", + "title": "拓扑排序" + }, + "metadata": { + "access": "free", + "author": null, + "companies": [ + "snap" + ], + "created": 1673395200, + "difficulty": "medium", + "duration": 20, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/topological-sort", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [ + "quick-sort" + ], + "published": true, + "ranking": 100, + "similarQuestions": [ + "selection-sort" + ], + "slug": "topological-sort", + "subtitle": null, + "topics": [ + "topological-sort", + "graph" + ] + } + }, + { + "info": { + "excerpt": "实现一个具有插入、搜索和以...开头功能的 trie 前缀树", + "title": "Trie(前缀树)" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1724976000, + "difficulty": "medium", + "duration": 40, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/trie-prefix-tree", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "trie-prefix-tree", + "subtitle": null, + "topics": [ + "tree", + "trie" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,找到所有和为 0 且索引不同的唯一三元组。", + "title": "三元组之和" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718928000, + "difficulty": "medium", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/triplet-sum", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "triplet-sum", + "subtitle": null, + "topics": [ + "array" + ] + } + }, + { + "info": { + "excerpt": "实现一个可以添加单词并支持通配符搜索的数据结构", + "title": "单词查找器" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1724976000, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/word-finder", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "word-finder", + "subtitle": null, + "topics": [ + "matrix", + "graph", + "trie" + ] + } + } +] \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/longest-common-subsequence/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/longest-common-subsequence/locales/zh-CN.json new file mode 100644 index 000000000..40ce8531b --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/longest-common-subsequence/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var x=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var z=(c,e)=>()=>(e||c((e={exports:{}}).exports,e),e.exports),f=(c,e)=>{for(var t in e)i(c,t,{get:e[t],enumerable:!0})},d=(c,e,t,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of m(e))!g.call(c,r)&&r!==t&&i(c,r,{get:()=>e[r],enumerable:!(o=p(e,r))||o.enumerable});return c};var j=(c,e,t)=>(t=c!=null?x(b(c)):{},d(e||!c||!c.__esModule?i(t,\"default\",{value:c,enumerable:!0}):t,c)),y=c=>d(i({},\"__esModule\",{value:!0}),c);var s=z((X,l)=>{l.exports=_jsx_runtime});var C={};f(C,{default:()=>q,frontmatter:()=>T});var n=j(s());var h=MDXTestExamples;var a=[{input:[[\"str1\",\"xyz\"],[\"str2\",\"axabz\"]],output:2,explanation:\"The longest common subsequence is 'xz'.\"},{input:[[\"str1\",\"xyz\"],[\"str2\",\"xyz\"]],output:3,explanation:\"The longest common subsequence is 'xyz'.\"},{input:[[\"str1\",\"xyz\"],[\"str2\",\"pqr\"]],output:0,explanation:\"There is no common subsequence.\"}];var T={title:\"\\u6700\\u957F\\u516C\\u5171\\u5B50\\u5E8F\\u5217\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u67E5\\u627E\\u4E24\\u4E2A\\u5B57\\u7B26\\u4E32\\u4E2D\\u6700\\u957F\\u7684\\u516C\\u5171\\u5B50\\u5E8F\\u5217\"};function u(c){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},c.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E24\\u4E2A\\u5B57\\u7B26\\u4E32 \",(0,n.jsx)(e.code,{children:\"str1\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"str2\"}),\"\\uFF0C\\u627E\\u5230\\u5B83\\u4EEC\\u6700\\u957F\\u516C\\u5171\\u5B50\\u5E8F\\u5217\\u7684\\u957F\\u5EA6\\u3002\\u5982\\u679C\\u4E0D\\u5B58\\u5728\\u516C\\u5171\\u5B50\\u5E8F\\u5217\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5B50\\u5E8F\\u5217\\u662F\\u4ECE\\u53E6\\u4E00\\u4E2A\\u5E8F\\u5217\\u6D3E\\u751F\\u7684\\u5E8F\\u5217\\uFF0C\\u901A\\u8FC7\\u5220\\u9664\\u4E00\\u4E9B\\u6216\\u4E0D\\u5220\\u9664\\u4EFB\\u4F55\\u5143\\u7D20\\u800C\\u4E0D\\u6539\\u53D8\\u5269\\u4F59\\u5143\\u7D20\\u7684\\u987A\\u5E8F\\u3002\\u4F8B\\u5982\\uFF0C\",(0,n.jsx)(e.code,{children:\"abc\"}),\" \\u7684\\u5B50\\u5E8F\\u5217\\u662F ``, \",(0,n.jsx)(e.code,{children:\"a\"}),\", \",(0,n.jsx)(e.code,{children:\"b\"}),\", \",(0,n.jsx)(e.code,{children:\"c\"}),\", \",(0,n.jsx)(e.code,{children:\"ab\"}),\", \",(0,n.jsx)(e.code,{children:\"ac\"}),\", \",(0,n.jsx)(e.code,{children:\"bc\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"abc\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E24\\u4E2A\\u5B57\\u7B26\\u4E32\\u4E4B\\u95F4\\u7684\\u516C\\u5171\\u5B50\\u5E8F\\u5217\\u662F\\u6307\\u4EE5\\u76F8\\u540C\\u76F8\\u5BF9\\u987A\\u5E8F\\u51FA\\u73B0\\u5728\\u4E24\\u4E2A\\u5B57\\u7B26\\u4E32\\u5E8F\\u5217\\u4E2D\\u7684\\u5B50\\u5E8F\\u5217\\u3002\\u4F8B\\u5982\\uFF0C\\u5728\\u5B57\\u7B26\\u4E32 \",(0,n.jsx)(e.code,{children:\"xyz\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"axabz\"}),\" \\u4E2D\\uFF0C\\u6700\\u957F\\u7684\\u516C\\u5171\\u5B50\\u5E8F\\u5217\\u662F \",(0,n.jsx)(e.code,{children:\"xz\"}),\"\\uFF0C\\u56E0\\u6B64\\uFF0C\\u6700\\u957F\\u516C\\u5171\\u5B50\\u5E8F\\u5217\\u7684\\u957F\\u5EA6\\u662F 2\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"str1: string\"}),\": \\u5B57\\u7B26\\u4E32\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"str2: string\"}),\": \\u5B57\\u7B26\\u4E32\"]}),`\n`]}),`\n`,(0,n.jsx)(h,{testCases:a}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"str1.length\"}),\", \",(0,n.jsx)(e.code,{children:\"str2.length\"}),\" <= 1000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"str1\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"str2\"}),\" \\u4EC5\\u7531\\u5C0F\\u5199\\u82F1\\u6587\\u5B57\\u7B26\\u7EC4\\u6210\"]}),`\n`]})]})}function M(c={}){let{wrapper:e}=c.components||{};return e?(0,n.jsx)(e,Object.assign({},c,{children:(0,n.jsx)(u,c)})):u(c)}var q=M;return y(C);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来查找两个字符串中最长的公共子序列", + "title": "最长公共子序列" + }, + "solution": "var Component=(()=>{var w=Object.create;var i=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty;var b=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),O=(r,e)=>{for(var c in e)i(r,c,{get:e[c],enumerable:!0})},o=(r,e,c,t)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let d of f(e))!R.call(r,d)&&d!==c&&i(r,d,{get:()=>e[d],enumerable:!(t=x(e,d))||t.enumerable});return r};var G=(r,e,c)=>(c=r!=null?w(p(r)):{},o(e||!r||!r.__esModule?i(c,\"default\",{value:r,enumerable:!0}):c,r)),y=r=>o(i({},\"__esModule\",{value:!0}),r);var s=b((k,h)=>{h.exports=_jsx_runtime});var v={};O(v,{default:()=>I});var n=G(s());var l=MDXCodeBlock;var a=`// Initialize a 2D array for memoization\nconst dp: number[][] = Array.from({ length: 1001 }, () => Array(1001).fill(-1));\n\n// Recursive function to find the length of the longest common subsequence\nfunction lcs(\n str1: string,\n str2: string,\n index1: number,\n index2: number,\n): number {\n // Check if the result is already computed\n if (dp[index1][index2] !== -1) {\n return dp[index1][index2];\n }\n\n // Base case: if any string is exhausted, return 0\n if (index1 === str1.length || index2 === str2.length) {\n return 0;\n }\n\n // If characters match, move both indices and add 1 to the result\n if (str1[index1] === str2[index2]) {\n dp[index1][index2] = 1 + lcs(str1, str2, index1 + 1, index2 + 1);\n } else {\n // If characters don't match, find the max between skipping one character in either string\n dp[index1][index2] = Math.max(\n lcs(str1, str2, index1 + 1, index2),\n lcs(str1, str2, index1, index2 + 1),\n );\n }\n\n return dp[index1][index2];\n}\n\nexport default function longestCommonSubsequence(\n str1: string,\n str2: string,\n): number {\n // Initialize the dp array with -1\n for (let i = 0; i <= 1000; i++) {\n for (let j = 0; j <= 1000; j++) {\n dp[i][j] = -1;\n }\n }\n // Start the recursion\n return lcs(str1, str2, 0, 0);\n}\n`;var u=`export default function longestCommonSubsequence(\n str1: string,\n str2: string,\n): number {\n // Create a 2D array (grid) of zeros with dimensions (str1.length + 1) x (str2.length + 1)\n const dpGrid: number[][] = Array.from({ length: str1.length + 1 }, () =>\n Array(str2.length + 1).fill(0),\n );\n\n // Iterate through each column starting from the last one\n for (let col = str2.length - 1; col >= 0; col--) {\n for (let row = str1.length - 1; row >= 0; row--) {\n // If the characters at the current positions in both strings are the same\n if (str1[row] === str2[col]) {\n // Set the current cell to 1 plus the value from the diagonally next cell\n dpGrid[row][col] = 1 + dpGrid[row + 1][col + 1];\n } else {\n // Otherwise, take the maximum value from the cell directly below or the cell to the right\n dpGrid[row][col] = Math.max(dpGrid[row + 1][col], dpGrid[row][col + 1]);\n }\n }\n }\n\n // The answer to the problem is in the top-left cell of the grid\n return dpGrid[0][0];\n}\n`;var m=`export default function longestCommonSubsequence(\n str1: string,\n str2: string,\n): number {\n // Create two rows for DP, initialized with zeros\n let currentRow: number[] = Array(str2.length + 1).fill(0);\n let nextRow: number[] = Array(str2.length + 1).fill(0);\n\n // Iterate through str1 from bottom to top\n for (let row = str1.length - 1; row >= 0; row--) {\n // Swap rows: \\`currentRow\\` becomes \\`nextRow\\`, and vice versa\n [currentRow, nextRow] = [nextRow, currentRow];\n\n // Iterate through str2 from right to left\n for (let col = str2.length - 1; col >= 0; col--) {\n if (str1[row] === str2[col]) {\n // If characters match, take 1 + diagonal value from \\`nextRow\\`\n currentRow[col] = 1 + nextRow[col + 1];\n } else {\n // Otherwise, take max of right or below values\n currentRow[col] = Math.max(nextRow[col], currentRow[col + 1]);\n }\n }\n }\n\n // The result is stored in \\`currentRow[0]\\` after the final iteration\n return currentRow[0];\n}\n`;function g(r){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u52A8\\u6001\\u89C4\\u5212\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u89E3\\u51B3\\u6700\\u957F\\u516C\\u5171\\u5B50\\u5E8F\\u5217\\u95EE\\u9898\\u7684\\u52A8\\u6001\\u89C4\\u5212\\u65B9\\u6CD5\\u6784\\u5EFA\\u4E86\\u4E00\\u4E2A\\u4E8C\\u7EF4\\u7F51\\u683C(\",(0,n.jsx)(e.code,{children:\"dpGrid\"}),\")\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u5355\\u5143\\u683C\\u8868\\u793A\\u4E24\\u4E2A\\u8F93\\u5165\\u5B57\\u7B26\\u4E32\\u7684\\u76F8\\u5E94\\u5B50\\u5B57\\u7B26\\u4E32\\u7684\\u6700\\u957F\\u516C\\u5171\\u5B50\\u5E8F\\u5217\\u7684\\u957F\\u5EA6\\u3002\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u4ECE\\u53F3\\u4E0B\\u89D2\\u5230\\u5DE6\\u4E0A\\u89D2\\u8FED\\u4EE3\\u5730\\u586B\\u5145\\u7F51\\u683C\\uFF0C\\u5229\\u7528\\u8F83\\u5C0F\\u5B50\\u95EE\\u9898\\u7684\\u7ED3\\u679C\\u6765\\u8BA1\\u7B97\\u8F83\\u5927\\u5B50\\u95EE\\u9898\\u7684\\u7ED3\\u679C\\u3002\\u8FD9\\u79CD\\u65B9\\u6CD5\\u907F\\u514D\\u4E86\\u5197\\u4F59\\u8BA1\\u7B97\\uFF0C\\u5E76\\u901A\\u8FC7\\u7CFB\\u7EDF\\u5730\\u8003\\u8651\\u6240\\u6709\\u53EF\\u80FD\\u6027\\u6765\\u786E\\u4FDD\\u6700\\u4F73\\u89E3\\u51B3\\u65B9\\u6848\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u96F6\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u4E8C\\u7EF4\\u6570\\u7EC4\",(0,n.jsx)(e.code,{children:\"dpGrid\"}),\"\\uFF0C\\u5176\\u7EF4\\u5EA6\\u4E3A\",(0,n.jsx)(e.code,{children:\"(str1.length + 1) x (str2.length + 1)\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u53F3\\u4E0B\\u89D2\\u5F00\\u59CB\\u904D\\u5386\\u7F51\\u683C\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\",(0,n.jsx)(e.code,{children:\"str2\"}),\"\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5B57\\u7B26\\uFF08\\u5217\\uFF0C\\u4ECE\\u53F3\\u5230\\u5DE6\\uFF09\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\",(0,n.jsx)(e.code,{children:\"str1\"}),\"\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5B57\\u7B26\\uFF08\\u884C\\uFF0C\\u4ECE\\u4E0B\\u5230\\u4E0A\\uFF09\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u4E24\\u4E2A\\u5B57\\u7B26\\u4E32\\u4E2D\\u5F53\\u524D\\u4F4D\\u7F6E\\u7684\\u5B57\\u7B26\\u76F8\\u7B49\\uFF0C\\u5219\\u5C06\",(0,n.jsx)(e.code,{children:\"dpGrid\"}),\"\\u4E2D\\u7684\\u5F53\\u524D\\u5355\\u5143\\u683C\\u8BBE\\u7F6E\\u4E3A\",(0,n.jsx)(e.code,{children:\"1 + dpGrid[row + 1][col + 1]\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5426\\u5219\\uFF0C\\u5C06\\u5F53\\u524D\\u5355\\u5143\\u683C\\u8BBE\\u7F6E\\u4E3A\",(0,n.jsx)(e.code,{children:\"dpGrid[row + 1][col]\"}),\"\\uFF08\\u4E0B\\u65B9\\uFF09\\u548C\",(0,n.jsx)(e.code,{children:\"dpGrid[row][col + 1]\"}),\"\\uFF08\\u53F3\\u4FA7\\uFF09\\u4E4B\\u95F4\\u7684\\u6700\\u5927\\u503C\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"dpGrid\"}),\"\\u7684\\u5DE6\\u4E0A\\u89D2\\u5355\\u5143\\u683C\\u5305\\u542B\",(0,n.jsx)(e.code,{children:\"str1\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"str2\"}),\"\\u7684\\u6700\\u957F\\u516C\\u5171\\u5B50\\u5E8F\\u5217\\u7684\\u957F\\u5EA6\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE\",(0,n.jsx)(e.code,{children:\"dpGrid[0][0]\"}),\"\\u4E2D\\u7684\\u503C\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(l,{children:u}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m.n)\"}),\"\\u3002\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u6D89\\u53CA\\u586B\\u5145\\u4E00\\u4E2A\\u5927\\u5C0F\\u4E3A\",(0,n.jsx)(e.code,{children:\"m x n\"}),\"\\u7684\\u7F51\\u683C\\uFF0C\\u5176\\u4E2D\",(0,n.jsx)(e.code,{children:\"m\"}),\"\\u662F\",(0,n.jsx)(e.code,{children:\"str1\"}),\"\\u7684\\u957F\\u5EA6\\uFF0C\",(0,n.jsx)(e.code,{children:\"n\"}),\"\\u662F\",(0,n.jsx)(e.code,{children:\"str2\"}),\"\\u7684\\u957F\\u5EA6\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m.n)\"}),\"\\u3002\",(0,n.jsx)(e.code,{children:\"dpGrid\"}),\"\\u6240\\u9700\\u7684\\u7A7A\\u95F4\\u4E0E\\u4E24\\u4E2A\\u5B57\\u7B26\\u4E32\\u7684\\u957F\\u5EA6\\u7684\\u4E58\\u79EF\\u6210\\u6B63\\u6BD4\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u52A8\\u6001\\u89C4\\u5212\\u4F18\\u5316\\u7A7A\\u95F4\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4F7F\\u7528\\u5B8C\\u6574\\u7684DP\\u8868\\uFF0C\\u4E0D\\u5982\\u4E00\\u6B21\\u53EA\\u7EF4\\u62A4\\u4E24\\u884C\\u6765\\u5B58\\u50A8\\u4E2D\\u95F4\\u7ED3\\u679C\\u3002\\u4F20\\u7EDF\\u7684DP\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u5927\\u5C0F\\u4E3A\",(0,n.jsx)(e.code,{children:\"(m+1) x (n+1)\"}),\"\\u7684\\u4E8C\\u7EF4\\u8868\\u6765\\u5B58\\u50A8\",(0,n.jsx)(e.code,{children:\"str1\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"str2\"}),\"\\u7684\\u6240\\u6709\\u5B50\\u5B57\\u7B26\\u4E32\\u7684\\u7ED3\\u679C\\uFF0C\\u5BFC\\u81F4\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u4E3AO(m.n)\\u3002\\u7136\\u800C\\uFF0C\\u5728\\u4EFB\\u4F55\\u65F6\\u5019\\uFF0C\\u53EA\\u9700\\u8981\\u5F53\\u524D\\u884C\\u548C\\u524D\\u4E00\\u884C\\u6765\\u8BA1\\u7B97\\u4E0B\\u4E00\\u884C\\u7684\\u503C\\u3002\\u8FD9\\u5BFC\\u81F4\\u4E86\\u4E00\\u4E2A\\u4F18\\u5316\\u7684\\u89E3\\u51B3\\u65B9\\u6848\\uFF0C\\u901A\\u8FC7\\u91CD\\u590D\\u4F7F\\u7528\\u884C\\uFF0C\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u4E3AO(n)\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4F18\\u5316\\u7684\\u65B9\\u6CD5\\u901A\\u8FC7\\u7EF4\\u62A4\\u4E24\\u884C\\u6765\\u6D88\\u9664\\u4E0D\\u5FC5\\u8981\\u7684\\u5B58\\u50A8\\uFF1A\",(0,n.jsx)(e.code,{children:\"currentRow\"}),\"\\u7528\\u4E8E\\u5B58\\u50A8\\u5F53\\u524D\\u72B6\\u6001\\u7684\\u7ED3\\u679C\\uFF0C\",(0,n.jsx)(e.code,{children:\"nextRow\"}),\"\\u7528\\u4E8E\\u5B58\\u50A8\\u524D\\u4E00\\u4E2A\\u72B6\\u6001\\u7684\\u7ED3\\u679C\\u3002\\u8BE5\\u7B97\\u6CD5\\u4EE5\\u76F8\\u53CD\\u7684\\u987A\\u5E8F\\u904D\\u5386\\u5B57\\u7B26\\u4E32\\uFF0C\\u6709\\u6548\\u5730\\u66F4\\u65B0\\u884C\\u3002\\u901A\\u8FC7\\u5229\\u7528\",(0,n.jsx)(e.code,{children:\"currentRow\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"nextRow\"}),\"\\u4E4B\\u95F4\\u7684\\u5173\\u7CFB\\uFF0C\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u5728\\u4E0D\\u6784\\u5EFA\\u6574\\u4E2ADP\\u8868\\u7684\\u60C5\\u51B5\\u4E0B\\u8BA1\\u7B97LCS\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E24\\u4E2A\\u6570\\u7EC4\",(0,n.jsx)(e.code,{children:\"currentRow\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"nextRow\"}),\"\\uFF0C\\u7528\\u96F6\\u586B\\u5145\\uFF0C\\u6BCF\\u4E2A\\u6570\\u7EC4\\u7684\\u5927\\u5C0F\\u4E3A\",(0,n.jsx)(e.code,{children:\"str2.length + 1\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u4E0B\\u5230\\u4E0A\\u904D\\u5386\",(0,n.jsx)(e.code,{children:\"str1\"}),\"\\uFF08\\u7D22\\u5F15\",(0,n.jsx)(e.code,{children:\"row\"}),\"\\u4ECE\",(0,n.jsx)(e.code,{children:\"str1.length - 1\"}),\"\\u5F00\\u59CB\\u5E76\\u9012\\u51CF\\u5230\",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF09\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4EA4\\u6362\",(0,n.jsx)(e.code,{children:\"currentRow\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"nextRow\"}),\"\\u7684\\u89D2\\u8272\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\",(0,n.jsx)(e.code,{children:\"currentRow\"}),\"\\u4FDD\\u5B58\\u5F53\\u524D\\u8FED\\u4EE3\\u7684\\u7ED3\\u679C\\uFF0C\\u800C\",(0,n.jsx)(e.code,{children:\"nextRow\"}),\"\\u4FDD\\u5B58\\u524D\\u4E00\\u6B21\\u8FED\\u4EE3\\u7684\\u7ED3\\u679C\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\",(0,n.jsx)(e.code,{children:\"str2\"}),\"\\u7684\\u6BCF\\u4E2A\\u5B57\\u7B26\\uFF0C\\u4ECE\\u53F3\\u5230\\u5DE6\\u8FED\\u4EE3\\uFF08\\u7D22\\u5F15\",(0,n.jsx)(e.code,{children:\"col\"}),\"\\u4ECE\",(0,n.jsx)(e.code,{children:\"str2.length - 1\"}),\"\\u5F00\\u59CB\\u5E76\\u9012\\u51CF\\u5230\",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF09\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\",(0,n.jsx)(e.code,{children:\"str1[row] === str2[col]\"}),\"\\uFF0C\\u5219\\u5C06\",(0,n.jsx)(e.code,{children:\"currentRow[col]\"}),\"\\u8BBE\\u7F6E\\u4E3A\",(0,n.jsx)(e.code,{children:\"1 + nextRow[col + 1]\"}),\"\\uFF0C\\u8868\\u793A\\u5BF9\\u89D2\\u7EBF\\u503C\\u52A0\\u4E00\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5426\\u5219\\uFF0C\\u5C06\",(0,n.jsx)(e.code,{children:\"currentRow[col]\"}),\"\\u8BBE\\u7F6E\\u4E3A\",(0,n.jsx)(e.code,{children:\"nextRow[col]\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"currentRow[col + 1]\"}),\"\\u7684\\u6700\\u5927\\u503C\\uFF0C\\u8868\\u793A\\u8DF3\\u8FC7\",(0,n.jsx)(e.code,{children:\"str1\"}),\"\\u6216\",(0,n.jsx)(e.code,{children:\"str2\"}),\"\\u7684\\u5F53\\u524D\\u5B57\\u7B26\\u4E4B\\u95F4\\u7684\\u6700\\u5927\\u503C\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B8C\\u6210\\u8FED\\u4EE3\\u540E\\uFF0C\\u7ED3\\u679C\\u5B58\\u50A8\\u5728\",(0,n.jsx)(e.code,{children:\"currentRow[0]\"}),\"\\u4E2D\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(l,{children:m}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m.n)\"}),\"\\u3002\\u4F7F\\u7528\\u4E24\\u4E2A\\u5D4C\\u5957\\u5FAA\\u73AF\\uFF1A\\u4E00\\u4E2A\\u5FAA\\u73AF\\u904D\\u5386\",(0,n.jsx)(e.code,{children:\"str1\"}),\"\\u7684\\u957F\\u5EA6(m)\\uFF0C\\u53E6\\u4E00\\u4E2A\\u5FAA\\u73AF\\u904D\\u5386\",(0,n.jsx)(e.code,{children:\"str2\"}),\"\\u7684\\u957F\\u5EA6(n)\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u4EC5\\u4F7F\\u7528\\u4E24\\u884C\\uFF0C\\u6BCF\\u884C\\u5927\\u5C0F\\u4E3A\",(0,n.jsx)(e.code,{children:\"n+1\"}),\"\\uFF0C\\u7528\\u4E8E\\u8BA1\\u7B97\\uFF0C\\u5C06\\u7A7A\\u95F4\\u4F7F\\u7528\\u4ECEO(m.n)\\u51CF\\u5C11\\u5230O(n)\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"3. \\u4F7F\\u7528\\u8BB0\\u5FC6\\u5316\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u89E3\\u51B3\\u6700\\u957F\\u516C\\u5171\\u5B50\\u5E8F\\u5217\\u95EE\\u9898\\u7684\\u8BB0\\u5FC6\\u5316\\u65B9\\u6CD5\\u80CC\\u540E\\u7684\\u5173\\u952E\\u76F4\\u89C9\\u662F\\u901A\\u8FC7\\u5B58\\u50A8\\u5148\\u524D\\u5DF2\\u89E3\\u51B3\\u7684\\u5B50\\u95EE\\u9898\\u7684\\u7ED3\\u679C\\u6765\\u907F\\u514D\\u5197\\u4F59\\u8BA1\\u7B97\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\\u4EC5\\u5904\\u7406\\u4E24\\u4E2A\\u5B57\\u7B26\\u4E32\\u7684\\u6BCF\\u4E2A\\u552F\\u4E00\\u7D22\\u5F15\\u5BF9\\u4E00\\u6B21\\u3002\\u901A\\u8FC7\\u5C06\\u95EE\\u9898\\u5206\\u89E3\\u4E3A\\u8F83\\u5C0F\\u7684\\u91CD\\u53E0\\u5B50\\u95EE\\u9898\\u5E76\\u5B58\\u50A8\\u5176\\u7ED3\\u679C\\uFF0C\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u6709\\u6548\\u5730\\u7EC4\\u5408\\u4E86\\u8FD9\\u4E9B\\u7ED3\\u679C\\u4EE5\\u627E\\u5230\\u6574\\u4F53\\u6700\\u957F\\u516C\\u5171\\u5B50\\u5E8F\\u5217\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521B\\u5EFA\\u4E00\\u4E2A\\u7528\",(0,n.jsx)(e.code,{children:\"-1\"}),\"\\u521D\\u59CB\\u5316\\u7684\\u4E8C\\u7EF4\",(0,n.jsx)(e.code,{children:\"dp\"}),\"\\u6570\\u7EC4\\uFF0C\\u7528\\u4E8E\\u5B58\\u50A8\\u5B50\\u95EE\\u9898\\u7684\\u7ED3\\u679C\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u9012\\u5F52\\u51FD\\u6570\",(0,n.jsx)(e.code,{children:\"lcs\"}),\"\\uFF0C\\u8BE5\\u51FD\\u6570\\u63A5\\u53D7\\u4E24\\u4E2A\\u5B57\\u7B26\\u4E32\",(0,n.jsx)(e.code,{children:\"str1\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"str2\"}),\"\\u4EE5\\u53CA\\u7D22\\u5F15\",(0,n.jsx)(e.code,{children:\"index1\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"index2\"}),\"\\u4F5C\\u4E3A\\u53C2\\u6570\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u5F53\\u524D\\u7D22\\u5F15\\u7684\\u7ED3\\u679C\\u662F\\u5426\\u5DF2\\u5728\",(0,n.jsx)(e.code,{children:\"dp\"}),\"\\u6570\\u7EC4\\u4E2D\\u8BA1\\u7B97\\u3002\\u5982\\u679C\\u662F\\uFF0C\\u5219\\u8FD4\\u56DE\\u5B58\\u50A8\\u7684\\u503C\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u4EFB\\u4E00\\u7D22\\u5F15\\u5230\\u8FBE\\u5176\\u5404\\u81EA\\u5B57\\u7B26\\u4E32\\u7684\\u672B\\u5C3E\\uFF0C\\u5219\\u8FD4\\u56DE\",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u56E0\\u4E3A\\u5728\\u8BE5\\u70B9\\u4E4B\\u540E\\u6CA1\\u6709\\u516C\\u5171\\u5B50\\u5E8F\\u5217\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5F53\\u524D\\u7D22\\u5F15\\u5904\\u7684\\u5B57\\u7B26\\u5339\\u914D\\uFF0C\\u5219\\u5C06\\u7ED3\\u679C\\u8BA1\\u7B97\\u4E3A\",(0,n.jsx)(e.code,{children:\"1 + lcs(str1, str2, index1 + 1, index2 + 1)\"}),\"\\u5E76\\u5C06\\u5176\\u5B58\\u50A8\\u5728\",(0,n.jsx)(e.code,{children:\"dp\"}),\"\\u6570\\u7EC4\\u4E2D\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5B57\\u7B26\\u4E0D\\u5339\\u914D\\uFF0C\\u5219\\u8BA1\\u7B97\\u8DF3\\u8FC7\\u4EFB\\u4E00\\u5B57\\u7B26\\u4E32\\u4E2D\\u7684\\u4E00\\u4E2A\\u5B57\\u7B26\\u7684\\u6700\\u5927\\u503C\\uFF0C\\u5E76\\u5C06\\u5176\\u5B58\\u50A8\\u5728\",(0,n.jsx)(e.code,{children:\"dp\"}),\"\\u6570\\u7EC4\\u4E2D\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\",(0,n.jsx)(e.code,{children:\"str1\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"str2\"}),\"\\u7684\\u7D22\\u5F15\",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u5F00\\u59CB\\u8C03\\u7528\",(0,n.jsx)(e.code,{children:\"lcs\"}),\"\\u51FD\\u6570\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE\",(0,n.jsx)(e.code,{children:\"lcs\"}),\"\\u4E3A\\u5B8C\\u6574\\u5B57\\u7B26\\u4E32\\u8BA1\\u7B97\\u7684\\u503C\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(l,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m.n)\"}),\"\\u3002\\u6BCF\\u4E2A\\u5B50\\u95EE\\u9898\\u6700\\u591A\\u53EA\\u89E3\\u51B3\\u4E00\\u6B21\\uFF0C\\u5176\\u4E2D\",(0,n.jsx)(e.code,{children:\"m\"}),\"\\u662F\",(0,n.jsx)(e.code,{children:\"str1\"}),\"\\u7684\\u957F\\u5EA6\\uFF0C\",(0,n.jsx)(e.code,{children:\"n\"}),\"\\u662F\",(0,n.jsx)(e.code,{children:\"str2\"}),\"\\u7684\\u957F\\u5EA6\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m.n)\"}),\"\\u3002\",(0,n.jsx)(e.code,{children:\"dp\"}),\"\\u6570\\u7EC4\\u6240\\u9700\\u7684\\u7A7A\\u95F4\\u4E0E\\u4E24\\u4E2A\\u5B57\\u7B26\\u4E32\\u7684\\u957F\\u5EA6\\u7684\\u4E58\\u79EF\\u6210\\u6B63\\u6BD4\\u3002\"]}),`\n`]})]})}function S(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(g,r)})):g(r)}var I=S;return y(v);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/longest-consecutive-number-sequence/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/longest-consecutive-number-sequence/locales/zh-CN.json new file mode 100644 index 000000000..a80ea21de --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/longest-consecutive-number-sequence/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var m=Object.create;var r=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var f=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),j=(n,e)=>{for(var i in e)r(n,i,{get:e[i],enumerable:!0})},o=(n,e,i,c)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let s of x(e))!b.call(n,s)&&s!==i&&r(n,s,{get:()=>e[s],enumerable:!(c=p(e,s))||c.enumerable});return n};var _=(n,e,i)=>(i=n!=null?m(g(n)):{},o(e||!n||!n.__esModule?r(i,\"default\",{value:n,enumerable:!0}):i,n)),T=n=>o(r({},\"__esModule\",{value:!0}),n);var u=f((w,l)=>{l.exports=_jsx_runtime});var X={};j(X,{default:()=>D,frontmatter:()=>M});var t=_(u());var h=MDXTestExamples;var a=[{input:[[\"numbers\",[5,1,-4]]],output:1,explanation:\"No consecutive numbers exist, so the longest consecutive sequence is any single number, giving a length of 1\"},{input:[[\"numbers\",[1,-1,-1,-4,-5]]],output:2,explanation:\"The consecutive sequences are [1], [-1], [-5, -4]. The longest is [-5, -4], with a length of 2\"},{input:[[\"numbers\",[1,-1,0,8,11,10,9,9]]],output:4,explanation:\"The longest consecutive sequence is 8, 9, 10, 11, with a length of 4 and duplicates are ignored.\"}];var M={title:\"\\u6700\\u957F\\u8FDE\\u7EED\\u6570\\u5B57\\u5E8F\\u5217\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u67E5\\u627E\\u6700\\u957F\\u8FDE\\u7EED\\u6570\\u5B57\\u5E8F\\u5217\\u7684\\u957F\\u5EA6\"};function d(n){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},n.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u672A\\u6392\\u5E8F\\u7684\\u6574\\u6570\\u6570\\u7EC4 \",(0,t.jsx)(e.code,{children:\"numbers\"}),\"\\uFF0C\\u786E\\u5B9A\\u6700\\u957F\\u5E8F\\u5217\\u7684\\u957F\\u5EA6\\uFF0C\\u5176\\u4E2D\\u6574\\u6570\\u8FDE\\u7EED\\u51FA\\u73B0\\uFF0C\\u8FD9\\u610F\\u5473\\u7740\\u6570\\u5B57\\u4E00\\u4E2A\\u63A5\\u4E00\\u4E2A\\u51FA\\u73B0\\uFF0C\\u6CA1\\u6709\\u4EFB\\u4F55\\u95F4\\u9699\\u3002\"]}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.code,{children:\"numbers: number[]\"}),\": \\u6574\\u6570\\u6570\\u7EC4\"]}),`\n`]}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u6CE8\\u610F\\u4E8B\\u9879\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsx)(e.li,{children:\"\\u89E3\\u51B3\\u65B9\\u6848\\u5E94\\u5177\\u6709 O(n) \\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\"}),`\n`]}),`\n`,(0,t.jsx)(h,{testCases:a}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[\"0 <= \",(0,t.jsx)(e.code,{children:\"numbers.length\"}),\" <= 100,000\"]}),`\n`,(0,t.jsxs)(e.li,{children:[\"-1,000,000,000 <= \",(0,t.jsx)(e.code,{children:\"numbers[i]\"}),\" <= 1,000,000,000\"]}),`\n`]})]})}function C(n={}){let{wrapper:e}=n.components||{};return e?(0,t.jsx)(e,Object.assign({},n,{children:(0,t.jsx)(d,n)})):d(n)}var D=C;return T(X);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来查找最长连续数字序列的长度", + "title": "最长连续数字序列" + }, + "solution": "var Component=(()=>{var k=Object.create;var l=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty;var x=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),N=(r,e)=>{for(var t in e)l(r,t,{get:e[t],enumerable:!0})},h=(r,e,t,d)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let c of b(e))!p.call(r,c)&&c!==t&&l(r,c,{get:()=>e[c],enumerable:!(d=S(e,c))||d.enumerable});return r};var C=(r,e,t)=>(t=r!=null?k(f(r)):{},h(e||!r||!r.__esModule?l(t,\"default\",{value:r,enumerable:!0}):t,r)),O=r=>h(l({},\"__esModule\",{value:!0}),r);var u=x((B,o)=>{o.exports=_jsx_runtime});var M={};N(M,{default:()=>y});var n=C(u());var i=MDXCodeBlock;var s=`export default function longestConsecutiveNumberSeq(numbers: number[]): number {\n // Create a set from the array to remove duplicates and allow O(1) lookups\n let num_set: Set = new Set(numbers);\n\n // Variable to keep track of the longest streak found\n let longestStreak: number = 0;\n\n // Iterate over each number in the set\n num_set.forEach((num) => {\n // Check if it's the start of a sequence (no preceding number)\n if (!num_set.has(num - 1)) {\n let currentNum: number = num; // Current number in the sequence\n let currentStreak: number = 1; // Current streak length\n\n // Continue the sequence while the next number is in the set\n while (num_set.has(currentNum + 1)) {\n currentNum += 1;\n currentStreak += 1;\n }\n\n // Update the longest streak found so far\n longestStreak = Math.max(longestStreak, currentStreak);\n }\n });\n\n // Return the length of the longest consecutive sequence\n return longestStreak;\n}\n`;var a=`export default function longestConsecutiveNumberSeq(numbers: number[]): number {\n // Return 0 if the array is empty\n if (numbers.length === 0) {\n return 0;\n }\n\n // Sort the array in ascending order\n numbers.sort((a, b) => a - b);\n\n // Initialize the longest and current streaks\n let longestStreak = 1;\n let currentStreak = 1;\n\n // Iterate through the sorted array starting from the second element\n for (let i = 1; i < numbers.length; i++) {\n // Check if the current number is different from the previous number\n if (numbers[i] !== numbers[i - 1]) {\n // Check if the current number is consecutive to the previous number\n if (numbers[i] === numbers[i - 1] + 1) {\n currentStreak += 1;\n } else {\n // Update the longest streak if the current streak is longer\n longestStreak = Math.max(longestStreak, currentStreak);\n // Reset the current streak\n currentStreak = 1;\n }\n }\n }\n\n // Return the maximum of the longest streak and the current streak\n return Math.max(longestStreak, currentStreak);\n}\n`;var m=`export default function longestConsecutiveNumberSeq(numbers: number[]): number {\n // Return 0 if the array is empty\n if (numbers.length === 0) {\n return 0;\n }\n\n // Variable to track the longest streak of consecutive numbers\n let longestStreak = 0;\n\n // Iterate through each number in the array\n for (let i = 0; i < numbers.length; i++) {\n // Start a new sequence with the current number\n let currentNum = numbers[i];\n let currentStreak = 1;\n\n // Keep checking for the next consecutive numbers\n while (numbers.includes(currentNum + 1)) {\n // Increment the current number and the streak length\n currentNum += 1;\n currentStreak += 1;\n }\n\n // Update the longest streak if the current streak is longer\n longestStreak = Math.max(longestStreak, currentStreak);\n }\n\n // Return the length of the longest consecutive number sequence\n return longestStreak;\n}\n`;function g(r){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u86EE\\u529B\\u6CD5\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u76EE\\u6807\\u662F\\u627E\\u5230\\u6570\\u7EC4\\u4E2D\\u6700\\u957F\\u8FDE\\u7EED\\u6574\\u6570\\u5E8F\\u5217\\u7684\\u957F\\u5EA6\\u3002\\u8FD9\\u79CD\\u86EE\\u529B\\u65B9\\u6CD5\\u904D\\u5386\\u6BCF\\u4E2A\\u5143\\u7D20\\uFF0C\\u5E76\\u901A\\u8FC7\\u91CD\\u590D\\u641C\\u7D22\\u6570\\u7EC4\\u6765\\u68C0\\u67E5\\u8FDE\\u7EED\\u7684\\u6570\\u5B57\\u3002\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8BE5\\u903B\\u8F91\\u9996\\u5148\\u5047\\u8BBE\\u5F53\\u524D\\u6570\\u5B57\\u662F\\u6F5C\\u5728\\u5E8F\\u5217\\u7684\\u5F00\\u59CB\\uFF0C\\u5E76\\u4F7F\\u7528\",(0,n.jsx)(e.code,{children:\"includes\"}),\"\\u65B9\\u6CD5\\u68C0\\u67E5\\u4E0B\\u4E00\\u4E2A\\u8FDE\\u7EED\\u6570\\u5B57\\u662F\\u5426\\u5B58\\u5728\\u3002\\u8BE5\\u8FC7\\u7A0B\\u6301\\u7EED\\u8FDB\\u884C\\uFF0C\\u76F4\\u5230\\u5E8F\\u5217\\u4E2D\\u6CA1\\u6709\\u66F4\\u591A\\u8FDE\\u7EED\\u6570\\u5B57\\u3002\\u7136\\u540E\\uFF0C\\u5C06\\u6B64\\u5E8F\\u5217\\u7684\\u957F\\u5EA6\\u4E0E\\u5230\\u76EE\\u524D\\u4E3A\\u6B62\\u627E\\u5230\\u7684\\u6700\\u957F\\u5E8F\\u5217\\u8FDB\\u884C\\u6BD4\\u8F83\\uFF0C\\u4EE5\\u66F4\\u65B0\\u7ED3\\u679C\\u3002\"]}),`\n`,(0,n.jsx)(i,{children:m}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u6570\\u7EC4\\u662F\\u5426\\u4E3A\\u7A7A\\u3002\\u5982\\u679C\\u662F\\uFF0C\\u5219\\u8FD4\\u56DE\",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u56E0\\u4E3A\\u6CA1\\u6709\\u6570\\u5B57\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u53D8\\u91CF\",(0,n.jsx)(e.code,{children:\"longestStreak\"}),\"\\u6765\\u8DDF\\u8E2A\\u5230\\u76EE\\u524D\\u4E3A\\u6B62\\u627E\\u5230\\u7684\\u6700\\u957F\\u8FDE\\u7EED\\u5E8F\\u5217\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\",(0,n.jsx)(e.code,{children:\"for\"}),\"\\u5FAA\\u73AF\\u904D\\u5386\\u6570\\u7EC4\\u4E2D\\u7684\\u6BCF\\u4E2A\\u6570\\u5B57\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\",(0,n.jsx)(e.code,{children:\"currentNum\"}),\"\\u8BBE\\u7F6E\\u4E3A\\u5F53\\u524D\\u6570\\u5B57\\uFF0C\\u5E76\\u5C06\",(0,n.jsx)(e.code,{children:\"currentStreak\"}),\"\\u521D\\u59CB\\u5316\\u4E3A\",(0,n.jsx)(e.code,{children:\"1\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\",(0,n.jsx)(e.code,{children:\"while\"}),\"\\u5FAA\\u73AF\\u68C0\\u67E5\\u4E0B\\u4E00\\u4E2A\\u8FDE\\u7EED\\u6570\\u5B57\\uFF08\",(0,n.jsx)(e.code,{children:\"currentNum + 1\"}),\"\\uFF09\\u662F\\u5426\\u5B58\\u5728\\u4E8E\\u6570\\u7EC4\\u4E2D\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5B58\\u5728\\uFF0C\\u5219\\u9012\\u589E\",(0,n.jsx)(e.code,{children:\"currentNum\"}),\"\\u5E76\\u5C06\",(0,n.jsx)(e.code,{children:\"currentStreak\"}),\"\\u589E\\u52A0\",(0,n.jsx)(e.code,{children:\"1\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\",(0,n.jsx)(e.code,{children:\"longestStreak\"}),\"\\u66F4\\u65B0\\u4E3A\",(0,n.jsx)(e.code,{children:\"longestStreak\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"currentStreak\"}),\"\\u4E4B\\u95F4\\u7684\\u6700\\u5927\\u503C\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5FAA\\u73AF\\u7ED3\\u675F\\u4E4B\\u540E\\uFF0C\\u8FD4\\u56DE\",(0,n.jsx)(e.code,{children:\"longestStreak\"}),\"\\u7684\\u503C\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,n.jsx)(\"sup\",{children:\"2\"}),\")\"]}),\"\\u3002\",(0,n.jsx)(e.code,{children:\"includes\"}),\"\\u65B9\\u6CD5\\u6267\\u884C\\u7EBF\\u6027\\u641C\\u7D22\\uFF0C\\u8FD9\\u4F7F\\u5F97\\u8FD9\\u79CD\\u65B9\\u6CD5\\u662F\\u4E8C\\u6B21\\u7684\\uFF0C\\u56E0\\u4E3A\\u5B83\\u5D4C\\u5957\\u5728\\u5FAA\\u73AF\\u4E2D\\uFF0C\\u5FAA\\u73AF\\u904D\\u5386\\u6240\\u6709\",(0,n.jsx)(e.code,{children:\"n\"}),\"\\u4E2A\\u5143\\u7D20\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u6CA1\\u6709\\u4F7F\\u7528\\u989D\\u5916\\u7684\\u6570\\u636E\\u7ED3\\u6784\\uFF1B\\u53EA\\u5206\\u914D\\u4E86\\u51E0\\u4E2A\\u53D8\\u91CF\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u6392\\u5E8F\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u901A\\u8FC7\\u5BF9\\u8F93\\u5165\\u6570\\u7EC4\\u8FDB\\u884C\\u6392\\u5E8F\\u6765\\u6539\\u8FDB\\u86EE\\u529B\\u65B9\\u6CD5\\uFF0C\\u4EE5\\u7B80\\u5316\\u67E5\\u627E\\u8FDE\\u7EED\\u6570\\u5B57\\u7684\\u8FC7\\u7A0B\\u3002\\u6392\\u5E8F\\u5C06\\u6240\\u6709\\u5143\\u7D20\\u6309\\u5347\\u5E8F\\u6392\\u5217\\uFF0C\\u8FD9\\u4F7F\\u5F97\\u8FDE\\u7EED\\u6570\\u5B57\\u5F7C\\u6B64\\u76F8\\u90BB\\u51FA\\u73B0\\u3002\\u8FD9\\u6D88\\u9664\\u4E86\\u91CD\\u590D\\u641C\\u7D22\\u5E8F\\u5217\\u4E2D\\u4E0B\\u4E00\\u4E2A\\u6570\\u5B57\\u7684\\u9700\\u8981\\uFF0C\\u4ECE\\u800C\\u663E\\u7740\\u51CF\\u5C11\\u4E86\\u5197\\u4F59\\u64CD\\u4F5C\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u7B97\\u6CD5\\u904D\\u5386\\u6392\\u5E8F\\u540E\\u7684\\u6570\\u7EC4\\uFF0C\\u5E76\\u8DDF\\u8E2A\\u5F53\\u524D\\u8FDE\\u7EED\\u6570\\u5B57\\u5E8F\\u5217\\u7684\\u957F\\u5EA6\\u3002\\u6BCF\\u5F53\\u5E8F\\u5217\\u4E2D\\u65AD\\u65F6\\uFF08\\u4E00\\u4E2A\\u6570\\u5B57\\u4E0E\\u524D\\u4E00\\u4E2A\\u6570\\u5B57\\u4E0D\\u8FDE\\u7EED\\uFF09\\uFF0C\\u5C06\\u5F53\\u524D\\u6761\\u7EB9\\u7684\\u957F\\u5EA6\\u4E0E\\u5230\\u76EE\\u524D\\u4E3A\\u6B62\\u627E\\u5230\\u7684\\u6700\\u957F\\u6761\\u7EB9\\u8FDB\\u884C\\u6BD4\\u8F83\\uFF0C\\u5E76\\u66F4\\u65B0\\u6700\\u5927\\u503C\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u6570\\u7EC4\\u662F\\u5426\\u4E3A\\u7A7A\\u3002\\u5982\\u679C\\u662F\\uFF0C\\u5219\\u8FD4\\u56DE\",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\",(0,n.jsx)(e.code,{children:\"sort\"}),\"\\u65B9\\u6CD5\\u6309\\u5347\\u5E8F\\u5BF9\\u6570\\u7EC4\\u8FDB\\u884C\\u6392\\u5E8F\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E24\\u4E2A\\u53D8\\u91CF\\uFF1A\",(0,n.jsx)(e.code,{children:\"longestStreak\"}),\"\\u4E3A\",(0,n.jsx)(e.code,{children:\"1\"}),\"\\uFF0C\\u7528\\u4E8E\\u8DDF\\u8E2A\\u6700\\u957F\\u5E8F\\u5217\\uFF0C\",(0,n.jsx)(e.code,{children:\"currentStreak\"}),\"\\u4E3A\",(0,n.jsx)(e.code,{children:\"1\"}),\"\\uFF0C\\u7528\\u4E8E\\u5F53\\u524D\\u8FDE\\u7EED\\u5E8F\\u5217\\u957F\\u5EA6\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u7B2C\\u4E8C\\u4E2A\\u5143\\u7D20\\u5F00\\u59CB\\u904D\\u5386\\u6392\\u5E8F\\u540E\\u7684\\u6570\\u7EC4\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u5F53\\u524D\\u6570\\u5B57\\u7B49\\u4E8E\\u524D\\u4E00\\u4E2A\\u6570\\u5B57\\uFF0C\\u5219\\u8DF3\\u8FC7\\u5B83\\u4EE5\\u907F\\u514D\\u91CD\\u590D\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5F53\\u524D\\u6570\\u5B57\\u6B63\\u597D\\u6BD4\\u524D\\u4E00\\u4E2A\\u6570\\u5B57\\u5927 1\\uFF0C\\u5219\\u9012\\u589E\",(0,n.jsx)(e.code,{children:\"currentStreak\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5F53\\u524D\\u6570\\u5B57\\u65E2\\u4E0D\\u7B49\\u4E8E\\u524D\\u4E00\\u4E2A\\u6570\\u5B57\\uFF0C\\u4E5F\\u4E0D\\u4E0E\\u524D\\u4E00\\u4E2A\\u6570\\u5B57\\u8FDE\\u7EED\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\",(0,n.jsx)(e.code,{children:\"longestStreak\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"currentStreak\"}),\"\\u4E4B\\u95F4\\u7684\\u6700\\u5927\\u503C\\u66F4\\u65B0\",(0,n.jsx)(e.code,{children:\"longestStreak\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\",(0,n.jsx)(e.code,{children:\"currentStreak\"}),\"\\u91CD\\u7F6E\\u4E3A\",(0,n.jsx)(e.code,{children:\"1\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5FAA\\u73AF\\u7ED3\\u675F\\u540E\\uFF0C\\u6700\\u540E\\u4E00\\u6B21\\u5C06\",(0,n.jsx)(e.code,{children:\"longestStreak\"}),\"\\u4E0E\",(0,n.jsx)(e.code,{children:\"currentStreak\"}),\"\\u8FDB\\u884C\\u6BD4\\u8F83\\uFF0C\\u5E76\\u8FD4\\u56DE\\u6700\\u5927\\u503C\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(i,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n log n)\"}),\"\\u3002\\u5BF9\\u6570\\u7EC4\\u8FDB\\u884C\\u6392\\u5E8F\\u4E3B\\u5BFC\\u4E86\\u8FD0\\u884C\\u65F6\\uFF0C\\u9700\\u8981 O(n log n)\\u3002\\u968F\\u540E\\u5BF9\\u6570\\u7EC4\\u7684\\u5355\\u6B21\\u904D\\u5386\\u662F O(n)\\uFF0C\\u4F7F\\u603B\\u590D\\u6742\\u5EA6\\u4E3A O(n log n)\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u6392\\u5E8F\\u662F\\u5C31\\u5730\\u6267\\u884C\\u7684\\uFF0C\\u5E76\\u4E14\\u4EC5\\u4F7F\\u7528\\u51E0\\u4E2A\\u53D8\\u91CF\\u6765\\u8DDF\\u8E2A\\u6761\\u7EB9\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"3. \\u4F7F\\u7528\\u54C8\\u5E0C\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u901A\\u8FC7\\u4F7F\\u7528\",(0,n.jsx)(e.code,{children:\"Set\"}),\"\\u5B58\\u50A8\\u8F93\\u5165\\u6570\\u5B57\\u6765\\u6539\\u8FDB\\u8FD0\\u884C\\u65F6\\u590D\\u6742\\u5EA6\\u3002\",(0,n.jsx)(e.code,{children:\"Set\"}),\"\\u4E3A\\u67E5\\u627E\\u63D0\\u4F9B\\u4E86 O(1) \\u7684\\u5E73\\u5747\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF0C\\u8FD9\\u6D88\\u9664\\u4E86\\u91CD\\u590D\\u641C\\u7D22\\u6570\\u7EC4\\u7684\\u9700\\u8981\\u3002\\u8BE5\\u65B9\\u6CD5\\u901A\\u8FC7\\u68C0\\u67E5\\u5F53\\u524D\\u6570\\u5B57\\u5728\\u96C6\\u5408\\u4E2D\\u662F\\u5426\\u6CA1\\u6709\\u524D\\u4E00\\u4E2A\\u6570\\u5B57\\uFF08\",(0,n.jsx)(e.code,{children:\"num - 1\"}),\"\\uFF09\\u6765\\u6807\\u8BC6\\u6F5C\\u5728\\u5E8F\\u5217\\u7684\\u5F00\\u59CB\\u3002\\u4E00\\u65E6\\u786E\\u5B9A\\u4E86\\u5E8F\\u5217\\u7684\\u5F00\\u59CB\\uFF0C\\u5B83\\u5C31\\u4F1A\\u8BA1\\u7B97\\u8FDE\\u7EED\\u7684\\u6570\\u5B57\\uFF0C\\u76F4\\u5230\\u5E8F\\u5217\\u7ED3\\u675F\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u8F93\\u5165\\u6570\\u7EC4\\u521B\\u5EFA\\u4E00\\u4E2A\",(0,n.jsx)(e.code,{children:\"Set\"}),\"\\uFF0C\\u4EE5\\u5220\\u9664\\u91CD\\u590D\\u9879\\u5E76\\u5141\\u8BB8 O(1) \\u67E5\\u627E\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\",(0,n.jsx)(e.code,{children:\"longestStreak\"}),\"\\u521D\\u59CB\\u5316\\u4E3A\",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u4EE5\\u8DDF\\u8E2A\\u6700\\u957F\\u5E8F\\u5217\\u957F\\u5EA6\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386\",(0,n.jsx)(e.code,{children:\"Set\"}),\"\\u4E2D\\u7684\\u6BCF\\u4E2A\\u6570\\u5B57\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u9A8C\\u8BC1\",(0,n.jsx)(e.code,{children:\"num - 1\"}),\"\\u4E0D\\u5728\",(0,n.jsx)(e.code,{children:\"Set\"}),\"\\u4E2D\\u6765\\u68C0\\u67E5\\u5F53\\u524D\\u6570\\u5B57\\u662F\\u5426\\u4E3A\\u5E8F\\u5217\\u7684\\u5F00\\u59CB\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u662F\\u5F00\\u59CB\\uFF0C\\u5219\\u5C06\",(0,n.jsx)(e.code,{children:\"currentNum\"}),\"\\u521D\\u59CB\\u5316\\u4E3A\\u5F53\\u524D\\u6570\\u5B57\\uFF0C\\u5C06\",(0,n.jsx)(e.code,{children:\"currentStreak\"}),\"\\u521D\\u59CB\\u5316\\u4E3A\",(0,n.jsx)(e.code,{children:\"1\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\",(0,n.jsx)(e.code,{children:\"while\"}),\"\\u5FAA\\u73AF\\u68C0\\u67E5\\u4E0B\\u4E00\\u4E2A\\u6570\\u5B57\\uFF08\",(0,n.jsx)(e.code,{children:\"currentNum + 1\"}),\"\\uFF09\\u662F\\u5426\\u5B58\\u5728\\u4E8E\",(0,n.jsx)(e.code,{children:\"Set\"}),\"\\u4E2D\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5B58\\u5728\\uFF0C\\u5219\\u9012\\u589E\",(0,n.jsx)(e.code,{children:\"currentNum\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"currentStreak\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\",(0,n.jsx)(e.code,{children:\"longestStreak\"}),\"\\u66F4\\u65B0\\u4E3A\",(0,n.jsx)(e.code,{children:\"longestStreak\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"currentStreak\"}),\"\\u4E4B\\u95F4\\u7684\\u6700\\u5927\\u503C\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\",(0,n.jsx)(e.code,{children:\"longestStreak\"}),\"\\u4F5C\\u4E3A\\u6700\\u957F\\u8FDE\\u7EED\\u5E8F\\u5217\\u7684\\u957F\\u5EA6\\u8FD4\\u56DE\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(i,{children:s}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u6BCF\\u4E2A\\u6570\\u5B57\\u6700\\u591A\\u5904\\u7406\\u4E24\\u6B21\\uFF1A\\u4E00\\u6B21\\u662F\\u68C0\\u67E5\\u5B83\\u662F\\u5426\\u662F\\u5E8F\\u5217\\u7684\\u5F00\\u59CB\\uFF0C\\u53E6\\u4E00\\u6B21\\u662F\\u5728\",(0,n.jsx)(e.code,{children:\"while\"}),\"\\u5FAA\\u73AF\\u4E2D\\u6269\\u5C55\\u5E8F\\u5217\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\",(0,n.jsx)(e.code,{children:\"Set\"}),\"\\u9700\\u8981\\u4E0E\\u8F93\\u5165\\u6570\\u7EC4\\u4E2D\\u552F\\u4E00\\u5143\\u7D20\\u7684\\u6570\\u91CF\\u6210\\u6BD4\\u4F8B\\u7684\\u7A7A\\u95F4\\u3002\"]}),`\n`]})]})}function _(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(g,r)})):g(r)}var y=_;return O(M);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/longest-increasing-subsequence/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/longest-increasing-subsequence/locales/zh-CN.json new file mode 100644 index 000000000..1a874d968 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/longest-increasing-subsequence/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var m=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var f=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),j=(t,e)=>{for(var r in e)i(t,r,{get:e[r],enumerable:!0})},o=(t,e,r,s)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let c of g(e))!b.call(t,c)&&c!==r&&i(t,c,{get:()=>e[c],enumerable:!(s=p(e,c))||s.enumerable});return t};var _=(t,e,r)=>(r=t!=null?m(x(t)):{},o(e||!t||!t.__esModule?i(r,\"default\",{value:t,enumerable:!0}):r,t)),T=t=>o(i({},\"__esModule\",{value:!0}),t);var h=f((E,l)=>{l.exports=_jsx_runtime});var q={};j(q,{default:()=>X,frontmatter:()=>C});var n=_(h());var d=MDXTestExamples;var u=[{input:[[\"numbers\",[0,1,0,3,2,3]]],output:4,explanation:\"The longest increasing subsequence is [0, 1, 2, 3], which has a length of 4.\"},{input:[[\"numbers\",[3,2]]],output:1,explanation:\"The longest increasing subsequence is either [3] or [2], both of which have a length of 1.\"},{input:[[\"numbers\",[3,3,3,3]]],output:1,explanation:\"The longest increasing subsequence is [3], since all elements are the same.\"}];var C={title:\"\\u6700\\u957F\\u9012\\u589E\\u5B50\\u5E8F\\u5217\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u67E5\\u627E\\u6700\\u957F\\u9012\\u589E\\u5B50\\u5E8F\\u5217\\u7684\\u957F\\u5EA6\"};function a(t){let e=Object.assign({p:\"p\",code:\"code\",strong:\"strong\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"numbers\"}),\"\\uFF0C\\u786E\\u5B9A\\u6700\\u957F\\u5B50\\u5E8F\\u5217\\u7684\\u957F\\u5EA6\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u6570\\u5B57\\u90FD\\u4E25\\u683C\\u5927\\u4E8E\\u5B83\\u524D\\u9762\\u7684\\u6570\\u5B57\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A\",(0,n.jsx)(e.strong,{children:\"\\u5B50\\u5E8F\\u5217\"}),\"\\u662F\\u4ECE\\u53E6\\u4E00\\u4E2A\\u5E8F\\u5217\\u4E2D\\u6D3E\\u751F\\u7684\\u5E8F\\u5217\\uFF0C\\u901A\\u8FC7\\u5220\\u9664\\u4E00\\u4E9B\\u6216\\u6CA1\\u6709\\u5143\\u7D20\\u800C\\u4E0D\\u6539\\u53D8\\u5269\\u4F59\\u5143\\u7D20\\u7684\\u987A\\u5E8F\\u3002\\u4F8B\\u5982\\uFF0C\",(0,n.jsx)(e.code,{children:\"[1, 2, 3]\"}),\" \\u7684\\u5B50\\u5E8F\\u5217\\u662F \",(0,n.jsx)(e.code,{children:\"[1]\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"[2]\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"[3]\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"[1, 2]\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"[2, 3]\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"[1, 3]\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"[1, 2, 3]\"}),\"\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"numbers: number[]\"}),\": \\u6574\\u6570\\u6570\\u7EC4\"]}),`\n`]}),`\n`,(0,n.jsx)(d,{testCases:u}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"numbers.length\"}),\" <= 2500\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"-10,000 <= \",(0,n.jsx)(e.code,{children:\"numbers[i]\"}),\" <= 10,000\"]}),`\n`]})]})}function D(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(a,t)})):a(t)}var X=D;return T(q);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来查找最长递增子序列的长度", + "title": "最长递增子序列" + }, + "solution": "var Component=(()=>{var a=Object.create;var l=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var I=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),S=(r,e)=>{for(var i in e)l(r,i,{get:e[i],enumerable:!0})},t=(r,e,i,h)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let c of p(e))!j.call(r,c)&&c!==i&&l(r,c,{get:()=>e[c],enumerable:!(h=g(e,c))||h.enumerable});return r};var x=(r,e,i)=>(i=r!=null?a(f(r)):{},t(e||!r||!r.__esModule?l(i,\"default\",{value:r,enumerable:!0}):i,r)),y=r=>t(l({},\"__esModule\",{value:!0}),r);var o=I((C,s)=>{s.exports=_jsx_runtime});var M={};S(M,{default:()=>q});var n=x(o());var d=MDXCodeBlock;var u=`function binarySearch(sub: number[], num: number): number {\n let left = 0;\n let right = sub.length - 1;\n\n // Perform binary search\n while (left < right) {\n const mid = Math.floor((left + right) / 2);\n if (sub[mid] === num) {\n return mid;\n }\n\n if (sub[mid] < num) {\n left = mid + 1;\n } else {\n right = mid;\n }\n }\n\n return left;\n}\n\nexport default function longestIncreasingSubsequence(\n numbers: number[],\n): number {\n // Array to store the current longest increasing subsequence\n const sub: number[] = [];\n sub.push(numbers[0]);\n\n // Iterate over the numbers array\n for (let i = 1; i < numbers.length; i++) {\n const num = numbers[i];\n\n // If the current number is greater than the last element in 'sub'\n // then add it to 'sub'\n if (num > sub[sub.length - 1]) {\n sub.push(num);\n } else {\n // Otherwise, find the position to replace in 'sub' using binary search\n const j = binarySearch(sub, num);\n sub[j] = num;\n }\n }\n\n // Return the size of 'sub', which represents the length of the LIS\n return sub.length;\n}\n`;var b=`export default function longestIncreasingSubsequence(\n numbers: number[],\n): number {\n // Initialize an array dp where dp[i] will store the length of the longest increasing subsequence ending at index i\n const dp: number[] = new Array(numbers.length).fill(1);\n\n // Iterate through each element in numbers array starting from the second element\n for (let i = 1; i < numbers.length; i++) {\n // Compare current element numbers[i] with all previous elements numbers[j] where j < i\n for (let j = 0; j < i; j++) {\n // If numbers[i] is greater than numbers[j], it means we can extend the subsequence ending at i with j\n if (numbers[i] > numbers[j]) {\n // Update dp[i] to be the maximum of its current value or dp[j] + 1\n dp[i] = Math.max(dp[i], dp[j] + 1);\n }\n }\n }\n\n // Find the maximum value in dp array, which represents the length of the longest increasing subsequence\n let longest = 0;\n for (let c of dp) {\n longest = Math.max(longest, c);\n }\n\n // Return the length of the longest increasing subsequence\n return longest;\n}\n`;function m(r){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u52A8\\u6001\\u89C4\\u5212\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u52A8\\u6001\\u89C4\\u5212\\u6765\\u67E5\\u627E\\u6570\\u7EC4\\u4E2D\\u6700\\u957F\\u9012\\u589E\\u5B50\\u5E8F\\u5217 (LIS) \\u7684\\u957F\\u5EA6\\u3002\\u5B50\\u5E8F\\u5217\\u53EF\\u4EE5\\u901A\\u8FC7\\u5220\\u9664\\u4E00\\u4E9B\\u6216\\u4E0D\\u5220\\u9664\\u4EFB\\u4F55\\u5143\\u7D20\\u800C\\u6D3E\\u751F\\u51FA\\u6765\\uFF0C\\u800C\\u4E0D\\u4F1A\\u6539\\u53D8\\u5269\\u4F59\\u5143\\u7D20\\u7684\\u987A\\u5E8F\\u3002\\u52A8\\u6001\\u89C4\\u5212\\u65B9\\u6CD5\\u901A\\u8FC7\\u5B58\\u50A8\\u4E2D\\u95F4\\u7ED3\\u679C\\u6765\\u6D88\\u9664\\u5197\\u4F59\\u8BA1\\u7B97\\u3002\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8BE5\\u7B97\\u6CD5\\u7EF4\\u62A4\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u6570\\u7EC4\\uFF0C\\u5176\\u4E2D \",(0,n.jsx)(e.code,{children:\"dp[i]\"}),\" \\u8868\\u793A\\u4EE5\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"i\"}),\" \\u7ED3\\u5C3E\\u7684 LIS \\u7684\\u957F\\u5EA6\\u3002\\u5BF9\\u4E8E\\u6570\\u7EC4\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5143\\u7D20\\uFF0C\\u8BE5\\u7B97\\u6CD5\\u68C0\\u67E5\\u6240\\u6709\\u5148\\u524D\\u7684\\u5143\\u7D20\\uFF0C\\u4EE5\\u786E\\u5B9A\\u5F53\\u524D\\u5143\\u7D20\\u662F\\u5426\\u53EF\\u4EE5\\u6269\\u5C55\\u9012\\u589E\\u5B50\\u5E8F\\u5217\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\\u89E3\\u51B3\\u65B9\\u6848\\u662F\\u9010\\u6B65\\u6784\\u5EFA\\u7684\\uFF0C\\u540C\\u65F6\\u907F\\u514D\\u4E86\\u91CD\\u590D\\u8BA1\\u7B97\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u5927\\u5C0F\\u4E3A \",(0,n.jsx)(e.code,{children:\"numbers.length\"}),\" \\u7684 \",(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u6570\\u7EC4\\uFF0C\\u6240\\u6709\\u503C\\u90FD\\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"1\"}),\"\\u3002\\u6BCF\\u4E2A\\u5143\\u7D20\\u6700\\u521D\\u90FD\\u662F\\u5B83\\u81EA\\u5DF1\\u7684\\u5B50\\u5E8F\\u5217\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u7B2C\\u4E8C\\u4E2A\\u5143\\u7D20\\u5F00\\u59CB\\u904D\\u5386 \",(0,n.jsx)(e.code,{children:\"numbers\"}),\" \\u6570\\u7EC4\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"i\"}),\" \\u5904\\u7684\\u6BCF\\u4E2A\\u5143\\u7D20\\uFF0C\\u904D\\u5386\\u6240\\u6709\\u5148\\u524D\\u7684\\u5143\\u7D20\\uFF08\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"j\"}),\"\\uFF0C\\u5176\\u4E2D \",(0,n.jsx)(e.code,{children:\"j < i\"}),\"\\uFF09\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"numbers[i]\"}),\" \\u5927\\u4E8E \",(0,n.jsx)(e.code,{children:\"numbers[j]\"}),\"\\uFF0C\\u5219\\u5C06 \",(0,n.jsx)(e.code,{children:\"dp[i]\"}),\" \\u66F4\\u65B0\\u4E3A \",(0,n.jsx)(e.code,{children:\"dp[i]\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"dp[j] + 1\"}),\" \\u7684\\u6700\\u5927\\u503C\\uFF0C\\u4EE5\\u5C06\\u5F53\\u524D\\u5143\\u7D20\\u5305\\u542B\\u5728\\u4EE5 \",(0,n.jsx)(e.code,{children:\"j\"}),\" \\u7ED3\\u5C3E\\u7684\\u5B50\\u5E8F\\u5217\\u4E2D\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u53D8\\u91CF \",(0,n.jsx)(e.code,{children:\"longest\"}),\" \\u521D\\u59CB\\u5316\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u5E76\\u904D\\u5386 \",(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u6570\\u7EC4\\u4EE5\\u627E\\u5230\\u6700\\u5927\\u503C\\uFF0C\\u8BE5\\u503C\\u8868\\u793A LIS\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"longest\"}),\" \\u7684\\u503C\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(d,{children:b}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,n.jsx)(\"sup\",{children:\"2\"}),\")\"]}),\"\\u3002\\u5BF9\\u4E8E\\u6570\\u7EC4\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5143\\u7D20\\uFF0C\\u7B97\\u6CD5\\u90FD\\u4F1A\\u904D\\u5386\\u6240\\u6709\\u5148\\u524D\\u7684\\u5143\\u7D20\\uFF0C\\u4ECE\\u800C\\u5BFC\\u81F4\\u5D4C\\u5957\\u5FAA\\u73AF\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\",(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u6570\\u7EC4\\u6240\\u9700\\u7684\\u7A7A\\u95F4\\u4E0E\\u8F93\\u5165\\u6570\\u7EC4\\u4E2D\\u7684\\u5143\\u7D20\\u6570\\u91CF\\u6210\\u6B63\\u6BD4\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u8D2A\\u5FC3\\u548C\\u4E8C\\u5206\\u67E5\\u627E\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u7ED3\\u5408\\u4E86\\u8D2A\\u5FC3\\u548C\\u4E8C\\u5206\\u67E5\\u627E\\u6280\\u672F\\uFF0C\\u4EE5\\u6709\\u6548\\u5730\\u8BA1\\u7B97\\u6700\\u957F\\u9012\\u589E\\u5B50\\u5E8F\\u5217 (LIS) \\u7684\\u957F\\u5EA6\\u3002\\u6838\\u5FC3\\u601D\\u60F3\\u662F\\u7EF4\\u62A4\\u4E00\\u4E2A\\u540D\\u4E3A \",(0,n.jsx)(e.code,{children:\"sub\"}),\" \\u7684\\u8F85\\u52A9\\u6570\\u7EC4\\u3002\\u6B64\\u6570\\u7EC4\\u8868\\u793A\\u4E0D\\u540C\\u957F\\u5EA6\\u7684\\u9012\\u589E\\u5B50\\u5E8F\\u5217\\u7684\\u6700\\u5C0F\\u7ED3\\u675F\\u503C\\u3002\\u4F8B\\u5982\\uFF0C\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"sub\"}),\" \\u6709\\u4E09\\u4E2A\\u5143\\u7D20\\uFF0C\\u5219\\u8868\\u660E\\u5DF2\\u786E\\u5B9A\\u957F\\u5EA6\\u4E3A 3 \\u7684\\u9012\\u589E\\u5B50\\u5E8F\\u5217\\uFF0C\\u5E76\\u4E14\\u5176\\u7ED3\\u675F\\u503C\\u5B58\\u50A8\\u4E3A \",(0,n.jsx)(e.code,{children:\"sub\"}),\" \\u7684\\u6700\\u540E\\u4E00\\u4E2A\\u5143\\u7D20\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:\"sub\"}),\" \\u6570\\u7EC4\\u5E76\\u4E0D\\u76F4\\u63A5\\u8868\\u793A LIS \\u672C\\u8EAB\\uFF0C\\u4F46\\u6709\\u52A9\\u4E8E\\u8DDF\\u8E2A\\u5E8F\\u5217\\u957F\\u5EA6\\u3002\\u5728\\u4EFB\\u4F55\\u65F6\\u5019\\uFF0C\",(0,n.jsx)(e.code,{children:\"sub\"}),\" \\u7684\\u5927\\u5C0F\\u90FD\\u5BF9\\u5E94\\u4E8E\\u5230\\u76EE\\u524D\\u4E3A\\u6B62\\u627E\\u5230\\u7684 LIS \\u7684\\u957F\\u5EA6\\u3002\\u5904\\u7406\\u4E00\\u4E2A\\u6570\\u5B57\\u65F6\\uFF1A\"]}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u8BE5\\u6570\\u5B57\\u5927\\u4E8E \",(0,n.jsx)(e.code,{children:\"sub\"}),\" \\u4E2D\\u7684\\u6700\\u5927\\u503C\\uFF0C\\u5219\\u5B83\\u4F1A\\u6269\\u5C55 LIS \\u5E76\\u9644\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"sub\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u8BE5\\u6570\\u5B57\\u5C0F\\u4E8E\\u6216\\u7B49\\u4E8E \",(0,n.jsx)(e.code,{children:\"sub\"}),\" \\u4E2D\\u7684\\u4E00\\u4E2A\\u5143\\u7D20\\uFF0C\\u5219\\u5B83\\u4F1A\\u66FF\\u6362 \",(0,n.jsx)(e.code,{children:\"sub\"}),\" \\u4E2D\\u5927\\u4E8E\\u6216\\u7B49\\u4E8E\\u5B83\\u7684\\u6700\\u5C0F\\u6570\\u5B57\\u3002\\u6B64\\u66FF\\u6362\\u53EF\\u786E\\u4FDD \",(0,n.jsx)(e.code,{children:\"sub\"}),\" \\u4FDD\\u6301\\u6700\\u4F73\\u72B6\\u6001\\uFF0C\\u4EE5\\u4FBF\\u7A0D\\u540E\\u6269\\u5C55 LIS\\u3002\"]}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E3A\\u4E86\\u6709\\u6548\\u5730\\u786E\\u5B9A\\u5728 \",(0,n.jsx)(e.code,{children:\"sub\"}),\" \\u4E2D\\u63D2\\u5165\\u6216\\u66FF\\u6362\\u7684\\u4F4D\\u7F6E\\uFF0C\\u4F7F\\u7528\\u4E86\\u4E8C\\u5206\\u67E5\\u627E\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\\u7B97\\u6CD5\\u4EE5 O(n log n) \\u65F6\\u95F4\\u8FD0\\u884C\\uFF0C\\u56E0\\u4E3A\\u4E8C\\u5206\\u67E5\\u627E\\u5141\\u8BB8\\u5FEB\\u901F\\u786E\\u5B9A\\u4F4D\\u7F6E\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u8F85\\u52A9\\u51FD\\u6570 \",(0,n.jsx)(e.code,{children:\"binarySearch\"}),\"\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E24\\u4E2A\\u6307\\u9488 \",(0,n.jsx)(e.code,{children:\"left\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"right\"}),\" \\u4EE5\\u8868\\u793A \",(0,n.jsx)(e.code,{children:\"sub\"}),\" \\u6570\\u7EC4\\u4E2D\\u7684\\u641C\\u7D22\\u7A7A\\u95F4\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u5FAA\\u73AF\\u6267\\u884C\\u4E8C\\u5206\\u67E5\\u627E\\uFF0C\\u6839\\u636E\\u6BD4\\u8F83\\u66F4\\u65B0 \",(0,n.jsx)(e.code,{children:\"left\"}),\" \\u6216 \",(0,n.jsx)(e.code,{children:\"right\"}),\" \\u6307\\u9488\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8FD4\\u56DE\\u5E94\\u63D2\\u5165\\u6216\\u66FF\\u6362\\u8BE5\\u6570\\u5B57\\u7684\\u7D22\\u5F15\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"numbers\"}),\" \\u7684\\u7B2C\\u4E00\\u4E2A\\u5143\\u7D20\\u521D\\u59CB\\u5316\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"sub\"}),\" \\u4EE5\\u5B58\\u50A8\\u5F53\\u524D\\u7684 LIS\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u7B2C\\u4E8C\\u4E2A\\u5143\\u7D20\\u5F00\\u59CB\\u904D\\u5386 \",(0,n.jsx)(e.code,{children:\"numbers\"}),\" \\u6570\\u7EC4\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5F53\\u524D\\u6570\\u5B57\\u5927\\u4E8E \",(0,n.jsx)(e.code,{children:\"sub\"}),\" \\u7684\\u6700\\u540E\\u4E00\\u4E2A\\u5143\\u7D20\\uFF0C\\u5219\\u5C06\\u5176\\u9644\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"sub\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5426\\u5219\\uFF0C\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"binarySearch\"}),\" \\u5728 \",(0,n.jsx)(e.code,{children:\"sub\"}),\" \\u4E2D\\u627E\\u5230\\u8BE5\\u6570\\u5B57\\u5E94\\u66FF\\u6362\\u73B0\\u6709\\u503C\\u7684\\u7D22\\u5F15\\u4EE5\\u7EF4\\u62A4 LIS\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"sub\"}),\" \\u6570\\u7EC4\\u7684\\u957F\\u5EA6\\u4F5C\\u4E3A LIS \\u7684\\u957F\\u5EA6\\u8FD4\\u56DE\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(d,{children:u}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n log n)\"}),\"\\u3002\\u6BCF\\u4E2A\\u6570\\u5B57\\u53EA\\u5904\\u7406\\u4E00\\u6B21\\uFF0C\\u5E76\\u4E14\\u5728 \",(0,n.jsx)(e.code,{children:\"sub\"}),\" \\u6570\\u7EC4\\u4E0A\\u8FDB\\u884C\\u4E8C\\u5206\\u67E5\\u627E\\u9700\\u8981 O(log n) \\u7684\\u65F6\\u95F4\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u5728\\u6700\\u574F\\u7684\\u60C5\\u51B5\\u4E0B\\uFF0C\",(0,n.jsx)(e.code,{children:\"sub\"}),\" \\u6570\\u7EC4\\u6240\\u9700\\u7684\\u7A7A\\u95F4\\u4E0E\\u8F93\\u5165\\u6570\\u7EC4\\u4E2D\\u7684\\u5143\\u7D20\\u6570\\u91CF\\u6210\\u6B63\\u6BD4\\u3002\"]}),`\n`]})]})}function O(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(m,r)})):m(r)}var q=O;return y(M);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/longest-non-repeating-substring/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/longest-non-repeating-substring/locales/zh-CN.json new file mode 100644 index 000000000..8ba629ba0 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/longest-non-repeating-substring/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var s=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var m=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),j=(n,e)=>{for(var r in e)s(n,r,{get:e[r],enumerable:!0})},o=(n,e,r,i)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let c of b(e))!f.call(n,c)&&c!==r&&s(n,c,{get:()=>e[c],enumerable:!(i=g(e,c))||i.enumerable});return n};var _=(n,e,r)=>(r=n!=null?p(x(n)):{},o(e||!n||!n.__esModule?s(r,\"default\",{value:n,enumerable:!0}):r,n)),T=n=>o(s({},\"__esModule\",{value:!0}),n);var a=m((v,d)=>{d.exports=_jsx_runtime});var w={};j(w,{default:()=>X,frontmatter:()=>C});var t=_(a());var l=MDXTestExamples;var h=[{input:[[\"str\",\"abcdefg\"]],output:7,explanation:\"The entire string 'abcdefg' has no repeating characters, so the longest substring is the entire string itself.\"},{input:[[\"str\",\"dvdf\"]],output:3,explanation:\"The longest substring without repeating characters is 'vdf'.\"},{input:[[\"str\",\"aabbccdde\"]],output:2,explanation:\"The longest substrings without repeating characters are 'ab', 'bc', 'cd', 'de'. Each of these substrings has a length of 2.\"}];var C={title:\"\\u6700\\u957F\\u4E0D\\u91CD\\u590D\\u5B50\\u4E32\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u67E5\\u627E\\u5177\\u6709\\u552F\\u4E00\\u5B57\\u7B26\\u7684\\u6700\\u957F\\u5B50\\u4E32\\u7684\\u957F\\u5EA6\"};function u(n){let e=Object.assign({p:\"p\",code:\"code\",strong:\"strong\",h3:\"h3\",ul:\"ul\",li:\"li\"},n.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u5B57\\u7B26\\u4E32\",(0,t.jsx)(e.code,{children:\"str\"}),\"\\uFF0C\\u786E\\u5B9A\\u4E0D\\u5305\\u542B\\u4EFB\\u4F55\\u91CD\\u590D\\u5B57\\u7B26\\u7684\\u6700\\u957F\\u5B50\\u4E32\\u7684\\u957F\\u5EA6\\u3002\"]}),`\n`,(0,t.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A\",(0,t.jsx)(e.strong,{children:\"\\u5B50\\u4E32\"}),\"\\u662F\\u5B57\\u7B26\\u4E32\\u4E2D\\u4EFB\\u610F\\u8FDE\\u7EED\\u7684\\u5B57\\u7B26\\u5E8F\\u5217\\u3002\\u4F8B\\u5982\\uFF0C\\u5B57\\u7B26\\u4E32\",(0,t.jsx)(e.code,{children:\"abc\"}),\"\\u7684\\u5B50\\u4E32\\u662F\",(0,t.jsx)(e.code,{children:\"a\"}),\"\\u3001\",(0,t.jsx)(e.code,{children:\"b\"}),\"\\u3001\",(0,t.jsx)(e.code,{children:\"c\"}),\"\\u3001\",(0,t.jsx)(e.code,{children:\"ab\"}),\"\\u3001\",(0,t.jsx)(e.code,{children:\"bc\"}),\"\\u548C\",(0,t.jsx)(e.code,{children:\"abc\"}),\"\\u3002\\u5B50\\u4E32\\u662F\\u901A\\u8FC7\\u9009\\u62E9\\u4E00\\u4E2A\\u8D77\\u59CB\\u70B9\\u548C\\u4E00\\u4E2A\\u7ED3\\u675F\\u70B9\\uFF0C\\u5E76\\u4E14\\u4E0D\\u8DF3\\u8FC7\\u4E2D\\u95F4\\u7684\\u5B57\\u7B26\\u800C\\u5F62\\u6210\\u7684\\u3002\"]}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.code,{children:\"str: string\"}),\": \\u5B57\\u7B26\\u4E32\"]}),`\n`]}),`\n`,(0,t.jsx)(l,{testCases:h}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[\"0 <= \",(0,t.jsx)(e.code,{children:\"str.length\"}),\" <= 10,000\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.code,{children:\"str\"}),\" \\u4EC5\\u5305\\u542B\\u5C0F\\u5199\\u82F1\\u6587\\u5B57\\u6BCD\"]}),`\n`]})]})}function D(n={}){let{wrapper:e}=n.components||{};return e?(0,t.jsx)(e,Object.assign({},n,{children:(0,t.jsx)(u,n)})):u(n)}var X=D;return T(w);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来查找具有唯一字符的最长子串的长度", + "title": "最长不重复子串" + }, + "solution": "var Component=(()=>{var f=Object.create;var l=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var j=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),v=(t,e)=>{for(var r in e)l(t,r,{get:e[r],enumerable:!0})},d=(t,e,r,c)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of p(e))!b.call(t,i)&&i!==r&&l(t,i,{get:()=>e[i],enumerable:!(c=m(e,i))||c.enumerable});return t};var M=(t,e,r)=>(r=t!=null?f(x(t)):{},d(e||!t||!t.__esModule?l(r,\"default\",{value:t,enumerable:!0}):r,t)),w=t=>d(l({},\"__esModule\",{value:!0}),t);var s=j((B,o)=>{o.exports=_jsx_runtime});var k={};v(k,{default:()=>I});var n=M(s());var h=MDXCodeBlock;var a=`export default function longestUniqueSubstring(str: string): number {\n // Create a map to store the last seen position of each character in the string\n const map = new Map();\n\n // Initialize variables to keep track of the maximum length of the substring without repeating characters\n let maxLen = 0;\n\n // 'left' is the starting index of the current substring being evaluated\n let left = 0;\n\n // Iterate over the string with 'right' as the end index of the current substring\n for (let right = 0; right < str.length; right++) {\n // If the current character has been seen before and is within the current substring\n if (map.has(str[right])) {\n // Move the 'left' pointer to the right of the last seen position of the current character\n // This ensures the substring being evaluated doesn't contain duplicate characters\n left = Math.max(map.get(str[right])!, left);\n }\n\n // Update the maximum length of the substring found so far\n maxLen = Math.max(maxLen, right - left + 1);\n\n // Store the current character's position in the map, adding 1 to handle 0-based indexing\n map.set(str[right], right + 1);\n }\n\n // Return the length of the longest substring without repeating characters\n return maxLen;\n}\n`;var g=`export default function longestUniqueSubstring(str: string): number {\n let n = str.length; // Get the length of the input string\n let res = 0; // Variable to store the length of the longest substring without repeating characters\n\n // Iterate over all possible starting points of substrings\n for (let i = 0; i < n; i++) {\n // Initializing all characters as not visited\n let visited = new Array(256).fill(false);\n\n for (let j = i; j < n; j++) {\n // If current character is visited\n // Break the loop\n if (visited[str.charCodeAt(j)] === true) {\n break;\n } else {\n // Else update the result if this window is larger,\n // and mark current character as visited.\n res = Math.max(res, j - i + 1);\n visited[str.charCodeAt(j)] = true;\n }\n }\n }\n return res;\n}\n`;function u(t){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u66B4\\u529B\\u89E3\\u6CD5\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4EFB\\u52A1\\u662F\\u627E\\u5230\\u7ED9\\u5B9A\\u5B57\\u7B26\\u4E32\\u4E2D\\u6700\\u957F\\u65E0\\u91CD\\u590D\\u5B57\\u7B26\\u5B50\\u4E32\\u7684\\u957F\\u5EA6\\u3002\\u66B4\\u529B\\u89E3\\u6CD5\\u904D\\u5386\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u5B50\\u4E32\\uFF0C\\u786E\\u4FDD\\u6BCF\\u4E2A\\u5B50\\u4E32\\u5305\\u542B\\u552F\\u4E00\\u7684\\u5B57\\u7B26\\u3002\\u901A\\u8FC7\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"visited\"}),\" \\u6570\\u7EC4\\u6765\\u8DDF\\u8E2A\\u9047\\u5230\\u7684\\u5B57\\u7B26\\uFF0C\\u8BE5\\u7B97\\u6CD5\\u786E\\u4FDD\\u5728\\u5F53\\u524D\\u5B50\\u4E32\\u4E2D\\u68C0\\u6D4B\\u5230\\u91CD\\u590D\\u9879\\u3002\\u6BCF\\u5F53\\u627E\\u5230\\u4E00\\u4E2A\\u66F4\\u5927\\u7684\\u65E0\\u91CD\\u590D\\u5B57\\u7B26\\u5B50\\u4E32\\u65F6\\uFF0C\\u7ED3\\u679C\\u5C31\\u4F1A\\u66F4\\u65B0\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u53D8\\u91CF \",(0,n.jsx)(e.code,{children:\"res\"}),\" \\u6765\\u5B58\\u50A8\\u6700\\u957F\\u65E0\\u91CD\\u590D\\u5B57\\u7B26\\u5B50\\u4E32\\u7684\\u957F\\u5EA6\\uFF0C\\u5E76\\u5C06\\u5176\\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u5B50\\u4E32\\u7684\\u6BCF\\u4E2A\\u53EF\\u80FD\\u7684\\u8D77\\u59CB\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"i\"}),\"\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u5927\\u5C0F\\u4E3A \",(0,n.jsx)(e.code,{children:\"256\"}),\" \\u7684 \",(0,n.jsx)(e.code,{children:\"visited\"}),\" \\u6570\\u7EC4\\uFF08\\u8868\\u793A\\u6240\\u6709 ASCII \\u5B57\\u7B26\\uFF09\\uFF0C\\u5E76\\u5C06\\u6240\\u6709\\u6761\\u76EE\\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u8D77\\u59CB\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"i\"}),\"\\uFF0C\\u904D\\u5386\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u7ED3\\u675F\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"j\"}),\"\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"j\"}),\" \\u5904\\u7684\\u5B57\\u7B26\\u5DF2\\u88AB\\u6807\\u8BB0\\u4E3A\\u5DF2\\u8BBF\\u95EE\\uFF0C\\u5219\\u4E2D\\u65AD\\u5185\\u5FAA\\u73AF\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5426\\u5219\\uFF0C\\u5C06\\u5F53\\u524D\\u5B50\\u4E32\\u957F\\u5EA6\\u8BA1\\u7B97\\u4E3A \",(0,n.jsx)(e.code,{children:\"j - i + 1\"}),\"\\uFF0C\\u5E76\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"res\"}),\" \\u548C\\u5F53\\u524D\\u5B50\\u4E32\\u957F\\u5EA6\\u4E4B\\u95F4\\u7684\\u6700\\u5927\\u503C\\u6765\\u66F4\\u65B0 \",(0,n.jsx)(e.code,{children:\"res\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"j\"}),\" \\u5904\\u7684\\u5B57\\u7B26\\u6807\\u8BB0\\u4E3A\\u5728 \",(0,n.jsx)(e.code,{children:\"visited\"}),\" \\u6570\\u7EC4\\u4E2D\\u5DF2\\u8BBF\\u95EE\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5728\\u5B8C\\u6210\\u6240\\u6709\\u8FED\\u4EE3\\u540E\\uFF0C\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"res\"}),\" \\u7684\\u503C\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(h,{children:g}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,n.jsx)(\"sup\",{children:\"2\"}),\")\"]}),\"\\u3002\\u5916\\u5FAA\\u73AF\\u8FED\\u4EE3 \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u6B21\\uFF0C\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u8D77\\u59CB\\u7D22\\u5F15\\uFF0C\\u5185\\u5FAA\\u73AF\\u5728\\u6700\\u574F\\u60C5\\u51B5\\u4E0B\\u53EF\\u80FD\\u8FED\\u4EE3\\u591A\\u8FBE \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\",(0,n.jsx)(e.code,{children:\"visited\"}),\" \\u6570\\u7EC4\\u7684\\u5927\\u5C0F\\u56FA\\u5B9A\\u4E3A 256\\uFF0C\\u8FD9\\u4E0D\\u53D6\\u51B3\\u4E8E\\u8F93\\u5165\\u5927\\u5C0F\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u6ED1\\u52A8\\u7A97\\u53E3\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u6ED1\\u52A8\\u7A97\\u53E3\\u4E0D\\u662F\\u904D\\u5386\\u6240\\u6709\\u5B50\\u4E32\\uFF0C\\u800C\\u662F\\u6839\\u636E\\u91CD\\u590D\\u5B57\\u7B26\\u7684\\u4F4D\\u7F6E\\u52A8\\u6001\\u8C03\\u6574\\u5176\\u5927\\u5C0F\\u3002\\u8FD9\\u964D\\u4F4E\\u4E86\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF0C\\u4ECE O(n\",(0,n.jsx)(\"sup\",{children:\"2\"}),\") \\u964D\\u81F3 O(n)\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u66B4\\u529B\\u89E3\\u6CD5\\u9700\\u8981\\u5D4C\\u5957\\u5FAA\\u73AF\\u6765\\u751F\\u6210\\u6240\\u6709\\u5B50\\u4E32\\u5E76\\u68C0\\u67E5\\u91CD\\u590D\\u9879\\uFF0C\\u5BFC\\u81F4\\u6548\\u7387\\u4F4E\\u4E0B\\u3002\\u8FD9\\u4F1A\\u5BFC\\u81F4\\u5197\\u4F59\\u68C0\\u67E5\\u548C\\u91CD\\u590D\\u8BA1\\u7B97\\u91CD\\u53E0\\u7684\\u5B50\\u4E32\\u3002\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u6ED1\\u52A8\\u7A97\\u53E3\\u65B9\\u6CD5\\u901A\\u8FC7\\u7EF4\\u62A4\\u4E00\\u4E2A\\u552F\\u4E00\\u5B57\\u7B26\\u7684\\u7A97\\u53E3\\u6765\\u6D88\\u9664\\u4E0D\\u5FC5\\u8981\\u7684\\u91CD\\u65B0\\u8BA1\\u7B97\\u3002\",(0,n.jsx)(e.code,{children:\"map\"}),\" \\u7528\\u4E8E\\u5B58\\u50A8\\u6BCF\\u4E2A\\u5B57\\u7B26\\u7684\\u6700\\u540E\\u4E00\\u6B21\\u51FA\\u73B0\\u4F4D\\u7F6E\\uFF0C\\u4ECE\\u800C\\u53EF\\u4EE5\\u6709\\u6548\\u5730\\u66F4\\u65B0\\u7A97\\u53E3\\u8FB9\\u754C\\u3002\\u5F53\\u9047\\u5230\\u91CD\\u590D\\u5B57\\u7B26\\u65F6\\uFF0C\\u7A97\\u53E3\\u7684\\u8D77\\u59CB\\u7D22\\u5F15 (\",(0,n.jsx)(e.code,{children:\"left\"}),\") \\u4F1A\\u8FDB\\u884C\\u8C03\\u6574\\u4EE5\\u6392\\u9664\\u91CD\\u590D\\u9879\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\\u6240\\u6709\\u5B50\\u4E32\\u90FD\\u5728\\u7EBF\\u6027\\u65F6\\u95F4\\u5185\\u88AB\\u68C0\\u67E5\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"map\"}),\" \\u6765\\u5B58\\u50A8\\u5B57\\u7B26\\u4E32\\u4E2D\\u5B57\\u7B26\\u7684\\u6700\\u540E\\u4E00\\u6B21\\u51FA\\u73B0\\u4F4D\\u7F6E\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u53D8\\u91CF \",(0,n.jsx)(e.code,{children:\"maxLen\"}),\" \\u4EE5\\u8DDF\\u8E2A\\u6700\\u957F\\u5B50\\u4E32\\u7684\\u957F\\u5EA6\\uFF0C\\u5E76\\u521D\\u59CB\\u5316 \",(0,n.jsx)(e.code,{children:\"left\"}),\" \\u4EE5\\u8868\\u793A\\u5F53\\u524D\\u7A97\\u53E3\\u7684\\u8D77\\u59CB\\u7D22\\u5F15\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"right\"}),\" \\u4F5C\\u4E3A\\u7A97\\u53E3\\u7684\\u7ED3\\u675F\\u7D22\\u5F15\\uFF0C\\u904D\\u5386\\u5B57\\u7B26\\u4E32\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5F53\\u524D\\u5B57\\u7B26\\u5B58\\u5728\\u4E8E \",(0,n.jsx)(e.code,{children:\"map\"}),\" \\u4E2D\\uFF0C\\u5E76\\u4E14\\u5176\\u6700\\u540E\\u4E00\\u6B21\\u51FA\\u73B0\\u4F4D\\u7F6E\\u5728\\u5F53\\u524D\\u7A97\\u53E3\\u5185\\uFF0C\\u5219\\u5C06 \",(0,n.jsx)(e.code,{children:\"left\"}),\" \\u66F4\\u65B0\\u4E3A \",(0,n.jsx)(e.code,{children:\"Math.max(map.get(str[right]), left)\"}),\" \\u4EE5\\u6392\\u9664\\u91CD\\u590D\\u9879\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"maxLen\"}),\" \\u66F4\\u65B0\\u4E3A \",(0,n.jsx)(e.code,{children:\"Math.max(maxLen, right - left + 1)\"}),\" \\u4EE5\\u5B58\\u50A8\\u5230\\u76EE\\u524D\\u4E3A\\u6B62\\u627E\\u5230\\u7684\\u6700\\u957F\\u5B50\\u4E32\\u7684\\u957F\\u5EA6\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u5F53\\u524D\\u5B57\\u7B26\\u7684\\u4F4D\\u7F6E \",(0,n.jsx)(e.code,{children:\"right + 1\"}),\" \\u66F4\\u65B0 \",(0,n.jsx)(e.code,{children:\"map\"}),\"\\uFF0C\\u4EE5\\u5904\\u7406\\u57FA\\u4E8E 0 \\u7684\\u7D22\\u5F15\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FED\\u4EE3\\u5B8C\\u6210\\u540E\\uFF0C\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"maxLen\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(h,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u5F53\\u79FB\\u52A8 \",(0,n.jsx)(e.code,{children:\"right\"}),\" \\u6307\\u9488\\u65F6\\uFF0C\\u6BCF\\u4E2A\\u5B57\\u7B26\\u90FD\\u4F1A\\u88AB\\u5904\\u7406\\u4E00\\u6B21\\uFF0C\\u5F53\\u8C03\\u6574 \",(0,n.jsx)(e.code,{children:\"left\"}),\" \\u6307\\u9488\\u65F6\\uFF0C\\u6BCF\\u4E2A\\u91CD\\u590D\\u5B57\\u7B26\\u90FD\\u4F1A\\u88AB\\u5904\\u7406\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\",(0,n.jsx)(e.code,{children:\"map\"}),\" \\u5B58\\u50A8\\u5B57\\u7B26\\u7684\\u6700\\u540E\\u4E00\\u6B21\\u51FA\\u73B0\\u4F4D\\u7F6E\\uFF0C\\u8FD9\\u53EF\\u80FD\\u9700\\u8981\\u4E0E\\u8F93\\u5165\\u5B57\\u7B26\\u4E32\\u5927\\u5C0F\\u6210\\u6BD4\\u4F8B\\u7684\\u7A7A\\u95F4\\u3002\"]}),`\n`]})]})}function L(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(u,t)})):u(t)}var I=L;return w(k);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/longest-palindromic-substring/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/longest-palindromic-substring/locales/zh-CN.json new file mode 100644 index 000000000..3584d7107 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/longest-palindromic-substring/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var i=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var f=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),z=(t,e)=>{for(var r in e)i(t,r,{get:e[r],enumerable:!0})},a=(t,e,r,s)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let c of g(e))!b.call(t,c)&&c!==r&&i(t,c,{get:()=>e[c],enumerable:!(s=m(e,c))||s.enumerable});return t};var j=(t,e,r)=>(r=t!=null?p(x(t)):{},a(e||!t||!t.__esModule?i(r,\"default\",{value:t,enumerable:!0}):r,t)),_=t=>a(i({},\"__esModule\",{value:!0}),t);var d=f((E,o)=>{o.exports=_jsx_runtime});var X={};z(X,{default:()=>T,frontmatter:()=>C});var n=j(d());var l=MDXTestExamples;var h=[{input:[[\"str\",\"cauumzssz\"]],output:\"zssz\",explanation:\"'zssz' is the longest palindromic substring within 'cauumzssz'.\"},{input:[[\"str\",\"racecar\"]],output:\"racecar\",explanation:\"The entire string 'racecar' is a palindrome and is the longest.\"},{input:[[\"str\",\"cacae\"]],output:\"cac\",explanation:\"Both 'cac' and 'aca' are valid palindromic substrings of the same length, and either can be returned.\"}];var C={title:\"\\u67E5\\u627E\\u6700\\u957F\\u56DE\\u6587\\u5B50\\u4E32\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u67E5\\u627E\\u6700\\u957F\\u56DE\\u6587\\u5B50\\u4E32\"};function u(t){let e=Object.assign({p:\"p\",code:\"code\",strong:\"strong\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u5B57\\u7B26\\u4E32\",(0,n.jsx)(e.code,{children:\"str\"}),\"\\uFF0C\\u8FD4\\u56DE\\u6700\\u957F\\u7684\\u8FDE\\u7EED\\u56DE\\u6587\\u5B50\\u4E32\\u3002\\u5982\\u679C\\u6709\\u591A\\u4E2A\\u8FD9\\u6837\\u7684\\u5B50\\u4E32\\uFF0C\\u5219\\u8FD4\\u56DE\\u5176\\u4E2D\\u4EFB\\u4F55\\u4E00\\u4E2A\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A\",(0,n.jsx)(e.strong,{children:\"\\u56DE\\u6587\"}),\"\\u662F\\u6307\\u4ECE\\u524D\\u5F80\\u540E\\u548C\\u4ECE\\u540E\\u5F80\\u524D\\u8BFB\\u90FD\\u4E00\\u6837\\u7684\\u5B57\\u7B26\\u5E8F\\u5217\\uFF08\\u4F8B\\u5982\\uFF0C\",(0,n.jsx)(e.code,{children:\"racecar\"}),\"\\uFF09\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A\",(0,n.jsx)(e.strong,{children:\"\\u5B50\\u4E32\"}),\"\\u662F\\u5B57\\u7B26\\u4E32\\u4E2D\\u4EFB\\u610F\\u8FDE\\u7EED\\u7684\\u5B57\\u7B26\\u5E8F\\u5217\\u3002\\u4F8B\\u5982\\uFF0C\\u5B57\\u7B26\\u4E32\",(0,n.jsx)(e.code,{children:\"abc\"}),\"\\u7684\\u5B50\\u4E32\\u662F\",(0,n.jsx)(e.code,{children:\"a\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"b\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"c\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"ab\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"bc\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"abc\"}),\"\\u3002\\u5B50\\u4E32\\u662F\\u901A\\u8FC7\\u9009\\u62E9\\u4E00\\u4E2A\\u8D77\\u59CB\\u70B9\\u548C\\u4E00\\u4E2A\\u7ED3\\u675F\\u70B9\\uFF0C\\u5E76\\u4E14\\u4E0D\\u8DF3\\u8FC7\\u4E2D\\u95F4\\u7684\\u5B57\\u7B26\\u800C\\u5F62\\u6210\\u7684\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"str: string\"}),\": \\u5B57\\u7B26\\u4E32\"]}),`\n`]}),`\n`,(0,n.jsx)(l,{testCases:h}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"str.length\"}),\" <= 1000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"str\"}),\" \\u4EC5\\u5305\\u542B\\u5C0F\\u5199\\u82F1\\u6587\\u5B57\\u6BCD\"]}),`\n`]})]})}function D(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(u,t)})):u(t)}var T=D;return _(X);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来查找最长回文子串", + "title": "查找最长回文子串" + }, + "solution": "var Component=(()=>{var p=Object.create;var l=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var v=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),O=(i,e)=>{for(var r in e)l(i,r,{get:e[r],enumerable:!0})},h=(i,e,r,c)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let t of b(e))!x.call(i,t)&&t!==r&&l(i,t,{get:()=>e[t],enumerable:!(c=m(e,t))||c.enumerable});return i};var w=(i,e,r)=>(r=i!=null?p(j(i)):{},h(e||!i||!i.__esModule?l(r,\"default\",{value:i,enumerable:!0}):r,i)),y=i=>h(l({},\"__esModule\",{value:!0}),i);var s=v((M,o)=>{o.exports=_jsx_runtime});var S={};O(S,{default:()=>I});var n=w(s());var d=MDXCodeBlock;var a=`export default function longestPalindromeSubstring(str: string): string {\n const n = str.length;\n\n // Initialize a 2D array \\`dp\\` where dp[i][j] will be true if the substring s[i..j] is a palindrome\n const dp: boolean[][] = Array.from(Array(n), () => Array(n).fill(false));\n\n // \\`ans\\` will store the starting and ending indices of the longest palindromic substring found\n let ans = [0, 0];\n\n // Every single character is a palindrome, so set dp[i][i] to true for all i\n for (let i = 0; i < n; i++) {\n dp[i][i] = true;\n }\n\n // Check for palindromes of length 2 (i.e., pairs of consecutive characters)\n for (let i = 0; i < n - 1; i++) {\n if (str[i] === str[i + 1]) {\n dp[i][i + 1] = true;\n ans = [i, i + 1]; // Update the longest palindrome indices\n }\n }\n\n // Check for palindromes of length 3 and greater\n for (let diff = 2; diff < n; diff++) {\n for (let i = 0; i < n - diff; i++) {\n let j = i + diff;\n // If the characters at the start and end of the substring are equal\n // and the substring s[i+1..j-1] is a palindrome, then s[i..j] is a palindrome\n if (str[i] === str[j] && dp[i + 1][j - 1]) {\n dp[i][j] = true;\n ans = [i, j]; // Update the longest palindrome indices\n }\n }\n }\n\n // Extract the longest palindromic substring from the string using the indices stored in \\`ans\\`\n const i = ans[0];\n const j = ans[1];\n return str.slice(i, j + 1);\n}\n`;var g=`export default function longestPalindromeSubstring(str: string): string {\n // Helper function to check if the substring s[i:j] is a palindrome\n const check = (i: number, j: number) => {\n let left = i; // Start pointer\n let right = j - 1; // End pointer (one less because j is exclusive)\n\n // Check characters from both ends moving towards the center\n while (left < right) {\n // If the characters at the current pointers don't match, it's not a palindrome\n if (str.charAt(left) !== str.charAt(right)) {\n return false;\n }\n\n // Move pointers closer to the center\n left++;\n right--;\n }\n\n // If all characters matched, it's a palindrome\n return true;\n };\n\n // Iterate over possible lengths of the substring, starting from the longest\n for (let length = str.length; length > 0; length--) {\n // For each length, iterate over all possible starting points of the substring\n for (let start = 0; start <= str.length - length; start++) {\n // If the substring s[start:start+length] is a palindrome, return it\n if (check(start, start + length)) {\n return str.substring(start, start + length);\n }\n }\n }\n\n // If no palindrome is found (though technically it shouldn't happen), return an empty string\n return '';\n}\n`;var u=`export default function longestPalindromeSubstring(str: string): string {\n // Helper function to expand around a center and find the longest palindromic substring\n function expand(i: number, j: number): string {\n let left: number = i; // Start pointer for the left side of the potential palindrome\n let right: number = j; // Start pointer for the right side of the potential palindrome\n\n // Expand outwards while the characters on both sides are equal\n // and the pointers are within bounds of the string\n while (left >= 0 && right < str.length && str[left] === str[right]) {\n left--; // Move left pointer to the left\n right++; // Move right pointer to the right\n }\n\n // Return the substring that is the palindrome found\n // Note: left + 1 and right are used to get the correct bounds of the palindrome\n return str.slice(left + 1, right);\n }\n\n let ans: string = ''; // Initialize the variable to store the longest palindromic substring\n\n // Iterate through each character in the string as potential centers of palindromes\n for (let i = 0; i < str.length; i++) {\n // Find the longest odd-length palindrome with center at \\`i\\`\n let odd: string = expand(i, i);\n // Update the result if the found palindrome is longer than the previous longest\n if (odd.length > ans.length) {\n ans = odd;\n }\n\n // Find the longest even-length palindrome with centers at \\`i\\` and \\`i + 1\\`\n let even: string = expand(i, i + 1);\n // Update the result if the found palindrome is longer than the previous longest\n if (even.length > ans.length) {\n ans = even;\n }\n }\n\n // Return the longest palindromic substring found\n return ans;\n}\n`;function f(i){let e=Object.assign({h2:\"h2\",p:\"p\",h3:\"h3\",ol:\"ol\",li:\"li\",code:\"code\",ul:\"ul\",strong:\"strong\"},i.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. BruteForce\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u95EE\\u9898\\u9700\\u8981\\u627E\\u5230\\u7ED9\\u5B9A\\u5B57\\u7B26\\u4E32\\u4E2D\\u6700\\u957F\\u7684\\u56DE\\u6587\\u5B50\\u4E32\\u3002\\u66B4\\u529B\\u65B9\\u6CD5\\u7CFB\\u7EDF\\u5730\\u68C0\\u67E5\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u5B50\\u4E32\\uFF0C\\u5E76\\u68C0\\u67E5\\u6BCF\\u4E2A\\u5B50\\u4E32\\u662F\\u5426\\u4E3A\\u56DE\\u6587\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\\u7B97\\u6CD5\\u6B63\\u786E\\u5730\\u8BC6\\u522B\\u56DE\\u6587\\u5E76\\u8FD4\\u56DE\\u6700\\u957F\\u7684\\u56DE\\u6587\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"Algorithm\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u8F85\\u52A9\\u51FD\\u6570 \",(0,n.jsx)(e.code,{children:\"check(i, j)\"}),\" \\u6765\\u786E\\u5B9A\\u4ECE\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"i\"}),\" \\u5230 \",(0,n.jsx)(e.code,{children:\"j-1\"}),\" \\u7684\\u5B50\\u4E32\\u662F\\u5426\\u4E3A\\u56DE\\u6587\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E24\\u4E2A\\u6307\\u9488\\uFF0C\",(0,n.jsx)(e.code,{children:\"left\"}),\" \\u5728 \",(0,n.jsx)(e.code,{children:\"i\"}),\"\\uFF0C\",(0,n.jsx)(e.code,{children:\"right\"}),\" \\u5728 \",(0,n.jsx)(e.code,{children:\"j-1\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u6BD4\\u8F83 \",(0,n.jsx)(e.code,{children:\"left\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"right\"}),\" \\u5904\\u7684\\u5B57\\u7B26\\uFF0C\\u540C\\u65F6\\u5C06\\u6307\\u9488\\u5411\\u4E2D\\u5FC3\\u79FB\\u52A8\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u4EFB\\u4F55\\u4E00\\u5BF9\\u5B57\\u7B26\\u4E0D\\u5339\\u914D\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\uFF1B\\u5426\\u5219\\uFF0C\\u5982\\u679C\\u6307\\u9488\\u76F8\\u9047\\u6216\\u4EA4\\u53C9\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u6309\\u7167\\u964D\\u5E8F\\u904D\\u5386\\u5B50\\u4E32\\u7684\\u53EF\\u80FD\\u957F\\u5EA6\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u5B57\\u7B26\\u4E32\\u7684\\u6700\\u5927\\u53EF\\u80FD\\u957F\\u5EA6\\u5F00\\u59CB\\uFF0C\\u5C06\\u957F\\u5EA6\\u51CF\\u5C11\\u5230 \",(0,n.jsx)(e.code,{children:\"1\"}),\"\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u957F\\u5EA6\\uFF0C\\u904D\\u5386\\u5B50\\u4E32\\u7684\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u8D77\\u59CB\\u7D22\\u5F15\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u5B50\\u4E32\\uFF0C\\u8C03\\u7528\\u8F85\\u52A9\\u51FD\\u6570 \",(0,n.jsx)(e.code,{children:\"check\"}),\" \\u6765\\u786E\\u5B9A\\u5B83\\u662F\\u5426\\u4E3A\\u56DE\\u6587\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u5B50\\u4E32\\u662F\\u56DE\\u6587\\uFF0C\\u5219\\u7ACB\\u5373\\u8FD4\\u56DE\\u5B83\\u4F5C\\u4E3A\\u6700\\u957F\\u7684\\u56DE\\u6587\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u672A\\u627E\\u5230\\u56DE\\u6587\\uFF0C\\u5219\\u8FD4\\u56DE\\u4E00\\u4E2A\\u7A7A\\u5B57\\u7B26\\u4E32\\uFF08\\u8FD9\\u79CD\\u60C5\\u51B5\\u4E0D\\u4F1A\\u5728\\u6709\\u6548\\u8F93\\u5165\\u4E2D\\u53D1\\u751F\\uFF09\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(d,{children:g}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O analysis\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,n.jsx)(\"sup\",{children:\"3\"}),\")\"]}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u4F7F\\u7528\\u4E24\\u4E2A\\u5D4C\\u5957\\u5FAA\\u73AF\\u68C0\\u67E5\\u6240\\u6709\\u5B50\\u4E32\\uFF0C\\u5E76\\u4E14\\u56DE\\u6587\\u68C0\\u67E5\\u9700\\u8981 O(n) \\u65F6\\u95F4\\u7528\\u4E8E\\u6BCF\\u4E2A\\u5B50\\u4E32\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u65E0\\u8BBA\\u8F93\\u5165\\u5927\\u5C0F\\u5982\\u4F55\\uFF0C\\u8BE5\\u7B97\\u6CD5\\u90FD\\u4F7F\\u7528\\u6052\\u5B9A\\u91CF\\u7684\\u989D\\u5916\\u7A7A\\u95F4\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. Using Dynamic Programming\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u52A8\\u6001\\u89C4\\u5212 (DP) \\u65B9\\u6CD5\\u901A\\u8FC7\\u51CF\\u5C11\\u5197\\u4F59\\u68C0\\u67E5\\u6765\\u4F18\\u5316\\u66B4\\u529B\\u65B9\\u6CD5\\u3002DP \\u65B9\\u6CD5\\u4E0D\\u662F\\u91CD\\u65B0\\u8BC4\\u4F30\\u91CD\\u53E0\\u7684\\u5B50\\u4E32\\uFF0C\\u800C\\u662F\\u5C06\\u4E2D\\u95F4\\u7ED3\\u679C\\u5B58\\u50A8\\u5728\\u8868 \",(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u4E2D\\uFF0C\\u5176\\u4E2D \",(0,n.jsx)(e.code,{children:\"dp[i][j]\"}),\" \\u5728\\u5B50\\u4E32 \",(0,n.jsx)(e.code,{children:\"s[i..j]\"}),\" \\u662F\\u56DE\\u6587\\u65F6\\u4E3A \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u52A8\\u6001\\u89C4\\u5212\\u65B9\\u6CD5\\u901A\\u8FC7\\u8003\\u8651\\u9012\\u589E\\u957F\\u5EA6\\u7684\\u5B50\\u4E32\\u6765\\u8FED\\u4EE3\\u5730\\u6784\\u5EFA\\u89E3\\u51B3\\u65B9\\u6848\\u3002\\u5B83\\u9996\\u5148\\u5C06\\u5355\\u4E2A\\u5B57\\u7B26\\u6807\\u8BB0\\u4E3A\\u56DE\\u6587\\uFF0C\\u7136\\u540E\\u68C0\\u67E5\\u8FDE\\u7EED\\u7684\\u5B57\\u7B26\\u5BF9\\uFF0C\\u6700\\u540E\\u8BC4\\u4F30\\u957F\\u5EA6\\u4E3A 3 \\u6216\\u66F4\\u957F\\u7684\\u5B50\\u4E32\\u3002DP \\u8868\\u901A\\u8FC7\\u786E\\u4FDD\\u5728\\u8BC4\\u4F30\\u66F4\\u5927\\u7684\\u5B50\\u4E32\\u65F6\\u91CD\\u7528\\u8F83\\u5C0F\\u5B50\\u4E32\\u7684\\u7ED3\\u679C\\uFF0C\\u4ECE\\u800C\\u6D88\\u9664\\u4E86\\u91CD\\u590D\\u8BA1\\u7B97\\u7684\\u9700\\u8981\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"Algorithm\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u5927\\u5C0F\\u4E3A \",(0,n.jsx)(e.code,{children:\"n x n\"}),\" \\u7684\\u4E8C\\u7EF4\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"dp\"}),\"\\uFF0C\\u5176\\u4E2D \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u662F\\u5B57\\u7B26\\u4E32\\u7684\\u957F\\u5EA6\\u3002\\u5C06\\u6240\\u6709\\u503C\\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u8BBE\\u7F6E \",(0,n.jsx)(e.code,{children:\"dp[i][i] = true\"}),\"\\uFF08\\u5BF9\\u4E8E\\u6240\\u6709 \",(0,n.jsx)(e.code,{children:\"i\"}),\"\\uFF09\\u5C06\\u6240\\u6709\\u5355\\u5B57\\u7B26\\u5B50\\u4E32\\u6807\\u8BB0\\u4E3A\\u56DE\\u6587\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u53CC\\u5B57\\u7B26\\u5B50\\u4E32\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"i\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"i + 1\"}),\"\\uFF0C\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"str[i] === str[i + 1]\"}),\"\\uFF0C\\u5219\\u8BBE\\u7F6E \",(0,n.jsx)(e.code,{children:\"dp[i][i + 1] = true\"}),\" \\u5E76\\u66F4\\u65B0\\u6700\\u957F\\u56DE\\u6587\\u7684\\u7D22\\u5F15\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FED\\u4EE3\\u4ECE 3 \\u5F00\\u59CB\\u7684\\u5B50\\u4E32\\u7684\\u53EF\\u80FD\\u957F\\u5EA6\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u957F\\u5EA6\\uFF0C\\u8FED\\u4EE3\\u53EF\\u80FD\\u7684\\u8D77\\u59CB\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"i\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8BA1\\u7B97\\u7ED3\\u675F\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"j = i + length - 1\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"str[i] === str[j]\"}),\" \\u4E14 \",(0,n.jsx)(e.code,{children:\"dp[i + 1][j - 1]\"}),\" \\u4E3A \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\uFF0C\\u5219\\u8BBE\\u7F6E \",(0,n.jsx)(e.code,{children:\"dp[i][j] = true\"}),\" \\u5E76\\u66F4\\u65B0\\u6700\\u957F\\u56DE\\u6587\\u7684\\u7D22\\u5F15\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u5B58\\u50A8\\u5728\\u53D8\\u91CF \",(0,n.jsx)(e.code,{children:\"ans\"}),\" \\u4E2D\\u7684\\u6700\\u957F\\u56DE\\u6587\\u7684\\u7D22\\u5F15\\u63D0\\u53D6\\u5B50\\u4E32\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8FD4\\u56DE\\u63D0\\u53D6\\u7684\\u5B50\\u4E32\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(d,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O analysis\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,n.jsx)(\"sup\",{children:\"2\"}),\")\"]}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u904D\\u5386\\u5B57\\u7B26\\u4E32\\u7684\\u6240\\u6709\\u5B50\\u4E32\\uFF0C\\u5E76\\u4E14\\u7531\\u4E8E\\u4F7F\\u7528\\u4E86 DP \\u8868\\uFF0C\\u6BCF\\u4E2A\\u5B50\\u4E32\\u8BC4\\u4F30\\u90FD\\u9700\\u8981\\u6052\\u5B9A\\u7684\\u65F6\\u95F4\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,n.jsx)(\"sup\",{children:\"2\"}),\")\"]}),\"\\u3002DP \\u8868\\u9700\\u8981\\u7684\\u5B58\\u50A8\\u7A7A\\u95F4\\u4E0E\\u5B57\\u7B26\\u4E32\\u957F\\u5EA6\\u7684\\u5E73\\u65B9\\u6210\\u6B63\\u6BD4\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"3. Expanding from Centers\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u4E2D\\u5FC3\\u6269\\u5C55\\u65B9\\u6CD5\\u662F\\u4E00\\u79CD\\u6709\\u6548\\u7684\\u89E3\\u51B3\\u65B9\\u6848\\uFF0C\\u5B83\\u907F\\u514D\\u4E86\\u6784\\u9020\\u52A8\\u6001\\u89C4\\u5212\\u8868\\u6216\\u68C0\\u67E5\\u6240\\u6709\\u5B50\\u4E32\\u3002\\u5173\\u952E\\u601D\\u60F3\\u662F\\u5C06\\u6BCF\\u4E2A\\u5B57\\u7B26\\uFF08\\u6216\\u5B57\\u7B26\\u5BF9\\uFF09\\u89C6\\u4E3A\\u6F5C\\u5728\\u56DE\\u6587\\u7684\\u4E2D\\u5FC3\\uFF0C\\u5E76\\u5411\\u5916\\u6269\\u5C55\\u4EE5\\u627E\\u5230\\u8BE5\\u4E2D\\u5FC3\\u5468\\u56F4\\u6700\\u5927\\u7684\\u56DE\\u6587\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u6B64\\u65B9\\u6CD5\\u901A\\u8FC7\\u4F7F\\u7528\\u56DE\\u6587\\u7684\\u5C5E\\u6027\\u6765\\u907F\\u514D\\u4E0D\\u5FC5\\u8981\\u7684\\u5DE5\\u4F5C\\uFF0C\\u56DE\\u6587\\u56F4\\u7ED5\\u4E2D\\u5FC3\\u5BF9\\u79F0\\u6269\\u5C55\\u3002\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u5B57\\u7B26\\uFF08\\u6216\\u5076\\u6570\\u957F\\u5EA6\\u56DE\\u6587\\u7684\\u5B57\\u7B26\\u5BF9\\uFF09\\uFF0C\\u7B97\\u6CD5\\u5411\\u5916\\u6269\\u5C55\\uFF0C\\u76F4\\u5230\\u51FA\\u73B0\\u4E0D\\u5339\\u914D\\u3002\\u8FD9\\u79CD\\u65B9\\u6CD5\\u51CF\\u5C11\\u4E86\\u5197\\u4F59\\u68C0\\u67E5\\uFF0C\\u5E76\\u6D88\\u9664\\u4E86\\u5B58\\u50A8\\u4E2D\\u95F4\\u7ED3\\u679C\\u7684\\u9700\\u8981\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"Algorithm\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u8F85\\u52A9\\u51FD\\u6570 \",(0,n.jsx)(e.code,{children:\"expand(i, j)\"}),\"\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E24\\u4E2A\\u6307\\u9488\\uFF0C\",(0,n.jsx)(e.code,{children:\"left\"}),\" \\u5728 \",(0,n.jsx)(e.code,{children:\"i\"}),\"\\uFF0C\",(0,n.jsx)(e.code,{children:\"right\"}),\" \\u5728 \",(0,n.jsx)(e.code,{children:\"j\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5F53 \",(0,n.jsx)(e.code,{children:\"left\"}),\" \\u4E3A\\u975E\\u8D1F\\u6570\\u3001\",(0,n.jsx)(e.code,{children:\"right\"}),\" \\u5728\\u8303\\u56F4\\u5185\\u4E14 \",(0,n.jsx)(e.code,{children:\"left\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"right\"}),\" \\u5904\\u7684\\u5B57\\u7B26\\u76F8\\u7B49\\u65F6\\uFF0C\\u5411\\u5916\\u6269\\u5C55\\u6307\\u9488\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE\\u7531 \",(0,n.jsx)(e.code,{children:\"left + 1\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"right\"}),\" \\u7EC4\\u6210\\u7684\\u5B50\\u4E32\\u4F5C\\u4E3A\\u56DE\\u6587\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u53D8\\u91CF \",(0,n.jsx)(e.code,{children:\"ans\"}),\" \\u4EE5\\u5B58\\u50A8\\u627E\\u5230\\u7684\\u6700\\u957F\\u56DE\\u6587\\u5B50\\u4E32\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u5B57\\u7B26\\u4E32\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5B57\\u7B26\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"i\"}),\" \\u5904\\u7684\\u5B57\\u7B26\\u89C6\\u4E3A\\u5947\\u6570\\u957F\\u5EA6\\u56DE\\u6587\\u7684\\u4E2D\\u5FC3\\u3002\\u8C03\\u7528 \",(0,n.jsx)(e.code,{children:\"expand(i, i)\"}),\" \\u5E76\\u5728\\u8FD4\\u56DE\\u7684\\u56DE\\u6587\\u6BD4 \",(0,n.jsx)(e.code,{children:\"ans\"}),\" \\u7684\\u5F53\\u524D\\u503C\\u957F\\u65F6\\u66F4\\u65B0 \",(0,n.jsx)(e.code,{children:\"ans\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"i\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"i + 1\"}),\" \\u5904\\u7684\\u5B57\\u7B26\\u89C6\\u4E3A\\u5076\\u6570\\u957F\\u5EA6\\u56DE\\u6587\\u7684\\u4E2D\\u5FC3\\u3002\\u8C03\\u7528 \",(0,n.jsx)(e.code,{children:\"expand(i, i + 1)\"}),\" \\u5E76\\u5728\\u8FD4\\u56DE\\u7684\\u56DE\\u6587\\u6BD4 \",(0,n.jsx)(e.code,{children:\"ans\"}),\" \\u7684\\u5F53\\u524D\\u503C\\u957F\\u65F6\\u66F4\\u65B0 \",(0,n.jsx)(e.code,{children:\"ans\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5904\\u7406\\u5B8C\\u6240\\u6709\\u5B57\\u7B26\\u540E\\uFF0C\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"ans\"}),\" \\u7684\\u503C\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(d,{children:u}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O analysis\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,n.jsx)(\"sup\",{children:\"2\"}),\")\"]}),\"\\u3002\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u5B57\\u7B26\\uFF0C\\u6269\\u5C55\\u5728\\u6700\\u574F\\u60C5\\u51B5\\u4E0B\\u53EF\\u80FD\\u4EE5 O(n) \\u8FD0\\u884C\\uFF0C\\u4ECE\\u800C\\u5BFC\\u81F4\\u603B\\u5171 O(n\",(0,n.jsx)(\"sup\",{children:\"2\"}),\")\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u4F7F\\u7528\\u6052\\u5B9A\\u7684\\u989D\\u5916\\u7A7A\\u95F4\\uFF0C\\u4E0D\\u5305\\u62EC\\u8F93\\u51FA\\u6240\\u9700\\u7684\\u7A7A\\u95F4\\u3002\"]}),`\n`]})]})}function C(i={}){let{wrapper:e}=i.components||{};return e?(0,n.jsx)(e,Object.assign({},i,{children:(0,n.jsx)(f,i)})):f(i)}var I=C;return y(S);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/longest-repeating-substring-after-replacements/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/longest-repeating-substring-after-replacements/locales/zh-CN.json new file mode 100644 index 000000000..539ce7990 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/longest-repeating-substring-after-replacements/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var m=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var A=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var f=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),b=(t,e)=>{for(var r in e)i(t,r,{get:e[r],enumerable:!0})},s=(t,e,r,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let c of g(e))!x.call(t,c)&&c!==r&&i(t,c,{get:()=>e[c],enumerable:!(o=p(e,c))||o.enumerable});return t};var j=(t,e,r)=>(r=t!=null?m(A(t)):{},s(e||!t||!t.__esModule?i(r,\"default\",{value:t,enumerable:!0}):r,t)),k=t=>s(i({},\"__esModule\",{value:!0}),t);var d=f((w,l)=>{l.exports=_jsx_runtime});var y={};b(y,{default:()=>M,frontmatter:()=>C});var n=j(d());var a=MDXTestExamples;var h=[{input:[[\"str\",\"ABCDE\"],[\"k\",2]],output:3,explanation:\"Modify any two characters to match each other, resulting in a maximum length of 3. For instance, change 'B' and 'C' to 'A', transforming the string into 'AAADE'.\"},{input:[[\"str\",\"AAAA\"],[\"k\",3]],output:4,explanation:\"All characters are already the same, so no changes needed, and the entire string forms the longest substring.\"},{input:[[\"str\",\"AABAA\"],[\"k\",2]],output:5,explanation:\"By replacing 'B' with 'A', the string becomes 'AAAAA', which is the longest substring of identical characters.\"}];var C={title:\"\\u66FF\\u6362\\u540E\\u6700\\u957F\\u91CD\\u590D\\u5B50\\u4E32\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u5728\\u6700\\u591A\\u8FDB\\u884C k \\u6B21\\u66FF\\u6362\\u540E\\uFF0C\\u627E\\u5230\\u6700\\u957F\\u7684\\u7EDF\\u4E00\\u5B50\\u4E32\"};function u(t){let e=Object.assign({p:\"p\",code:\"code\",strong:\"strong\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u7531\\u5927\\u5199\\u82F1\\u6587\\u5B57\\u6BCD\\u7EC4\\u6210\\u7684\\u5B57\\u7B26\\u4E32 \",(0,n.jsx)(e.code,{children:\"str\"}),\" \\u548C\\u4E00\\u4E2A\\u6574\\u6570 \",(0,n.jsx)(e.code,{children:\"k\"}),\"\\uFF0C\\u786E\\u5B9A\\u53EF\\u4EE5\\u5F62\\u6210\\u7684\\u6700\\u957F\\u5B50\\u4E32\\u7684\\u957F\\u5EA6\\uFF0C\\u5176\\u4E2D\\u6240\\u6709\\u5B57\\u7B26\\u90FD\\u76F8\\u540C\\u3002\\u4E3A\\u4E86\\u5B9E\\u73B0\\u8FD9\\u4E00\\u70B9\\uFF0C\\u6700\\u591A\\u53EF\\u4EE5\\u8FDB\\u884C \",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u6B21\\u5B57\\u7B26\\u66FF\\u6362\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A\",(0,n.jsx)(e.strong,{children:\"\\u5B50\\u4E32\"}),\"\\u662F\\u5B57\\u7B26\\u4E32\\u4E2D\\u4EFB\\u4F55\\u8FDE\\u7EED\\u7684\\u5B57\\u7B26\\u5E8F\\u5217\\u3002\\u4F8B\\u5982\\uFF0C\\u5B57\\u7B26\\u4E32 \",(0,n.jsx)(e.code,{children:\"abc\"}),\" \\u7684\\u5B50\\u4E32\\u662F \",(0,n.jsx)(e.code,{children:\"a\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"b\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"c\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"ab\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"bc\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"abc\"}),\"\\u3002\\u5B50\\u4E32\\u662F\\u901A\\u8FC7\\u9009\\u62E9\\u4E00\\u4E2A\\u8D77\\u59CB\\u70B9\\u548C\\u7ED3\\u675F\\u70B9\\u5F62\\u6210\\u7684\\uFF0C\\u4E2D\\u95F4\\u6CA1\\u6709\\u8DF3\\u8FC7\\u5B57\\u7B26\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"str: string\"}),\": \\u5B57\\u7B26\\u4E32\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"k\"}),\": \\u4E00\\u4E2A\\u6574\\u6570\"]}),`\n`]}),`\n`,(0,n.jsx)(a,{testCases:h}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"str.length\"}),\" <= 10,000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"str\"}),\" \\u4EC5\\u5305\\u542B\\u5927\\u5199\\u82F1\\u6587\\u5B57\\u6BCD\"]}),`\n`]})]})}function D(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(u,t)})):u(t)}var M=D;return k(y);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,在最多进行 k 次替换后,找到最长的统一子串", + "title": "替换后最长重复子串" + }, + "solution": "var Component=(()=>{var f=Object.create;var c=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var q=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),y=(r,e)=>{for(var t in e)c(r,t,{get:e[t],enumerable:!0})},h=(r,e,t,d)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of p(e))!w.call(r,i)&&i!==t&&c(r,i,{get:()=>e[i],enumerable:!(d=m(e,i))||d.enumerable});return r};var x=(r,e,t)=>(t=r!=null?f(b(r)):{},h(e||!r||!r.__esModule?c(t,\"default\",{value:r,enumerable:!0}):t,r)),k=r=>h(c({},\"__esModule\",{value:!0}),r);var a=q((L,o)=>{o.exports=_jsx_runtime});var F={};y(F,{default:()=>A});var n=x(a());var l=MDXCodeBlock;var s=`export default function longestSubstringReplacement(\n str: string,\n k: number,\n): number {\n let start = 0;\n const frequencyMap: number[] = new Array(26).fill(0);\n let maxFrequency = 0;\n let longestSubstringLength = 0;\n\n for (let end = 0; end < str.length; end++) {\n // Calculate the relative order of the current character entering the window\n const currentChar = str.charCodeAt(end) - 'A'.charCodeAt(0);\n\n // Increment the frequency of the current character\n frequencyMap[currentChar] += 1;\n\n // Update the maximum frequency we've seen in any window\n maxFrequency = Math.max(maxFrequency, frequencyMap[currentChar]);\n\n // If the window is invalid, move the start pointer to the right\n const isValid = end + 1 - start - maxFrequency <= k;\n if (!isValid) {\n const outgoingChar = str.charCodeAt(start) - 'A'.charCodeAt(0);\n\n // Decrease the frequency of the outgoing character\n frequencyMap[outgoingChar] -= 1;\n\n // Move the start pointer forward\n start += 1;\n }\n\n // The window is valid at this point, update the length of the longest valid substring\n longestSubstringLength = end + 1 - start;\n }\n\n return longestSubstringLength;\n}\n`;var u=`export default function longestSubstringReplacement(\n str: string,\n k: number,\n): number {\n // Binary search over the length of the substring\n // \\`low\\` holds the valid value, and \\`high\\` holds the invalid value\n let low = 1;\n let high = str.length + 1;\n\n while (low + 1 < high) {\n const mid = low + Math.floor((high - low) / 2);\n\n // Check if we can make a valid substring of length \\`mid\\`\n if (canMakeValidSubstring(str, mid, k)) {\n // Explore the right half\n low = mid;\n } else {\n // Explore the left half\n high = mid;\n }\n }\n\n // Return the length of the longest substring that satisfies the condition\n return low;\n}\n\n// Helper function to check if a valid substring of a given length can be made\nfunction canMakeValidSubstring(\n str: string,\n substringLength: number,\n k: number,\n): boolean {\n // Frequency map to store the frequency of characters in the current window\n const freqMap: number[] = new Array(26).fill(0);\n let maxFrequency = 0;\n let start = 0;\n\n for (let end = 0; end < str.length; end++) {\n // Update the frequency of the current character\n freqMap[str.charCodeAt(end) - 'A'.charCodeAt(0)] += 1;\n\n // If the window [start, end] exceeds \\`substringLength\\`, move the start pointer\n if (end + 1 - start > substringLength) {\n // Decrease the frequency of the character at the start before moving the pointer\n freqMap[str.charCodeAt(start) - 'A'.charCodeAt(0)] -= 1;\n start += 1;\n }\n\n // Record the maximum frequency seen so far\n maxFrequency = Math.max(\n maxFrequency,\n freqMap[str.charCodeAt(end) - 'A'.charCodeAt(0)],\n );\n\n // Check if the current window can be made valid with at most \\`k\\` replacements\n if (substringLength - maxFrequency <= k) {\n return true;\n }\n }\n\n // If no valid substring of the given size was found\n return false;\n}\n`;function g(r){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u6ED1\\u52A8\\u7A97\\u53E3\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8BE5\\u4EFB\\u52A1\\u662F\\u627E\\u5230\\u5728\\u7ED9\\u5B9A\\u5B57\\u7B26\\u4E32\\u4E2D\\u66FF\\u6362\\u6700\\u591A \",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u4E2A\\u5B57\\u7B26\\u540E\\u5177\\u6709\\u76F8\\u540C\\u5B57\\u7B26\\u7684\\u6700\\u957F\\u5B50\\u5B57\\u7B26\\u4E32\\u7684\\u957F\\u5EA6\\u3002 \\u4F7F\\u7528\\u6ED1\\u52A8\\u7A97\\u53E3\\u65B9\\u6CD5\\u52A8\\u6001\\u7BA1\\u7406\\u6709\\u6548\\u5B50\\u5B57\\u7B26\\u4E32\\u7684\\u7A97\\u53E3\\u3002 \\u89E3\\u51B3\\u65B9\\u6848\\u4FA7\\u91CD\\u4E8E\\u4FDD\\u6301\\u5F53\\u524D\\u7A97\\u53E3\\u4E2D\\u4EFB\\u4F55\\u5B57\\u7B26\\u7684\\u6700\\u5927\\u9891\\u7387\\u4E0E\\u5141\\u8BB8\\u7684\\u66FF\\u6362\\u6B21\\u6570 (\",(0,n.jsx)(e.code,{children:\"k\"}),\") \\u4E4B\\u95F4\\u7684\\u5E73\\u8861\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u6ED1\\u52A8\\u7A97\\u53E3\\u4E0D\\u662F\\u68C0\\u67E5\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u5B50\\u5B57\\u7B26\\u4E32\\uFF0C\\u800C\\u662F\\u52A8\\u6001\\u8C03\\u6574\\u7A97\\u53E3\\u5927\\u5C0F\\u4EE5\\u786E\\u4FDD\\u6709\\u6548\\u6027\\u3002 \\u9891\\u7387\\u6620\\u5C04\\u8DDF\\u8E2A\\u5F53\\u524D\\u7A97\\u53E3\\u5185\\u6BCF\\u4E2A\\u5B57\\u7B26\\u7684\\u51FA\\u73B0\\u6B21\\u6570\\uFF0C\",(0,n.jsx)(e.code,{children:\"maxFrequency\"}),\" \\u53D8\\u91CF\\u6709\\u52A9\\u4E8E\\u786E\\u5B9A\\u4F7F\\u7A97\\u53E3\\u4E2D\\u6240\\u6709\\u5B57\\u7B26\\u76F8\\u540C\\u7684\\u6240\\u9700\\u6700\\u5C11\\u66FF\\u6362\\u6B21\\u6570\\u3002 \\u5982\\u679C\\u66FF\\u6362\\u6B21\\u6570\\u8D85\\u8FC7 \",(0,n.jsx)(e.code,{children:\"k\"}),\"\\uFF0C\\u5219\\u901A\\u8FC7\\u79FB\\u52A8 \",(0,n.jsx)(e.code,{children:\"start\"}),\" \\u6307\\u9488\\u6765\\u8C03\\u6574\\u7A97\\u53E3\\u5927\\u5C0F\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"start\"}),\" \\u6307\\u9488\\u521D\\u59CB\\u5316\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u5C06\\u5927\\u5C0F\\u4E3A \",(0,n.jsx)(e.code,{children:\"26\"}),\" \\u7684\\u9891\\u7387\\u6620\\u5C04 \",(0,n.jsx)(e.code,{children:\"frequencyMap\"}),\"\\uFF08\\u7528\\u4E8E\\u6240\\u6709\\u5927\\u5199\\u82F1\\u6587\\u5B57\\u6BCD\\uFF09\\u586B\\u5145\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u5C06 \",(0,n.jsx)(e.code,{children:\"maxFrequency\"}),\" \\u521D\\u59CB\\u5316\\u4E3A\\u8DDF\\u8E2A\\u5F53\\u524D\\u7A97\\u53E3\\u4E2D\\u4EFB\\u4F55\\u5B57\\u7B26\\u7684\\u6700\\u9AD8\\u9891\\u7387\\uFF0C\\u5E76\\u5C06 \",(0,n.jsx)(e.code,{children:\"longestSubstringLength\"}),\" \\u521D\\u59CB\\u5316\\u4E3A\\u5B58\\u50A8\\u627E\\u5230\\u7684\\u6700\\u957F\\u6709\\u6548\\u5B50\\u5B57\\u7B26\\u4E32\\u7684\\u957F\\u5EA6\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"end\"}),\" \\u6307\\u9488\\u904D\\u5386\\u5B57\\u7B26\\u4E32\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u8BA1\\u7B97\\u5F53\\u524D\\u5B57\\u7B26\\u5728\\u9891\\u7387\\u6620\\u5C04\\u4E2D\\u7684\\u76F8\\u5BF9\\u7D22\\u5F15\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u589E\\u52A0\\u9891\\u7387\\u6620\\u5C04\\u4E2D\\u5F53\\u524D\\u5B57\\u7B26\\u7684\\u9891\\u7387\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"maxFrequency\"}),\" \\u66F4\\u65B0\\u4E3A\\u5F53\\u524D\\u7A97\\u53E3\\u4E2D\\u89C2\\u5BDF\\u5230\\u7684\\u6700\\u5927\\u9891\\u7387\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u68C0\\u67E5\\u6240\\u9700\\u66FF\\u6362\\u6B21\\u6570 (\",(0,n.jsx)(e.code,{children:\"end + 1 - start - maxFrequency\"}),\") \\u662F\\u5426\\u5C0F\\u4E8E\\u6216\\u7B49\\u4E8E \",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u6765\\u786E\\u5B9A\\u5F53\\u524D\\u7A97\\u53E3\\u662F\\u5426\\u6709\\u6548\\u3002\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u7A97\\u53E3\\u65E0\\u6548\\uFF0C\\u5219\\u79FB\\u52A8 \",(0,n.jsx)(e.code,{children:\"start\"}),\" \\u6307\\u9488\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u51CF\\u5C11\\u79FB\\u51FA\\u7A97\\u53E3\\u7684\\u5B57\\u7B26\\u7684\\u9891\\u7387\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u589E\\u52A0 \",(0,n.jsx)(e.code,{children:\"start\"}),\" \\u6307\\u9488\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u5F53\\u524D\\u6709\\u6548\\u7A97\\u53E3\\u7684\\u5927\\u5C0F (\",(0,n.jsx)(e.code,{children:\"end + 1 - start\"}),\") \\u66F4\\u65B0 \",(0,n.jsx)(e.code,{children:\"longestSubstringLength\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"longestSubstringLength\"}),\" \\u7684\\u503C\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(l,{children:s}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002 \",(0,n.jsx)(e.code,{children:\"end\"}),\" \\u6307\\u9488\\u904D\\u5386\\u5B57\\u7B26\\u4E32\\u4E00\\u6B21\\uFF0C\",(0,n.jsx)(e.code,{children:\"start\"}),\" \\u6307\\u9488\\u6839\\u636E\\u9700\\u8981\\u8FDB\\u884C\\u8C03\\u6574\\uFF0C\\u4ECE\\u800C\\u4EA7\\u751F\\u7EBF\\u6027\\u65F6\\u95F4\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002 \",(0,n.jsx)(e.code,{children:\"frequencyMap\"}),\" \\u7684\\u5927\\u5C0F\\u662F\\u6052\\u5B9A\\u7684 (\",(0,n.jsx)(e.code,{children:\"26\"}),\")\\uFF0C\\u4E0E\\u8F93\\u5165\\u5B57\\u7B26\\u4E32\\u7684\\u957F\\u5EA6\\u65E0\\u5173\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u4E8C\\u5206\\u67E5\\u627E\\u548C\\u6ED1\\u52A8\\u7A97\\u53E3\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u5C06\\u4E8C\\u5206\\u67E5\\u627E\\u4E0E\\u6ED1\\u52A8\\u7A97\\u53E3\\u4F18\\u5316\\u76F8\\u7ED3\\u5408\\uFF0C\\u4EE5\\u6709\\u6548\\u5730\\u786E\\u5B9A\\u7ED3\\u679C\\u3002 \\u4E8C\\u5206\\u67E5\\u627E\\u7528\\u4E8E\\u63A2\\u7D22\\u6709\\u6548\\u5B50\\u5B57\\u7B26\\u4E32\\u7684\\u53EF\\u80FD\\u957F\\u5EA6\\u3002 \\u901A\\u8FC7\\u68C0\\u67E5\\u7ED9\\u5B9A\\u957F\\u5EA6\\u7684\\u5B50\\u5B57\\u7B26\\u4E32\\u662F\\u5426\\u53EF\\u4EE5\\u4F7F\\u7528\\u6700\\u591A \",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u6B21\\u66FF\\u6362\\u4F7F\\u5176\\u6709\\u6548\\uFF0C\\u53EF\\u4EE5\\u5BF9\\u53EF\\u80FD\\u7684\\u957F\\u5EA6\\u8303\\u56F4\\u8FDB\\u884C\\u5BF9\\u6570\\u51CF\\u5C11\\u3002 \\u6ED1\\u52A8\\u7A97\\u53E3\\u6280\\u672F\\u901A\\u8FC7\\u7EF4\\u62A4\\u5F53\\u524D\\u7A97\\u53E3\\u4E2D\\u5B57\\u7B26\\u7684\\u9891\\u7387\\u5E76\\u786E\\u5B9A\\u6240\\u9700\\u7684\\u66FF\\u6362\\u662F\\u5426\\u5728\\u5141\\u8BB8\\u7684 \",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u8303\\u56F4\\u5185\\u6765\\u9A8C\\u8BC1\\u6BCF\\u4E2A\\u957F\\u5EA6\\u7684\\u6709\\u6548\\u6027\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u6838\\u5FC3\\u601D\\u60F3\\u662F\\u5728\\u786E\\u4FDD\\u7A97\\u53E3\\u5927\\u5C0F\\u4E0D\\u8D85\\u8FC7\\u5141\\u8BB8\\u7684\\u66FF\\u6362\\u6B21\\u6570\\u7684\\u540C\\u65F6\\uFF0C\\u6700\\u5927\\u5316\\u7A97\\u53E3\\u4E2D\\u4EFB\\u4F55\\u5B57\\u7B26\\u7684\\u9891\\u7387\\u3002 \\u5982\\u679C\\u53EF\\u4EE5\\u4F7F\\u6240\\u9700\\u957F\\u5EA6\\u7684\\u7A97\\u53E3\\u6709\\u6548\\uFF0C\\u5219\\u4F1A\\u63A2\\u7D22\\u66F4\\u5927\\u7684\\u957F\\u5EA6\\u3002 \\u5426\\u5219\\uFF0C\\u5C06\\u68C0\\u67E5\\u8F83\\u5C0F\\u7684\\u957F\\u5EA6\\u3002 \\u8FD9\\u79CD\\u4E8C\\u5206\\u67E5\\u627E\\u548C\\u6ED1\\u52A8\\u7A97\\u53E3\\u7684\\u7EC4\\u5408\\u786E\\u4FDD\\u4E86\\u89E3\\u51B3\\u65B9\\u6848\\u7684\\u9AD8\\u6548\\u6027\\u548C\\u53EF\\u6269\\u5C55\\u6027\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E8C\\u5206\\u67E5\\u627E\\u8FB9\\u754C\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"low\"}),\" \\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"1\"}),\"\\uFF0C\\u8868\\u793A\\u6700\\u5C0F\\u53EF\\u80FD\\u7684\\u5B50\\u5B57\\u7B26\\u4E32\\u957F\\u5EA6\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"high\"}),\" \\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"str.length + 1\"}),\"\\uFF0C\\u8868\\u793A\\u8D85\\u51FA\\u8F93\\u5165\\u5B57\\u7B26\\u4E32\\u957F\\u5EA6\\u7684\\u65E0\\u6548\\u5B50\\u5B57\\u7B26\\u4E32\\u957F\\u5EA6\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u6267\\u884C\\u4E8C\\u5206\\u67E5\\u627E\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8BA1\\u7B97\\u5F53\\u524D\\u8303\\u56F4\\u7684\\u4E2D\\u70B9 \",(0,n.jsx)(e.code,{children:\"mid\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u662F\\u5426\\u53EF\\u4EE5\\u4F7F\\u7528\\u8F85\\u52A9\\u51FD\\u6570 \",(0,n.jsx)(e.code,{children:\"canMakeValidSubstring\"}),\" \\u521B\\u5EFA\\u957F\\u5EA6\\u4E3A \",(0,n.jsx)(e.code,{children:\"mid\"}),\" \\u7684\\u6709\\u6548\\u5B50\\u5B57\\u7B26\\u4E32\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u6709\\u6548\\uFF0C\\u5C06 \",(0,n.jsx)(e.code,{children:\"low\"}),\" \\u79FB\\u52A8\\u5230 \",(0,n.jsx)(e.code,{children:\"mid\"}),\" \\u4EE5\\u63A2\\u7D22\\u66F4\\u5927\\u7684\\u5B50\\u5B57\\u7B26\\u4E32\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5426\\u5219\\uFF0C\\u5C06 \",(0,n.jsx)(e.code,{children:\"high\"}),\" \\u79FB\\u52A8\\u5230 \",(0,n.jsx)(e.code,{children:\"mid\"}),\" \\u4EE5\\u63A2\\u7D22\\u66F4\\u5C0F\\u7684\\u5B50\\u5B57\\u7B26\\u4E32\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"low\"}),\"\\uFF0C\\u5B83\\u8868\\u793A\\u6700\\u5927\\u7684\\u6709\\u6548\\u5B50\\u5B57\\u7B26\\u4E32\\u957F\\u5EA6\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"canMakeValidSubstring\"}),\" \\u51FD\\u6570\\u9A8C\\u8BC1\\u7ED9\\u5B9A\\u957F\\u5EA6\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u7EF4\\u62A4\\u4E00\\u4E2A\\u9891\\u7387\\u6620\\u5C04 \",(0,n.jsx)(e.code,{children:\"freqMap\"}),\" \\u4EE5\\u8DDF\\u8E2A\\u5F53\\u524D\\u7A97\\u53E3\\u4E2D\\u7684\\u5B57\\u7B26\\u51FA\\u73B0\\u6B21\\u6570\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u6ED1\\u52A8\\u7A97\\u53E3\\u904D\\u5386\\u5B57\\u7B26\\u4E32\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u5C06\\u5F53\\u524D\\u5B57\\u7B26\\u6DFB\\u52A0\\u5230\\u9891\\u7387\\u6620\\u5C04\\u4E2D\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u7A97\\u53E3\\u5927\\u5C0F\\u8D85\\u8FC7\\u5019\\u9009\\u5B50\\u5B57\\u7B26\\u4E32\\u957F\\u5EA6\\uFF0C\\u5219\\u5220\\u9664\\u7A97\\u53E3\\u5F00\\u5934\\u7684\\u5B57\\u7B26\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u5F53\\u524D\\u7A97\\u53E3\\u4E2D\\u89C2\\u5BDF\\u5230\\u7684\\u6700\\u9AD8\\u9891\\u7387\\u66F4\\u65B0 \",(0,n.jsx)(e.code,{children:\"maxFrequency\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u5F53\\u524D\\u7A97\\u53E3\\u662F\\u5426\\u53EF\\u4EE5\\u4F7F\\u7528\\u6700\\u591A \",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u6B21\\u66FF\\u6362\\u4F7F\\u5176\\u6709\\u6548\\u3002\\u5982\\u679C\\u6709\\u6548\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u672A\\u627E\\u5230\\u7ED9\\u5B9A\\u957F\\u5EA6\\u7684\\u6709\\u6548\\u5B50\\u5B57\\u7B26\\u4E32\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(l,{children:u}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n log n)\"}),\"\\u3002 \\u4E8C\\u5206\\u67E5\\u627E\\u6267\\u884C \",(0,n.jsx)(e.code,{children:\"O(log n)\"}),\" \\u6B21\\u8FED\\u4EE3\\uFF0C\\u5E76\\u4E14\\u6BCF\\u6B21\\u8FED\\u4EE3\\u90FD\\u4F1A\\u8C03\\u7528 \",(0,n.jsx)(e.code,{children:\"canMakeValidSubstring\"}),\"\\uFF0C\\u8BE5\\u51FD\\u6570\\u4EE5 O(n) \\u8FD0\\u884C\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002 \\u9891\\u7387\\u6620\\u5C04\\u7684\\u5927\\u5C0F\\u662F\\u56FA\\u5B9A\\u7684 (\",(0,n.jsx)(e.code,{children:\"26\"}),\")\\uFF0C\\u4E0E\\u8F93\\u5165\\u5927\\u5C0F\\u65E0\\u5173\\u3002\"]}),`\n`]})]})}function v(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(g,r)})):g(r)}var A=v;return k(F);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/matrix-rotation/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/matrix-rotation/locales/zh-CN.json new file mode 100644 index 000000000..7bfbb1656 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/matrix-rotation/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var m=Object.create;var c=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var j=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),_=(t,e)=>{for(var r in e)c(t,r,{get:e[r],enumerable:!0})},l=(t,e,r,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of p(e))!g.call(t,i)&&i!==r&&c(t,i,{get:()=>e[i],enumerable:!(o=u(e,i))||o.enumerable});return t};var T=(t,e,r)=>(r=t!=null?m(f(t)):{},l(e||!t||!t.__esModule?c(r,\"default\",{value:t,enumerable:!0}):r,t)),M=t=>l(c({},\"__esModule\",{value:!0}),t);var d=j((k,a)=>{a.exports=_jsx_runtime});var b={};_(b,{default:()=>X,frontmatter:()=>C});var n=T(d());var s=MDXTestExamples;var x=[{input:[[\"matrix\",[[1,4],[2,6]]]],output:[[2,1],[6,4]],explanation:\"The 2x2 matrix is rotated 90 degrees clockwise.\"},{input:[[\"matrix\",[[1,2,3],[4,5,6],[7,8,9]]]],output:[[7,4,1],[8,5,2],[9,6,3]],explanation:\"The 3x3 matrix is rotated 90 degrees clockwise.\"},{input:[[\"matrix\",[[3]]]],output:[[3]],explanation:\"The 1x1 matrix remains the same after rotation.\"}];var C={title:\"\\u77E9\\u9635\\u65CB\\u8F6C\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u5C06\\u7ED9\\u5B9A\\u7684\\u77E9\\u9635\\u65CB\\u8F6C 90 \\u5EA6\"};function h(t){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"n\"}),\" x \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u7684\\u4E8C\\u7EF4\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"matrix\"}),\"\\uFF0C\\u5C06\\u77E9\\u9635\\u987A\\u65F6\\u9488\\u65CB\\u8F6C 90 \\u5EA6\\u3002\\u8FD9\\u610F\\u5473\\u7740\\u5E94\\u8BE5\\u76F4\\u63A5\\u4FEE\\u6539\\u8F93\\u5165\\u7684\\u4E8C\\u7EF4\\u77E9\\u9635\\uFF0C\\u800C\\u65E0\\u9700\\u4F7F\\u7528\\u4EFB\\u4F55\\u989D\\u5916\\u7684\\u4E8C\\u7EF4\\u77E9\\u9635\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"matrix: number[][]\"}),\": \\u5927\\u5C0F\\u4E3A \",(0,n.jsx)(e.code,{children:\"n\"}),\" x \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u7684\\u4E8C\\u7EF4\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"matrix\"})]}),`\n`]}),`\n`,(0,n.jsx)(s,{testCases:x}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.code,{children:\"n = matrix.length = matrix[i].length\"})}),`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"n\"}),\" <= 20\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"-1000 <= \",(0,n.jsx)(e.code,{children:\"matrix[row][col]\"}),\" <= 1000\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u4F7F\\u7528 O(1) \\u989D\\u5916\\u7A7A\\u95F4\"}),`\n`]})]})}function D(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(h,t)})):h(t)}var X=D;return M(b);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,将给定的矩阵旋转 90 度", + "title": "矩阵旋转" + }, + "solution": "var Component=(()=>{var x=Object.create;var t=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var v=(i,n)=>()=>(n||i((n={exports:{}}).exports,n),n.exports),M=(i,n)=>{for(var r in n)t(i,r,{get:n[r],enumerable:!0})},c=(i,n,r,h)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let l of f(n))!g.call(i,l)&&l!==r&&t(i,l,{get:()=>n[l],enumerable:!(h=p(n,l))||h.enumerable});return i};var b=(i,n,r)=>(r=i!=null?x(u(i)):{},c(n||!i||!i.__esModule?t(r,\"default\",{value:i,enumerable:!0}):r,i)),w=i=>c(t({},\"__esModule\",{value:!0}),i);var a=v((C,d)=>{d.exports=_jsx_runtime});var T={};M(T,{default:()=>R});var e=b(a());var o=MDXCodeBlock;var m=`export default function matrixRotation(matrix: number[][]): void {\n // Get the number of rows (or columns) of the matrix\n let n = matrix.length;\n\n // Loop through each layer of the matrix\n // The outer loop goes over each \"layer\" from the outside towards the center\n for (let i = 0; i < Math.floor((n + 1) / 2); i++) {\n // The inner loop goes over each element in the layer\n for (let j = 0; j < Math.floor(n / 2); j++) {\n // Store the value of the top-left element temporarily\n let temp = matrix[n - 1 - j][i];\n\n // Move the bottom-left element to the top-left\n matrix[n - 1 - j][i] = matrix[n - 1 - i][n - j - 1];\n\n // Move the bottom-right element to the bottom-left\n matrix[n - 1 - i][n - j - 1] = matrix[j][n - 1 - i];\n\n // Move the top-right element to the bottom-right\n matrix[j][n - 1 - i] = matrix[i][j];\n\n // Move the stored top-left element to the top-right\n matrix[i][j] = temp;\n }\n }\n}\n`;var s=`export default function matrixRotation(matrix: number[][]): void {\n // Get the number of rows (or columns) of the matrix\n const n = matrix.length;\n\n // Step 1: Transpose the matrix\n // Transposing involves swapping matrix[i][j] with matrix[j][i]\n for (let i = 0; i < n; i++) {\n for (let j = i + 1; j < n; j++) {\n [matrix[i][j], matrix[j][i]] = [matrix[j][i], matrix[i][j]];\n }\n }\n\n // Step 2: Reflect the matrix horizontally\n // Reflecting involves swapping elements in each row, from the start to the middle\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < n / 2; j++) {\n [matrix[i][j], matrix[i][n - 1 - j]] = [\n matrix[i][n - 1 - j],\n matrix[i][j],\n ];\n }\n }\n}\n`;function j(i){let n=Object.assign({h2:\"h2\",p:\"p\",ul:\"ul\",li:\"li\",h3:\"h3\",ol:\"ol\",code:\"code\",strong:\"strong\"},i.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"1. \\u65CB\\u8F6C\\u56DB\\u7EC4\\u5355\\u5143\\u683C\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u8BE5\\u4EFB\\u52A1\\u6D89\\u53CA\\u5C06\\u4E00\\u4E2A\\u6B63\\u65B9\\u5F62\\u77E9\\u9635\\u987A\\u65F6\\u9488\\u65CB\\u8F6C 90 \\u5EA6\\u3002\\u8FD9\\u610F\\u5473\\u7740\\u53D8\\u6362\\u4E0D\\u80FD\\u4F7F\\u7528\\u989D\\u5916\\u7684\\u5185\\u5B58\\u6765\\u5B58\\u50A8\\u53E6\\u4E00\\u4E2A\\u77E9\\u9635\\u3002\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u5206\\u7EC4\\u65CB\\u8F6C\\u65B9\\u6CD5\\u6765\\u79FB\\u52A8\\u77E9\\u9635\\u6BCF\\u4E00\\u5C42\\u4E2D\\u7684\\u503C\\u3002\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u76F4\\u89C9\\u662F\\uFF0C\\u5BF9\\u4E8E 90 \\u5EA6\\u987A\\u65F6\\u9488\\u65CB\\u8F6C\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5DE6\\u4E0A\\u89D2\\u7684\\u5143\\u7D20\\u79FB\\u52A8\\u5230\\u53F3\\u4E0A\\u89D2\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u53F3\\u4E0A\\u89D2\\u7684\\u5143\\u7D20\\u79FB\\u52A8\\u5230\\u53F3\\u4E0B\\u89D2\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u53F3\\u4E0B\\u89D2\\u7684\\u5143\\u7D20\\u79FB\\u52A8\\u5230\\u5DE6\\u4E0B\\u89D2\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5DE6\\u4E0B\\u89D2\\u7684\\u5143\\u7D20\\u79FB\\u52A8\\u5230\\u5DE6\\u4E0A\\u89D2\\u3002\"}),`\n`]}),`\n`,(0,e.jsx)(n.p,{children:\"\\u8FD9\\u79CD\\u53D8\\u6362\\u53EF\\u4EE5\\u901A\\u8FC7\\u9010\\u5C42\\u904D\\u5386\\u77E9\\u9635\\u6765\\u5B9E\\u73B0\\u3002\\u6BCF\\u4E00\\u5C42\\u4EE3\\u8868\\u4E00\\u7EC4\\u5D4C\\u5957\\u7684\\u6B63\\u65B9\\u5F62\\uFF0C\\u4ECE\\u6700\\u5916\\u5C42\\u5F00\\u59CB\\uFF0C\\u5411\\u4E2D\\u5FC3\\u79FB\\u52A8\\u3002\\u5BF9\\u4E8E\\u6BCF\\u4E00\\u5C42\\uFF0C\\u5143\\u7D20\\u4EE5\\u56DB\\u7EC4\\u4E3A\\u5355\\u4F4D\\u8FDB\\u884C\\u4EA4\\u6362\\uFF0C\\u6709\\u6548\\u5730\\u6267\\u884C\\u65CB\\u8F6C\\uFF0C\\u800C\\u65E0\\u9700\\u989D\\u5916\\u7684\\u5185\\u5B58\\u4F7F\\u7528\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u83B7\\u53D6\\u77E9\\u9635\\u7684\\u5927\\u5C0F \",(0,e.jsx)(n.code,{children:\"n\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u9010\\u5C42\\u904D\\u5386\\u77E9\\u9635\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5916\\u5FAA\\u73AF\\u5904\\u7406\\u4ECE\\u5916\\u5230\\u4E2D\\u5FC3\\u7684\\u6BCF\\u4E00\\u5C42\\u3002\\u5C42\\u6570\\u4E3A \",(0,e.jsx)(n.code,{children:\"Math.floor((n + 1) / 2)\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5185\\u5FAA\\u73AF\\u5904\\u7406\\u5C42\\u5185\\u7684\\u5143\\u7D20\\u3002\\u6BCF\\u5C42\\u4E2D\\u7684\\u5143\\u7D20\\u6570\\u91CF\\u7531 \",(0,e.jsx)(n.code,{children:\"Math.floor(n / 2)\"}),\" \\u51B3\\u5B9A\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5BF9\\u4E8E\\u5F53\\u524D\\u5C42\\u4E2D\\u7684\\u6BCF\\u7EC4\\u56DB\\u4E2A\\u5355\\u5143\\u683C\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u4E34\\u65F6\\u5B58\\u50A8\\u5DE6\\u4E0A\\u89D2\\u5143\\u7D20\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5C06\\u5DE6\\u4E0B\\u89D2\\u5143\\u7D20\\u79FB\\u52A8\\u5230\\u5DE6\\u4E0A\\u89D2\\u4F4D\\u7F6E\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5C06\\u53F3\\u4E0B\\u89D2\\u5143\\u7D20\\u79FB\\u52A8\\u5230\\u5DE6\\u4E0B\\u89D2\\u4F4D\\u7F6E\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5C06\\u53F3\\u4E0A\\u89D2\\u5143\\u7D20\\u79FB\\u52A8\\u5230\\u53F3\\u4E0B\\u89D2\\u4F4D\\u7F6E\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5C06\\u5B58\\u50A8\\u7684\\u5DE6\\u4E0A\\u89D2\\u503C\\u5206\\u914D\\u7ED9\\u53F3\\u4E0A\\u89D2\\u4F4D\\u7F6E\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5BF9\\u6240\\u6709\\u5C42\\u91CD\\u590D\\u6B64\\u8FC7\\u7A0B\\u3002\"}),`\n`]}),`\n`,(0,e.jsx)(o,{children:m}),`\n`,(0,e.jsx)(n.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsxs)(n.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,e.jsx)(\"sup\",{children:\"2\"}),\")\"]}),\"\\u3002\\u5728\\u9010\\u5C42\\u904D\\u5386\\u671F\\u95F4\\uFF0C\\u77E9\\u9635\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5143\\u7D20\\u90FD\\u4F1A\\u88AB\\u8BBF\\u95EE\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u65CB\\u8F6C\\u662F\\u5728\\u539F\\u5730\\u6267\\u884C\\u7684\\uFF0C\\u6CA1\\u6709\\u4F7F\\u7528\\u989D\\u5916\\u7684\\u5185\\u5B58\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"2. \\u4F7F\\u7528\\u77E9\\u9635\\u8F6C\\u7F6E\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u8BE5\\u4EFB\\u52A1\\u6D89\\u53CA\\u5C06\\u4E00\\u4E2A\\u6B63\\u65B9\\u5F62\\u77E9\\u9635\\u987A\\u65F6\\u9488\\u65CB\\u8F6C 90 \\u5EA6\\u3002\\u8FD9\\u79CD\\u53D8\\u6362\\u53EF\\u4EE5\\u901A\\u8FC7\\u4E24\\u4E2A\\u6B65\\u9AA4\\u5B9E\\u73B0\\uFF1A\\u8F6C\\u7F6E\\u77E9\\u9635\\uFF0C\\u7136\\u540E\\u6C34\\u5E73\\u53CD\\u5C04\\u5B83\\u3002\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.strong,{children:\"\\u8F6C\\u7F6E\"}),\"\\uFF1A\\u8F6C\\u7F6E\\u64CD\\u4F5C\\u901A\\u8FC7\\u5C06\\u4F4D\\u7F6E \",(0,e.jsx)(n.code,{children:\"(i, j)\"}),\" \\u5904\\u7684\\u5143\\u7D20\\u4E0E \",(0,e.jsx)(n.code,{children:\"(j, i)\"}),\" \\u5904\\u7684\\u5143\\u7D20\\u4EA4\\u6362\\u6765\\u4EA4\\u6362\\u884C\\u548C\\u5217\\u3002\\u6B64\\u6B65\\u9AA4\\u5C06\\u539F\\u59CB\\u77E9\\u9635\\u7684\\u884C\\u8F6C\\u6362\\u4E3A\\u7ED3\\u679C\\u77E9\\u9635\\u7684\\u5217\\u3002\"]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.strong,{children:\"\\u6C34\\u5E73\\u53CD\\u5C04\"}),\"\\uFF1A\\u8F6C\\u7F6E\\u540E\\uFF0C\\u6C34\\u5E73\\u53CD\\u5C04\\u77E9\\u9635\\u4F1A\\u4EA4\\u6362\\u6BCF\\u4E00\\u884C\\u4E2D\\u7684\\u5143\\u7D20\\uFF0C\\u5C06\\u6700\\u5DE6\\u8FB9\\u7684\\u5143\\u7D20\\u4E0E\\u6700\\u53F3\\u8FB9\\u7684\\u5143\\u7D20\\u4EA4\\u6362\\u3002\\u8FD9\\u5B8C\\u6210\\u4E86 90 \\u5EA6\\u987A\\u65F6\\u9488\\u65CB\\u8F6C\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsx)(n.p,{children:\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u6709\\u6548\\u5730\\u5728\\u539F\\u5730\\u64CD\\u4F5C\\u77E9\\u9635\\uFF0C\\u800C\\u65E0\\u9700\\u4E3A\\u53E6\\u4E00\\u4E2A\\u77E9\\u9635\\u5206\\u914D\\u989D\\u5916\\u7684\\u7A7A\\u95F4\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u68C0\\u7D22\\u77E9\\u9635\\u7684\\u5927\\u5C0F \",(0,e.jsx)(n.code,{children:\"n\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u6267\\u884C\\u8F6C\\u7F6E\\u64CD\\u4F5C\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u904D\\u5386\\u77E9\\u9635\\u7684\\u6BCF\\u4E00\\u884C \",(0,e.jsx)(n.code,{children:\"i\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E00\\u884C\\uFF0C\\u904D\\u5386\\u5217 \",(0,e.jsx)(n.code,{children:\"j\"}),\"\\uFF0C\\u5176\\u4E2D \",(0,e.jsx)(n.code,{children:\"j > i\"}),\" \\u4EE5\\u907F\\u514D\\u5197\\u4F59\\u4EA4\\u6362\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4EA4\\u6362 \",(0,e.jsx)(n.code,{children:\"(i, j)\"}),\" \\u548C \",(0,e.jsx)(n.code,{children:\"(j, i)\"}),\" \\u5904\\u7684\\u5143\\u7D20\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u6267\\u884C\\u6C34\\u5E73\\u53CD\\u5C04\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u904D\\u5386\\u77E9\\u9635\\u7684\\u6BCF\\u4E00\\u884C \",(0,e.jsx)(n.code,{children:\"i\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E00\\u884C\\uFF0C\\u904D\\u5386\\u524D\\u4E00\\u534A\\u7684\\u5217 \",(0,e.jsx)(n.code,{children:\"j\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4EA4\\u6362 \",(0,e.jsx)(n.code,{children:\"(i, j)\"}),\" \\u548C \",(0,e.jsx)(n.code,{children:\"(i, n-1-j)\"}),\" \\u5904\\u7684\\u5143\\u7D20\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsx)(n.li,{children:\"\\u73B0\\u5728\\u77E9\\u9635\\u987A\\u65F6\\u9488\\u65CB\\u8F6C 90 \\u5EA6\\u3002\"}),`\n`]}),`\n`,(0,e.jsx)(o,{children:s}),`\n`,(0,e.jsx)(n.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsxs)(n.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,e.jsx)(\"sup\",{children:\"2\"}),\")\"]}),\"\\u3002\\u8F6C\\u7F6E\\u548C\\u53CD\\u5C04\\u64CD\\u4F5C\\u90FD\\u6D89\\u53CA\\u8BBF\\u95EE\\u77E9\\u9635\\u7684\\u6BCF\\u4E2A\\u5143\\u7D20\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u65CB\\u8F6C\\u662F\\u5728\\u539F\\u5730\\u6267\\u884C\\u7684\\uFF0C\\u6CA1\\u6709\\u4F7F\\u7528\\u989D\\u5916\\u7684\\u5185\\u5B58\\u3002\"]}),`\n`]})]})}function y(i={}){let{wrapper:n}=i.components||{};return n?(0,e.jsx)(n,Object.assign({},i,{children:(0,e.jsx)(j,i)})):j(i)}var R=y;return w(T);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/matrix-spiral-traversal/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/matrix-spiral-traversal/locales/zh-CN.json new file mode 100644 index 000000000..9076a2ea1 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/matrix-spiral-traversal/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var u=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var w=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports),v=(n,t)=>{for(var r in t)i(n,r,{get:t[r],enumerable:!0})},a=(n,t,r,l)=>{if(t&&typeof t==\"object\"||typeof t==\"function\")for(let o of x(t))!g.call(n,o)&&o!==r&&i(n,o,{get:()=>t[o],enumerable:!(l=p(t,o))||l.enumerable});return n};var b=(n,t,r)=>(r=n!=null?u(f(n)):{},a(t||!n||!n.__esModule?i(r,\"default\",{value:n,enumerable:!0}):r,n)),j=n=>a(i({},\"__esModule\",{value:!0}),n);var s=w((T,c)=>{c.exports=_jsx_runtime});var X={};v(X,{default:()=>D,frontmatter:()=>C});var e=b(s());var h=MDXTestExamples;var d=[{input:[[\"matrix\",[[1,2,3],[4,5,6],[7,8,9]]]],output:[1,2,3,6,9,8,7,4,5],explanation:\"Starting from the top-left corner, move right across the first row, then go down across the last column, then move left along the bottom row, and travel up in the first column. Continue this pattern, spiraling inward, until all the elements have been traversed.\"},{input:[[\"matrix\",[[7,7,0,7],[4,3,7,2],[9,8,6,0],[6,1,3,6]]]],output:[7,7,0,7,2,0,6,3,1,6,9,4,3,7,6,8],explanation:\"Starting from the top-left corner, move right across the first row, then go down in the last column, move left along the bottom row, and travel up in the first column. Continue this pattern, spiraling inward, until all the elements have been traversed.\"},{input:[[\"matrix\",[[1,2],[3,4]]]],output:[1,2,4,3],explanation:\"Starting from the top-left corner, move right across the first row, then go down in the last column, and finally move left across the bottom row.\"}];var C={title:\"\\u77E9\\u9635\\u87BA\\u65CB\\u904D\\u5386\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u4EE5\\u87BA\\u65CB\\u987A\\u5E8F\\u904D\\u5386\\u77E9\\u9635\"};function m(n){let t=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},n.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)(t.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u5927\\u5C0F\\u4E3A \",(0,e.jsx)(t.code,{children:\"m\"}),\" x \",(0,e.jsx)(t.code,{children:\"n\"}),\" \\u7684 \",(0,e.jsx)(t.code,{children:\"matrix\"}),\"\\uFF0C\\u7F16\\u5199\\u4E00\\u4E2A\\u51FD\\u6570\\u4EE5\\u87BA\\u65CB\\u987A\\u5E8F\\u8FD4\\u56DE\\u77E9\\u9635\\u7684\\u5143\\u7D20\\u3002\"]}),`\n`,(0,e.jsx)(t.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,e.jsxs)(t.ul,{children:[`\n`,(0,e.jsxs)(t.li,{children:[(0,e.jsx)(t.code,{children:\"matrix: number[][]\"}),\": \\u5927\\u5C0F\\u4E3A \",(0,e.jsx)(t.code,{children:\"m\"}),\" x \",(0,e.jsx)(t.code,{children:\"n\"}),\" \\u7684\\u4E8C\\u7EF4\\u6570\\u7EC4 \",(0,e.jsx)(t.code,{children:\"matrix\"})]}),`\n`]}),`\n`,(0,e.jsx)(h,{testCases:d}),`\n`,(0,e.jsx)(t.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,e.jsxs)(t.ul,{children:[`\n`,(0,e.jsxs)(t.li,{children:[\"1 <= \",(0,e.jsx)(t.code,{children:\"m\"}),\", \",(0,e.jsx)(t.code,{children:\"n\"}),\" <= 100\"]}),`\n`,(0,e.jsxs)(t.li,{children:[\"-1,000 <= \",(0,e.jsx)(t.code,{children:\"matrix[row][col]\"}),\" <= 1,000\"]}),`\n`]})]})}function M(n={}){let{wrapper:t}=n.components||{};return t?(0,e.jsx)(t,Object.assign({},n,{children:(0,e.jsx)(m,n)})):m(n)}var D=M;return j(X);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,以螺旋顺序遍历矩阵", + "title": "矩阵螺旋遍历" + }, + "solution": "var Component=(()=>{var g=Object.create;var c=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var x=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),v=(r,e)=>{for(var i in e)c(r,i,{get:e[i],enumerable:!0})},d=(r,e,i,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let l of f(e))!D.call(r,l)&&l!==i&&c(r,l,{get:()=>e[l],enumerable:!(o=w(e,l))||o.enumerable});return r};var M=(r,e,i)=>(i=r!=null?g(p(r)):{},d(e||!r||!r.__esModule?c(i,\"default\",{value:r,enumerable:!0}):i,r)),T=r=>d(c({},\"__esModule\",{value:!0}),r);var s=x((j,h)=>{h.exports=_jsx_runtime});var k={};v(k,{default:()=>C});var n=M(s());var t=MDXCodeBlock;var u=`export default function matrixSpiralTraversal(matrix: number[][]): number[] {\n let result = [];\n const rows = matrix.length;\n const columns = matrix[0].length;\n let up = 0;\n let left = 0;\n let right = columns - 1;\n let down = rows - 1;\n\n // Continue until all elements are added to the result\n while (result.length < rows * columns) {\n // Traverse from left to right along the top row\n for (let col = left; col <= right; col++) {\n result.push(matrix[up][col]);\n }\n // Traverse downwards along the right column\n for (let row = up + 1; row <= down; row++) {\n result.push(matrix[row][right]);\n }\n // Make sure we are now on a different row to avoid reprocessing\n if (up !== down) {\n // Traverse from right to left along the bottom row\n for (let col = right - 1; col >= left; col--) {\n result.push(matrix[down][col]);\n }\n }\n // Make sure we are now on a different column to avoid reprocessing\n if (left !== right) {\n // Traverse upwards along the left column\n for (let row = down - 1; row > up; row--) {\n result.push(matrix[row][left]);\n }\n }\n // Move the boundaries inward\n left++;\n right--;\n up++;\n down--;\n }\n return result;\n}\n`;var a=`export default function matrixSpiralTraversal(matrix: number[][]): number[] {\n const VISITED = 1001; // Marker for visited cells\n let rows = matrix.length, // Total number of rows\n cols = matrix[0].length; // Total number of columns\n let result: number[] = [matrix[0][0]]; // Result array initialized with the first element\n matrix[0][0] = VISITED; // Mark the first element as visited\n\n // Four directions: right, down, left, up.\n let directions: number[][] = [\n [0, 1], // Move right\n [1, 0], // Move down\n [0, -1], // Move left\n [-1, 0], // Move up\n ];\n\n let currentDirection = 0; // Initial direction: moving right\n let changeDirection = 0; // Counter for direction changes\n let row = 0,\n col = 0; // Starting position\n\n // Continue until the direction changes twice without adding new elements\n while (changeDirection < 2) {\n // Continue moving in the current direction until a boundary or visited cell is encountered\n while (\n row + directions[currentDirection][0] >= 0 &&\n row + directions[currentDirection][0] < rows &&\n col + directions[currentDirection][1] >= 0 &&\n col + directions[currentDirection][1] < cols &&\n matrix[row + directions[currentDirection][0]][\n col + directions[currentDirection][1]\n ] !== VISITED\n ) {\n changeDirection = 0; // Reset changeDirection as we are still adding elements\n\n // Move to the next cell in the current direction\n row += directions[currentDirection][0];\n col += directions[currentDirection][1];\n\n result.push(matrix[row][col]); // Add the element to the result\n matrix[row][col] = VISITED; // Mark the cell as visited\n }\n\n // Change direction\n currentDirection = (currentDirection + 1) % 4; // Cycle through directions\n changeDirection++; // Increment changeDirection as we changed direction\n }\n\n return result;\n}\n`;function m(r){let e=Object.assign({h2:\"h2\",p:\"p\",ol:\"ol\",li:\"li\",h3:\"h3\",code:\"code\",ul:\"ul\",strong:\"strong\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u8BBE\\u7F6E\\u8FB9\\u754C\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u4EFB\\u52A1\\u8981\\u6C42\\u4EE5\\u87BA\\u65CB\\u987A\\u5E8F\\u904D\\u5386\\u4E8C\\u7EF4\\u77E9\\u9635\\uFF0C\\u4ECE\\u5DE6\\u4E0A\\u89D2\\u5F00\\u59CB\\uFF0C\\u6309\\u987A\\u65F6\\u9488\\u65B9\\u5411\\u8FDB\\u884C\\u3002 \\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u8FB9\\u754C\\u53D8\\u91CF\\u6765\\u5B9A\\u4E49\\u5F53\\u524D\\u7684\\u904D\\u5386\\u9650\\u5236\\uFF0C\\u5E76\\u8FED\\u4EE3\\u5730\\u5411\\u5185\\u79FB\\u52A8\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u76F4\\u89C9\\u662F\\u5C06\\u77E9\\u9635\\u89C6\\u4E3A\\u5C42\\uFF0C\\u4ECE\\u6700\\u5916\\u5C42\\u5F00\\u59CB\\u5E76\\u5411\\u5185\\u79FB\\u52A8\\u3002 \\u5BF9\\u4E8E\\u6BCF\\u4E00\\u5C42\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u6CBF\\u4E0A\\u8FB9\\u754C\\u4ECE\\u5DE6\\u5411\\u53F3\\u904D\\u5386\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u6CBF\\u53F3\\u8FB9\\u754C\\u4ECE\\u4E0A\\u5230\\u4E0B\\u904D\\u5386\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u6CBF\\u4E0B\\u8FB9\\u754C\\u4ECE\\u53F3\\u5411\\u5DE6\\u904D\\u5386\\uFF0C\\u786E\\u4FDD\\u5B83\\u4E0D\\u4E0E\\u4E0A\\u884C\\u91CD\\u53E0\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u6CBF\\u5DE6\\u8FB9\\u754C\\u4ECE\\u4E0B\\u5230\\u4E0A\\u904D\\u5386\\uFF0C\\u786E\\u4FDD\\u5B83\\u4E0D\\u4E0E\\u53F3\\u5217\\u91CD\\u53E0\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u6BCF\\u6B21\\u904D\\u5386\\u540E\\uFF0C\\u8FB9\\u754C\\u5411\\u5185\\u8C03\\u6574\\uFF0C\\u8BE5\\u8FC7\\u7A0B\\u6301\\u7EED\\u8FDB\\u884C\\uFF0C\\u76F4\\u5230\\u904D\\u5386\\u5B8C\\u6240\\u6709\\u5143\\u7D20\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u7ED3\\u679C\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"result\"}),\" \\u4EE5\\u5B58\\u50A8\\u87BA\\u65CB\\u987A\\u5E8F\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u8FB9\\u754C\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"up\"}),\" \\u4F5C\\u4E3A\\u6700\\u9876\\u884C\\u7D22\\u5F15\\uFF0C\\u4ECE \",(0,n.jsx)(e.code,{children:\"0\"}),\" \\u5F00\\u59CB\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"down\"}),\" \\u4F5C\\u4E3A\\u6700\\u5E95\\u884C\\u7D22\\u5F15\\uFF0C\\u4ECE \",(0,n.jsx)(e.code,{children:\"rows - 1\"}),\" \\u5F00\\u59CB\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"left\"}),\" \\u4F5C\\u4E3A\\u6700\\u5DE6\\u5217\\u7D22\\u5F15\\uFF0C\\u4ECE \",(0,n.jsx)(e.code,{children:\"0\"}),\" \\u5F00\\u59CB\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"right\"}),\" \\u4F5C\\u4E3A\\u6700\\u53F3\\u5217\\u7D22\\u5F15\\uFF0C\\u4ECE \",(0,n.jsx)(e.code,{children:\"columns - 1\"}),\" \\u5F00\\u59CB\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5F53 \",(0,n.jsx)(e.code,{children:\"result\"}),\" \\u7684\\u5927\\u5C0F\\u5C0F\\u4E8E\\u77E9\\u9635\\u4E2D\\u5143\\u7D20\\u7684\\u603B\\u6570\\u65F6\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u6CBF \",(0,n.jsx)(e.code,{children:\"up\"}),\" \\u884C\\u4ECE \",(0,n.jsx)(e.code,{children:\"left\"}),\" \\u904D\\u5386\\u5230 \",(0,n.jsx)(e.code,{children:\"right\"}),\"\\uFF0C\\u5E76\\u5C06\\u5143\\u7D20\\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"result\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u6CBF \",(0,n.jsx)(e.code,{children:\"right\"}),\" \\u5217\\u4ECE \",(0,n.jsx)(e.code,{children:\"up + 1\"}),\" \\u904D\\u5386\\u5230 \",(0,n.jsx)(e.code,{children:\"down\"}),\"\\uFF0C\\u5E76\\u5C06\\u5143\\u7D20\\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"result\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"up\"}),\" \\u4E0D\\u7B49\\u4E8E \",(0,n.jsx)(e.code,{children:\"down\"}),\"\\uFF0C\\u5219\\u6CBF \",(0,n.jsx)(e.code,{children:\"down\"}),\" \\u884C\\u4ECE \",(0,n.jsx)(e.code,{children:\"right - 1\"}),\" \\u904D\\u5386\\u5230 \",(0,n.jsx)(e.code,{children:\"left\"}),\"\\uFF0C\\u5E76\\u5C06\\u5143\\u7D20\\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"result\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"left\"}),\" \\u4E0D\\u7B49\\u4E8E \",(0,n.jsx)(e.code,{children:\"right\"}),\"\\uFF0C\\u5219\\u6CBF \",(0,n.jsx)(e.code,{children:\"left\"}),\" \\u5217\\u4ECE \",(0,n.jsx)(e.code,{children:\"down - 1\"}),\" \\u904D\\u5386\\u5230 \",(0,n.jsx)(e.code,{children:\"up\"}),\"\\uFF0C\\u5E76\\u5C06\\u5143\\u7D20\\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"result\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5411\\u5185\\u79FB\\u52A8\\u8FB9\\u754C\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u9012\\u589E \",(0,n.jsx)(e.code,{children:\"up\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"left\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u9012\\u51CF \",(0,n.jsx)(e.code,{children:\"down\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"right\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"result\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(t,{children:u}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m.n)\"}),\"\\u3002 \\u77E9\\u9635\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5143\\u7D20\\u53EA\\u8BBF\\u95EE\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002 \\u5FFD\\u7565 \",(0,n.jsx)(e.code,{children:\"result\"}),\" \\u6570\\u7EC4\\uFF0C\\u6240\\u9700\\u7684\\u989D\\u5916\\u7A7A\\u95F4\\u662F\\u6052\\u5B9A\\u7684\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u6807\\u8BB0\\u5DF2\\u8BBF\\u95EE\\u7684\\u5143\\u7D20\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u4EFB\\u52A1\\u6D89\\u53CA\\u4EE5\\u87BA\\u65CB\\u987A\\u5E8F\\u904D\\u5386\\u4E8C\\u7EF4\\u77E9\\u9635\\uFF0C\\u4ECE\\u5DE6\\u4E0A\\u89D2\\u5F00\\u59CB\\uFF0C\\u6309\\u987A\\u65F6\\u9488\\u65B9\\u5411\\u8FDB\\u884C\\u3002 \\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u6807\\u8BB0\\u6765\\u6807\\u8BC6\\u5DF2\\u8BBF\\u95EE\\u7684\\u5355\\u5143\\u683C\\uFF0C\\u5E76\\u786E\\u4FDD\\u904D\\u5386\\u7EE7\\u7EED\\u8FDB\\u884C\\uFF0C\\u76F4\\u5230\\u6240\\u6709\\u5143\\u7D20\\u90FD\\u6DFB\\u52A0\\u5230\\u7ED3\\u679C\\u4E2D\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u77E9\\u9635\\u4EE5\\u56DB\\u79CD\\u53EF\\u80FD\\u7684\\u65B9\\u5411\\u904D\\u5386\\uFF1A\\u53F3\\u3001\\u4E0B\\u3001\\u5DE6\\u548C\\u4E0A\\u3002 \\u8BE5\\u7B97\\u6CD5\\u8DDF\\u8E2A\\u5F53\\u524D\\u4F4D\\u7F6E\\u548C\\u65B9\\u5411\\u3002 \\u5F53\\u9047\\u5230\\u8FB9\\u754C\\u6216\\u5148\\u524D\\u8BBF\\u95EE\\u8FC7\\u7684\\u5355\\u5143\\u683C\\u65F6\\uFF0C\\u65B9\\u5411\\u4F1A\\u53D1\\u751F\\u53D8\\u5316\\u3002 \\u6B64\\u8FC7\\u7A0B\\u4E00\\u76F4\\u6301\\u7EED\\u5230\\u7B97\\u6CD5\\u5FAA\\u73AF\\u4E24\\u6B21\\u65B9\\u5411\\u53D8\\u5316\\u800C\\u672A\\u6DFB\\u52A0\\u4EFB\\u4F55\\u65B0\\u5143\\u7D20\\uFF0C\\u8FD9\\u8868\\u660E\\u6240\\u6709\\u5143\\u7D20\\u90FD\\u5DF2\\u88AB\\u8BBF\\u95EE\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u6D88\\u9664\\u4E86\\u901A\\u8FC7\\u52A8\\u6001\\u68C0\\u67E5\\u4E0B\\u4E00\\u4E2A\\u5355\\u5143\\u683C\\u7684\\u6709\\u6548\\u6027\\u6765\\u663E\\u5F0F\\u8DDF\\u8E2A\\u8FB9\\u754C\\u7684\\u9700\\u8981\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u53D8\\u91CF\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"VISITED\"}),\" \\u5B9A\\u4E49\\u4E3A\\u5DF2\\u8BBF\\u95EE\\u5355\\u5143\\u683C\\u7684\\u6807\\u8BB0\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u68C0\\u7D22\\u77E9\\u9635\\u4E2D\\u7684\\u884C\\u6570\\u548C\\u5217\\u6570\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521B\\u5EFA \",(0,n.jsx)(e.code,{children:\"result\"}),\" \\u6570\\u7EC4\\uFF0C\\u4ECE\\u5DE6\\u4E0A\\u89D2\\u5143\\u7D20\\u5F00\\u59CB\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u4E3A\\u5176\\u5206\\u914D \",(0,n.jsx)(e.code,{children:\"VISITED\"}),\" \\u503C\\u6765\\u5C06\\u5DE6\\u4E0A\\u89D2\\u5355\\u5143\\u683C\\u6807\\u8BB0\\u4E3A\\u5DF2\\u8BBF\\u95EE\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5B9A\\u4E49\\u904D\\u5386\\u7684\\u56DB\\u4E2A\\u53EF\\u80FD\\u65B9\\u5411\\uFF1A\\u53F3\\u3001\\u4E0B\\u3001\\u5DE6\\u548C\\u4E0A\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"currentDirection\"}),\" \\u521D\\u59CB\\u5316\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF08\\u53F3\\uFF09\\uFF0C\\u5C06 \",(0,n.jsx)(e.code,{children:\"changeDirection\"}),\" \\u521D\\u59CB\\u5316\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u4EE5\\u8DDF\\u8E2A\\u8FDE\\u7EED\\u7684\\u65B9\\u5411\\u53D8\\u5316\\uFF0C\\u800C\\u65E0\\u9700\\u6DFB\\u52A0\\u5143\\u7D20\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u77E9\\u9635\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5F53 \",(0,n.jsx)(e.code,{children:\"changeDirection\"}),\" \\u5C0F\\u4E8E \",(0,n.jsx)(e.code,{children:\"2\"}),\" \\u65F6\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u6CBF\\u5F53\\u524D\\u65B9\\u5411\\u79FB\\u52A8\\uFF0C\\u76F4\\u5230\\u9047\\u5230\\u8FB9\\u754C\\u6216\\u5DF2\\u8BBF\\u95EE\\u7684\\u5355\\u5143\\u683C\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u6B21\\u6709\\u6548\\u79FB\\u52A8\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u66F4\\u65B0\\u5F53\\u524D\\u4F4D\\u7F6E\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u5F53\\u524D\\u4F4D\\u7F6E\\u7684\\u5143\\u7D20\\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"result\"}),\" \\u6570\\u7EC4\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5C06\\u5355\\u5143\\u683C\\u6807\\u8BB0\\u4E3A\\u5DF2\\u8BBF\\u95EE\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"changeDirection\"}),\" \\u91CD\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u5C06 \",(0,n.jsx)(e.code,{children:\"currentDirection\"}),\" \\u66F4\\u65B0\\u4E3A\\u5E8F\\u5217\\u4E2D\\u7684\\u4E0B\\u4E00\\u4E2A\\u503C\\u6765\\u66F4\\u6539\\u65B9\\u5411\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u9012\\u589E \",(0,n.jsx)(e.code,{children:\"changeDirection\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"result\"}),\" \\u6570\\u7EC4\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(t,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m.n)\"}),\"\\u3002 \\u77E9\\u9635\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5143\\u7D20\\u53EA\\u8BBF\\u95EE\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002 \\u5FFD\\u7565 \",(0,n.jsx)(e.code,{children:\"result\"}),\" \\u6570\\u7EC4\\uFF0C\\u6240\\u9700\\u7684\\u989D\\u5916\\u7A7A\\u95F4\\u662F\\u6052\\u5B9A\\u7684\\u3002\"]}),`\n`]})]})}function S(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(m,r)})):m(r)}var C=S;return T(k);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/matrix-zeroing/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/matrix-zeroing/locales/zh-CN.json new file mode 100644 index 000000000..8232af28f --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/matrix-zeroing/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var u=Object.create;var c=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var j=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),w=(t,e)=>{for(var r in e)c(t,r,{get:e[r],enumerable:!0})},l=(t,e,r,i)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let o of p(e))!g.call(t,o)&&o!==r&&c(t,o,{get:()=>e[o],enumerable:!(i=x(e,o))||i.enumerable});return t};var _=(t,e,r)=>(r=t!=null?u(f(t)):{},l(e||!t||!t.__esModule?c(r,\"default\",{value:t,enumerable:!0}):r,t)),T=t=>l(c({},\"__esModule\",{value:!0}),t);var s=j((E,d)=>{d.exports=_jsx_runtime});var b={};w(b,{default:()=>X,frontmatter:()=>C});var n=_(s());var a=MDXTestExamples;var m=[{input:[[\"matrix\",[[1,2,0],[4,0,6],[7,8,9]]]],output:[[0,0,0],[0,0,0],[7,0,0]],explanation:\"The elements at (row 0, column 2) and (row 1, column 1) are 0, so their corresponding rows and columns are set to 0.\"},{input:[[\"matrix\",[[1,2,3],[4,5,6],[7,8,9]]]],output:[[1,2,3],[4,5,6],[7,8,9]],explanation:\"There are no zeroes in the matrix, so no changes are made.\"},{input:[[\"matrix\",[[1,2],[3,4],[5,0],[7,8]]]],output:[[1,0],[3,0],[0,0],[7,0]],explanation:\"The element at (row 2, column 1) is 0, so its corresponding rows and columns are set to 0.\"}];var C={title:\"\\u77E9\\u9635\\u7F6E\\u96F6\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u5C06\\u77E9\\u9635\\u7684\\u884C\\u548C\\u5217\\u8BBE\\u7F6E\\u4E3A\\u96F6\\u7684\\u51FD\\u6570\"};function h(t){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u5927\\u5C0F\\u4E3A \",(0,n.jsx)(e.code,{children:\"m\"}),\" x \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u7684 \",(0,n.jsx)(e.code,{children:\"matrix\"}),\"\\uFF0C\\u4FEE\\u6539\\u77E9\\u9635\\uFF0C\\u4F7F\\u5F97\\u5982\\u679C\\u4E00\\u4E2A\\u5143\\u7D20\\u662F \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u5219\\u5176\\u6574\\u884C\\u548C\\u6574\\u5217\\u90FD\\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u3002\\u66F4\\u6539\\u5E94\\u5C31\\u5730\\u8FDB\\u884C\\uFF0C\\u5373\\u76F4\\u63A5\\u5BF9\\u539F\\u59CB\\u77E9\\u9635\\u8FDB\\u884C\\u66F4\\u6539\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"matrix: number[][]\"}),\": \\u5927\\u5C0F\\u4E3A \",(0,n.jsx)(e.code,{children:\"m\"}),\" x \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u7684\\u4E8C\\u7EF4\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"matrix\"})]}),`\n`]}),`\n`,(0,n.jsx)(a,{testCases:m}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"m\"}),\", \",(0,n.jsx)(e.code,{children:\"n\"}),\" <= 100\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"-1000 <= \",(0,n.jsx)(e.code,{children:\"matrix[row][col]\"}),\" <= 1000\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u6311\\u6218\\uFF1A\\u4EC5\\u4F7F\\u7528 O(1) \\u989D\\u5916\\u7A7A\\u95F4\"}),`\n`]})]})}function D(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(h,t)})):h(t)}var X=D;return T(b);})();\n;return Component;", + "info": { + "excerpt": "实现一个将矩阵的行和列设置为零的函数", + "title": "矩阵置零" + }, + "solution": "var Component=(()=>{var u=Object.create;var c=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty;var w=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),C=(i,e)=>{for(var r in e)c(i,r,{get:e[r],enumerable:!0})},t=(i,e,r,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let l of j(e))!p.call(i,l)&&l!==r&&c(i,l,{get:()=>e[l],enumerable:!(o=x(e,l))||o.enumerable});return i};var O=(i,e,r)=>(r=i!=null?u(g(i)):{},t(e||!i||!i.__esModule?c(r,\"default\",{value:i,enumerable:!0}):r,i)),S=i=>t(c({},\"__esModule\",{value:!0}),i);var s=w((B,h)=>{h.exports=_jsx_runtime});var _={};C(_,{default:()=>M});var n=O(s());var d=MDXCodeBlock;var a=`export default function matrixZeroing(matrix: number[][]): void {\n // Flag to indicate if the first column should be zeroed\n let isCol = false;\n const ROWS = matrix.length;\n const COLS = matrix[0].length;\n\n // Iterate through the matrix\n for (let i = 0; i < ROWS; i++) {\n // Check if the first column needs to be zeroed\n if (matrix[i][0] === 0) {\n isCol = true;\n }\n // Check each cell in the row starting from the second column\n for (let j = 1; j < COLS; j++) {\n if (matrix[i][j] === 0) {\n // Mark the corresponding row and column in the first row and column\n matrix[0][j] = 0;\n matrix[i][0] = 0;\n }\n }\n }\n\n // Use the markers to set zeroes in the matrix (excluding the first row and column)\n for (let i = 1; i < ROWS; i++) {\n for (let j = 1; j < COLS; j++) {\n if (matrix[i][0] === 0 || matrix[0][j] === 0) {\n matrix[i][j] = 0;\n }\n }\n }\n\n // If the first cell of the matrix is zero, set the entire first row to zero\n if (matrix[0][0] === 0) {\n for (let j = 0; j < COLS; j++) {\n matrix[0][j] = 0;\n }\n }\n\n // If the first column needs to be zeroed, set the entire first column to zero\n if (isCol) {\n for (let i = 0; i < ROWS; i++) {\n matrix[i][0] = 0;\n }\n }\n}\n`;var m=`export default function matrixZeroing(matrix: number[][]): void {\n const rows = new Set(); // Set to keep track of rows that need to be zeroed\n const cols = new Set(); // Set to keep track of columns that need to be zeroed\n\n // First pass: Identify all rows and columns that contain a zero\n for (let i = 0; i < matrix.length; i++) {\n for (let j = 0; j < matrix[0].length; j++) {\n if (matrix[i][j] === 0) {\n rows.add(i); // Mark this row for zeroing\n cols.add(j); // Mark this column for zeroing\n }\n }\n }\n\n // Second pass: Update the matrix based on identified rows and columns\n for (let i = 0; i < matrix.length; i++) {\n for (let j = 0; j < matrix[0].length; j++) {\n if (rows.has(i) || cols.has(j)) {\n matrix[i][j] = 0; // Set element to zero if its row or column is marked\n }\n }\n }\n}\n`;function f(i){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",ol:\"ol\",li:\"li\",h3:\"h3\",ul:\"ul\",strong:\"strong\"},i.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u989D\\u5916\\u7A7A\\u95F4\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8BE5\\u95EE\\u9898\\u9700\\u8981\\u4FEE\\u6539\\u77E9\\u9635\\uFF0C\\u4F7F\\u5F97\\u5982\\u679C\\u4EFB\\u4F55\\u5355\\u5143\\u683C\\u5305\\u542B \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u5219\\u540C\\u4E00\\u884C\\u548C\\u5217\\u4E2D\\u7684\\u6240\\u6709\\u5355\\u5143\\u683C\\u90FD\\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u3002\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u989D\\u5916\\u7684\\u96C6\\u5408\\u6765\\u8DDF\\u8E2A\\u9700\\u8981\\u6E05\\u96F6\\u7684\\u884C\\u548C\\u5217\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u65B9\\u6CD5\\u6D89\\u53CA\\u5BF9\\u77E9\\u9635\\u8FDB\\u884C\\u4E24\\u6B21\\u904D\\u5386\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5728\\u7B2C\\u4E00\\u6B21\\u904D\\u5386\\u4E2D\\uFF0C\\u8BC6\\u522B\\u5305\\u542B\\u81F3\\u5C11\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"0\"}),\" \\u7684\\u6240\\u6709\\u884C\\u548C\\u5217\\uFF0C\\u5E76\\u5C06\\u5B83\\u4EEC\\u5B58\\u50A8\\u5728\\u5355\\u72EC\\u7684\\u96C6\\u5408\\u4E2D\\u3002\\u8FD9\\u907F\\u514D\\u4E86\\u7ACB\\u5373\\u4FEE\\u6539\\u77E9\\u9635\\uFF0C\\u8FD9\\u53EF\\u80FD\\u4F1A\\u5E72\\u6270\\u540E\\u7EED\\u68C0\\u67E5\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5728\\u7B2C\\u4E8C\\u6B21\\u904D\\u5386\\u4E2D\\uFF0C\\u6839\\u636E\\u5B58\\u50A8\\u5728\\u96C6\\u5408\\u4E2D\\u7684\\u4FE1\\u606F\\uFF0C\\u901A\\u8FC7\\u5C06\\u5DF2\\u8BC6\\u522B\\u7684\\u884C\\u548C\\u5217\\u4E2D\\u7684\\u6240\\u6709\\u5355\\u5143\\u683C\\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\" \\u6765\\u66F4\\u65B0\\u77E9\\u9635\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8FD9\\u79CD\\u8BC6\\u522B\\u548C\\u4FEE\\u6539\\u7684\\u5206\\u79BB\\u786E\\u4FDD\\u4E86\\u6B63\\u786E\\u6027\\uFF0C\\u5E76\\u907F\\u514D\\u4E86\\u8FC7\\u65E9\\u5730\\u5C06\\u53EF\\u80FD\\u5F71\\u54CD\\u540E\\u7EED\\u8BA1\\u7B97\\u7684\\u5143\\u7D20\\u6E05\\u96F6\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E24\\u4E2A\\u96C6\\u5408\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"rows\"}),\" \\u7528\\u4E8E\\u8DDF\\u8E2A\\u5305\\u542B\\u81F3\\u5C11\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"0\"}),\" \\u7684\\u884C\\u7D22\\u5F15\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"cols\"}),\" \\u7528\\u4E8E\\u8DDF\\u8E2A\\u5305\\u542B\\u81F3\\u5C11\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"0\"}),\" \\u7684\\u5217\\u7D22\\u5F15\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u77E9\\u9635\\u8FDB\\u884C\\u7B2C\\u4E00\\u6B21\\u904D\\u5386\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u5355\\u5143\\u683C \",(0,n.jsx)(e.code,{children:\"(i, j)\"}),\"\\uFF0C\\u5982\\u679C\\u5355\\u5143\\u683C\\u5305\\u542B \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u5219\\u5C06 \",(0,n.jsx)(e.code,{children:\"i\"}),\" \\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"rows\"}),\"\\uFF0C\\u5C06 \",(0,n.jsx)(e.code,{children:\"j\"}),\" \\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"cols\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u77E9\\u9635\\u8FDB\\u884C\\u7B2C\\u4E8C\\u6B21\\u904D\\u5386\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u5355\\u5143\\u683C \",(0,n.jsx)(e.code,{children:\"(i, j)\"}),\"\\uFF0C\\u68C0\\u67E5 \",(0,n.jsx)(e.code,{children:\"i\"}),\" \\u662F\\u5426\\u5728 \",(0,n.jsx)(e.code,{children:\"rows\"}),\" \\u4E2D\\u6216 \",(0,n.jsx)(e.code,{children:\"j\"}),\" \\u662F\\u5426\\u5728 \",(0,n.jsx)(e.code,{children:\"cols\"}),\" \\u4E2D\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u4EFB\\u4E00\\u6761\\u4EF6\\u4E3A\\u771F\\uFF0C\\u5219\\u5C06 \",(0,n.jsx)(e.code,{children:\"matrix[i][j]\"}),\" \\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u73B0\\u5728\\uFF0C\\u77E9\\u9635\\u5DF2\\u66F4\\u65B0\\uFF0C\\u6240\\u6709\\u76F8\\u5173\\u7684\\u884C\\u548C\\u5217\\u90FD\\u5DF2\\u6E05\\u96F6\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(d,{children:m}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m.n)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u6D89\\u53CA\\u5BF9\\u77E9\\u9635\\u8FDB\\u884C\\u4E24\\u6B21\\u904D\\u5386\\uFF0C\\u6BCF\\u6B21\\u8BBF\\u95EE\\u6240\\u6709 \",(0,n.jsx)(e.code,{children:\"m.n\"}),\" \\u4E2A\\u5143\\u7D20\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m + n)\"}),\"\\u3002\\u989D\\u5916\\u7684\\u96C6\\u5408 \",(0,n.jsx)(e.code,{children:\"rows\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"cols\"}),\" \\u6700\\u591A\\u5B58\\u50A8 \",(0,n.jsx)(e.code,{children:\"m\"}),\" \\u4E2A\\u884C\\u7D22\\u5F15\\u548C \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u4E2A\\u5217\\u7D22\\u5F15\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u7A7A\\u95F4\\u9AD8\\u6548\\u7684\\u89E3\\u51B3\\u65B9\\u6848\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8BE5\\u4EFB\\u52A1\\u9700\\u8981\\u4FEE\\u6539\\u77E9\\u9635\\uFF0C\\u4F7F\\u5F97\\u5982\\u679C\\u4EFB\\u4F55\\u5355\\u5143\\u683C\\u5305\\u542B \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u5219\\u540C\\u4E00\\u884C\\u548C\\u5217\\u4E2D\\u7684\\u6240\\u6709\\u5355\\u5143\\u683C\\u90FD\\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u3002\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u901A\\u8FC7\\u4F7F\\u7528\\u77E9\\u9635\\u7684\\u7B2C\\u4E00\\u884C\\u548C\\u7B2C\\u4E00\\u5217\\u4F5C\\u4E3A\\u6807\\u8BB0\\u800C\\u4E0D\\u662F\\u5206\\u914D\\u989D\\u5916\\u7684\\u7A7A\\u95F4\\uFF0C\\u4EE5\\u7A7A\\u95F4\\u9AD8\\u6548\\u7684\\u65B9\\u5F0F\\u5B9E\\u73B0\\u4E86\\u76EE\\u6807\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u65B9\\u6CD5\\u6D89\\u53CA\\u4E09\\u4E2A\\u4E3B\\u8981\\u6B65\\u9AA4\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u904D\\u5386\\u77E9\\u9635\\u5E76\\u4F7F\\u7528\\u7B2C\\u4E00\\u884C\\u548C\\u7B2C\\u4E00\\u5217\\u6765\\u6807\\u8BB0\\u9700\\u8981\\u6E05\\u96F6\\u7684\\u884C\\u548C\\u5217\\u3002\\u4F7F\\u7528\\u4E00\\u4E2A\\u5355\\u72EC\\u7684\\u6807\\u5FD7\\u6765\\u786E\\u5B9A\\u662F\\u5426\\u9700\\u8981\\u5C06\\u7B2C\\u4E00\\u5217\\u6E05\\u96F6\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u518D\\u6B21\\u904D\\u5386\\u77E9\\u9635\\uFF0C\\u6392\\u9664\\u7B2C\\u4E00\\u884C\\u548C\\u7B2C\\u4E00\\u5217\\uFF0C\\u5E76\\u6839\\u636E\\u6807\\u8BB0\\u66F4\\u65B0\\u5143\\u7D20\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u9700\\u8981\\uFF0C\\u6839\\u636E\\u6807\\u8BB0\\u548C\\u5355\\u72EC\\u7684\\u6807\\u5FD7\\u66F4\\u65B0\\u7B2C\\u4E00\\u884C\\u548C\\u7B2C\\u4E00\\u5217\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u6B64\\u65B9\\u6CD5\\u786E\\u4FDD\\u4E0D\\u9700\\u8981\\u8F93\\u5165\\u77E9\\u9635\\u4E4B\\u5916\\u7684\\u989D\\u5916\\u7A7A\\u95F4\\uFF0C\\u4F7F\\u5176\\u5177\\u6709\\u7A7A\\u95F4\\u6548\\u7387\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u6807\\u5FD7 \",(0,n.jsx)(e.code,{children:\"isCol\"}),\" \\u521D\\u59CB\\u5316\\u4E3A \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\uFF0C\\u4EE5\\u8DDF\\u8E2A\\u662F\\u5426\\u9700\\u8981\\u5C06\\u7B2C\\u4E00\\u5217\\u6E05\\u96F6\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u77E9\\u9635\\u8FDB\\u884C\\u7B2C\\u4E00\\u6B21\\u904D\\u5386\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u5355\\u5143\\u683C \",(0,n.jsx)(e.code,{children:\"(i, j)\"}),\"\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5355\\u5143\\u683C\\u5728\\u7B2C\\u4E00\\u5217\\u4E2D\\u5E76\\u5305\\u542B \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u5219\\u5C06 \",(0,n.jsx)(e.code,{children:\"isCol\"}),\" \\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5355\\u5143\\u683C\\u4E0D\\u5728\\u7B2C\\u4E00\\u5217\\u4E2D\\u5E76\\u5305\\u542B \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u5219\\u5C06\\u76F8\\u5E94\\u7684\\u7B2C\\u4E00\\u4E2A\\u884C\\u548C\\u7B2C\\u4E00\\u4E2A\\u5217\\u6807\\u8BB0\\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u77E9\\u9635\\u8FDB\\u884C\\u7B2C\\u4E8C\\u6B21\\u904D\\u5386\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u5355\\u5143\\u683C \",(0,n.jsx)(e.code,{children:\"(i, j)\"}),\"\\uFF0C\\u5176\\u4E2D \",(0,n.jsx)(e.code,{children:\"i > 0\"}),\" \\u4E14 \",(0,n.jsx)(e.code,{children:\"j > 0\"}),\"\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u7B2C\\u4E00\\u884C\\u6216\\u7B2C\\u4E00\\u5217\\u4E2D\\u7684\\u76F8\\u5E94\\u6807\\u8BB0\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u5219\\u5C06 \",(0,n.jsx)(e.code,{children:\"matrix[i][j]\"}),\" \\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u77E9\\u9635\\u7684\\u7B2C\\u4E00\\u4E2A\\u5355\\u5143\\u683C (\",(0,n.jsx)(e.code,{children:\"matrix[0][0]\"}),\") \\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u5219\\u5C06\\u6574\\u4E2A\\u7B2C\\u4E00\\u884C\\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"isCol\"}),\" \\u4E3A \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\uFF0C\\u5219\\u5C06\\u6574\\u4E2A\\u7B2C\\u4E00\\u5217\\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(d,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m.n)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u6D89\\u53CA\\u5BF9\\u77E9\\u9635\\u8FDB\\u884C\\u4E24\\u6B21\\u904D\\u5386\\uFF0C\\u6BCF\\u6B21\\u8BBF\\u95EE\\u6240\\u6709 \",(0,n.jsx)(e.code,{children:\"m.n\"}),\" \\u4E2A\\u5143\\u7D20\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u9664\\u4E86\\u8F93\\u5165\\u77E9\\u9635\\u548C\\u5355\\u4E2A\\u6807\\u5FD7\\u5916\\uFF0C\\u6CA1\\u6709\\u4F7F\\u7528\\u989D\\u5916\\u7684\\u7A7A\\u95F4\\u3002\"]}),`\n`]})]})}function b(i={}){let{wrapper:e}=i.components||{};return e?(0,n.jsx)(e,Object.assign({},i,{children:(0,n.jsx)(f,i)})):f(i)}var M=b;return S(_);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/maximum-water-between-walls/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/maximum-water-between-walls/locales/zh-CN.json new file mode 100644 index 000000000..ebbc5ad9e --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/maximum-water-between-walls/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var w=Object.create;var s=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var f=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),b=(e,t)=>{for(var i in t)s(e,i,{get:t[i],enumerable:!0})},o=(e,t,i,r)=>{if(t&&typeof t==\"object\"||typeof t==\"function\")for(let l of p(t))!g.call(e,l)&&l!==i&&s(e,l,{get:()=>t[l],enumerable:!(r=m(t,l))||r.enumerable});return e};var j=(e,t,i)=>(i=e!=null?w(x(e)):{},o(t||!e||!e.__esModule?s(i,\"default\",{value:e,enumerable:!0}):i,e)),C=e=>o(s({},\"__esModule\",{value:!0}),e);var a=f((E,h)=>{h.exports=_jsx_runtime});var D={};b(D,{default:()=>y,frontmatter:()=>T});var n=j(a());var c=MDXTestExamples;var d=[{input:[[\"walls\",[1,4,2,3]]],output:6,explanation:\"Consider two walls (i=1 & i=3) with heights 4 and 3. The water is limited by the shorter wall with height 3, so the container holds 2 (distance) * 3 (shorter height) = 6 units. All other combination of walls result in smaller area.\"},{input:[[\"walls\",[1,1]]],output:1,explanation:\"Consider two walls (i=0 & i=1) with heights 1 and 1. The water is limited by the shorter wall (both same in this case i.e. 1), so the container holds 1 (distance) * 1 (shorter height) = 1 unit\"},{input:[[\"walls\",[1,0]]],output:0,explanation:\"Consider two walls (i=0 & i=1) with heights 1 and 0. The water is limited by the shorter wall with height 0, so the container holds 1 (distance) * 0 (shorter height) = 0 unit\"}];var T={title:\"\\u5899\\u58C1\\u4E4B\\u95F4\\u7684\\u6700\\u5927\\u84C4\\u6C34\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u7528\\u4E8E\\u67E5\\u627E\\u5899\\u58C1\\u6570\\u7EC4\\u4E2D\\u4E24\\u4E2A\\u5899\\u58C1\\u4E4B\\u95F4\\u7684\\u6700\\u5927\\u84C4\\u6C34\\u4F53\\u79EF\"};function u(e){let t=Object.assign({p:\"p\",code:\"code\",strong:\"strong\",h3:\"h3\",ul:\"ul\",li:\"li\"},e.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u5899\\u58C1\\u9AD8\\u5EA6\\u6570\\u7EC4\",(0,n.jsx)(t.code,{children:\"walls\"}),\"\\uFF0C\\u8BA1\\u7B97\\u5728\\u503E\\u76C6\\u5927\\u96E8\\u540E\\uFF0C\",(0,n.jsx)(t.strong,{children:\"\\u4E24\\u4E2A\\u5899\\u58C1\"}),\"\\u548Cx\\u8F74\\u4E4B\\u95F4\\u5C06\\u6355\\u83B7\\u7684\\u6700\\u5927\\u84C4\\u6C34\\u4F53\\u79EF\\u3002\"]}),`\n`,(0,n.jsx)(t.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(t.ul,{children:[`\n`,(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:\"walls: number[]\"}),\": \\u6574\\u6570\\u6570\\u7EC4\"]}),`\n`]}),`\n`,(0,n.jsx)(c,{testCases:d}),`\n`,(0,n.jsx)(t.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(t.ul,{children:[`\n`,(0,n.jsxs)(t.li,{children:[\"2 <= \",(0,n.jsx)(t.code,{children:\"walls.length\"}),\" <= 1000\"]}),`\n`,(0,n.jsxs)(t.li,{children:[\"0 <= \",(0,n.jsx)(t.code,{children:\"walls[i]\"}),\" <= 10,000\"]}),`\n`]})]})}function M(e={}){let{wrapper:t}=e.components||{};return t?(0,n.jsx)(t,Object.assign({},e,{children:(0,n.jsx)(u,e)})):u(e)}var y=M;return C(D);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,用于查找墙壁数组中两个墙壁之间的最大蓄水体积", + "title": "墙壁之间的最大蓄水" + }, + "solution": "var Component=(()=>{var u=Object.create;var i=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty;var A=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),W=(n,e)=>{for(var r in e)i(n,r,{get:e[r],enumerable:!0})},c=(n,e,r,a)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let t of w(e))!p.call(n,t)&&t!==r&&i(n,t,{get:()=>e[t],enumerable:!(a=g(e,t))||a.enumerable});return n};var b=(n,e,r)=>(r=n!=null?u(x(n)):{},c(e||!n||!n.__esModule?i(r,\"default\",{value:n,enumerable:!0}):r,n)),M=n=>c(i({},\"__esModule\",{value:!0}),n);var o=A((y,d)=>{d.exports=_jsx_runtime});var _={};W(_,{default:()=>C});var l=b(o());var h=MDXCodeBlock;var s=`export default function maximumWaterBetweenWalls(walls: number[]): number {\n // Initialize variables for pointers and maximum area\n let left = 0;\n let right = walls.length - 1;\n let maxWaterArea = 0;\n\n // Iterate while left and right pointers haven't crossed\n while (left < right) {\n // Calculate the area formed between the walls pointed by 'left' and 'right'.\n // The height is limited by the shorter wall, and the width is (right - left).\n const currentArea = (right - left) * Math.min(walls[left], walls[right]);\n maxWaterArea = Math.max(maxWaterArea, currentArea);\n\n // Move the pointer with the shorter height towards the center\n // By doing this, we give a chance to find a taller wall and potentially increase the area.\n if (walls[left] < walls[right]) {\n left++;\n } else {\n right--;\n }\n }\n\n return maxWaterArea;\n}\n`;var m=`export default function maximumWaterBetweenWalls(walls: number[]): number {\n // Initialize the maximum area to 0\n let maxArea = 0;\n\n // Iterate over each pair of walls\n for (let left = 0; left < walls.length; left++) {\n for (let right = left + 1; right < walls.length; right++) {\n // Calculate the width between the walls\n const width = right - left;\n\n // Calculate the area using the shorter wall\n const currentArea = Math.min(walls[left], walls[right]) * width;\n\n // Update maxArea if the current area is larger\n maxArea = Math.max(maxArea, currentArea);\n }\n }\n\n // Return the maximum area found\n return maxArea;\n}\n`;function f(n){let e=Object.assign({h2:\"h2\",p:\"p\",h3:\"h3\",ol:\"ol\",li:\"li\",code:\"code\",ul:\"ul\",strong:\"strong\"},n.components);return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(e.h2,{children:\"1. \\u66B4\\u529B\\u89E3\\u6CD5\"}),`\n`,(0,l.jsx)(e.p,{children:\"\\u66B4\\u529B\\u89E3\\u6CD5\\u662F\\u627E\\u5230\\u4E24\\u4E2A\\u5899\\u4E4B\\u95F4\\u53EF\\u4EE5\\u622A\\u7559\\u7684\\u6700\\u5927\\u6C34\\u91CF\\u3002 \\u60F3\\u6CD5\\u662F\\u8BC4\\u4F30\\u8F93\\u5165\\u6570\\u7EC4\\u4E2D\\u6BCF\\u5BF9\\u53EF\\u80FD\\u7684\\u5899\\uFF0C\\u5E76\\u8BA1\\u7B97\\u5B83\\u4EEC\\u4E4B\\u95F4\\u53EF\\u4EE5\\u5BB9\\u7EB3\\u7684\\u6C34\\u91CF\\u3002 \\u5BB9\\u7EB3\\u7684\\u6C34\\u91CF\\u7531\\u8BE5\\u5BF9\\u4E2D\\u8F83\\u77ED\\u7684\\u5899\\u548C\\u4E24\\u4E2A\\u5899\\u4E4B\\u95F4\\u7684\\u8DDD\\u79BB\\u51B3\\u5B9A\\u3002\"}),`\n`,(0,l.jsx)(e.p,{children:\"\\u66B4\\u529B\\u89E3\\u6CD5\\u786E\\u4FDD\\u8003\\u8651\\u4E86\\u6240\\u6709\\u5899\\u5BF9\\u3002 \\u8BE5\\u7B97\\u6CD5\\u4F7F\\u7528\\u5D4C\\u5957\\u5FAA\\u73AF\\u904D\\u5386\\u6BCF\\u5BF9\\u53EF\\u80FD\\u7684\\u5899\\uFF0C\\u5E76\\u8BA1\\u7B97\\u6BCF\\u5BF9\\u5899\\u7684\\u9762\\u79EF\\u3002 \\u5728\\u6B64\\u8FC7\\u7A0B\\u4E2D\\u627E\\u5230\\u7684\\u6700\\u5927\\u9762\\u79EF\\u4F5C\\u4E3A\\u7ED3\\u679C\\u8FD4\\u56DE\\u3002\"}),`\n`,(0,l.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,l.jsxs)(e.ol,{children:[`\n`,(0,l.jsxs)(e.li,{children:[\"\\u5C06\\u53D8\\u91CF \",(0,l.jsx)(e.code,{children:\"maxArea\"}),\" \\u521D\\u59CB\\u5316\\u4E3A \",(0,l.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u4EE5\\u8DDF\\u8E2A\\u627E\\u5230\\u7684\\u6700\\u5927\\u6C34\\u57DF\\u9762\\u79EF\\u3002\"]}),`\n`,(0,l.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u5D4C\\u5957\\u5FAA\\u73AF\\u904D\\u5386\\u6240\\u6709\\u5899\\u5BF9\\uFF1A\",`\n`,(0,l.jsxs)(e.ol,{children:[`\n`,(0,l.jsx)(e.li,{children:\"\\u5916\\u5FAA\\u73AF\\u4EE3\\u8868\\u5DE6\\u5899\\uFF0C\\u4ECE\\u7B2C\\u4E00\\u5835\\u5899\\u8FED\\u4EE3\\u5230\\u5012\\u6570\\u7B2C\\u4E8C\\u5835\\u5899\\u3002\"}),`\n`,(0,l.jsx)(e.li,{children:\"\\u5185\\u5FAA\\u73AF\\u4EE3\\u8868\\u53F3\\u5899\\uFF0C\\u4ECE\\u5DE6\\u5899\\u4E4B\\u540E\\u7684\\u4E00\\u5835\\u5899\\u8FED\\u4EE3\\u5230\\u6700\\u540E\\u4E00\\u5835\\u5899\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,l.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u5BF9\\u5899\\uFF0C\\u8BA1\\u7B97\\u5899\\u4E4B\\u95F4\\u7684\\u5BBD\\u5EA6\\u4E3A \",(0,l.jsx)(e.code,{children:\"right - left\"}),\"\\u3002\"]}),`\n`,(0,l.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u8F83\\u77ED\\u7684\\u5899\\u901A\\u8FC7\\u8C03\\u7528 \",(0,l.jsx)(e.code,{children:\"Math.min(walls[left], walls[right])\"}),\" \\u6765\\u786E\\u5B9A\\u5BB9\\u5668\\u7684\\u9AD8\\u5EA6\\u3002\"]}),`\n`,(0,l.jsx)(e.li,{children:\"\\u901A\\u8FC7\\u5C06\\u9AD8\\u5EA6\\u548C\\u5BBD\\u5EA6\\u76F8\\u4E58\\u6765\\u8BA1\\u7B97\\u53EF\\u4EE5\\u5BB9\\u7EB3\\u7684\\u6C34\\u57DF\\u9762\\u79EF\\u3002\"}),`\n`,(0,l.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u5F53\\u524D \",(0,l.jsx)(e.code,{children:\"maxArea\"}),\" \\u548C\\u65B0\\u8BA1\\u7B97\\u7684\\u9762\\u79EF\\u4E4B\\u95F4\\u7684\\u8F83\\u5927\\u503C\\u66F4\\u65B0 \",(0,l.jsx)(e.code,{children:\"maxArea\"}),\"\\u3002\"]}),`\n`,(0,l.jsxs)(e.li,{children:[\"\\u5B8C\\u6210\\u5D4C\\u5957\\u5FAA\\u73AF\\u540E\\uFF0C\\u8FD4\\u56DE \",(0,l.jsx)(e.code,{children:\"maxArea\"}),\" \\u4F5C\\u4E3A\\u7ED3\\u679C\\u3002\"]}),`\n`]}),`\n`,(0,l.jsx)(h,{children:m}),`\n`,(0,l.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,l.jsxs)(e.ul,{children:[`\n`,(0,l.jsxs)(e.li,{children:[(0,l.jsxs)(e.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,l.jsx)(\"sup\",{children:\"2\"}),\")\"]}),\"\\u3002 \\u5D4C\\u5957\\u5FAA\\u73AF\\u904D\\u5386\\u6240\\u6709\\u5899\\u5BF9\\uFF0C\\u5BFC\\u81F4\\u4E8C\\u6B21\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u3002\"]}),`\n`,(0,l.jsxs)(e.li,{children:[(0,l.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002 \\u9664\\u4E86\\u7528\\u4E8E\\u8DDF\\u8E2A\\u6700\\u5927\\u9762\\u79EF\\u548C\\u8BA1\\u7B97\\u503C\\u7684\\u4E00\\u4E9B\\u53D8\\u91CF\\u5916\\uFF0C\\u6CA1\\u6709\\u4F7F\\u7528\\u989D\\u5916\\u7684\\u7A7A\\u95F4\\u3002\"]}),`\n`]}),`\n`,(0,l.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u53CC\\u6307\\u9488\"}),`\n`,(0,l.jsx)(e.p,{children:\"\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u53CC\\u6307\\u9488\\u6280\\u672F\\u6765\\u4F18\\u5316\\u67E5\\u627E\\u4E24\\u4E2A\\u5899\\u4E4B\\u95F4\\u53EF\\u4EE5\\u622A\\u7559\\u7684\\u6700\\u5927\\u6C34\\u91CF\\u7684\\u8FC7\\u7A0B\\u3002 \\u60F3\\u6CD5\\u662F\\u4F7F\\u7528\\u4E24\\u4E2A\\u6307\\u9488\\uFF0C\\u4E00\\u4E2A\\u4ECE\\u6700\\u5DE6\\u8FB9\\u7684\\u5899\\u5F00\\u59CB\\uFF0C\\u53E6\\u4E00\\u4E2A\\u4ECE\\u6700\\u53F3\\u8FB9\\u7684\\u5899\\u5F00\\u59CB\\uFF0C\\u5E76\\u8BA1\\u7B97\\u5B83\\u4EEC\\u4E4B\\u95F4\\u7684\\u9762\\u79EF\\u3002 \\u9762\\u79EF\\u7531\\u8F83\\u77ED\\u7684\\u5899\\u51B3\\u5B9A\\uFF0C\\u56E0\\u4E3A\\u5B83\\u9650\\u5236\\u4E86\\u9AD8\\u5EA6\\uFF0C\\u4EE5\\u53CA\\u4E24\\u4E2A\\u5899\\u4E4B\\u95F4\\u7684\\u5BBD\\u5EA6\\u3002\"}),`\n`,(0,l.jsxs)(e.p,{children:[\"\\u4E0E\\u66B4\\u529B\\u89E3\\u6CD5\\u4E00\\u6837\\uFF0C\\u4E0D\\u662F\\u8BC4\\u4F30\\u6BCF\\u5BF9\\u53EF\\u80FD\\u7684\\u5899\\uFF0C\\u53CC\\u6307\\u9488\\u6280\\u672F\\u901A\\u8FC7\\u79FB\\u52A8\\u6307\\u9488\\u6D88\\u9664\\u4E86\\u4E0D\\u5FC5\\u8981\\u7684\\u6BD4\\u8F83\\u3002 \\u901A\\u8FC7\\u59CB\\u7EC8\\u5C06\\u8F83\\u77ED\\u5899\\u7684\\u6307\\u9488\\u5411\\u5185\\u79FB\\u52A8\\uFF0C\\u8BE5\\u7B97\\u6CD5\\u786E\\u4FDD\\u5BBD\\u5EA6\\u51CF\\u5C0F\\uFF0C\\u540C\\u65F6\\u5C1D\\u8BD5\\u627E\\u5230\\u53EF\\u80FD\\u589E\\u52A0\\u9762\\u79EF\\u7684\\u8F83\\u9AD8\\u5899\\u3002 \\u8FD9\\u79CD\\u65B9\\u6CD5\\u907F\\u514D\\u4E86\\u4E0D\\u5FC5\\u8981\\u6216\\u91CD\\u590D\\u7684\\u5DE5\\u4F5C\\uFF0C\\u5C06\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4ECE O(n\",(0,l.jsx)(\"sup\",{children:\"2\"}),\") \\u964D\\u4F4E\\u5230 O(n)\\u3002\"]}),`\n`,(0,l.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,l.jsxs)(e.ol,{children:[`\n`,(0,l.jsxs)(e.li,{children:[\"\\u5C06\\u4E24\\u4E2A\\u6307\\u9488\\u521D\\u59CB\\u5316\\uFF0C\",(0,l.jsx)(e.code,{children:\"left\"}),\" \\u5728\\u6570\\u7EC4\\u7684\\u5F00\\u5934\\uFF0C\",(0,l.jsx)(e.code,{children:\"right\"}),\" \\u5728\\u6570\\u7EC4\\u7684\\u7ED3\\u5C3E\\u3002\"]}),`\n`,(0,l.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u53D8\\u91CF \",(0,l.jsx)(e.code,{children:\"maxWaterArea\"}),\" \\u6765\\u5B58\\u50A8\\u627E\\u5230\\u7684\\u6700\\u5927\\u6C34\\u57DF\\u9762\\u79EF\\u3002\"]}),`\n`,(0,l.jsxs)(e.li,{children:[\"\\u4F7F\\u7528 \",(0,l.jsx)(e.code,{children:\"while\"}),\" \\u5FAA\\u73AF\\u8FDB\\u884C\\u8FED\\u4EE3\\uFF0C\\u53EA\\u8981 \",(0,l.jsx)(e.code,{children:\"left\"}),\" \\u5C0F\\u4E8E \",(0,l.jsx)(e.code,{children:\"right\"}),\"\\uFF1A\",`\n`,(0,l.jsxs)(e.ol,{children:[`\n`,(0,l.jsxs)(e.li,{children:[\"\\u8BA1\\u7B97\\u7531 \",(0,l.jsx)(e.code,{children:\"left\"}),\" \\u548C \",(0,l.jsx)(e.code,{children:\"right\"}),\" \\u6307\\u5411\\u7684\\u5899\\u4E4B\\u95F4\\u7684\\u9762\\u79EF\\u3002 \\u9AD8\\u5EA6\\u662F\\u4E24\\u5835\\u5899\\u4E2D\\u8F83\\u5C0F\\u7684\\u4E00\\u5835\\uFF0C\\u5BBD\\u5EA6\\u662F\\u6307\\u9488\\u4E4B\\u95F4\\u7684\\u8DDD\\u79BB (\",(0,l.jsx)(e.code,{children:\"right - left\"}),\")\\u3002\"]}),`\n`,(0,l.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u5F53\\u524D \",(0,l.jsx)(e.code,{children:\"maxWaterArea\"}),\" \\u548C\\u65B0\\u8BA1\\u7B97\\u7684\\u9762\\u79EF\\u4E4B\\u95F4\\u7684\\u8F83\\u5927\\u503C\\u66F4\\u65B0 \",(0,l.jsx)(e.code,{children:\"maxWaterArea\"}),\"\\u3002\"]}),`\n`,(0,l.jsxs)(e.li,{children:[\"\\u5C06\\u8F83\\u77ED\\u5899\\u7684\\u6307\\u9488\\u5411\\u5185\\u79FB\\u52A8\\uFF1A\",`\n`,(0,l.jsxs)(e.ul,{children:[`\n`,(0,l.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,l.jsx)(e.code,{children:\"walls[left]\"}),\" \\u8F83\\u5C0F\\uFF0C\\u5219\\u9012\\u589E \",(0,l.jsx)(e.code,{children:\"left\"}),\" \\u4EE5\\u627E\\u5230\\u66F4\\u9AD8\\u7684\\u5899\\u3002\"]}),`\n`,(0,l.jsxs)(e.li,{children:[\"\\u5426\\u5219\\uFF0C\\u9012\\u51CF \",(0,l.jsx)(e.code,{children:\"right\"}),\" \\u4EE5\\u5728\\u53F3\\u4FA7\\u627E\\u5230\\u66F4\\u9AD8\\u7684\\u5899\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,l.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE \",(0,l.jsx)(e.code,{children:\"maxWaterArea\"}),\" \\u4F5C\\u4E3A\\u627E\\u5230\\u7684\\u6700\\u5927\\u6C34\\u57DF\\u9762\\u79EF\\u3002\"]}),`\n`]}),`\n`,(0,l.jsx)(h,{children:s}),`\n`,(0,l.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,l.jsxs)(e.ul,{children:[`\n`,(0,l.jsxs)(e.li,{children:[(0,l.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002 \\u6BCF\\u4E2A\\u6307\\u9488\\u6700\\u591A\\u79FB\\u52A8 \",(0,l.jsx)(e.code,{children:\"n\"}),\" \\u6B65\\uFF0C\\u5BFC\\u81F4\\u7EBF\\u6027\\u8FD0\\u884C\\u65F6\\u3002\"]}),`\n`,(0,l.jsxs)(e.li,{children:[(0,l.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002 \\u9664\\u4E86\\u7528\\u4E8E\\u8DDF\\u8E2A\\u6307\\u9488\\u548C\\u9762\\u79EF\\u8BA1\\u7B97\\u7684\\u51E0\\u4E2A\\u53D8\\u91CF\\u5916\\uFF0C\\u4E0D\\u9700\\u8981\\u989D\\u5916\\u7684\\u7A7A\\u95F4\\u3002\"]}),`\n`]})]})}function j(n={}){let{wrapper:e}=n.components||{};return e?(0,l.jsx)(e,Object.assign({},n,{children:(0,l.jsx)(f,n)})):f(n)}var C=j;return M(_);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/merge-sort/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/merge-sort/locales/zh-CN.json new file mode 100644 index 000000000..ab1decff4 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/merge-sort/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var o=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var x=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),j=(n,e)=>{for(var r in e)o(n,r,{get:e[r],enumerable:!0})},i=(n,e,r,c)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let s of d(e))!u.call(n,s)&&s!==r&&o(n,s,{get:()=>e[s],enumerable:!(c=l(e,s))||c.enumerable});return n};var _=(n,e,r)=>(r=n!=null?p(h(n)):{},i(e||!n||!n.__esModule?o(r,\"default\",{value:n,enumerable:!0}):r,n)),f=n=>i(o({},\"__esModule\",{value:!0}),n);var a=x((F,m)=>{m.exports=_jsx_runtime});var C={};j(C,{default:()=>q,frontmatter:()=>M});var t=_(a()),M={title:\"\\u5F52\\u5E76\\u6392\\u5E8F\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u6267\\u884C\\u9012\\u5F52\\u5F52\\u5E76\\u6392\\u5E8F\\u7684\\u51FD\\u6570\"};function g(n){let e=Object.assign({p:\"p\",img:\"img\",h2:\"h2\",pre:\"pre\",code:\"code\"},n.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(e.p,{children:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u6267\\u884C\\u9012\\u5F52\\u5F52\\u5E76\\u6392\\u5E8F\\u7684\\u51FD\\u6570\\u3002\\u8BE5\\u51FD\\u6570\\u5E94\\u8BE5\\u662F\\u9012\\u5F52\\u7684\\uFF0C\\u5E76\\u63A5\\u53D7\\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4\\u3002\\u8F93\\u51FA\\u5E94\\u8BE5\\u662F\\u4E00\\u4E2A\\u6309\\u5347\\u5E8F\\u6392\\u5E8F\\u7684\\u6570\\u7EC4\\u3002\"}),`\n`,(0,t.jsx)(e.p,{children:(0,t.jsx)(e.img,{src:\"/img/questions/merge-sort/merge-sort-input-output.png\",alt:\"\\u9012\\u5F52\\u5F52\\u5E76\\u6392\\u5E8F\\u7684\\u9884\\u671F\\u8F93\\u5165\\u548C\\u8F93\\u51FA\"})}),`\n`,(0,t.jsx)(e.h2,{children:\"\\u4F8B\\u5B50\"}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-js\",children:`mergeSort([9, 3, 6, 2, 1, 11]); // [1, 2, 3, 6, 9, 11]\nmergeSort([12, 16, 14, 1, 2, 3]); // [1, 2, 3, 12, 14, 16]\n`})}),`\n`,(0,t.jsx)(e.h2,{children:\"\\u56DE\\u987E\"}),`\n`,(0,t.jsx)(e.p,{children:\"\\u5F52\\u5E76\\u6392\\u5E8F\\u662F\\u4E00\\u79CD\\u9012\\u5F52\\u7B97\\u6CD5\\uFF0C\\u5B83\\u5206\\u800C\\u6CBB\\u4E4B\\u2014\\u2014\\u5B83\\u4E0D\\u65AD\\u5730\\u5C06\\u8F93\\u5165\\u6570\\u7EC4\\u5206\\u6210\\u4E24\\u534A\\uFF0C\\u76F4\\u5230\\u5B83\\u4E0D\\u80FD\\u518D\\u5206\\uFF08\\u5373\\u8FBE\\u5230\\u6570\\u7EC4\\u201C<= 1\\u201D\\u4E2A\\u5143\\u7D20\\u7684\\u57FA\\u672C\\u60C5\\u51B5\\u2014\\u2014\\u6839\\u636E\\u5B9A\\u4E49\\uFF0C\\u5B83\\u662F\\u6709\\u5E8F\\u7684\\uFF09\\u3002\\u7136\\u540E\\uFF0C\\u7B97\\u6CD5\\u7684\\u201C\\u5408\\u5E76\\u201D\\u90E8\\u5206\\u91CD\\u590D\\u5730\\u5C06\\u5355\\u72EC\\u6392\\u5E8F\\u7684\\u5B50\\u6570\\u7EC4\\u5408\\u5E76\\u6210\\u66F4\\u5927\\u7684\\u6570\\u7EC4\\uFF0C\\u76F4\\u5230\\u6574\\u4E2A\\u6570\\u7EC4\\u88AB\\u5408\\u5E76\\u3002\"}),`\n`,(0,t.jsx)(e.p,{children:\"\\u5408\\u5E76\\u8FC7\\u7A0B\\u6D89\\u53CA\\u521B\\u5EFA\\u4E00\\u4E2A\\u65B0\\u7684\\u7A7A\\u6570\\u7EC4\\uFF0C\\u5E76\\u91CD\\u590D\\u5730\\u4ECE\\u7B2C\\u4E00\\u534A\\u6216\\u7B2C\\u4E8C\\u534A\\u4E2D\\u53D6\\u6700\\u5C0F\\u7684\\u5143\\u7D20\\u3002\\u5F53\\u4E00\\u534A\\u4E3A\\u7A7A\\u65F6\\uFF0C\\u6211\\u4EEC\\u5C06\\u53E6\\u4E00\\u534A\\u7684\\u6240\\u6709\\u5143\\u7D20\\u9644\\u52A0\\u5230\\u65B0\\u6570\\u7EC4\\u4E2D\\u5E76\\u8FD4\\u56DE\\u5B83\\u3002\"}),`\n`,(0,t.jsx)(e.p,{children:(0,t.jsx)(e.img,{src:\"/img/questions/merge-sort/merge-sort-explanation.png\",alt:\"\\u9012\\u5F52\\u5F52\\u5E76\\u6392\\u5E8F\\u8BF4\\u660E\"})})]})}function b(n={}){let{wrapper:e}=n.components||{};return e?(0,t.jsx)(e,Object.assign({},n,{children:(0,t.jsx)(g,n)})):g(n)}var q=b;return f(C);})();\n;return Component;", + "info": { + "excerpt": "实现一个执行递归归并排序的函数", + "title": "归并排序" + }, + "solution": "var Component=(()=>{var u=Object.create;var i=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty;var b=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),x=(t,e)=>{for(var n in e)i(t,n,{get:e[n],enumerable:!0})},a=(t,e,n,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let l of p(e))!R.call(t,l)&&l!==n&&i(t,l,{get:()=>e[l],enumerable:!(o=f(e,l))||o.enumerable});return t};var M=(t,e,n)=>(n=t!=null?u(y(t)):{},a(e||!t||!t.__esModule?i(n,\"default\",{value:t,enumerable:!0}):n,t)),A=t=>a(i({},\"__esModule\",{value:!0}),t);var h=b((C,s)=>{s.exports=_jsx_runtime});var _={};x(_,{default:()=>w});var r=M(h());var m=MDXCodeBlock;var d=`/**\n * @param {Array} arr The input integer array to be sorted.\n * @return {Array}\n */\nexport default function mergeSort(arr) {\n // Return if array only has 0 or 1 elements (base case).\n if (arr.length <= 1) {\n return arr;\n }\n\n // Divide the array into two.\n const midPoint = Math.floor(arr.length / 2);\n const left = arr.slice(0, midPoint);\n const right = arr.slice(midPoint);\n\n // Merge sort each half recursively.\n const sortedLeft = mergeSort(left);\n const sortedRight = mergeSort(right);\n\n // Merge sorted halves.\n return merge(sortedLeft, sortedRight);\n}\n\n/**\n * Merges two sorted arrays of elements into one.\n * @param {Array} left\n * @param {Array} right\n * @return {Array}\n */\nfunction merge(left, right) {\n // Create an empty array to store the merged result.\n const mergedResult = [];\n\n let l = 0;\n let r = 0;\n // Repeatedly compare smallest element from each half\n // and append it to the merged result.\n // When one half runs out of elements,\n // append all the elements of the remaining half to the merged array\n while (l < left.length && r < right.length) {\n if (left[l] < right[r]) {\n mergedResult.push(left[l]);\n l++;\n } else {\n mergedResult.push(right[r]);\n r++;\n }\n }\n\n // Append any remaining elements from each sides.\n mergedResult.push(...left.slice(l), ...right.slice(r));\n return mergedResult;\n}\n`;var g=`export default function mergeSort(arr: Array): Array {\n // Return if array only has 0 or 1 elements (base case).\n if (arr.length <= 1) {\n return arr;\n }\n\n // Divide the array into two.\n const midPoint = Math.floor(arr.length / 2);\n const left = arr.slice(0, midPoint);\n const right = arr.slice(midPoint);\n\n // Merge sort each half recursively.\n const sortedLeft = mergeSort(left);\n const sortedRight = mergeSort(right);\n\n // Merge sorted halves.\n return merge(sortedLeft, sortedRight);\n}\n\n/**\n * Merges two sorted arrays of elements into one.\n */\nfunction merge(left: Array, right: Array): Array {\n // Create an empty array to store the merged result.\n const mergedResult = [];\n\n let l = 0;\n let r = 0;\n // Repeatedly compare smallest element from each half\n // and append it to the merged result.\n // When one half runs out of elements,\n // append all the elements of the remaining half to the merged array\n while (l < left.length && r < right.length) {\n if (left[l] < right[r]) {\n mergedResult.push(left[l]);\n l++;\n } else {\n mergedResult.push(right[r]);\n r++;\n }\n }\n\n // Append any remaining elements from each sides.\n mergedResult.push(...left.slice(l), ...right.slice(r));\n return mergedResult;\n}\n`;function c(t){let e=Object.assign({p:\"p\",h2:\"h2\",ul:\"ul\",li:\"li\",h3:\"h3\"},t.components);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e.p,{children:\"\\u5F52\\u5E76\\u6392\\u5E8F\\u662F\\u4E00\\u79CD\\u57FA\\u4E8E\\u6BD4\\u8F83\\u7684\\u7A33\\u5B9A\\u7B97\\u6CD5\\uFF0C\\u5728\\u6240\\u6709\\u60C5\\u51B5\\u4E0B\\uFF0C\\u5176\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u5747\\u4E3A O(nlog(n))\\u3002\\u5B83\\u901A\\u5E38\\u5728\\u5B9E\\u8DF5\\u4E2D\\u7528\\u4F5C\\u5BF9\\u5404\\u79CD\\u5927\\u5C0F\\u7684\\u6570\\u7EC4\\u8FDB\\u884C\\u6392\\u5E8F\\u7684\\u901A\\u7528\\u7B97\\u6CD5\\u3002\"}),`\n`,(0,r.jsx)(e.h2,{children:\"\\u6F84\\u6E05\\u95EE\\u9898\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u5982\\u679C\\u672A\\u6307\\u5B9A\\uFF1A\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"\\u6570\\u636E\\u5E94\\u8BE5\\u6309\\u5347\\u5E8F\\u8FD8\\u662F\\u964D\\u5E8F\\u6392\\u5E8F\\uFF1F\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u6570\\u636E\\u5E94\\u8BE5\\u5C31\\u5730\\u6392\\u5E8F\\u8FD8\\u662F\\u53EF\\u4EE5\\u4F7F\\u7528\\u5176\\u4ED6\\u6570\\u636E\\u7ED3\\u6784\\uFF1F\"}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u6211\\u4EEC\\u9700\\u8981\\u5904\\u7406\\u4EC0\\u4E48\\u6837\\u7684\\u8F93\\u5165\\uFF1F\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"\\u5B83\\u53EA\\u662F\\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4\\uFF0C\\u8FD8\\u662F\\u6211\\u4EEC\\u5E94\\u8BE5\\u5904\\u7406\\u5176\\u4ED6\\u6570\\u636E\\u7C7B\\u578B\\uFF1F\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u662F\\u5426\\u5B58\\u5728\\u5927\\u91CF\\u91CD\\u590D\\u5143\\u7D20\\uFF1F\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u5E94\\u8BE5\\u5982\\u4F55\\u5904\\u7406\\u8D1F\\u6570\\uFF1F\"}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,r.jsx)(e.h2,{children:\"\\u89E3\\u51B3\\u65B9\\u6848\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u6CE8\\u610F\\uFF1A\\u8FD9\\u4E2A\\u95EE\\u9898\\u5904\\u7406\\u7684\\u662F\\u6807\\u51C6\\u7684\\u5F52\\u5E76\\u6392\\u5E8F\\uFF0C\\u5B83\\u662F\\u9012\\u5F52\\u7684\\uFF0C\\u5E76\\u4E14\\u5BF9\\u4E8E\\u5347\\u5E8F\\u8F93\\u51FA\\u4E0D\\u662F\\u201C\\u5C31\\u5730\\u201D\\u7684\\u3002\"}),`\n`,(0,r.jsx)(m,{languages:{jsx:d,tsx:g}}),`\n`,(0,r.jsx)(e.h2,{children:\"\\u8FB9\\u7F18\\u60C5\\u51B5\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"\\u975E\\u6574\\u6570\\u5143\\u7D20\\u8F93\\u5165\\uFF1A\\u5982\\u679C\\u8F93\\u5165\\u6570\\u7EC4\\u5305\\u542B\\u4E0D\\u540C\\u6570\\u636E\\u7C7B\\u578B\\u7684\\u5143\\u7D20\\uFF0C\\u60A8\\u53EF\\u80FD\\u9700\\u8981\\u8FD4\\u56DE\\u4E00\\u4E2A\\u9519\\u8BEF\\uFF0C\\u5C1D\\u8BD5\\u8FDB\\u884C\\u6700\\u4F73\\u6392\\u5E8F\\uFF0C\\u4F8B\\u5982\\uFF0C\\u4EC5\\u5BF9\\u8F93\\u5165\\u6570\\u636E\\u7684\\u5B50\\u96C6\\u8FDB\\u884C\\u6392\\u5E8F\\uFF0C\\u751A\\u81F3\\u4E3A\\u975E\\u6574\\u6570\\u5B9A\\u4E49\\u81EA\\u5B9A\\u4E49\\u6BD4\\u8F83\\u51FD\\u6570\\u3002\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u5355\\u4E2A\\u5143\\u7D20/\\u7A7A\\u8F93\\u5165\\uFF1A\\u8FD4\\u56DE\\u539F\\u59CB\\u6570\\u636E\\u7ED3\\u6784\\u3001\\u5F15\\u53D1\\u9519\\u8BEF\\u6216\\u6F84\\u6E05\\u6240\\u9700\\u5904\\u7406\\u3002\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u5DF2\\u6392\\u5E8F\\u7684\\u8F93\\u5165\\uFF1A\\u60A8\\u53EF\\u80FD\\u9700\\u8981\\u68C0\\u6D4B\\u6392\\u5E8F\\u5E76\\u539F\\u6837\\u8FD4\\u56DE\\u8F93\\u5165\\u3002\"}),`\n`,(0,r.jsx)(e.li,{children:\"\\u65E0\\u6548\\u8F93\\u5165\\uFF1A\\u5982\\u679C\\u8F93\\u5165\\u4E0D\\u662F\\u6570\\u7EC4\\uFF0C\\u8BF7\\u8003\\u8651\\u629B\\u51FA\\u9519\\u8BEF\\u3002\"}),`\n`]}),`\n`,(0,r.jsx)(e.h2,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u8BA9\\u6211\\u4EEC\\u5206\\u6790\\u4E00\\u4E0B\\u7B97\\u6CD5\\u7684\\u65F6\\u95F4\\u548C\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u3002\"}),`\n`,(0,r.jsx)(e.h3,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u5BF9\\u4E8E\\u5F52\\u5E76\\u6392\\u5E8F\\uFF0C\\u6700\\u4F73\\u3001\\u5E73\\u5747\\u548C\\u6700\\u574F\\u60C5\\u51B5\\u4E0B\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u5747\\u4E3A O(nlog(n))\\u3002\\u8FD9\\u610F\\u5473\\u7740\\u6392\\u5E8F\\u6240\\u9700\\u7684\\u65F6\\u95F4\\u4E0E\\u6570\\u7EC4\\u5927\\u5C0F\\u548C\\u6570\\u7EC4\\u5927\\u5C0F\\u7684\\u5BF9\\u6570\\u7684\\u4E58\\u79EF\\u6210\\u6B63\\u6BD4\\u3002\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u5212\\u5206\\u6B65\\u9AA4\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E0E\\u7531\\u4E8E\\u8F93\\u5165\\u6570\\u7EC4\\u88AB\\u53CD\\u590D\\u5BF9\\u534A\\u5206\\u800C\\u521B\\u5EFA\\u7684\\u4E8C\\u53C9\\u6811\\u7684\\u9AD8\\u5EA6\\u6210\\u6B63\\u6BD4\\uFF0C\\u5E76\\u4E14\\u6B65\\u6570\\u6700\\u591A\\u4E3A log(n) + 1\\u3002\\u627E\\u5230\\u4EFB\\u4F55\\u5B50\\u6570\\u7EC4\\u7684\\u4E2D\\u95F4\\u503C\\u662F\\u4E00\\u4E2A\\u5355\\u6B65\\u64CD\\u4F5C\\uFF0C\\u6210\\u672C\\u4E3A O(1)\\u3002\\u56E0\\u6B64\\uFF0C\\u6211\\u4EEC\\u9884\\u8BA1\\u5B83\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(log(n))\\u3002\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u5408\\u5E76\\u6B65\\u9AA4\\u9700\\u8981 O(n) \\u65F6\\u95F4\\uFF0C\\u7528\\u4E8E\\u7531\\u5212\\u5206\\u521B\\u5EFA\\u7684\\u6BCF\\u4E2A\\u5B50\\u6570\\u7EC4\\uFF0C\\u56E0\\u4E3A\\u5B83\\u9700\\u8981\\u5C06 n \\u4E2A\\u5143\\u7D20\\u7EC4\\u5408\\u6210\\u4E00\\u4E2A\\u5DF2\\u6392\\u5E8F\\u7684\\u5217\\u8868\\u3002\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u603B\\u7684\\u6765\\u8BF4\\uFF0C\\u5F52\\u5E76\\u6392\\u5E8F\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A n(log(n) + 1) = O(nlog(n))\\u3002\"}),`\n`,(0,r.jsx)(e.h3,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u5728\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u65B9\\u9762\\uFF0C\\u5BF9\\u4E8E\\u9012\\u5F52\\u4E14\\u975E\\u5C31\\u5730\\u7684\\u6807\\u51C6\\u5F52\\u5E76\\u6392\\u5E8F\\uFF0C\\u5B83\\u662F O(n)\\u3002\\u5408\\u5E76\\u6B65\\u9AA4\\u9700\\u8981\\u521B\\u5EFA\\u4E00\\u4E2A\\u65B0\\u6570\\u7EC4\\u6765\\u5B58\\u50A8 2 \\u4E2A\\u90E8\\u5206\\u7684\\u5408\\u5E76\\u7ED3\\u679C\\u3002\\u5728\\u6700\\u540E\\u4E00\\u4E2A\\u5408\\u5E76\\u6B65\\u9AA4\\u4E2D\\uFF0C\\u6211\\u4EEC\\u5E0C\\u671B\\u6570\\u7EC4\\u4E0E\\u8F93\\u5165\\u6570\\u7EC4\\u4E00\\u6837\\u5927\\u3002\\u56E0\\u6B64\\uFF0C\\u7A7A\\u95F4\\u9700\\u6C42\\u662F\\u7EBF\\u6027\\u7684\\u3002\"})]})}function S(t={}){let{wrapper:e}=t.components||{};return e?(0,r.jsx)(e,Object.assign({},t,{children:(0,r.jsx)(c,t)})):c(t)}var w=S;return A(_);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/neighborhood-theft-circular/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/neighborhood-theft-circular/locales/zh-CN.json new file mode 100644 index 000000000..8f41b018f --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/neighborhood-theft-circular/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var m=Object.create;var a=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var g=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),j=(t,e)=>{for(var r in e)a(t,r,{get:e[r],enumerable:!0})},l=(t,e,r,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of b(e))!f.call(t,i)&&i!==r&&a(t,i,{get:()=>e[i],enumerable:!(o=x(e,i))||o.enumerable});return t};var v=(t,e,r)=>(r=t!=null?m(p(t)):{},l(e||!t||!t.__esModule?a(r,\"default\",{value:t,enumerable:!0}):r,t)),_=t=>l(a({},\"__esModule\",{value:!0}),t);var s=g((E,u)=>{u.exports=_jsx_runtime});var D={};j(D,{default:()=>C,frontmatter:()=>M});var n=v(s());var c=MDXTestExamples;var d=[{input:[[\"numbers\",[1,2,3,1]]],output:4,explanation:\"The robber can steal a maximum of 4 by robbing house at index 0 (value 1) and house at index 2 (value 3).\"},{input:[[\"numbers\",[2,7,9,3,1]]],output:11,explanation:\"The robber can steal a maximum of 12 by robbing house at index 0 (value 2), house at index 2 (value 9).\"},{input:[[\"numbers\",[3,6,1,0,6,0,0,9]]],output:21,explanation:\"The robber can steal a maximum of 21 by robbing house at index 1 (value 6), house at index 4 (value 6), house at index 7 (value 9).\"}];var M={title:\"\\u90BB\\u91CC\\u76D7\\u7A83\\uFF08\\u73AF\\u5F62\\uFF09\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u7528\\u4E8E\\u5728\\u73AF\\u5F62\\u623F\\u5C4B\\u4E2D\\u627E\\u5230\\u5728\\u4E0D\\u60CA\\u52A8\\u8B66\\u5BDF\\u7684\\u60C5\\u51B5\\u4E0B\\u62A2\\u52AB\\u7684\\u6700\\u5927\\u91D1\\u989D\"};function h(t){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.p,{children:\"\\u4E00\\u4F4D\\u7ECF\\u9A8C\\u4E30\\u5BCC\\u7684\\u7A83\\u8D3C\\u6B63\\u8BA1\\u5212\\u5728\\u4E00\\u6761\\u73AF\\u5F62\\u8857\\u9053\\u4E0A\\u8FDB\\u884C\\u62A2\\u52AB\\u3002\\u6BCF\\u6240\\u623F\\u5B50\\u91CC\\u90FD\\u88C5\\u7740\\u4E00\\u5B9A\\u6570\\u91CF\\u7684\\u94B1\\uFF0C\\u6240\\u6709\\u623F\\u5B50\\u90FD\\u6392\\u6210\\u4E00\\u4E2A\\u5706\\u5708\\uFF0C\\u8FD9\\u610F\\u5473\\u7740\\u7B2C\\u4E00\\u6240\\u623F\\u5B50\\u4E0E\\u6700\\u540E\\u4E00\\u6240\\u623F\\u5B50\\u76F8\\u90BB\\u3002\\u6B64\\u5916\\uFF0C\\u76F8\\u90BB\\u7684\\u623F\\u5C4B\\u6709\\u8FDE\\u63A5\\u7684\\u5B89\\u5168\\u7CFB\\u7EDF\\uFF0C\\u5982\\u679C\\u4E24\\u4E2A\\u76F8\\u90BB\\u7684\\u623F\\u5C4B\\u5728\\u540C\\u4E00\\u5929\\u665A\\u4E0A\\u88AB\\u62A2\\u52AB\\uFF0C\\u5C31\\u4F1A\\u63D0\\u9192\\u8B66\\u5BDF\\u3002\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"numbers\"}),\"\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u5143\\u7D20\\u4EE3\\u8868\\u4E00\\u6240\\u623F\\u5B50\\u91CC\\u7684\\u94B1\\u7684\\u6570\\u91CF\\uFF0C\\u8FD4\\u56DE\\u7A83\\u8D3C\\u5728\\u4E0D\\u89E6\\u53D1\\u8B66\\u62A5\\u7684\\u60C5\\u51B5\\u4E0B\\u53EF\\u4EE5\\u5077\\u7A83\\u7684\\u6700\\u5927\\u91D1\\u989D\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"numbers: number[]\"}),\": \\u6574\\u6570\\u6570\\u7EC4\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u6CE8\\u610F\\u4E8B\\u9879\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u7A83\\u8D3C\\u4E0D\\u80FD\\u4ECE\\u76F8\\u90BB\\u7684\\u4E24\\u6240\\u623F\\u5B50\\u91CC\\u5077\\u4E1C\\u897F\"}),`\n`]}),`\n`,(0,n.jsx)(c,{testCases:d}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"numbers.length\"}),\" <= 100\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"0 <= \",(0,n.jsx)(e.code,{children:\"numbers[i]\"}),\" <= 400\"]}),`\n`]})]})}function y(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(h,t)})):h(t)}var C=y;return _(D);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,用于在环形房屋中找到在不惊动警察的情况下抢劫的最大金额", + "title": "邻里盗窃(环形)" + }, + "solution": "var Component=(()=>{var b=Object.create;var o=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var y=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),M=(r,e)=>{for(var i in e)o(r,i,{get:e[i],enumerable:!0})},c=(r,e,i,h)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let t of p(e))!x.call(r,t)&&t!==i&&o(r,t,{get:()=>e[t],enumerable:!(h=f(e,t))||h.enumerable});return r};var v=(r,e,i)=>(i=r!=null?b(g(r)):{},c(e||!r||!r.__esModule?o(i,\"default\",{value:r,enumerable:!0}):i,r)),C=r=>c(o({},\"__esModule\",{value:!0}),r);var u=y((_,d)=>{d.exports=_jsx_runtime});var R={};M(R,{default:()=>w});var n=v(u());var l=MDXCodeBlock;var m=`export default function neighborhoodTheftCircular(numbers: number[]): number {\n // If there are no houses, return 0\n if (numbers.length === 0) return 0;\n // If there is only one house, return the amount in that house\n if (numbers.length === 1) return numbers[0];\n\n // Calculate the maximum amount of money that can be robbed by excluding either the first or the last house\n const max1 = robSimple(numbers, 0, numbers.length - 2);\n const max2 = robSimple(numbers, 1, numbers.length - 1);\n\n // Return the maximum amount from the two calculated values\n return Math.max(max1, max2);\n}\n\n// Helper function to find the maximum amount of money that can be robbed from a range of houses\nfunction robSimple(numbers: number[], start: number, end: number): number {\n let t1 = 0,\n t2 = 0;\n\n // Iterate over the range of houses\n for (let i = start; i <= end; i++) {\n // Store the current value of t1 in a temporary variable\n const temp = t1;\n // Update t1 to be the maximum of robbing the current house plus the amount from t2, or the current value of t1\n t1 = Math.max(numbers[i] + t2, t1);\n // Update t2 to the previous value of t1\n t2 = temp;\n }\n\n // Return the maximum amount of money that can be robbed from the given range of houses\n return t1;\n}\n`;var a=`export default function neighborhoodTheftCircular(numbers: number[]): number {\n // If there are no houses, return 0\n if (numbers.length === 0) return 0;\n // If there is only one house, return the amount in that house\n if (numbers.length === 1) return numbers[0];\n\n // Calculate the maximum amount of money that can be robbed by excluding either the first or the last house\n const max1 = robWithMemo(numbers, 0, numbers.length - 2);\n const max2 = robWithMemo(numbers, 1, numbers.length - 1);\n\n // Return the maximum amount from the two calculated values\n return Math.max(max1, max2);\n}\n\n// Helper function to find the maximum amount of money that can be robbed from a range of houses using memoization\nfunction robWithMemo(numbers: number[], start: number, end: number): number {\n // Initialize the memoization array with -1 indicating uncomputed values\n const memo: number[] = new Array(numbers.length).fill(-1);\n\n // Recursive function with memoization\n function dp(i: number): number {\n // Base case: if i is beyond the end of the range, return 0\n if (i > end) return 0;\n\n // Return the cached value if it's already computed\n if (memo[i] !== -1) return memo[i];\n\n // Recursively compute the maximum amount by choosing to rob or not rob the current house\n const robCurrent = numbers[i] + dp(i + 2); // Rob current house and move to the house after next\n const skipCurrent = dp(i + 1); // Skip current house and move to the next house\n\n // Store the result in the memo array\n memo[i] = Math.max(robCurrent, skipCurrent);\n\n return memo[i];\n }\n\n // Start the recursion from the starting index\n return dp(start);\n}\n`;function s(r){let e=Object.assign({h2:\"h2\",p:\"p\",ol:\"ol\",li:\"li\",code:\"code\",ul:\"ul\",h3:\"h3\",strong:\"strong\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u81EA\\u9876\\u5411\\u4E0B\\u52A8\\u6001\\u89C4\\u5212\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u5C06\\u90BB\\u91CC\\u76D7\\u7A83\\u95EE\\u9898\\u6269\\u5C55\\u5230\\u623F\\u5C4B\\u7684\\u73AF\\u5F62\\u6392\\u5217\\u3002\\u5728\\u8FD9\\u79CD\\u60C5\\u51B5\\u4E0B\\uFF0C\\u7B2C\\u4E00\\u4E2A\\u548C\\u6700\\u540E\\u4E00\\u4E2A\\u623F\\u5C4B\\u662F\\u76F8\\u90BB\\u7684\\uFF0C\\u56E0\\u6B64\\u5B83\\u4EEC\\u4E0D\\u80FD\\u540C\\u65F6\\u88AB\\u62A2\\u52AB\\u3002\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u5206\\u6CBB\\u6CD5\\uFF0C\\u5C06\\u5FAA\\u73AF\\u95EE\\u9898\\u5206\\u89E3\\u4E3A\\u4E24\\u4E2A\\u7EBF\\u6027\\u5B50\\u95EE\\u9898\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u6392\\u9664\\u7B2C\\u4E00\\u4E2A\\u623F\\u5C4B\\u5E76\\u8BA1\\u7B97\\u5176\\u4F59\\u623F\\u5C4B\\u7684\\u6700\\u5927\\u91D1\\u989D\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u6392\\u9664\\u6700\\u540E\\u4E00\\u4E2A\\u623F\\u5C4B\\u5E76\\u8BA1\\u7B97\\u5176\\u4F59\\u623F\\u5C4B\\u7684\\u6700\\u5927\\u91D1\\u989D\\u3002\"}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8FD9\\u4E9B\\u5B50\\u95EE\\u9898\\u4F7F\\u7528\\u81EA\\u9876\\u5411\\u4E0B\\u7684\\u52A8\\u6001\\u89C4\\u5212\\u65B9\\u6CD5\\u548C\\u8BB0\\u5FC6\\u5316\\u6765\\u89E3\\u51B3\\u3002\\u8F85\\u52A9\\u51FD\\u6570 \",(0,n.jsx)(e.code,{children:\"robWithMemo\"}),\" \\u901A\\u8FC7\\u9012\\u5F52\\u5730\\u63A2\\u7D22\\u6BCF\\u4E2A\\u623F\\u5C4B\\u7684\\u4E24\\u4E2A\\u9009\\u9879\\u6765\\u8BA1\\u7B97\\u53EF\\u4EE5\\u4ECE\\u7ED9\\u5B9A\\u8303\\u56F4\\u7684\\u623F\\u5C4B\\u4E2D\\u62A2\\u52AB\\u7684\\u6700\\u5927\\u91D1\\u989D\\uFF1A\"]}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u62A2\\u52AB\\u5F53\\u524D\\u623F\\u5C4B\\u5E76\\u8DF3\\u8FC7\\u4E0B\\u4E00\\u4E2A\\u623F\\u5C4B\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8DF3\\u8FC7\\u5F53\\u524D\\u623F\\u5C4B\\u5E76\\u79FB\\u81F3\\u4E0B\\u4E00\\u4E2A\\u623F\\u5C4B\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BB0\\u5FC6\\u5316\\u786E\\u4FDD\\u7F13\\u5B58\\u4E2D\\u95F4\\u7ED3\\u679C\\uFF0C\\u907F\\u514D\\u5197\\u4F59\\u8BA1\\u7B97\\u5E76\\u63D0\\u9AD8\\u6548\\u7387\\u3002\\u6700\\u7EC8\\u7ED3\\u679C\\u662F\\u4E24\\u4E2A\\u5B50\\u95EE\\u9898\\u7684\\u6700\\u5927\\u503C\\uFF0C\\u4EE3\\u8868\\u5FAA\\u73AF\\u6392\\u5217\\u7684\\u6700\\u4F18\\u89E3\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5904\\u7406\\u7279\\u6B8A\\u60C5\\u51B5\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u6CA1\\u6709\\u623F\\u5C4B\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u53EA\\u6709\\u4E00\\u4E2A\\u623F\\u5C4B\\uFF0C\\u5219\\u8FD4\\u56DE\\u5176\\u503C\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u8F85\\u52A9\\u51FD\\u6570 \",(0,n.jsx)(e.code,{children:\"robWithMemo\"}),\" \\u6765\\u8BA1\\u7B97\\u53EF\\u4EE5\\u4ECE\\u7ED9\\u5B9A\\u8303\\u56F4\\u7684\\u623F\\u5C4B\\u4E2D\\u62A2\\u52AB\\u7684\\u6700\\u5927\\u91D1\\u989D\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"memo\"}),\" \\u6570\\u7EC4\\u6765\\u5B58\\u50A8\\u4E2D\\u95F4\\u7ED3\\u679C\\uFF0C\\u7528 \",(0,n.jsx)(e.code,{children:\"-1\"}),\" \\u586B\\u5145\\u4EE5\\u6307\\u793A\\u672A\\u8BA1\\u7B97\\u7684\\u503C\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u9012\\u5F52\\u51FD\\u6570 \",(0,n.jsx)(e.code,{children:\"dp(i)\"}),\"\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"i\"}),\" \\u8D85\\u8FC7\\u8303\\u56F4\\u7684\\u672B\\u5C3E\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u56E0\\u4E3A\\u6CA1\\u6709\\u623F\\u5C4B\\u53EF\\u4EE5\\u62A2\\u52AB\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5DF2\\u8BA1\\u7B97\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"memo[i]\"}),\" \\u4E2D\\u7684\\u7F13\\u5B58\\u503C\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u9009\\u62E9\\u4EE5\\u4E0B\\u9009\\u9879\\u6765\\u8BA1\\u7B97\\u5F53\\u524D\\u623F\\u5C4B\\u7684\\u6700\\u5927\\u91D1\\u989D\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u62A2\\u52AB\\u5F53\\u524D\\u623F\\u5C4B\\u5E76\\u6DFB\\u52A0\\u8DF3\\u8FC7\\u4E0B\\u4E00\\u4E2A\\u623F\\u5C4B\\u7684\\u7ED3\\u679C (\",(0,n.jsx)(e.code,{children:\"numbers[i] + dp(i + 2)\"}),\")\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8DF3\\u8FC7\\u5F53\\u524D\\u623F\\u5C4B\\u5E76\\u79FB\\u81F3\\u4E0B\\u4E00\\u4E2A\\u623F\\u5C4B (\",(0,n.jsx)(e.code,{children:\"dp(i + 1)\"}),\")\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u7ED3\\u679C\\u7F13\\u5B58\\u5728 \",(0,n.jsx)(e.code,{children:\"memo[i]\"}),\" \\u4E2D\\u5E76\\u8FD4\\u56DE\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u4ECE\\u7ED9\\u5B9A\\u8303\\u56F4\\u7684\\u8D77\\u59CB\\u7D22\\u5F15\\u5F00\\u59CB\\u9012\\u5F52\\uFF0C\\u5E76\\u8FD4\\u56DE\\u7ED3\\u679C\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8BA1\\u7B97\\u4E24\\u4E2A\\u5B50\\u95EE\\u9898\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u6392\\u9664\\u7B2C\\u4E00\\u4E2A\\u623F\\u5C4B\\u7684\\u6700\\u5927\\u91D1\\u989D (\",(0,n.jsx)(e.code,{children:\"robWithMemo(numbers, 1, numbers.length - 1)\"}),\")\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u6392\\u9664\\u6700\\u540E\\u4E00\\u4E2A\\u623F\\u5C4B\\u7684\\u6700\\u5927\\u91D1\\u989D (\",(0,n.jsx)(e.code,{children:\"robWithMemo(numbers, 0, numbers.length - 2)\"}),\")\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8FD4\\u56DE\\u4E24\\u4E2A\\u7ED3\\u679C\\u7684\\u6700\\u5927\\u503C\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(l,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u6BCF\\u4E2A\\u5B50\\u95EE\\u9898\\u5728\\u5176\\u8303\\u56F4\\u5185\\u5904\\u7406\\u6240\\u6709\\u623F\\u5C4B\\u4E00\\u6B21\\uFF0C\\u4ECE\\u800C\\u4EA7\\u751F\\u7EBF\\u6027\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u8BB0\\u5FC6\\u5316\\u6570\\u7EC4\\u9700\\u8981\\u4E0E\\u8303\\u56F4\\u5185\\u7684\\u623F\\u5C4B\\u6570\\u91CF\\u6210\\u6BD4\\u4F8B\\u7684\\u7A7A\\u95F4\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u81EA\\u5E95\\u5411\\u4E0A\\u52A8\\u6001\\u89C4\\u5212\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u5FAA\\u73AF\\u90BB\\u91CC\\u76D7\\u7A83\\u95EE\\u9898\\u9700\\u8981\\u5904\\u7406\\u7B2C\\u4E00\\u4E2A\\u548C\\u6700\\u540E\\u4E00\\u4E2A\\u623F\\u5C4B\\u662F\\u90BB\\u5C45\\u7684\\u9644\\u52A0\\u7EA6\\u675F\\u3002\\u5F53\\u540C\\u65F6\\u8003\\u8651\\u62A2\\u52AB\\u8FD9\\u4E24\\u4E2A\\u623F\\u5C4B\\u65F6\\uFF0C\\u8FD9\\u4F1A\\u4EA7\\u751F\\u51B2\\u7A81\\uFF0C\\u56E0\\u4E3A\\u540C\\u65F6\\u62A2\\u52AB\\u5B83\\u4EEC\\u4F1A\\u8FDD\\u53CD\\u95EE\\u9898\\u7684\\u7EA6\\u675F\\u3002\\u4E3A\\u4E86\\u89E3\\u51B3\\u8FD9\\u4E2A\\u95EE\\u9898\\uFF0C\\u5C06\\u95EE\\u9898\\u5206\\u4E3A\\u4E24\\u4E2A\\u72EC\\u7ACB\\u7684\\u573A\\u666F\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u4ECE\\u7B2C\\u4E8C\\u4E2A\\u623F\\u5C4B\\u62A2\\u52AB\\u5230\\u6700\\u540E\\u4E00\\u4E2A\\u623F\\u5C4B\\uFF0C\\u4E0D\\u5305\\u62EC\\u7B2C\\u4E00\\u4E2A\\u623F\\u5C4B\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u4ECE\\u7B2C\\u4E00\\u4E2A\\u623F\\u5C4B\\u62A2\\u52AB\\u5230\\u5012\\u6570\\u7B2C\\u4E8C\\u4E2A\\u623F\\u5C4B\\uFF0C\\u4E0D\\u5305\\u62EC\\u6700\\u540E\\u4E00\\u4E2A\\u623F\\u5C4B\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u901A\\u8FC7\\u72EC\\u7ACB\\u5730\\u89E3\\u51B3\\u8FD9\\u4E24\\u4E2A\\u7EBF\\u6027\\u5B50\\u95EE\\u9898\\uFF0C\\u53EF\\u4EE5\\u6709\\u6548\\u5730\\u5904\\u7406\\u5FAA\\u73AF\\u7EA6\\u675F\\u3002\\u7136\\u540E\\u6BD4\\u8F83\\u8FD9\\u4E24\\u79CD\\u60C5\\u51B5\\u7684\\u7ED3\\u679C\\uFF0C\\u4EE5\\u786E\\u5B9A\\u53EF\\u4EE5\\u62A2\\u52AB\\u7684\\u6700\\u5927\\u91D1\\u989D\\u3002\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8FD9\\u4E9B\\u5B50\\u95EE\\u9898\\u4E2D\\u7684\\u6BCF\\u4E00\\u4E2A\\u90FD\\u4F7F\\u7528\\u7A7A\\u95F4\\u4F18\\u5316\\u7684\\u52A8\\u6001\\u89C4\\u5212\\u65B9\\u6CD5\\u6765\\u89E3\\u51B3\\u3002\\u4E0D\\u662F\\u7EF4\\u62A4\\u4E00\\u4E2A\\u5B8C\\u6574\\u7684 \",(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u6570\\u7EC4\\u6765\\u5B58\\u50A8\\u6240\\u6709\\u623F\\u5C4B\\u7684\\u6700\\u5927\\u91D1\\u989D\\uFF0C\\u800C\\u662F\\u4F7F\\u7528\\u4E24\\u4E2A\\u53D8\\u91CF\\u6765\\u8DDF\\u8E2A\\u5F53\\u524D\\u623F\\u5C4B\\u548C\\u524D\\u4E00\\u4E2A\\u623F\\u5C4B\\u7684\\u7ED3\\u679C\\u3002\\u8FD9\\u964D\\u4F4E\\u4E86\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF0C\\u540C\\u65F6\\u786E\\u4FDD\\u6709\\u6548\\u5730\\u8BA1\\u7B97\\u6BCF\\u4E2A\\u5B50\\u95EE\\u9898\\u7684\\u6700\\u4F18\\u89E3\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u6838\\u5FC3\\u601D\\u60F3\\u662F\\u4F7F\\u7528\\u4E00\\u4E2A\\u89C2\\u5BDF\\u7ED3\\u679C\\uFF0C\\u5373\\u5728\\u7EBF\\u6027\\u623F\\u5C4B\\u6392\\u5217\\u4E2D\\uFF0C\\u62A2\\u52AB\\u6216\\u8DF3\\u8FC7\\u6BCF\\u4E2A\\u623F\\u5C4B\\u7684\\u51B3\\u5B9A\\u4EC5\\u53D6\\u51B3\\u4E8E\\u53EF\\u4EE5\\u4ECE\\u524D\\u4E24\\u4E2A\\u623F\\u5C4B\\u62A2\\u52AB\\u7684\\u6700\\u5927\\u91D1\\u989D\\u3002\\u8FD9\\u91CC\\u91C7\\u7528\\u4E86\\u8FD9\\u4E00\\u539F\\u5219\\uFF0C\\u901A\\u8FC7\\u89E3\\u51B3\\u4E24\\u4E2A\\u5355\\u72EC\\u7684\\u7EBF\\u6027\\u60C5\\u51B5\\u5E76\\u7ED3\\u5408\\u5B83\\u4EEC\\u7684\\u7ED3\\u679C\\u6765\\u5904\\u7406\\u5FAA\\u73AF\\u6392\\u5217\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5 \",(0,n.jsx)(e.code,{children:\"numbers\"}),\" \\u6570\\u7EC4\\u662F\\u5426\\u4E3A\\u7A7A\\u3002\\u5982\\u679C\\u662F\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u56E0\\u4E3A\\u6CA1\\u6709\\u623F\\u5C4B\\u53EF\\u4EE5\\u62A2\\u52AB\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5 \",(0,n.jsx)(e.code,{children:\"numbers\"}),\" \\u6570\\u7EC4\\u662F\\u5426\\u53EA\\u6709\\u4E00\\u4E2A\\u623F\\u5C4B\\u3002\\u5982\\u679C\\u662F\\uFF0C\\u5219\\u8FD4\\u56DE\\u8BE5\\u623F\\u5C4B\\u7684\\u503C\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u89E3\\u51B3\\u4E24\\u4E2A\\u7EBF\\u6027\\u5B50\\u95EE\\u9898\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u4ECE\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"0\"}),\" \\u5230 \",(0,n.jsx)(e.code,{children:\"n - 2\"}),\"\\uFF08\\u4E0D\\u5305\\u62EC\\u6700\\u540E\\u4E00\\u4E2A\\u623F\\u5C4B\\uFF09\\u7684\\u8303\\u56F4\\u8C03\\u7528 \",(0,n.jsx)(e.code,{children:\"robSimple\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u4ECE\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"1\"}),\" \\u5230 \",(0,n.jsx)(e.code,{children:\"n - 1\"}),\"\\uFF08\\u4E0D\\u5305\\u62EC\\u7B2C\\u4E00\\u4E2A\\u623F\\u5C4B\\uFF09\\u7684\\u8303\\u56F4\\u8C03\\u7528 \",(0,n.jsx)(e.code,{children:\"robSimple\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8FD4\\u56DE\\u4E24\\u4E2A\\u7ED3\\u679C\\u7684\\u6700\\u5927\\u503C\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u8F85\\u52A9\\u51FD\\u6570 \",(0,n.jsx)(e.code,{children:\"robSimple\"}),\" \\u6765\\u89E3\\u51B3\\u7EBF\\u6027\\u62A2\\u52AB\\u95EE\\u9898\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u4E24\\u4E2A\\u53D8\\u91CF \",(0,n.jsx)(e.code,{children:\"t1\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"t2\"}),\" \\u521D\\u59CB\\u5316\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u3002\\u8FD9\\u4E9B\\u53D8\\u91CF\\u8868\\u793A\\u53EF\\u4EE5\\u62A2\\u52AB\\u5230\\u5F53\\u524D\\u623F\\u5C4B\\u548C\\u524D\\u4E00\\u4E2A\\u623F\\u5C4B\\u7684\\u6700\\u5927\\u91D1\\u989D\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u4ECE \",(0,n.jsx)(e.code,{children:\"start\"}),\" \\u5230 \",(0,n.jsx)(e.code,{children:\"end\"}),\" \\u7684\\u623F\\u5C4B\\u8303\\u56F4\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u5F53\\u524D\\u623F\\u5C4B\\u53EF\\u4EE5\\u62A2\\u52AB\\u7684\\u6700\\u5927\\u91D1\\u989D\\u8BA1\\u7B97\\u4E3A\\u4EE5\\u4E0B\\u5404\\u9879\\u7684\\u6700\\u5927\\u503C\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u62A2\\u52AB\\u5F53\\u524D\\u623F\\u5C4B\\u5E76\\u6DFB\\u52A0 \",(0,n.jsx)(e.code,{children:\"t2\"}),\"\\uFF08\\u8868\\u793A\\u62A2\\u52AB\\u5230\\u4E24\\u4E2A\\u623F\\u5C4B\\u4E4B\\u524D\\u7684\\u6700\\u5927\\u91D1\\u989D\\uFF09\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8DF3\\u8FC7\\u5F53\\u524D\\u623F\\u5C4B\\u5E76\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"t1\"}),\"\\uFF08\\u8868\\u793A\\u62A2\\u52AB\\u5230\\u524D\\u4E00\\u4E2A\\u623F\\u5C4B\\u7684\\u6700\\u5927\\u91D1\\u989D\\uFF09\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"t2\"}),\" \\u66F4\\u65B0\\u4E3A \",(0,n.jsx)(e.code,{children:\"t1\"}),\" \\u7684\\u503C\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"t1\"}),\" \\u66F4\\u65B0\\u4E3A\\u8BA1\\u7B97\\u51FA\\u7684\\u6700\\u5927\\u503C\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5FAA\\u73AF\\u7ED3\\u675F\\u540E\\uFF0C\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"t1\"}),\"\\uFF0C\\u5176\\u4E2D\\u5305\\u542B\\u5728\\u8BE5\\u8303\\u56F4\\u5185\\u53EF\\u4EE5\\u62A2\\u52AB\\u7684\\u6700\\u5927\\u91D1\\u989D\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(l,{children:m}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u5728\\u8F85\\u52A9\\u51FD\\u6570\\u7684\\u4E24\\u6B21\\u7EBF\\u6027\\u8FED\\u4EE3\\u4E2D\\uFF0C\\u6BCF\\u4E2A\\u623F\\u5C4B\\u53EA\\u5904\\u7406\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u4EC5\\u4F7F\\u7528\\u4E24\\u4E2A\\u53D8\\u91CF \",(0,n.jsx)(e.code,{children:\"t1\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"t2\"}),\" \\u6765\\u8DDF\\u8E2A\\u4E2D\\u95F4\\u7ED3\\u679C\\u3002\"]}),`\n`]})]})}function j(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(s,r)})):s(r)}var w=j;return C(R);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/neighborhood-theft/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/neighborhood-theft/locales/zh-CN.json new file mode 100644 index 000000000..9ce148e22 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/neighborhood-theft/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var m=Object.create;var a=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var g=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),v=(t,e)=>{for(var r in e)a(t,r,{get:e[r],enumerable:!0})},u=(t,e,r,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of b(e))!f.call(t,i)&&i!==r&&a(t,i,{get:()=>e[i],enumerable:!(o=x(e,i))||o.enumerable});return t};var j=(t,e,r)=>(r=t!=null?m(p(t)):{},u(e||!t||!t.__esModule?a(r,\"default\",{value:t,enumerable:!0}):r,t)),_=t=>u(a({},\"__esModule\",{value:!0}),t);var s=g((E,l)=>{l.exports=_jsx_runtime});var D={};v(D,{default:()=>C,frontmatter:()=>M});var n=j(s());var c=MDXTestExamples;var d=[{input:[[\"numbers\",[1,2,3,1]]],output:4,explanation:\"The robber can steal a maximum of 4 by robbing house at index 0 (value 1) and house at index 2 (value 3).\"},{input:[[\"numbers\",[2,7,9,3,1]]],output:12,explanation:\"The robber can steal a maximum of 12 by robbing house at index 0 (value 2), house at index 2 (value 9), and house at index 4 (value 1).\"},{input:[[\"numbers\",[3,6,1,0,6,0,0,9]]],output:21,explanation:\"The robber can steal a maximum of 21 by robbing house at index 1 (value 6), house at index 4 (value 6), house at index 7 (value 9).\"}];var M={title:\"\\u90BB\\u91CC\\u76D7\\u7A83\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u627E\\u5230\\u5728\\u4E0D\\u60CA\\u52A8\\u8B66\\u5BDF\\u7684\\u60C5\\u51B5\\u4E0B\\u62A2\\u52AB\\u7684\\u6700\\u5927\\u91D1\\u989D\"};function h(t){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.p,{children:\"\\u4E00\\u4F4D\\u7ECF\\u9A8C\\u4E30\\u5BCC\\u7684\\u7A83\\u8D3C\\u7684\\u76EE\\u6807\\u662F\\u5077\\u53D6\\u8857\\u9053\\u4E0A\\u623F\\u5C4B\\u91CC\\u7684\\u94B1\\u3002\\u6BCF\\u6240\\u623F\\u5B50\\u90FD\\u85CF\\u6709\\u4E00\\u5B9A\\u6570\\u91CF\\u7684\\u94B1\\uFF0C\\u4F46\\u6709\\u4E00\\u4E2A\\u95EE\\u9898\\uFF1A\\u76F8\\u90BB\\u623F\\u5C4B\\u4E2D\\u7684\\u5B89\\u5168\\u7CFB\\u7EDF\\u662F\\u76F8\\u4E92\\u8FDE\\u63A5\\u7684\\u3002\\u5982\\u679C\\u7A83\\u8D3C\\u95EF\\u5165\\u4E24\\u680B\\u76F8\\u90BB\\u7684\\u623F\\u5C4B\\uFF0C\\u8B66\\u5BDF\\u5C31\\u4F1A\\u88AB\\u60CA\\u52A8\\u3002\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"numbers\"}),\"\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u5143\\u7D20\\u4EE3\\u8868\\u4E00\\u6240\\u623F\\u5B50\\u91CC\\u7684\\u94B1\\u7684\\u6570\\u91CF\\uFF0C\\u786E\\u5B9A\\u7A83\\u8D3C\\u5728\\u4E0D\\u89E6\\u53D1\\u8B66\\u62A5\\u7684\\u60C5\\u51B5\\u4E0B\\u53EF\\u4EE5\\u5077\\u53D6\\u7684\\u6700\\u5927\\u91D1\\u989D\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"numbers: number[]\"}),\": \\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u6CE8\\u610F\\u4E8B\\u9879\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u7A83\\u8D3C\\u4E0D\\u80FD\\u4ECE\\u4E24\\u680B\\u76F8\\u90BB\\u7684\\u623F\\u5C4B\\u4E2D\\u5077\\u7A83\"}),`\n`]}),`\n`,(0,n.jsx)(c,{testCases:d}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"numbers.length\"}),\" <= 100\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"0 <= \",(0,n.jsx)(e.code,{children:\"numbers[i]\"}),\" <= 400\"]}),`\n`]})]})}function y(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(h,t)})):h(t)}var C=y;return _(D);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,找到在不惊动警察的情况下抢劫的最大金额", + "title": "邻里盗窃" + }, + "solution": "var Component=(()=>{var p=Object.create;var d=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var R=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),A=(r,e)=>{for(var i in e)d(r,i,{get:e[i],enumerable:!0})},t=(r,e,i,h)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let o of x(e))!v.call(r,o)&&o!==i&&d(r,o,{get:()=>e[o],enumerable:!(h=f(e,o))||h.enumerable});return r};var N=(r,e,i)=>(i=r!=null?p(g(r)):{},t(e||!r||!r.__esModule?d(i,\"default\",{value:r,enumerable:!0}):i,r)),y=r=>t(d({},\"__esModule\",{value:!0}),r);var m=R((B,c)=>{c.exports=_jsx_runtime});var M={};A(M,{default:()=>T});var n=N(m());var l=MDXCodeBlock;var u=`export default function neighborhoodTheft(numbers: number[]): number {\n const N = numbers.length;\n\n // Special handling for empty case (no houses to rob).\n if (N === 0) {\n return 0;\n }\n\n // This array stores the maximum amount of money that can be robbed when considering up to each house.\n // Note: The calculation starts from the last house and moves backward.\n const maxRobbedAmount: number[] = new Array(N + 1).fill(0);\n\n // Base case initializations:\n // - maxRobbedAmount[N] (robbing the last house + next house is impossible): set to 0.\n // - maxRobbedAmount[N - 1] (robbing only the last house): set to the value in the last house.\n maxRobbedAmount[N] = 0;\n maxRobbedAmount[N - 1] = numbers[N - 1];\n\n // DP table calculations (iterating backwards from the second-last house):\n // For each house 'i' (from N-2 to 0):\n // - Consider two options:\n // 1. Rob the current house 'i' and skip the next house (i+1).\n // 2. Skip the current house 'i' and rob the house after next (i+2).\n // - Choose the option that yields the maximum total amount for ending at house 'i'.\n // - Store the chosen maximum amount in maxRobbedAmount[i].\n for (let i = N - 2; i >= 0; i--) {\n maxRobbedAmount[i] = Math.max(\n maxRobbedAmount[i + 1],\n maxRobbedAmount[i + 2] + numbers[i],\n );\n }\n\n // The maximum amount the robber can steal is stored in maxRobbedAmount[0]\n // (represents the maximum achievable by ending at the first house).\n return maxRobbedAmount[0];\n}\n`;var a=`// Memoization array to store the results of subproblems\nlet memo: number[] = [];\n\n// Main function to calculate the maximum amount of money that can be robbed\nexport default function neighborhoodTheft(numbers: number[]): number {\n // Initialize the memo array with -1 to indicate uncomputed values\n memo = new Array(numbers.length).fill(-1);\n\n // Start the recursive function from the first house\n return robFrom(0, numbers);\n}\n\n// Helper function to calculate the maximum amount of money that can be robbed from the ith house onwards\nfunction robFrom(i: number, numbers: number[]): number {\n // Base case: No more houses left to examine\n if (i >= numbers.length) {\n return 0;\n }\n\n // If the result for this subproblem is already computed, return the cached value\n if (memo[i] > -1) {\n return memo[i];\n }\n\n // Calculate the maximum amount by either:\n // 1. Skipping the current house and moving to the next one\n // 2. Robbing the current house and moving to the house after the next one\n const ans = Math.max(\n robFrom(i + 1, numbers),\n robFrom(i + 2, numbers) + numbers[i],\n );\n\n // Cache the result for future use\n memo[i] = ans;\n\n // Return the computed result\n return ans;\n}\n`;var s=`export default function neighborhoodTheft(numbers: number[]): number {\n const N = numbers.length;\n\n // Special handling for empty case (no houses to rob).\n if (N === 0) {\n return 0;\n }\n\n // If there's only one house, return its value.\n if (N === 1) {\n return numbers[0];\n }\n\n // Initialize two variables to keep track of the maximum amounts:\n // prev1: max amount for robbing from house i+1 to the end\n // prev2: max amount for robbing from house i+2 to the end\n let prev1 = 0; // Equivalent to maxRobbedAmount[i+1]\n let prev2 = 0; // Equivalent to maxRobbedAmount[i+2]\n\n // Iterate backwards from the last house\n for (let i = N - 1; i >= 0; i--) {\n // Current maximum is either:\n // - Skipping the current house (prev1)\n // - Robbing the current house and adding prev2\n const current = Math.max(prev1, prev2 + numbers[i]);\n\n // Update prev2 and prev1 for the next iteration\n prev2 = prev1;\n prev1 = current;\n }\n\n // The final result is stored in prev1\n return prev1;\n}\n`;function b(r){let e=Object.assign({h2:\"h2\",p:\"p\",ol:\"ol\",li:\"li\",h3:\"h3\",code:\"code\",ul:\"ul\",strong:\"strong\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u81EA\\u9876\\u5411\\u4E0B\\u52A8\\u6001\\u89C4\\u5212\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u81EA\\u9876\\u5411\\u4E0B\\u7684\\u52A8\\u6001\\u89C4\\u5212\\u65B9\\u6CD5\\u548C\\u8BB0\\u5FC6\\u5316\\u6765\\u89E3\\u51B3\\u201C\\u90BB\\u5C45\\u76D7\\u7A83\\u201D\\u95EE\\u9898\\u3002\\u8BE5\\u95EE\\u9898\\u6D89\\u53CA\\u5728\\u786E\\u4FDD\\u4E0D\\u62A2\\u52AB\\u76F8\\u90BB\\u623F\\u5C4B\\u7684\\u60C5\\u51B5\\u4E0B\\uFF0C\\u6700\\u5927\\u5316\\u4ECE\\u623F\\u5C4B\\u4E2D\\u5077\\u8D70\\u7684\\u91D1\\u989D\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u7B97\\u6CD5\\u4ECE\\u7B2C\\u4E00\\u6240\\u623F\\u5B50\\u5F00\\u59CB\\uFF0C\\u5E76\\u9012\\u5F52\\u5730\\u63A2\\u7D22\\u4E24\\u4E2A\\u9009\\u9879\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u8DF3\\u8FC7\\u5F53\\u524D\\u623F\\u5C4B\\u5E76\\u79FB\\u81F3\\u4E0B\\u4E00\\u6240\\u623F\\u5C4B\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u62A2\\u52AB\\u5F53\\u524D\\u623F\\u5C4B\\u5E76\\u79FB\\u81F3\\u4E0B\\u4E00\\u6240\\u623F\\u5C4B\\u4E4B\\u540E\\u7684\\u623F\\u5C4B\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BB0\\u5FC6\\u5316\\u7528\\u4E8E\\u5B58\\u50A8\\u5DF2\\u8BA1\\u7B97\\u7684\\u5B50\\u95EE\\u9898\\u7684\\u7ED3\\u679C\\u3002\\u8FD9\\u907F\\u514D\\u4E86\\u5197\\u4F59\\u8BA1\\u7B97\\uFF0C\\u5E76\\u663E\\u7740\\u964D\\u4F4E\\u4E86\\u8FD0\\u884C\\u65F6\\u590D\\u6742\\u5EA6\\u3002\\u901A\\u8FC7\\u7F13\\u5B58\\u6BCF\\u4E2A\\u623F\\u5C4B\\u7684\\u7ED3\\u679C\\uFF0C\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u4EC5\\u8BA1\\u7B97\\u6BCF\\u4E2A\\u5B50\\u95EE\\u9898\\u4E00\\u6B21\\uFF0C\\u4E0E\\u7EAF\\u9012\\u5F52\\u65B9\\u6CD5\\u76F8\\u6BD4\\uFF0C\\u4F18\\u5316\\u4E86\\u6027\\u80FD\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u5927\\u5C0F\\u4E0E\\u8F93\\u5165\\u6570\\u7EC4\\u76F8\\u540C\\u7684 \",(0,n.jsx)(e.code,{children:\"memo\"}),\" \\u6570\\u7EC4\\uFF0C\\u5E76\\u7528 \",(0,n.jsx)(e.code,{children:\"-1\"}),\" \\u586B\\u5145\\uFF0C\\u4EE5\\u6307\\u793A\\u672A\\u8BA1\\u7B97\\u7684\\u503C\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u8F85\\u52A9\\u51FD\\u6570 \",(0,n.jsx)(e.code,{children:\"robFrom\"}),\"\\uFF0C\\u8BE5\\u51FD\\u6570\\u9012\\u5F52\\u5730\\u8BA1\\u7B97\\u4ECE\\u7B2C \",(0,n.jsx)(e.code,{children:\"i\"}),\" \\u4E2A\\u623F\\u5C4B\\u5F00\\u59CB\\u53EF\\u4EE5\\u62A2\\u52AB\\u7684\\u6700\\u5927\\u91D1\\u989D\\u3002\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u57FA\\u672C\\u60C5\\u51B5\\uFF0C\\u5176\\u4E2D \",(0,n.jsx)(e.code,{children:\"i\"}),\" \\u8D85\\u8FC7\\u6570\\u7EC4\\u7684\\u8FB9\\u754C\\uFF0C\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u56E0\\u4E3A\\u6CA1\\u6709\\u623F\\u5C4B\\u53EF\\u4EE5\\u62A2\\u52AB\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u623F\\u5C4B \",(0,n.jsx)(e.code,{children:\"i\"}),\" \\u7684\\u7ED3\\u679C\\u5DF2\\u8BA1\\u7B97\\u5E76\\u5B58\\u50A8\\u5728 \",(0,n.jsx)(e.code,{children:\"memo[i]\"}),\" \\u4E2D\\uFF0C\\u5219\\u8FD4\\u56DE\\u7F13\\u5B58\\u503C\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8BA1\\u7B97\\u4EE5\\u4E0B\\u4E24\\u8005\\u4E4B\\u95F4\\u7684\\u6700\\u5927\\u503C\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8DF3\\u8FC7\\u5F53\\u524D\\u623F\\u5C4B\\uFF0C\\u8C03\\u7528 \",(0,n.jsx)(e.code,{children:\"robFrom(i + 1, numbers)\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u62A2\\u52AB\\u5F53\\u524D\\u623F\\u5C4B\\uFF0C\\u5E76\\u5C06\\u5176\\u503C\\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"robFrom(i + 2, numbers)\"}),\" \\u7684\\u7ED3\\u679C\\u4E2D\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u8BA1\\u7B97\\u7ED3\\u679C\\u5B58\\u50A8\\u5728 \",(0,n.jsx)(e.code,{children:\"memo[i]\"}),\" \\u4E2D\\u4EE5\\u5907\\u5C06\\u6765\\u4F7F\\u7528\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u8C03\\u7528 \",(0,n.jsx)(e.code,{children:\"robFrom(0, numbers)\"}),\" \\u6765\\u5904\\u7406\\u6240\\u6709\\u623F\\u5C4B\\uFF0C\\u5F00\\u59CB\\u8BA1\\u7B97\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8FD4\\u56DE\\u8BA1\\u7B97\\u7ED3\\u679C\\uFF0C\\u8BE5\\u7ED3\\u679C\\u8868\\u793A\\u5728\\u4E0D\\u89E6\\u53D1\\u8B66\\u62A5\\u7684\\u60C5\\u51B5\\u4E0B\\u53EF\\u4EE5\\u62A2\\u52AB\\u7684\\u6700\\u5927\\u91D1\\u989D\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(l,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u6BCF\\u4E2A\\u623F\\u5C4B\\u6700\\u591A\\u5904\\u7406\\u4E00\\u6B21\\uFF0C\\u7ED3\\u679C\\u5B58\\u50A8\\u5728 \",(0,n.jsx)(e.code,{children:\"memo\"}),\" \\u6570\\u7EC4\\u4E2D\\uFF0C\\u907F\\u514D\\u4E86\\u5197\\u4F59\\u7684\\u9012\\u5F52\\u8C03\\u7528\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\",(0,n.jsx)(e.code,{children:\"memo\"}),\" \\u6570\\u7EC4\\u6240\\u9700\\u7684\\u7A7A\\u95F4\\u4E0E\\u623F\\u5C4B\\u6570\\u91CF\\u6210\\u6B63\\u6BD4\\uFF0C\\u5E76\\u4E14\\u9012\\u5F52\\u5806\\u6808\\u5728\\u6700\\u574F\\u7684\\u60C5\\u51B5\\u4E0B\\u53EF\\u80FD\\u8FBE\\u5230 \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u7684\\u6DF1\\u5EA6\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u81EA\\u5E95\\u5411\\u4E0A\\u52A8\\u6001\\u89C4\\u5212\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u901A\\u8FC7\\u8FED\\u4EE3\\u5730\\u4ECE\\u6700\\u540E\\u4E00\\u4E2A\\u623F\\u5C4B\\u5230\\u7B2C\\u4E00\\u4E2A\\u623F\\u5C4B\\u6784\\u5EFA \",(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u8868\\uFF08\\u6216\\u6570\\u7EC4\\uFF09\\u6765\\u6D88\\u9664\\u9012\\u5F52\\uFF0C\\u786E\\u4FDD\\u6240\\u6709\\u5B50\\u95EE\\u9898\\u90FD\\u6309\\u987A\\u5E8F\\u89E3\\u51B3\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"maxRobbedAmount\"}),\" \\u5B58\\u50A8\\u4E86\\u53EF\\u4EE5\\u62A2\\u52AB\\u7684\\u6700\\u5927\\u91D1\\u989D\\uFF0C\\u8003\\u8651\\u4ECE\\u5F53\\u524D\\u7D22\\u5F15\\u5230\\u6700\\u540E\\u4E00\\u4E2A\\u623F\\u5C4B\\u7684\\u623F\\u5C4B\\u3002\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u623F\\u5C4B\\uFF0C\\u8003\\u8651\\u4E24\\u4E2A\\u9009\\u9879\\uFF1A\"]}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8DF3\\u8FC7\\u5F53\\u524D\\u623F\\u5C4B\\u5E76\\u83B7\\u53D6\\u4E3A\\u4E0B\\u4E00\\u6240\\u623F\\u5C4B\\u5B58\\u50A8\\u7684\\u7ED3\\u679C (\",(0,n.jsx)(e.code,{children:\"maxRobbedAmount[i + 1]\"}),\")\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u62A2\\u52AB\\u5F53\\u524D\\u623F\\u5C4B\\u5E76\\u5C06\\u5176\\u503C\\u6DFB\\u52A0\\u5230\\u4E3A\\u8DF3\\u8FC7\\u4E0B\\u4E00\\u6240\\u623F\\u5C4B\\u5B58\\u50A8\\u7684\\u7ED3\\u679C (\",(0,n.jsx)(e.code,{children:\"maxRobbedAmount[i + 2] + numbers[i]\"}),\")\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u6BCF\\u4E2A\\u623F\\u5C4B\\u7684\\u51B3\\u7B56\\u662F\\u901A\\u8FC7\\u9009\\u62E9\\u63D0\\u4F9B\\u6700\\u5927\\u91D1\\u989D\\u7684\\u9009\\u9879\\u6765\\u505A\\u51FA\\u7684\\u3002\\u8FD9\\u907F\\u514D\\u4E86\\u5197\\u4F59\\u8BA1\\u7B97\\uFF0C\\u5E76\\u786E\\u4FDD\\u4E86\\u6709\\u6548\\u7684\\u89E3\\u51B3\\u65B9\\u6848\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5904\\u7406\\u8F93\\u5165\\u6570\\u7EC4\\u4E3A\\u7A7A\\u7684\\u57FA\\u672C\\u60C5\\u51B5\\u3002\\u5982\\u679C\\u6CA1\\u6709\\u623F\\u5C4B\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u5927\\u5C0F\\u4E3A \",(0,n.jsx)(e.code,{children:\"N + 1\"}),\" \\u7684 \",(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"maxRobbedAmount\"}),\"\\uFF0C\\u5E76\\u7528 \",(0,n.jsx)(e.code,{children:\"0\"}),\" \\u586B\\u5145\\u3002\\u6B64\\u6570\\u7EC4\\u5C06\\u5B58\\u50A8\\u4ECE\\u6BCF\\u4E2A\\u623F\\u5C4B\\u5F00\\u59CB\\u53EF\\u4EE5\\u62A2\\u52AB\\u7684\\u6700\\u5927\\u91D1\\u989D\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8BBE\\u7F6E\\u6700\\u540E\\u4E24\\u6240\\u623F\\u5C4B\\u7684\\u57FA\\u672C\\u60C5\\u51B5\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"maxRobbedAmount[N]\"}),\" \\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u8868\\u793A\\u6CA1\\u6709\\u623F\\u5C4B\\u53EF\\u4EE5\\u62A2\\u52AB\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"maxRobbedAmount[N - 1]\"}),\" \\u8BBE\\u7F6E\\u4E3A\\u6700\\u540E\\u4E00\\u4E2A\\u623F\\u5C4B\\u7684\\u503C (\",(0,n.jsx)(e.code,{children:\"numbers[N - 1]\"}),\")\\uFF0C\\u56E0\\u4E3A\\u5BF9\\u4E8E\\u6700\\u540E\\u4E00\\u4E2A\\u623F\\u5C4B\\u6CA1\\u6709\\u5176\\u4ED6\\u9009\\u9879\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u5012\\u6570\\u7B2C\\u4E8C\\u4E2A\\u623F\\u5C4B (\",(0,n.jsx)(e.code,{children:\"N - 2\"}),\") \\u5411\\u540E\\u8FED\\u4EE3\\u5230\\u7B2C\\u4E00\\u4E2A\\u623F\\u5C4B (\",(0,n.jsx)(e.code,{children:\"0\"}),\")\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u623F\\u5C4B \",(0,n.jsx)(e.code,{children:\"i\"}),\"\\uFF0C\\u901A\\u8FC7\\u5728\\u4EE5\\u4E0B\\u4E24\\u8005\\u4E4B\\u95F4\\u8FDB\\u884C\\u9009\\u62E9\\u6765\\u8BA1\\u7B97\\u53EF\\u4EE5\\u62A2\\u52AB\\u7684\\u6700\\u5927\\u91D1\\u989D\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8DF3\\u8FC7\\u5F53\\u524D\\u623F\\u5C4B\\uFF1A\",(0,n.jsx)(e.code,{children:\"maxRobbedAmount[i + 1]\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u62A2\\u52AB\\u5F53\\u524D\\u623F\\u5C4B\\u5E76\\u8DF3\\u8FC7\\u4E0B\\u4E00\\u6240\\u623F\\u5C4B\\uFF1A\",(0,n.jsx)(e.code,{children:\"maxRobbedAmount[i + 2] + numbers[i]\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u6700\\u5927\\u503C\\u5B58\\u50A8\\u5728 \",(0,n.jsx)(e.code,{children:\"maxRobbedAmount[i]\"}),\" \\u4E2D\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"maxRobbedAmount[0]\"}),\"\\uFF0C\\u5B83\\u8868\\u793A\\u4ECE\\u7B2C\\u4E00\\u4E2A\\u623F\\u5C4B\\u5F00\\u59CB\\u53EF\\u4EE5\\u62A2\\u52AB\\u7684\\u6700\\u5927\\u91D1\\u989D\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(l,{children:u}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u5728\\u5411\\u540E\\u8FED\\u4EE3\\u4E2D\\u6070\\u597D\\u5904\\u7406\\u6BCF\\u4E2A\\u623F\\u5C4B\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\",(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"maxRobbedAmount\"}),\" \\u6240\\u9700\\u7684\\u7A7A\\u95F4\\u4E0E\\u623F\\u5C4B\\u6570\\u91CF\\u6210\\u6B63\\u6BD4\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"3. \\u81EA\\u5E95\\u5411\\u4E0A\\u52A8\\u6001\\u89C4\\u5212\\uFF0C\\u4F18\\u5316\\u7A7A\\u95F4\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u57FA\\u4E8E\\u524D\\u4E00\\u4E2A\\u95EE\\u9898\\u4E2D\\u4F7F\\u7528\\u7684\\u81EA\\u5E95\\u5411\\u4E0A\\u52A8\\u6001\\u89C4\\u5212\\u65B9\\u6CD5\\uFF0C\\u4F46\\u5C06\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u4ECE O(n) \\u4F18\\u5316\\u5230 O(1)\\u3002\\u5728\\u4E4B\\u524D\\u7684\\u89E3\\u51B3\\u65B9\\u6848\\u4E2D\\uFF0C\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u6570\\u7EC4\\u6765\\u5B58\\u50A8\\u4ECE\\u6BCF\\u4E2A\\u623F\\u5C4B\\u5F00\\u59CB\\u53EF\\u4EE5\\u62A2\\u52AB\\u7684\\u6700\\u5927\\u91D1\\u989D\\uFF0C\\u8FD9\\u9700\\u8981\\u989D\\u5916\\u7684\\u7A7A\\u95F4\\uFF0C\\u4E0E\\u623F\\u5C4B\\u6570\\u91CF\\u6210\\u6B63\\u6BD4\\u3002\\u4F46\\u662F\\uFF0C\\u5728\\u4EFB\\u4F55\\u7ED9\\u5B9A\\u65F6\\u95F4\\uFF0C\\u53EA\\u9700\\u8981\\u8BE5\\u6570\\u7EC4\\u7684\\u6700\\u540E\\u4E24\\u4E2A\\u503C\\u6765\\u8BA1\\u7B97\\u5F53\\u524D\\u7ED3\\u679C\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E3A\\u4E86\\u6D88\\u9664\\u4E0D\\u5FC5\\u8981\\u7684\\u5B58\\u50A8\\uFF0C\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u7528\\u4E24\\u4E2A\\u53D8\\u91CF \",(0,n.jsx)(e.code,{children:\"prev1\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"prev2\"}),\" \\u66FF\\u6362\\u4E86 \",(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u6570\\u7EC4\\uFF0C\\u8FD9\\u4E24\\u4E2A\\u53D8\\u91CF\\u5B58\\u50A8\\u4E86\\u4E0B\\u4E00\\u4E2A\\u623F\\u5C4B\\uFF08\",(0,n.jsx)(e.code,{children:\"i + 1\"}),\"\\uFF09\\u548C\\u4E4B\\u540E\\u623F\\u5C4B\\uFF08\",(0,n.jsx)(e.code,{children:\"i + 2\"}),\"\\uFF09\\u7684\\u6700\\u5927\\u91D1\\u989D\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\\u7B97\\u6CD5\\u4ECD\\u7136\\u8BA1\\u7B97\\u76F8\\u540C\\u7684\\u7ED3\\u679C\\uFF0C\\u4F46\\u5927\\u5927\\u51CF\\u5C11\\u4E86\\u7A7A\\u95F4\\u4F7F\\u7528\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u7B97\\u6CD5\\u5411\\u540E\\u904D\\u5386\\u6570\\u7EC4\\uFF0C\\u5728\\u6BCF\\u4E00\\u6B65\\u66F4\\u65B0\\u8FD9\\u4E24\\u4E2A\\u53D8\\u91CF\\u3002\\u4F7F\\u7528\\u4E24\\u4E2A\\u53D8\\u91CF\\u800C\\u4E0D\\u662F\\u6574\\u4E2A\\u6570\\u7EC4\\u6D88\\u9664\\u4E86\\u7A7A\\u95F4\\u5F00\\u9500\\uFF0C\\u540C\\u65F6\\u4FDD\\u7559\\u4E86\\u5148\\u524D\\u65B9\\u6CD5\\u7684\\u65F6\\u95F4\\u6548\\u7387\\u3002\\u5F53\\u5904\\u7406\\u5927\\u91CF\\u623F\\u5C4B\\u65F6\\uFF0C\\u8FD9\\u79CD\\u6539\\u8FDB\\u5C24\\u5176\\u6709\\u76CA\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5904\\u7406\\u7279\\u6B8A\\u60C5\\u51B5\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u6CA1\\u6709\\u623F\\u5C4B\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u53EA\\u6709\\u4E00\\u4E2A\\u623F\\u5C4B\\uFF0C\\u5219\\u8FD4\\u56DE\\u5176\\u503C\\uFF0C\\u56E0\\u4E3A\\u4E0D\\u5B58\\u5728\\u5176\\u4ED6\\u9009\\u9879\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E24\\u4E2A\\u53D8\\u91CF\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"prev1\"}),\" \\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u8868\\u793A\\u4ECE\\u4E0B\\u4E00\\u4E2A\\u623F\\u5C4B\\uFF08\",(0,n.jsx)(e.code,{children:\"i + 1\"}),\"\\uFF09\\u5F00\\u59CB\\u53EF\\u4EE5\\u62A2\\u52AB\\u7684\\u6700\\u5927\\u91D1\\u989D\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"prev2\"}),\" \\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u8868\\u793A\\u4ECE\\u4E0B\\u4E00\\u4E2A\\u623F\\u5C4B\\uFF08\",(0,n.jsx)(e.code,{children:\"i + 2\"}),\"\\uFF09\\u4E4B\\u540E\\u7684\\u623F\\u5C4B\\u5F00\\u59CB\\u53EF\\u4EE5\\u62A2\\u52AB\\u7684\\u6700\\u5927\\u91D1\\u989D\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5411\\u540E\\u904D\\u5386\\u623F\\u5C4B\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8BA1\\u7B97\\u53EF\\u4EE5\\u4ECE\\u5F53\\u524D\\u623F\\u5C4B\\u62A2\\u52AB\\u7684\\u6700\\u5927\\u91D1\\u989D\\uFF0C\\u5373\\u4EE5\\u4E0B\\u4E24\\u8005\\u7684\\u6700\\u5927\\u503C\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8DF3\\u8FC7\\u5F53\\u524D\\u623F\\u5C4B\\uFF08\",(0,n.jsx)(e.code,{children:\"prev1\"}),\"\\uFF09\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u62A2\\u52AB\\u5F53\\u524D\\u623F\\u5C4B\\u5E76\\u52A0\\u4E0A \",(0,n.jsx)(e.code,{children:\"prev2\"}),\" \\u7684\\u503C\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"prev2\"}),\" \\u66F4\\u65B0\\u4E3A \",(0,n.jsx)(e.code,{children:\"prev1\"}),\" \\u7684\\u5F53\\u524D\\u503C\\uFF0C\\u5E76\\u5C06 \",(0,n.jsx)(e.code,{children:\"prev1\"}),\" \\u66F4\\u65B0\\u4E3A\\u65B0\\u8BA1\\u7B97\\u7684\\u6700\\u5927\\u503C\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5FAA\\u73AF\\u7ED3\\u675F\\u540E\\uFF0C\",(0,n.jsx)(e.code,{children:\"prev1\"}),\" \\u5305\\u542B\\u4ECE\\u7B2C\\u4E00\\u4E2A\\u623F\\u5C4B\\u5F00\\u59CB\\u53EF\\u4EE5\\u62A2\\u52AB\\u7684\\u6700\\u5927\\u91D1\\u989D\\u3002\\u8FD4\\u56DE\\u6B64\\u503C\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(l,{children:s}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u6BCF\\u4E2A\\u623F\\u5C4B\\u5728\\u5411\\u540E\\u8FED\\u4EE3\\u4E2D\\u53EA\\u5904\\u7406\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u4EC5\\u4F7F\\u7528\\u4E24\\u4E2A\\u53D8\\u91CF\\u6765\\u8DDF\\u8E2A\\u4E2D\\u95F4\\u7ED3\\u679C\\uFF0C\\u65E0\\u9700\\u989D\\u5916\\u7684\\u6570\\u7EC4\\u3002\"]}),`\n`]})]})}function F(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(b,r)})):b(r)}var T=F;return y(M);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/number-stream-median/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/number-stream-median/locales/zh-CN.json new file mode 100644 index 000000000..483556008 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/number-stream-median/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var u=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var M=(d,e)=>()=>(e||d((e={exports:{}}).exports,e),e.exports),b=(d,e)=>{for(var l in e)i(d,l,{get:e[l],enumerable:!0})},c=(d,e,l,r)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let t of x(e))!g.call(d,t)&&t!==l&&i(d,t,{get:()=>e[t],enumerable:!(r=p(e,t))||r.enumerable});return d};var j=(d,e,l)=>(l=d!=null?u(f(d)):{},c(e||!d||!d.__esModule?i(l,\"default\",{value:d,enumerable:!0}):l,d)),_=d=>c(i({},\"__esModule\",{value:!0}),d);var o=M((S,h)=>{h.exports=_jsx_runtime});var A={};b(A,{default:()=>X,frontmatter:()=>C});var n=j(o());var a=MDXTestExamples;var s=[{input:[[\"methods\",[\"add\",\"getMedian\"]],[\"params\",[4,null]]],output:[null,4],explanation:\"Add 4 to the stream, then find the median, which is 4.\"},{input:[[\"methods\",[\"add\",\"add\",\"getMedian\"]],[\"params\",[10,20,null]]],output:[null,null,15],explanation:\"Add 10 and 20 to the stream. The median of [10, 20] is (10 + 20) / 2 = 15.\"},{input:[[\"methods\",[\"add\",\"add\",\"add\",\"getMedian\"]],[\"params\",[1,2,3,null]]],output:[null,null,null,2],explanation:\"Add 1, 2, 3 to the stream. The median of [1, 2, 3] is 2.\"}];var C={title:\"\\u6570\\u5B57\\u6D41\\u7684\\u4E2D\\u4F4D\\u6570\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u67E5\\u627E\\u52A8\\u6001\\u6574\\u6570\\u6D41\\u7684\\u4E2D\\u4F4D\\u6570\"};function m(d){let e=Object.assign({p:\"p\",ul:\"ul\",li:\"li\",code:\"code\",h3:\"h3\"},d.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.p,{children:\"\\u4E00\\u7EC4\\u6570\\u5B57\\u7684\\u4E2D\\u4F4D\\u6570\\u5B9A\\u4E49\\u4E3A\\u6392\\u5E8F\\u5217\\u8868\\u4E2D\\u95F4\\u7684\\u90A3\\u4E2A\\u503C\\u3002\\u5F53\\u5217\\u8868\\u6709\\u5076\\u6570\\u4E2A\\u5143\\u7D20\\u65F6\\uFF0C\\u4E2D\\u4F4D\\u6570\\u662F\\u4E2D\\u95F4\\u4E24\\u4E2A\\u503C\\u7684\\u5E73\\u5747\\u503C\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u4F8B\\u5982\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u5217\\u8868 \",(0,n.jsx)(e.code,{children:\"[1, 2, 3]\"}),\"\\uFF0C\\u4E2D\\u4F4D\\u6570\\u662F 2\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u5217\\u8868 \",(0,n.jsx)(e.code,{children:\"[1, 2]\"}),\"\\uFF0C\\u4E2D\\u4F4D\\u6570\\u662F (1 + 2) / 2 = 1.5\"]}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u5177\\u6709\\u4EE5\\u4E0B\\u65B9\\u6CD5\\u7684 \",(0,n.jsx)(e.code,{children:\"NumberStream\"}),\" \\u7C7B\\uFF1A\"]}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"add(num: number): void\"}),\": \\u5C06\\u4E00\\u4E2A\\u6574\\u6570 num \\u6DFB\\u52A0\\u5230\\u6570\\u636E\\u7ED3\\u6784\\u4E2D\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"getMedian(): number\"}),\": \\u8FD4\\u56DE\\u5230\\u76EE\\u524D\\u4E3A\\u6B62\\u6DFB\\u52A0\\u7684\\u6240\\u6709\\u6570\\u5B57\\u7684\\u4E2D\\u4F4D\\u6570\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:\"NumberStream\"}),\" \\u5B9E\\u4F8B\\u5C06\\u6839\\u636E\\u4EE5\\u4E0B\\u5185\\u5BB9\\u8C03\\u7528\\u5176\\u65B9\\u6CD5\\uFF0C\\u5E76\\u4F7F\\u7528\\u5404\\u79CD\\u53C2\\u6570\\uFF1A\"]}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"methods: string[]\"}),\": \",(0,n.jsx)(e.code,{children:\"NumberStream\"}),\" \\u65B9\\u6CD5\\u540D\\u79F0\\u7684\\u6570\\u7EC4\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"params: (number | null)[]\"}),\": \\u6574\\u6570\\u6570\\u7EC4\"]}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:\"methods[i]\"}),\" \\u5C06\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"params[i]\"}),\" \\u8C03\\u7528\\u3002\"]}),`\n`,(0,n.jsx)(a,{testCases:s}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"num\"}),\" <= 100,000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"methods.length\"}),\" <= 1000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5728\\u8C03\\u7528 \",(0,n.jsx)(e.code,{children:\"getMedian()\"}),\" \\u4E4B\\u524D\\uFF0C\\u6570\\u636E\\u7ED3\\u6784\\u4E2D\\u5C06\\u81F3\\u5C11\\u6709\\u4E00\\u4E2A\\u5143\\u7D20\"]}),`\n`]})]})}function D(d={}){let{wrapper:e}=d.components||{};return e?(0,n.jsx)(e,Object.assign({},d,{children:(0,n.jsx)(m,d)})):m(d)}var X=D;return _(A);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来查找动态整数流的中位数", + "title": "数字流的中位数" + }, + "solution": "var Component=(()=>{var u=Object.create;var a=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,H=Object.prototype.hasOwnProperty;var x=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),v=(r,e)=>{for(var i in e)a(r,i,{get:e[i],enumerable:!0})},d=(r,e,i,l)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let t of b(e))!H.call(r,t)&&t!==i&&a(r,t,{get:()=>e[t],enumerable:!(l=g(e,t))||l.enumerable});return r};var M=(r,e,i)=>(i=r!=null?u(f(r)):{},d(e||!r||!r.__esModule?a(i,\"default\",{value:r,enumerable:!0}):i,r)),y=r=>d(a({},\"__esModule\",{value:!0}),r);var c=x((_,o)=>{o.exports=_jsx_runtime});var j={};v(j,{default:()=>T});var n=M(c());var h=MDXCodeBlock;var m=`export default class NumberStream {\n // Max heap to store the smaller half of the numbers\n private maxHeap: number[] = [];\n\n // Min heap to store the larger half of the numbers\n private minHeap: number[] = [];\n\n // Adds a number into the data structure\n add(num: number): void {\n // Add the new number to the max heap (lo)\n this.addNumberToHeap(this.maxHeap, num, (a, b) => b - a);\n\n // Balance the heaps: move the largest number from maxHeap to minHeap\n this.addNumberToHeap(\n this.minHeap,\n this.removeTopFromHeap(this.maxHeap),\n (a, b) => a - b,\n );\n\n // Ensure that maxHeap has more elements than minHeap if their sizes differ\n if (this.maxHeap.length < this.minHeap.length) {\n this.addNumberToHeap(\n this.maxHeap,\n this.removeTopFromHeap(this.minHeap),\n (a, b) => b - a,\n );\n }\n }\n\n // Returns the median of the current data stream\n getMedian(): number {\n // If maxHeap has more elements, the median is its top element\n if (this.maxHeap.length > this.minHeap.length) {\n return this.maxHeap[0];\n }\n // Otherwise, the median is the average of the tops of maxHeap and minHeap\n else {\n return (this.maxHeap[0] + this.minHeap[0]) * 0.5;\n }\n }\n\n // Utility function to add a number to a heap, maintaining the heap property\n private addNumberToHeap(\n heap: number[],\n num: number,\n comparator: (a: number, b: number) => number,\n ): void {\n heap.push(num);\n let i = heap.length - 1;\n\n while (i > 0) {\n let parent = Math.floor((i - 1) / 2);\n if (comparator(heap[i], heap[parent]) > 0) {\n [heap[i], heap[parent]] = [heap[parent], heap[i]];\n i = parent;\n } else {\n break;\n }\n }\n }\n\n // Utility function to remove the top element from a heap, maintaining the heap property\n private removeTopFromHeap(heap: number[]): number {\n if (heap.length === 0) return NaN;\n const top = heap[0];\n const last = heap.pop();\n\n if (heap.length > 0 && last !== undefined) {\n heap[0] = last;\n this.heapify(heap, 0, (a, b) => (heap === this.maxHeap ? b - a : a - b));\n }\n\n return top;\n }\n\n // Utility function to maintain the heap property from the given index downwards\n private heapify(\n heap: number[],\n i: number,\n comparator: (a: number, b: number) => number,\n ): void {\n const length = heap.length;\n let largest = i;\n const left = 2 * i + 1;\n const right = 2 * i + 2;\n\n if (left < length && comparator(heap[left], heap[largest]) > 0) {\n largest = left;\n }\n\n if (right < length && comparator(heap[right], heap[largest]) > 0) {\n largest = right;\n }\n\n if (largest !== i) {\n [heap[i], heap[largest]] = [heap[largest], heap[i]];\n this.heapify(heap, largest, comparator);\n }\n }\n}\n`;var p=`export default class NumberStream {\n // Array to store the numbers\n private store: number[] = [];\n\n // Adds a number into the data structure\n add(num: number): void {\n // Add the number to the array\n this.store.push(num);\n }\n\n // Returns the median of the current number stream\n getMedian(): number {\n // Sort the array\n this.store.sort((a, b) => a - b);\n\n const n = this.store.length;\n\n // Compute the median\n if (n % 2 === 1) {\n // If the size is odd, return the middle element\n return this.store[Math.floor(n / 2)];\n }\n\n // If the size is even, return the average of the two middle elements\n const mid1 = this.store[n / 2 - 1];\n const mid2 = this.store[n / 2];\n return (mid1 + mid2) * 0.5;\n }\n}\n`;function s(r){let e=Object.assign({h2:\"h2\",p:\"p\",ul:\"ul\",li:\"li\",ol:\"ol\",code:\"code\",h3:\"h3\",strong:\"strong\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u6392\\u5E8F\\u7684\\u66B4\\u529B\\u65B9\\u6CD5\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u6B64\\u95EE\\u9898\\u7684\\u76EE\\u6807\\u662F\\u52A8\\u6001\\u5730\\u8BA1\\u7B97\\u6570\\u5B57\\u6D41\\u7684\\u4E2D\\u4F4D\\u6570\\u3002\\u66B4\\u529B\\u65B9\\u6CD5\\u7EF4\\u62A4\\u4E00\\u4E2A\\u5230\\u76EE\\u524D\\u4E3A\\u6B62\\u6536\\u5230\\u7684\\u6240\\u6709\\u6570\\u5B57\\u7684\\u5217\\u8868\\uFF0C\\u5E76\\u5728\\u6BCF\\u6B21\\u8BF7\\u6C42\\u4E2D\\u4F4D\\u6570\\u65F6\\u5BF9\\u5217\\u8868\\u8FDB\\u884C\\u6392\\u5E8F\\u540E\\u8BA1\\u7B97\\u4E2D\\u4F4D\\u6570\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u4E2D\\u4F4D\\u6570\\u5B9A\\u4E49\\u4E3A\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u6570\\u5B57\\u603B\\u6570\\u4E3A\\u5947\\u6570\\uFF0C\\u5219\\u4E3A\\u4E2D\\u95F4\\u5143\\u7D20\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u6570\\u5B57\\u603B\\u6570\\u4E3A\\u5076\\u6570\\uFF0C\\u5219\\u4E3A\\u4E24\\u4E2A\\u4E2D\\u95F4\\u5143\\u7D20\\u7684\\u5E73\\u5747\\u503C\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u6B64\\u65B9\\u6CD5\\u901A\\u8FC7\\u4EE5\\u4E0B\\u65B9\\u5F0F\\u5DE5\\u4F5C\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u5C06\\u6240\\u6709\\u4F20\\u5165\\u7684\\u6570\\u5B57\\u5B58\\u50A8\\u5728\\u4E00\\u4E2A\\u6570\\u7EC4\\u4E2D\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u6BCF\\u6B21\\u8C03\\u7528 \",(0,n.jsx)(e.code,{children:\"getMedian\"}),\" \\u65B9\\u6CD5\\u65F6\\u5BF9\\u6570\\u7EC4\\u8FDB\\u884C\\u6392\\u5E8F\\uFF0C\\u4EE5\\u786E\\u4FDD\\u6570\\u5B57\\u6309\\u5347\\u5E8F\\u6392\\u5217\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u6839\\u636E\\u6392\\u5E8F\\u540E\\u7684\\u6570\\u7EC4\\u8BA1\\u7B97\\u4E2D\\u4F4D\\u6570\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521B\\u5EFA\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"NumberStream\"}),\" \\u7C7B\\uFF0C\\u5176\\u4E2D\\u5305\\u542B\\u4E00\\u4E2A\\u79C1\\u6709\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"store\"}),\"\\uFF0C\\u7528\\u4E8E\\u4FDD\\u5B58\\u6240\\u6709\\u4F20\\u5165\\u7684\\u6570\\u5B57\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"add\"}),\" \\u65B9\\u6CD5\\uFF0C\\u7528\\u4E8E\\u5C06\\u6570\\u5B57\\u8FFD\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"store\"}),\" \\u6570\\u7EC4\\u4E2D\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"getMedian\"}),\" \\u65B9\\u6CD5\\u6765\\u8BA1\\u7B97\\u4E2D\\u4F4D\\u6570\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u6309\\u5347\\u5E8F\\u5BF9 \",(0,n.jsx)(e.code,{children:\"store\"}),\" \\u6570\\u7EC4\\u8FDB\\u884C\\u6392\\u5E8F\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u786E\\u5B9A\\u6570\\u7EC4\\u7684\\u5927\\u5C0F (\",(0,n.jsx)(e.code,{children:\"n\"}),\")\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u4E3A\\u5947\\u6570\\uFF0C\\u5219\\u8FD4\\u56DE\\u4E2D\\u95F4\\u5143\\u7D20\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u4E3A\\u5076\\u6570\\uFF0C\\u5219\\u8BA1\\u7B97\\u4E24\\u4E2A\\u4E2D\\u95F4\\u5143\\u7D20\\u7684\\u5E73\\u5747\\u503C\\u5E76\\u8FD4\\u56DE\\u7ED3\\u679C\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(h,{children:p}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n log n)\"}),\"\\u3002\\u5BF9\\u6570\\u7EC4\\u8FDB\\u884C\\u6392\\u5E8F\\u4E3B\\u5BFC\\u4E86 \",(0,n.jsx)(e.code,{children:\"getMedian\"}),\" \\u65B9\\u6CD5\\u7684\\u8FD0\\u884C\\u65F6\\u3002\\u5C06\\u6570\\u5B57\\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"store\"}),\" \\u6570\\u7EC4\\u9700\\u8981 O(1) \\u7684\\u65F6\\u95F4\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\",(0,n.jsx)(e.code,{children:\"store\"}),\" \\u6570\\u7EC4\\u968F\\u6D41\\u4E2D\\u5143\\u7D20\\u7684\\u6570\\u91CF\\u7EBF\\u6027\\u589E\\u957F\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u4E24\\u4E2A\\u5806\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u901A\\u8FC7\\u4F7F\\u7528\\u4E24\\u4E2A\\u5806\\u6765\\u4F18\\u5316\\u5728\\u52A8\\u6001\\u6570\\u636E\\u6D41\\u4E2D\\u67E5\\u627E\\u4E2D\\u4F4D\\u6570\\u7684\\u8FC7\\u7A0B\\uFF1A\\u4E00\\u4E2A\\u6700\\u5927\\u5806\\u548C\\u4E00\\u4E2A\\u6700\\u5C0F\\u5806\\u3002\\u6838\\u5FC3\\u601D\\u60F3\\u662F\\u7EF4\\u62A4\\u4E24\\u4E2A\\u5E73\\u8861\\u7684\\u5806\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4E00\\u4E2A\\u6700\\u5927\\u5806 (\",(0,n.jsx)(e.code,{children:\"maxHeap\"}),\")\\uFF0C\\u5305\\u542B\\u8F83\\u5C0F\\u7684\\u4E00\\u534A\\u6570\\u5B57\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4E00\\u4E2A\\u6700\\u5C0F\\u5806 (\",(0,n.jsx)(e.code,{children:\"minHeap\"}),\")\\uFF0C\\u5305\\u542B\\u8F83\\u5927\\u7684\\u4E00\\u534A\\u6570\\u5B57\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u5806\\u7684\\u7ED3\\u6784\\u4F7F\\u5F97\\u6700\\u5927\\u5806\\u7684\\u9876\\u90E8\\u8868\\u793A\\u8F83\\u5C0F\\u4E00\\u534A\\u4E2D\\u7684\\u6700\\u5927\\u6570\\u5B57\\uFF0C\\u6700\\u5C0F\\u5806\\u7684\\u9876\\u90E8\\u8868\\u793A\\u8F83\\u5927\\u4E00\\u534A\\u4E2D\\u7684\\u6700\\u5C0F\\u6570\\u5B57\\u3002\\u8FD9\\u79CD\\u7ED3\\u6784\\u5141\\u8BB8\\u9AD8\\u6548\\u5730\\u68C0\\u7D22\\u4E2D\\u4F4D\\u6570\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u5806\\u7684\\u5927\\u5C0F\\u662F\\u5E73\\u8861\\u7684\\uFF0C\\u5219\\u4E2D\\u4F4D\\u6570\\u662F\\u4E24\\u4E2A\\u5806\\u7684\\u9876\\u90E8\\u7684\\u5E73\\u5747\\u503C\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u6700\\u5927\\u5806\\u6BD4\\u6700\\u5C0F\\u5806\\u591A\\u4E00\\u4E2A\\u5143\\u7D20\\uFF0C\\u5219\\u4E2D\\u4F4D\\u6570\\u662F\\u6700\\u5927\\u5806\\u7684\\u9876\\u90E8\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u65B9\\u6CD5\\u786E\\u4FDD\\u5806\\u5728\\u6BCF\\u6B21\\u63D2\\u5165\\u540E\\u4FDD\\u6301\\u5E73\\u8861\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u9996\\u5148\\u5C06\\u4E00\\u4E2A\\u65B0\\u6570\\u5B57\\u6DFB\\u52A0\\u5230\\u6700\\u5927\\u5806\\u4E2D\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5C06\\u6700\\u5927\\u5806\\u4E2D\\u7684\\u6700\\u5927\\u6570\\u5B57\\u79FB\\u52A8\\u5230\\u6700\\u5C0F\\u5806\\u4E2D\\u4EE5\\u4FDD\\u6301\\u987A\\u5E8F\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u6700\\u5C0F\\u5806\\u589E\\u957F\\u5230\\u5927\\u4E8E\\u6700\\u5927\\u5806\\uFF0C\\u5219\\u5C06\\u6700\\u5C0F\\u5806\\u4E2D\\u7684\\u6700\\u5C0F\\u6570\\u5B57\\u79FB\\u56DE\\u6700\\u5927\\u5806\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u901A\\u8FC7\\u4F7F\\u7528\\u5806\\u5C5E\\u6027\\uFF0C\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u907F\\u514D\\u4E86\\u66B4\\u529B\\u65B9\\u6CD5\\u4E2D\\u7684 O(n log n) \\u6392\\u5E8F\\u6B65\\u9AA4\\uFF0C\\u5B9E\\u73B0\\u4E86\\u63D2\\u5165\\u548C\\u4E2D\\u4F4D\\u6570\\u8BA1\\u7B97\\u7684 O(log n) \\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E24\\u4E2A\\u5806\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"maxHeap\"}),\" \\u7528\\u4E8E\\u8F83\\u5C0F\\u7684\\u4E00\\u534A\\u6570\\u5B57\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"minHeap\"}),\" \\u7528\\u4E8E\\u8F83\\u5927\\u7684\\u4E00\\u534A\\u6570\\u5B57\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"add\"}),\" \\u65B9\\u6CD5\\uFF0C\\u7528\\u4E8E\\u5C06\\u65B0\\u6570\\u5B57\\u63D2\\u5165\\u6570\\u636E\\u6D41\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u6570\\u5B57\\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"maxHeap\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"maxHeap\"}),\" \\u4E2D\\u6700\\u5927\\u7684\\u6570\\u5B57\\u79FB\\u52A8\\u5230 \",(0,n.jsx)(e.code,{children:\"minHeap\"}),\" \\u4EE5\\u4FDD\\u6301\\u987A\\u5E8F\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"minHeap\"}),\" \\u589E\\u957F\\u5927\\u4E8E \",(0,n.jsx)(e.code,{children:\"maxHeap\"}),\"\\uFF0C\\u5219\\u5C06 \",(0,n.jsx)(e.code,{children:\"minHeap\"}),\" \\u4E2D\\u6700\\u5C0F\\u7684\\u6570\\u5B57\\u79FB\\u56DE \",(0,n.jsx)(e.code,{children:\"maxHeap\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"getMedian\"}),\" \\u65B9\\u6CD5\\u6765\\u8BA1\\u7B97\\u4E2D\\u4F4D\\u6570\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"maxHeap\"}),\" \\u7684\\u5143\\u7D20\\u591A\\u4E8E \",(0,n.jsx)(e.code,{children:\"minHeap\"}),\"\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"maxHeap\"}),\" \\u7684\\u9876\\u90E8\\u5143\\u7D20\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5426\\u5219\\uFF0C\\u8FD4\\u56DE\\u4E24\\u4E2A\\u5806\\u9876\\u90E8\\u7684\\u5E73\\u5747\\u503C\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u5806\\u64CD\\u4F5C\\u7684\\u5B9E\\u7528\\u51FD\\u6570\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"addNumberToHeap\"}),\" \\u7528\\u4E8E\\u5728\\u4FDD\\u6301\\u5806\\u5C5E\\u6027\\u7684\\u540C\\u65F6\\u63D2\\u5165\\u6570\\u5B57\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"removeTopFromHeap\"}),\" \\u7528\\u4E8E\\u5728\\u6062\\u590D\\u5806\\u5C5E\\u6027\\u7684\\u540C\\u65F6\\u5220\\u9664\\u9876\\u90E8\\u5143\\u7D20\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"heapify\"}),\" \\u7528\\u4E8E\\u786E\\u4FDD\\u4ECE\\u7ED9\\u5B9A\\u7D22\\u5F15\\u5411\\u4E0B\\u7684\\u5806\\u5C5E\\u6027\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(h,{children:m}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n log n)\"}),\"\\u3002\\u6BCF\\u6B21\\u63D2\\u5165\\u90FD\\u6D89\\u53CA O(log n) \\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u6765\\u7EF4\\u62A4\\u5806\\u5C5E\\u6027\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u5806\\u4E00\\u8D77\\u5B58\\u50A8\\u6570\\u636E\\u6D41\\u4E2D\\u7684\\u6240\\u6709\\u5143\\u7D20\\u3002\"]}),`\n`]})]})}function F(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(s,r)})):s(r)}var T=F;return y(j);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/ocean-flow/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/ocean-flow/locales/zh-CN.json new file mode 100644 index 000000000..6abab5ab5 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/ocean-flow/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var u=Object.create;var r=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var g=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),j=(t,e)=>{for(var o in e)r(t,o,{get:e[o],enumerable:!0})},i=(t,e,o,l)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let c of x(e))!b.call(t,c)&&c!==o&&r(t,c,{get:()=>e[c],enumerable:!(l=p(e,c))||l.enumerable});return t};var w=(t,e,o)=>(o=t!=null?u(f(t)):{},i(e||!t||!t.__esModule?r(o,\"default\",{value:t,enumerable:!0}):o,t)),_=t=>i(r({},\"__esModule\",{value:!0}),t);var h=g((F,a)=>{a.exports=_jsx_runtime});var X={};j(X,{default:()=>D,frontmatter:()=>M});var n=w(h());var d=MDXTestExamples;var s=[{input:[[\"matrix\",[[1,2,3,1],[4,3,3,4],[5,2,4,3],[5,2,1,5],[1,5,1,3]]]],output:[[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,2],[3,0],[4,0],[4,1]],explanation:\"The listed cells are capable of reaching both oceans. For instance, the cell at (row 0, column 2) can flow directly to the top left ocean, and then from (row 0, column 2) it can reach the bottom right ocean through (row 0, column 3).\"},{input:[[\"matrix\",[[1]]]],output:[[0,0]],explanation:\"The only cell can flow to both oceans.\"},{input:[[\"matrix\",[[1,2,3],[4,5,6],[7,8,9]]]],output:[[0,2],[1,2],[2,0],[2,1],[2,2]],explanation:\"The listed cells are capable of reaching both oceans\"}];var M={title:\"\\u6D77\\u6D0B\\u6D41\\u52A8\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u8FD4\\u56DE\\u53EF\\u4EE5\\u6D41\\u5411\\u4E24\\u4E2A\\u5927\\u6D0B\\u7684\\u5355\\u5143\\u683C\"};function m(t){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"m\"}),\" x \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u7684\\u4E8C\\u7EF4 \",(0,n.jsx)(e.code,{children:\"matrix\"}),\"\\uFF0C\\u8868\\u793A\\u7531\\u4E24\\u4E2A\\u4E0D\\u540C\\u5927\\u6D0B\\uFF08\\u4E00\\u4E2A\\u5728\\u5DE6\\u4FA7\\u548C\\u9876\\u90E8\\u8FB9\\u7F18\\uFF0C\\u53E6\\u4E00\\u4E2A\\u5728\\u53F3\\u4FA7\\u548C\\u5E95\\u90E8\\u8FB9\\u7F18\\uFF09\\u63A5\\u58E4\\u7684\\u5C9B\\u5C7F\\uFF0C\\u786E\\u5B9A\\u54EA\\u4E9B\\u5355\\u5143\\u683C\\u53EF\\u4EE5\\u4F7F\\u96E8\\u6C34\\u6D41\\u5411\\u4E24\\u4E2A\\u5927\\u6D0B\\u3002\\u6BCF\\u4E2A\\u5355\\u5143\\u683C\\u5305\\u542B\\u4E00\\u4E2A\\u6574\\u6570\\uFF0C\\u8868\\u793A\\u5176\\u9AD8\\u4E8E\\u6D77\\u5E73\\u9762\\u7684\\u9AD8\\u5EA6\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u5982\\u679C\\u76F8\\u90BB\\u5355\\u5143\\u683C\\u7684\\u9AD8\\u5EA6\\u5C0F\\u4E8E\\u6216\\u7B49\\u4E8E\\u5F53\\u524D\\u5355\\u5143\\u683C\\u7684\\u9AD8\\u5EA6\\uFF0C\\u5219\\u6C34\\u53EF\\u4EE5\\u4ECE\\u4E00\\u4E2A\\u5355\\u5143\\u683C\\u6D41\\u5411\\u53E6\\u4E00\\u4E2A\\u5355\\u5143\\u683C\\u3002\\u76F8\\u90BB\\u5355\\u5143\\u683C\\u662F\\u6307\\u4E00\\u4E2A\\u5355\\u5143\\u683C\\u7684\\u6B63\\u5317\\u3001\\u6B63\\u5357\\u3001\\u6B63\\u897F\\u548C\\u6B63\\u4E1C\\u65B9\\u5411\\u7684\\u5355\\u5143\\u683C\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8FD4\\u56DE\\u4E00\\u4E2A\\u5217\\u8868\\uFF0C\\u5176\\u4E2D\\u5305\\u542B\\u6240\\u6709\\u53EF\\u4EE5\\u6D41\\u5411\\u4E24\\u4E2A\\u5927\\u6D0B\\u7684\\u5355\\u5143\\u683C\\uFF0C\\u5E76\\u6309\\u5176\\u5728\\u4ECE\\u5DE6\\u4E0A\\u89D2\\u5230\\u53F3\\u4E0B\\u89D2\\u904D\\u5386\\u77E9\\u9635\\u65F6\\u7684\\u4F4D\\u7F6E\\u6392\\u5E8F\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"matrix: number[][]\"}),\": \\u4E00\\u4E2A\\u4E8C\\u7EF4\\u6574\\u6570\\u6570\\u7EC4\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u6CE8\\u610F\\u4E8B\\u9879\"}),`\n`,(0,n.jsx)(d,{testCases:s}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"m\"}),\", \",(0,n.jsx)(e.code,{children:\"n\"}),\" <= 100\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"0 <= \",(0,n.jsx)(e.code,{children:\"matrix[row][col]\"}),\" <= 100,000\"]}),`\n`]})]})}function C(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(m,t)})):m(t)}var D=C;return _(X);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,返回可以流向两个大洋的单元格", + "title": "海洋流动" + }, + "solution": "var Component=(()=>{var w=Object.create;var r=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var R=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var C=(l,e)=>()=>(e||l((e={exports:{}}).exports,e),e.exports),p=(l,e)=>{for(var o in e)r(l,o,{get:e[o],enumerable:!0})},h=(l,e,o,t)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let c of b(e))!g.call(l,c)&&c!==o&&r(l,c,{get:()=>e[c],enumerable:!(t=f(e,c))||t.enumerable});return l};var B=(l,e,o)=>(o=l!=null?w(R(l)):{},h(e||!l||!l.__esModule?r(o,\"default\",{value:l,enumerable:!0}):o,l)),x=l=>h(r({},\"__esModule\",{value:!0}),l);var d=C((y,a)=>{a.exports=_jsx_runtime});var L={};p(L,{default:()=>D});var n=B(d());var i=MDXCodeBlock;var s=`const DIRECTIONS: number[][] = [\n [0, 1],\n [1, 0],\n [-1, 0],\n [0, -1],\n];\n\nexport default function oceanFlow(matrix: number[][]): number[][] {\n // Check if input is empty\n if (matrix.length === 0 || matrix[0].length === 0) {\n return [];\n }\n\n const numRows = matrix.length;\n const numCols = matrix[0].length;\n\n function dfs(row: number, col: number, reachable: boolean[][]): void {\n // This cell is reachable, so mark it\n reachable[row][col] = true;\n for (const dir of DIRECTIONS) {\n // Check all 4 directions\n const newRow = row + dir[0];\n const newCol = col + dir[1];\n // Check if new cell is within bounds\n if (newRow < 0 || newRow >= numRows || newCol < 0 || newCol >= numCols) {\n continue;\n }\n // Check that the new cell hasn't already been visited\n if (reachable[newRow][newCol]) {\n continue;\n }\n // Check that the new cell has a higher or equal height,\n // So that water can flow from the new cell to the old cell\n if (matrix[newRow][newCol] < matrix[row][col]) {\n continue;\n }\n // If we've gotten this far, that means the new cell is reachable\n dfs(newRow, newCol, reachable);\n }\n }\n\n const oceanTopLeftReachable: boolean[][] = Array.from(Array(numRows), () =>\n Array(numCols).fill(false),\n );\n const oceanBottomRightReachable: boolean[][] = Array.from(\n Array(numRows),\n () => Array(numCols).fill(false),\n );\n\n // Explore each cell adjacent to the oceans and start a DFS\n for (let row = 0; row < numRows; row++) {\n dfs(row, 0, oceanTopLeftReachable); // Left edge\n dfs(row, numCols - 1, oceanBottomRightReachable); // Right edge\n }\n\n for (let col = 0; col < numCols; col++) {\n dfs(0, col, oceanTopLeftReachable); // Top edge\n dfs(numRows - 1, col, oceanBottomRightReachable); // Bottom edge\n }\n\n // Find all cells that can reach both oceans\n const commonCells: number[][] = [];\n\n for (let row = 0; row < numRows; row++) {\n for (let col = 0; col < numCols; col++) {\n if (\n oceanTopLeftReachable[row][col] &&\n oceanBottomRightReachable[row][col]\n ) {\n commonCells.push([row, col]);\n }\n }\n }\n\n return commonCells;\n}\n`;var u=`const DIRECTIONS: number[][] = [\n [0, 1],\n [1, 0],\n [-1, 0],\n [0, -1],\n];\n\nexport default function oceanFlow(matrix: number[][]): number[][] {\n // Check if input is empty\n if (matrix.length === 0 || matrix[0].length === 0) {\n return [];\n }\n\n const numRows = matrix.length;\n const numCols = matrix[0].length;\n\n function bfs(queue: number[][]): boolean[][] {\n const reachable: boolean[][] = Array.from({ length: numRows }, () =>\n Array(numCols).fill(false),\n );\n while (queue.length > 0) {\n const cell = queue.shift() as number[];\n // This cell is reachable, so mark it\n reachable[cell[0]][cell[1]] = true;\n for (const dir of DIRECTIONS) {\n // Check all 4 directions\n const newRow = cell[0] + dir[0];\n const newCol = cell[1] + dir[1];\n // Check if new cell is within bounds\n if (\n newRow < 0 ||\n newRow >= numRows ||\n newCol < 0 ||\n newCol >= numCols\n ) {\n continue;\n }\n // Check that the new cell hasn't already been visited\n if (reachable[newRow][newCol]) {\n continue;\n }\n // Check that the new cell has a higher or equal height,\n // So that water can flow from the new cell to the old cell\n if (matrix[newRow][newCol] < matrix[cell[0]][cell[1]]) {\n continue;\n }\n // If we've gotten this far, that means the new cell is reachable\n queue.push([newRow, newCol]);\n }\n }\n return reachable;\n }\n\n // Setup each queue with cells adjacent to their respective ocean\n const oceanTopLeftQueue: number[][] = [];\n const oceanBottomRightQueue: number[][] = [];\n\n for (let row = 0; row < numRows; row++) {\n oceanTopLeftQueue.push([row, 0]); // Left edge\n oceanBottomRightQueue.push([row, numCols - 1]); // Right edge\n }\n\n for (let col = 0; col < numCols; col++) {\n oceanTopLeftQueue.push([0, col]); // Top edge\n oceanBottomRightQueue.push([numRows - 1, col]); // Bottom edge\n }\n\n // Perform a BFS for each ocean to find all cells accessible by each ocean\n const oceanTopLeftReachable = bfs(oceanTopLeftQueue);\n const oceanBottomRightReachable = bfs(oceanBottomRightQueue);\n\n // Find all cells that can reach both oceans\n const commonCells: number[][] = [];\n\n for (let row = 0; row < numRows; row++) {\n for (let col = 0; col < numCols; col++) {\n if (\n oceanTopLeftReachable[row][col] &&\n oceanBottomRightReachable[row][col]\n ) {\n commonCells.push([row, col]);\n }\n }\n }\n\n return commonCells;\n}\n`;function m(l){let e=Object.assign({h2:\"h2\",p:\"p\",ul:\"ul\",li:\"li\",h3:\"h3\",ol:\"ol\",code:\"code\",strong:\"strong\"},l.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u6DF1\\u5EA6\\u4F18\\u5148\\u641C\\u7D22\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u95EE\\u9898\\u6D89\\u53CA\\u5728\\u77E9\\u9635\\u4E2D\\u627E\\u5230\\u6C34\\u53EF\\u4EE5\\u6D41\\u5230\\u592A\\u5E73\\u6D0B\\uFF08\\u9876\\u90E8\\u548C\\u5DE6\\u4FA7\\u8FB9\\u7F18\\uFF09\\u548C\\u5927\\u897F\\u6D0B\\uFF08\\u5E95\\u90E8\\u548C\\u53F3\\u4FA7\\u8FB9\\u7F18\\uFF09\\u7684\\u5355\\u5143\\u683C\\u3002 \\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u6DF1\\u5EA6\\u4F18\\u5148\\u641C\\u7D22 (DFS) \\u6765\\u63A2\\u7D22\\u4ECE\\u6BCF\\u4E2A\\u6D77\\u6D0B\\u7684\\u8FB9\\u754C\\u5F00\\u59CB\\u7684\\u53EF\\u5230\\u8FBE\\u5355\\u5143\\u683C\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u7684\\u76F4\\u89C9\\u662F\\u5C06\\u95EE\\u9898\\u89C6\\u4E3A\\u4E00\\u4E2A\\u8FDE\\u901A\\u6027\\u56FE\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u6C34\\u53EF\\u4EE5\\u6D41\\u5230\\u8BE5\\u6D77\\u6D0B\\uFF0C\\u5219\\u4E00\\u4E2A\\u5355\\u5143\\u683C\\u201C\\u8FDE\\u63A5\\u201D\\u5230\\u8BE5\\u6D77\\u6D0B\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u4E00\\u4E2A\\u5355\\u5143\\u683C\\u6D41\\u5411\\u7684\\u6240\\u6709\\u76F8\\u90BB\\u5355\\u5143\\u683C\\u7684\\u9AD8\\u5EA6\\u5927\\u4E8E\\u6216\\u7B49\\u4E8E\\u5176\\u81EA\\u8EAB\\uFF0C\\u5219\\u8BA4\\u4E3A\\u8BE5\\u5355\\u5143\\u683C\\u662F\\u53EF\\u5230\\u8FBE\\u7684\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u7B97\\u6CD5\\u4F7F\\u7528\\u4E24\\u4E2A\\u5E03\\u5C14\\u77E9\\u9635\\u6765\\u8DDF\\u8E2A\\u592A\\u5E73\\u6D0B\\u548C\\u5927\\u897F\\u6D0B\\u7684\\u53EF\\u8FBE\\u6027\\u3002 \\u4ECE\\u5404\\u81EA\\u7684\\u6D77\\u6D0B\\u8FB9\\u754C\\u5F00\\u59CB DFS \\u53EF\\u786E\\u4FDD\\u4EC5\\u63A2\\u7D22\\u6709\\u6548\\u8DEF\\u5F84\\u3002 \\u5904\\u7406\\u540E\\uFF0C\\u4E24\\u4E2A\\u53EF\\u8FBE\\u6027\\u77E9\\u9635\\u7684\\u4EA4\\u96C6\\u7ED9\\u51FA\\u4E86\\u6240\\u9700\\u7684\\u5355\\u5143\\u683C\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49 \",(0,n.jsx)(e.code,{children:\"DIRECTIONS\"}),\" \\u6570\\u7EC4\\u4EE5\\u8868\\u793A\\u56DB\\u79CD\\u53EF\\u80FD\\u7684\\u79FB\\u52A8\\uFF08\\u4E0A\\u3001\\u4E0B\\u3001\\u5DE6\\u3001\\u53F3\\uFF09\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E24\\u4E2A\\u4E8C\\u7EF4\\u5E03\\u5C14\\u77E9\\u9635\\uFF1A\",(0,n.jsx)(e.code,{children:\"oceanTopLeftReachable\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"oceanBottomRightReachable\"}),\"\\uFF0C\\u4EE5\\u5206\\u522B\\u6807\\u8BB0\\u4ECE\\u592A\\u5E73\\u6D0B\\u548C\\u5927\\u897F\\u6D0B\\u53EF\\u5230\\u8FBE\\u7684\\u5355\\u5143\\u683C\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49 \",(0,n.jsx)(e.code,{children:\"dfs\"}),\" \\u51FD\\u6570\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u5C06\\u5F53\\u524D\\u5355\\u5143\\u683C\\u6807\\u8BB0\\u4E3A\\u5728\\u7ED9\\u5B9A\\u7684\\u5E03\\u5C14\\u77E9\\u9635\\u4E2D\\u53EF\\u5230\\u8FBE\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u63A2\\u7D22\\u6240\\u6709\\u6709\\u6548\\u7684\\u76F8\\u90BB\\u5355\\u5143\\u683C\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u5728\\u8303\\u56F4\\u5185\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5C1A\\u672A\\u8BBF\\u95EE\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u9AD8\\u5EA6\\u5927\\u4E8E\\u6216\\u7B49\\u4E8E\\u5F53\\u524D\\u5355\\u5143\\u683C\\u3002\"}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u592A\\u5E73\\u6D0B\\u7684\\u8FB9\\u754C\\u5F00\\u59CB DFS\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u904D\\u5386\\u77E9\\u9635\\u7684\\u9876\\u884C\\u548C\\u5DE6\\u5217\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u5927\\u897F\\u6D0B\\u7684\\u8FB9\\u754C\\u5F00\\u59CB DFS\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u904D\\u5386\\u77E9\\u9635\\u7684\\u5E95\\u884C\\u548C\\u53F3\\u5217\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u77E9\\u9635\\u4E2D\\u7684\\u6240\\u6709\\u5355\\u5143\\u683C\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u4E00\\u4E2A\\u5355\\u5143\\u683C\\u5728 \",(0,n.jsx)(e.code,{children:\"oceanTopLeftReachable\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"oceanBottomRightReachable\"}),\" \\u4E2D\\u90FD\\u88AB\\u6807\\u8BB0\\u4E3A\\u53EF\\u5230\\u8FBE\\uFF0C\\u5219\\u5C06\\u5176\\u6DFB\\u52A0\\u5230\\u7ED3\\u679C\\u4E2D\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8FD4\\u56DE\\u53EF\\u4EE5\\u6D41\\u5230\\u4E24\\u4E2A\\u6D77\\u6D0B\\u7684\\u5355\\u5143\\u683C\\u5217\\u8868\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(i,{children:s}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m.n)\"}),\"\\u3002 \\u5728 DFS \\u671F\\u95F4\\uFF0C\\u6BCF\\u4E2A\\u5355\\u5143\\u683C\\u6700\\u591A\\u8BBF\\u95EE\\u4E00\\u6B21\\uFF0C\\u5E76\\u4E14\\u77E9\\u9635\\u6709 \",(0,n.jsx)(e.code,{children:\"m.n\"}),\" \\u4E2A\\u5355\\u5143\\u683C\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m.n)\"}),\"\\u3002 \\u4F7F\\u7528\\u4E24\\u4E2A\\u5927\\u5C0F\\u4E3A \",(0,n.jsx)(e.code,{children:\"m.n\"}),\" \\u7684\\u5E03\\u5C14\\u77E9\\u9635\\u6765\\u8DDF\\u8E2A\\u53EF\\u8FBE\\u6027\\uFF0C\\u5E76\\u4E14 DFS \\u7684\\u8C03\\u7528\\u5806\\u6808\\u5728\\u6700\\u574F\\u7684\\u60C5\\u51B5\\u4E0B\\u53EF\\u4EE5\\u8FBE\\u5230 \",(0,n.jsx)(e.code,{children:\"m.n\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u5E7F\\u5EA6\\u4F18\\u5148\\u641C\\u7D22\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u95EE\\u9898\\u6D89\\u53CA\\u8BC6\\u522B\\u77E9\\u9635\\u4E2D\\u6C34\\u53EF\\u4EE5\\u6D41\\u5230\\u592A\\u5E73\\u6D0B\\uFF08\\u9876\\u90E8\\u548C\\u5DE6\\u4FA7\\u8FB9\\u7F18\\uFF09\\u548C\\u5927\\u897F\\u6D0B\\uFF08\\u5E95\\u90E8\\u548C\\u53F3\\u4FA7\\u8FB9\\u7F18\\uFF09\\u7684\\u5355\\u5143\\u683C\\u3002 \\u4F7F\\u7528\\u5E7F\\u5EA6\\u4F18\\u5148\\u641C\\u7D22 (BFS) \\u53EF\\u786E\\u4FDD\\u5728\\u63A2\\u7D22\\u6240\\u6709\\u6709\\u6548\\u5355\\u5143\\u683C\\u65F6\\u6EE1\\u8DB3\\u6D41\\u91CF\\u7EA6\\u675F\\u3002 \\u6BCF\\u4E2A\\u5355\\u5143\\u683C\\u7684\\u9AD8\\u5EA6\\u5FC5\\u987B\\u5927\\u4E8E\\u6216\\u7B49\\u4E8E\\u5176\\u76F8\\u90BB\\u5355\\u5143\\u683C\\uFF0C\\u6C34\\u624D\\u80FD\\u53CD\\u5411\\u6D41\\u52A8\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u4E24\\u4E2A BFS \\u904D\\u5386\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u4E00\\u4E2A\\u4ECE\\u592A\\u5E73\\u6D0B\\u7684\\u8FB9\\u754C\\u5F00\\u59CB\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u53E6\\u4E00\\u4E2A\\u4ECE\\u5927\\u897F\\u6D0B\\u7684\\u8FB9\\u754C\\u5F00\\u59CB\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u4ECE\\u4E24\\u4E2A BFS \\u904D\\u5386\\u90FD\\u53EF\\u5230\\u8FBE\\u7684\\u5355\\u5143\\u683C\\u662F\\u6240\\u9700\\u7684\\u7ED3\\u679C\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49 \",(0,n.jsx)(e.code,{children:\"DIRECTIONS\"}),\" \\u6570\\u7EC4\\u4EE5\\u8868\\u793A\\u56DB\\u79CD\\u53EF\\u80FD\\u7684\\u79FB\\u52A8\\uFF08\\u4E0A\\u3001\\u4E0B\\u3001\\u5DE6\\u3001\\u53F3\\uFF09\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9E\\u73B0 \",(0,n.jsx)(e.code,{children:\"bfs\"}),\" \\u51FD\\u6570\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"reachable\"}),\" \\u5E03\\u5C14\\u77E9\\u9635\\u6765\\u8DDF\\u8E2A\\u904D\\u5386\\u671F\\u95F4\\u53EF\\u8BBF\\u95EE\\u7684\\u5355\\u5143\\u683C\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u4F7F\\u7528\\u961F\\u5217\\u8FED\\u4EE3\\u5904\\u7406\\u5355\\u5143\\u683C\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u5355\\u5143\\u683C\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u5C06\\u5176\\u6807\\u8BB0\\u4E3A\\u53EF\\u5230\\u8FBE\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u6240\\u6709\\u6709\\u6548\\u7684\\u76F8\\u90BB\\u5355\\u5143\\u683C\\u6392\\u961F\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u786E\\u4FDD\\u90BB\\u5C45\\u5728\\u8303\\u56F4\\u5185\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u786E\\u4FDD\\u90BB\\u5C45\\u5C1A\\u672A\\u88AB\\u8BBF\\u95EE\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u786E\\u4FDD\\u90BB\\u5C45\\u7684\\u9AD8\\u5EA6\\u5927\\u4E8E\\u6216\\u7B49\\u4E8E\\u5F53\\u524D\\u5355\\u5143\\u683C\\u3002\"}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"reachable\"}),\" \\u77E9\\u9635\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4E3A BFS \\u51C6\\u5907\\u961F\\u5217\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u592A\\u5E73\\u6D0B\\u961F\\u5217\\u4ECE\\u9876\\u884C\\u548C\\u5DE6\\u5217\\u5F00\\u59CB\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5927\\u897F\\u6D0B\\u961F\\u5217\\u4ECE\\u5E95\\u884C\\u548C\\u53F3\\u5217\\u5F00\\u59CB\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"bfs\"}),\" \\u51FD\\u6570\\u5BF9\\u4E24\\u4E2A\\u6D77\\u6D0B\\u6267\\u884C BFS\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u77E9\\u9635\\u4E2D\\u7684\\u6240\\u6709\\u5355\\u5143\\u683C\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u5355\\u5143\\u683C\\u53EF\\u4EE5\\u4ECE\\u592A\\u5E73\\u6D0B\\u548C\\u5927\\u897F\\u6D0B\\u5230\\u8FBE\\uFF0C\\u5219\\u5C06\\u5176\\u6DFB\\u52A0\\u5230\\u7ED3\\u679C\\u4E2D\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8FD4\\u56DE\\u516C\\u5171\\u5355\\u5143\\u683C\\u7684\\u5217\\u8868\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(i,{children:u}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m.n)\"}),\"\\u3002 \\u5728 BFS \\u671F\\u95F4\\uFF0C\\u6BCF\\u4E2A\\u5355\\u5143\\u683C\\u6700\\u591A\\u5904\\u7406\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(m.n)\"}),\"\\u3002 \\u4F7F\\u7528\\u4E24\\u4E2A\\u5E03\\u5C14\\u77E9\\u9635\\u6765\\u8DDF\\u8E2A\\u53EF\\u8FBE\\u6027\\uFF0C\\u5E76\\u4E14 BFS \\u4F7F\\u7528\\u4E00\\u4E2A\\u53EF\\u80FD\\u589E\\u957F\\u5230\\u77E9\\u9635\\u5927\\u5C0F\\u7684\\u961F\\u5217\\u3002\"]}),`\n`]})]})}function T(l={}){let{wrapper:e}=l.components||{};return e?(0,n.jsx)(e,Object.assign({},l,{children:(0,n.jsx)(m,l)})):m(l)}var D=T;return x(L);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/optimal-stock-trading/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/optimal-stock-trading/locales/zh-CN.json new file mode 100644 index 000000000..c280250e4 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/optimal-stock-trading/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var h=Object.create;var c=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var j=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),_=(n,e)=>{for(var i in e)c(n,i,{get:e[i],enumerable:!0})},s=(n,e,i,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of x(e))!y.call(n,r)&&r!==i&&c(n,r,{get:()=>e[r],enumerable:!(o=m(e,r))||o.enumerable});return n};var g=(n,e,i)=>(i=n!=null?h(f(n)):{},s(e||!n||!n.__esModule?c(i,\"default\",{value:n,enumerable:!0}):i,n)),b=n=>s(c({},\"__esModule\",{value:!0}),n);var p=j((E,l)=>{l.exports=_jsx_runtime});var T={};_(T,{default:()=>X,frontmatter:()=>C});var t=g(p());var d=MDXTestExamples;var a=[{input:[[\"prices\",[1,2,3,4]]],output:3,explanation:\"Buy the stock at day 1 (price = 1) and sell it on day 4 (price = 4), profit: 4 - 1 = 3\"},{input:[[\"prices\",[4,3,2,1]]],output:0,explanation:\"Not possible to profit because the prices is only declining\"},{input:[[\"prices\",[6,8,1,2,30,19]]],output:29,explanation:\"Buy at day 3 (price = 1) and sell it on day 5 (price = 30), profit: 30 - 1 = 29\"}];var C={title:\"\\u6700\\u4F73\\u80A1\\u7968\\u4EA4\\u6613\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u901A\\u8FC7\\u4E70\\u5165\\u548C\\u5356\\u51FA\\u80A1\\u7968\\u4E00\\u6B21\\u6765\\u627E\\u5230\\u53EF\\u5B9E\\u73B0\\u7684\\u6700\\u5927\\u5229\\u6DA6\"};function u(n){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},n.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\",(0,t.jsx)(e.code,{children:\"prices\"}),\"\\u5217\\u8868\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u5143\\u7D20\",(0,t.jsx)(e.code,{children:\"prices[i]\"}),\"\\u4EE3\\u8868\\u7279\\u5B9A\\u80A1\\u7968\\u5728\\u7B2C\",(0,t.jsx)(e.code,{children:\"i\"}),\"\\u5929\\u7684\\u4EF7\\u683C\\uFF0C\\u786E\\u5B9A\\u901A\\u8FC7\\u8D2D\\u4E70\\u80A1\\u7968\\u5E76\\u5728\\u672A\\u6765\\u65E5\\u671F\\u5356\\u51FA\\u80A1\\u7968\\u53EF\\u4EE5\\u83B7\\u5F97\\u7684\\u6700\\u5927\\u5229\\u6DA6\\u3002\\u5982\\u679C\\u65E0\\u6CD5\\u4EA7\\u751F\\u5229\\u6DA6\\uFF0C\\u5219\\u8FD4\\u56DE\",(0,t.jsx)(e.code,{children:\"0\"}),\"\\u3002\"]}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.code,{children:\"prices: number[]\"}),\": \\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4\\uFF0C\\u8868\\u793A\\u6BCF\\u5929\\u7684\\u80A1\\u7968\\u4EF7\\u683C\"]}),`\n`]}),`\n`,(0,t.jsx)(d,{testCases:a}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[\"1 <= \",(0,t.jsx)(e.code,{children:\"prices.length\"}),\" <= 10,000\"]}),`\n`,(0,t.jsxs)(e.li,{children:[\"0 <= \",(0,t.jsx)(e.code,{children:\"prices[i]\"}),\" <= 10,000\"]}),`\n`]})]})}function D(n={}){let{wrapper:e}=n.components||{};return e?(0,t.jsx)(e,Object.assign({},n,{children:(0,t.jsx)(u,n)})):u(n)}var X=D;return b(T);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,通过买入和卖出股票一次来找到可实现的最大利润", + "title": "最佳股票交易" + }, + "solution": "var Component=(()=>{var p=Object.create;var t=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var w=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),b=(r,e)=>{for(var n in e)t(r,n,{get:e[n],enumerable:!0})},d=(r,e,n,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let c of P(e))!g.call(r,c)&&c!==n&&t(r,c,{get:()=>e[c],enumerable:!(o=u(e,c))||o.enumerable});return r};var j=(r,e,n)=>(n=r!=null?p(x(r)):{},d(e||!r||!r.__esModule?t(n,\"default\",{value:r,enumerable:!0}):n,r)),_=r=>d(t({},\"__esModule\",{value:!0}),r);var a=w((E,h)=>{h.exports=_jsx_runtime});var T={};b(T,{default:()=>k});var i=j(a());var l=MDXCodeBlock;var m=`export default function optimalStockTrading(prices: number[]): number {\n // Initialize maximum profit to 0, assuming no profit initially\n let maxProfit: number = 0;\n\n // Track the lowest buying price seen so far\n let lowestPrice: number = Number.MAX_SAFE_INTEGER;\n\n for (const currentPrice of prices) {\n // Update the lowest buying price if a lower price is encountered\n lowestPrice = Math.min(lowestPrice, currentPrice);\n\n // Calculate potential profit for the current price\n const potentialProfit: number = currentPrice - lowestPrice;\n\n // Update the maximum profit if a higher potential profit is found\n maxProfit = Math.max(maxProfit, potentialProfit);\n }\n\n return maxProfit;\n}\n`;var s=`export default function optimalStockTrading(prices: number[]): number {\n // Initialize the maximum profit to 0\n let maxProfit = 0;\n\n // Iterate through each day's price\n for (let i = 0; i < prices.length - 1; i++) {\n // For each day, compare it with the prices of the subsequent days\n for (let j = i + 1; j < prices.length; j++) {\n // Calculate the profit by subtracting the current day's price from the future day's price\n const profit = prices[j] - prices[i];\n\n // If the calculated profit is greater than the current maximum profit, update the maximum profit\n if (profit > maxProfit) {\n maxProfit = profit;\n }\n }\n }\n\n // Return the maximum profit\n return maxProfit;\n}\n`;function f(r){let e=Object.assign({h2:\"h2\",p:\"p\",h3:\"h3\",ol:\"ol\",li:\"li\",code:\"code\",ul:\"ul\",strong:\"strong\"},r.components);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(e.h2,{children:\"1. \\u66B4\\u529B\\u7834\\u89E3\\u65B9\\u6CD5\"}),`\n`,(0,i.jsx)(e.p,{children:\"\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u66B4\\u529B\\u7834\\u89E3\\u65B9\\u6CD5\\u8BA1\\u7B97\\u901A\\u8FC7\\u5728\\u4E0D\\u540C\\u65E5\\u671F\\u4E70\\u5356\\u80A1\\u7968\\u53EF\\u4EE5\\u83B7\\u5F97\\u7684\\u6700\\u5927\\u5229\\u6DA6\\u3002 \\u60F3\\u6CD5\\u662F\\u8BC4\\u4F30\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u65E5\\u671F\\u5BF9\\uFF0C\\u5E76\\u8BA1\\u7B97\\u6BCF\\u5BF9\\u7684\\u5229\\u6DA6\\u3002 \\u6700\\u5927\\u5229\\u6DA6\\u901A\\u8FC7\\u6BD4\\u8F83\\u6240\\u6709\\u8BA1\\u7B97\\u51FA\\u7684\\u5229\\u6DA6\\u6765\\u786E\\u5B9A\\u3002\"}),`\n`,(0,i.jsx)(e.p,{children:\"\\u5BF9\\u4E8E\\u6BCF\\u4E00\\u5929\\uFF0C\\u8BE5\\u7B97\\u6CD5\\u5047\\u8BBE\\u5B83\\u662F\\u4E70\\u5165\\u65E5\\uFF0C\\u5E76\\u904D\\u5386\\u6240\\u6709\\u540E\\u7EED\\u65E5\\u671F\\u4EE5\\u68C0\\u67E5\\u53EF\\u80FD\\u7684\\u5356\\u51FA\\u65E5\\u3002 \\u6BCF\\u5BF9\\u7684\\u5229\\u6DA6\\u8BA1\\u7B97\\u4E3A\\u5356\\u51FA\\u4EF7\\u548C\\u4E70\\u5165\\u4EF7\\u4E4B\\u95F4\\u7684\\u5DEE\\u989D\\u3002 \\u5728\\u8FD9\\u4E9B\\u6BD4\\u8F83\\u671F\\u95F4\\u9047\\u5230\\u7684\\u6700\\u5927\\u5229\\u6DA6\\u88AB\\u5B58\\u50A8\\u5E76\\u4F5C\\u4E3A\\u7ED3\\u679C\\u8FD4\\u56DE\\u3002\"}),`\n`,(0,i.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,i.jsxs)(e.ol,{children:[`\n`,(0,i.jsxs)(e.li,{children:[\"\\u5C06\\u53D8\\u91CF \",(0,i.jsx)(e.code,{children:\"maxProfit\"}),\" \\u521D\\u59CB\\u5316\\u4E3A \",(0,i.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u4EE5\\u5B58\\u50A8\\u9047\\u5230\\u7684\\u6700\\u5927\\u5229\\u6DA6\\u3002\"]}),`\n`,(0,i.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u5D4C\\u5957\\u5FAA\\u73AF\\u904D\\u5386\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u65E5\\u671F\\u5BF9\\uFF1A\",`\n`,(0,i.jsxs)(e.ol,{children:[`\n`,(0,i.jsxs)(e.li,{children:[\"\\u5916\\u5FAA\\u73AF\\u4EE3\\u8868\\u4E70\\u5165\\u65E5 (\",(0,i.jsx)(e.code,{children:\"i\"}),\")\\uFF0C\\u4ECE\\u7B2C\\u4E00\\u5929\\u8FED\\u4EE3\\u5230\\u5012\\u6570\\u7B2C\\u4E8C\\u5929\\u3002\"]}),`\n`,(0,i.jsxs)(e.li,{children:[\"\\u5185\\u5FAA\\u73AF\\u4EE3\\u8868\\u5356\\u51FA\\u65E5 (\",(0,i.jsx)(e.code,{children:\"j\"}),\")\\uFF0C\\u4ECE \",(0,i.jsx)(e.code,{children:\"i\"}),\" \\u4E4B\\u540E\\u7684\\u4E00\\u5929\\u8FED\\u4EE3\\u5230\\u6700\\u540E\\u4E00\\u5929\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,i.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E00\\u5BF9\\u65E5\\u671F\\uFF1A\",`\n`,(0,i.jsxs)(e.ol,{children:[`\n`,(0,i.jsxs)(e.li,{children:[\"\\u8BA1\\u7B97\\u5229\\u6DA6\\uFF0C\\u5373\\u5356\\u51FA\\u65E5 (\",(0,i.jsx)(e.code,{children:\"prices[j]\"}),\") \\u7684\\u4EF7\\u683C\\u4E0E\\u4E70\\u5165\\u65E5 (\",(0,i.jsx)(e.code,{children:\"prices[i]\"}),\") \\u7684\\u4EF7\\u683C\\u4E4B\\u5DEE\\u3002\"]}),`\n`,(0,i.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u8BA1\\u7B97\\u51FA\\u7684\\u5229\\u6DA6\\u5927\\u4E8E \",(0,i.jsx)(e.code,{children:\"maxProfit\"}),\"\\uFF0C\\u5219\\u4F7F\\u7528\\u65B0\\u7684\\u5229\\u6DA6\\u503C\\u66F4\\u65B0 \",(0,i.jsx)(e.code,{children:\"maxProfit\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,i.jsxs)(e.li,{children:[\"\\u5728\\u6240\\u6709\\u8FED\\u4EE3\\u4E4B\\u540E\\uFF0C\\u8FD4\\u56DE \",(0,i.jsx)(e.code,{children:\"maxProfit\"}),\" \\u4F5C\\u4E3A\\u53EF\\u4EE5\\u5B9E\\u73B0\\u7684\\u6700\\u5927\\u5229\\u6DA6\\u3002\"]}),`\n`]}),`\n`,(0,i.jsx)(l,{children:s}),`\n`,(0,i.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,i.jsxs)(e.ul,{children:[`\n`,(0,i.jsxs)(e.li,{children:[(0,i.jsxs)(e.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,i.jsx)(\"sup\",{children:\"2\"}),\")\"]}),\"\\u3002\\u5D4C\\u5957\\u5FAA\\u73AF\\u904D\\u5386\\u6240\\u6709\\u65E5\\u5BF9\\uFF0C\\u5BFC\\u81F4\\u4E8C\\u6B21\\u65B9\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u3002\"]}),`\n`,(0,i.jsxs)(e.li,{children:[(0,i.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u6CA1\\u6709\\u4F7F\\u7528\\u989D\\u5916\\u7684\\u6570\\u636E\\u7ED3\\u6784\\uFF1B\\u4EC5\\u9700\\u8981\\u51E0\\u4E2A\\u53D8\\u91CF\\u8FDB\\u884C\\u8BA1\\u7B97\\u3002\"]}),`\n`]}),`\n`,(0,i.jsx)(e.h2,{children:\"2. \\u8D2A\\u5FC3\\u65B9\\u6CD5\"}),`\n`,(0,i.jsx)(e.p,{children:\"\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u8D2A\\u5FC3\\u65B9\\u6CD5\\u8BA1\\u7B97\\u901A\\u8FC7\\u5728\\u4E0D\\u540C\\u65E5\\u671F\\u4E70\\u5356\\u80A1\\u7968\\u53EF\\u4EE5\\u83B7\\u5F97\\u7684\\u6700\\u5927\\u5229\\u6DA6\\u3002 \\u8BE5\\u7B97\\u6CD5\\u4FA7\\u91CD\\u4E8E\\u901A\\u8FC7\\u8DDF\\u8E2A\\u5230\\u76EE\\u524D\\u4E3A\\u6B62\\u9047\\u5230\\u7684\\u6700\\u4F4E\\u4EF7\\u683C\\u5E76\\u5728\\u8FED\\u4EE3\\u8FC7\\u7A0B\\u4E2D\\u52A8\\u6001\\u8BA1\\u7B97\\u5229\\u6DA6\\u6765\\u6700\\u5927\\u9650\\u5EA6\\u5730\\u51CF\\u5C11\\u4E0D\\u5FC5\\u8981\\u7684\\u8BA1\\u7B97\\u3002\"}),`\n`,(0,i.jsx)(e.p,{children:\"\\u5173\\u952E\\u601D\\u60F3\\u662F\\u7EF4\\u62A4\\u4E24\\u4E2A\\u53D8\\u91CF\\uFF1A\"}),`\n`,(0,i.jsxs)(e.ol,{children:[`\n`,(0,i.jsxs)(e.li,{children:[(0,i.jsx)(e.code,{children:\"lowestPrice\"}),\"\\uFF0C\\u5B83\\u8DDF\\u8E2A\\u5230\\u76EE\\u524D\\u4E3A\\u6B62\\u5728\\u6570\\u7EC4\\u4E2D\\u9047\\u5230\\u7684\\u6700\\u4F4E\\u4EF7\\u683C\\u3002\"]}),`\n`,(0,i.jsxs)(e.li,{children:[(0,i.jsx)(e.code,{children:\"maxProfit\"}),\"\\uFF0C\\u5B83\\u8DDF\\u8E2A\\u57FA\\u4E8E\\u5F53\\u524D\\u7684 \",(0,i.jsx)(e.code,{children:\"lowestPrice\"}),\" \\u548C\\u5F53\\u524D\\u4EF7\\u683C\\u53EF\\u80FD\\u83B7\\u5F97\\u7684\\u6700\\u5927\\u5229\\u6DA6\\u3002\"]}),`\n`]}),`\n`,(0,i.jsxs)(e.p,{children:[\"\\u5BF9\\u4E8E\\u6570\\u7EC4\\u4E2D\\u7684\\u6BCF\\u4E2A\\u4EF7\\u683C\\uFF0C\\u5982\\u679C\\u5F53\\u524D\\u4EF7\\u683C\\u8F83\\u4F4E\\uFF0C\\u5219\\u7B97\\u6CD5\\u4F1A\\u66F4\\u65B0 \",(0,i.jsx)(e.code,{children:\"lowestPrice\"}),\"\\u3002 \\u7136\\u540E\\uFF0C\\u5B83\\u901A\\u8FC7\\u4ECE\\u5F53\\u524D\\u4EF7\\u683C\\u4E2D\\u51CF\\u53BB \",(0,i.jsx)(e.code,{children:\"lowestPrice\"}),\" \\u6765\\u8BA1\\u7B97\\u6F5C\\u5728\\u5229\\u6DA6\\uFF0C\\u5982\\u679C\\u8BA1\\u7B97\\u51FA\\u7684\\u5229\\u6DA6\\u66F4\\u5927\\uFF0C\\u5219\\u66F4\\u65B0 \",(0,i.jsx)(e.code,{children:\"maxProfit\"}),\"\\u3002 \\u4E0E\\u66B4\\u529B\\u7834\\u89E3\\u65B9\\u6CD5\\u76F8\\u6BD4\\uFF0C\\u8FD9\\u79CD\\u65B9\\u6CD5\\u6D88\\u9664\\u4E86\\u6BD4\\u8F83\\u6240\\u6709\\u4EF7\\u683C\\u5BF9\\u7684\\u9700\\u8981\\uFF0C\\u4ECE\\u800C\\u663E\\u7740\\u964D\\u4F4E\\u4E86\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u3002\"]}),`\n`,(0,i.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,i.jsxs)(e.ol,{children:[`\n`,(0,i.jsxs)(e.li,{children:[\"\\u5C06 \",(0,i.jsx)(e.code,{children:\"maxProfit\"}),\" \\u521D\\u59CB\\u5316\\u4E3A \",(0,i.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u4EE5\\u5B58\\u50A8\\u9047\\u5230\\u7684\\u6700\\u5927\\u5229\\u6DA6\\u3002\"]}),`\n`,(0,i.jsxs)(e.li,{children:[\"\\u5C06 \",(0,i.jsx)(e.code,{children:\"lowestPrice\"}),\" \\u521D\\u59CB\\u5316\\u4E3A\\u4E00\\u4E2A\\u975E\\u5E38\\u5927\\u7684\\u503C (\",(0,i.jsx)(e.code,{children:\"Number.MAX_SAFE_INTEGER\"}),\")\\uFF0C\\u4EE5\\u8DDF\\u8E2A\\u5230\\u76EE\\u524D\\u4E3A\\u6B62\\u9047\\u5230\\u7684\\u6700\\u5C0F\\u4EF7\\u683C\\u3002\"]}),`\n`,(0,i.jsxs)(e.li,{children:[\"\\u904D\\u5386 \",(0,i.jsx)(e.code,{children:\"prices\"}),\" \\u6570\\u7EC4\\u4E2D\\u7684\\u6BCF\\u4E2A\\u4EF7\\u683C\\uFF1A\",`\n`,(0,i.jsxs)(e.ol,{children:[`\n`,(0,i.jsxs)(e.li,{children:[\"\\u4F7F\\u7528 \",(0,i.jsx)(e.code,{children:\"lowestPrice\"}),\" \\u548C\\u5F53\\u524D\\u4EF7\\u683C\\u4E2D\\u8F83\\u5C0F\\u7684\\u503C\\u66F4\\u65B0 \",(0,i.jsx)(e.code,{children:\"lowestPrice\"}),\"\\u3002\"]}),`\n`,(0,i.jsxs)(e.li,{children:[\"\\u8BA1\\u7B97\\u6F5C\\u5728\\u5229\\u6DA6\\uFF0C\\u5373\\u5F53\\u524D\\u4EF7\\u683C\\u4E0E \",(0,i.jsx)(e.code,{children:\"lowestPrice\"}),\" \\u4E4B\\u95F4\\u7684\\u5DEE\\u989D\\u3002\"]}),`\n`,(0,i.jsxs)(e.li,{children:[\"\\u4F7F\\u7528 \",(0,i.jsx)(e.code,{children:\"maxProfit\"}),\" \\u548C\\u6F5C\\u5728\\u5229\\u6DA6\\u4E2D\\u8F83\\u5927\\u7684\\u503C\\u66F4\\u65B0 \",(0,i.jsx)(e.code,{children:\"maxProfit\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,i.jsxs)(e.li,{children:[\"\\u5B8C\\u6210\\u8FED\\u4EE3\\u540E\\uFF0C\\u8FD4\\u56DE \",(0,i.jsx)(e.code,{children:\"maxProfit\"}),\" \\u4F5C\\u4E3A\\u53EF\\u4EE5\\u5B9E\\u73B0\\u7684\\u6700\\u5927\\u5229\\u6DA6\\u3002\"]}),`\n`]}),`\n`,(0,i.jsx)(l,{children:m}),`\n`,(0,i.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,i.jsxs)(e.ul,{children:[`\n`,(0,i.jsxs)(e.li,{children:[(0,i.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u904D\\u5386\\u4EF7\\u683C\\u5217\\u8868\\u4E00\\u6B21\\uFF0C\\u4E3A\\u6BCF\\u4E2A\\u4EF7\\u683C\\u4EE5\\u6052\\u5B9A\\u65F6\\u95F4\\u66F4\\u65B0 \",(0,i.jsx)(e.code,{children:\"lowestPrice\"}),\" \\u5E76\\u8BA1\\u7B97 \",(0,i.jsx)(e.code,{children:\"maxProfit\"}),\"\\u3002\"]}),`\n`,(0,i.jsxs)(e.li,{children:[(0,i.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u4EC5\\u4F7F\\u7528\\u4E24\\u4E2A\\u53D8\\u91CF \",(0,i.jsx)(e.code,{children:\"lowestPrice\"}),\" \\u548C \",(0,i.jsx)(e.code,{children:\"maxProfit\"}),\" \\u6765\\u8DDF\\u8E2A\\u4E2D\\u95F4\\u7ED3\\u679C\\u3002\"]}),`\n`]})]})}function O(r={}){let{wrapper:e}=r.components||{};return e?(0,i.jsx)(e,Object.assign({},r,{children:(0,i.jsx)(f,r)})):f(r)}var k=O;return _(T);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/pair-sum/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/pair-sum/locales/zh-CN.json new file mode 100644 index 000000000..eee68dd9d --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/pair-sum/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var m=Object.create;var c=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var f=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),j=(t,e)=>{for(var r in e)c(t,r,{get:e[r],enumerable:!0})},s=(t,e,r,l)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of b(e))!g.call(t,i)&&i!==r&&c(t,i,{get:()=>e[i],enumerable:!(l=p(e,i))||l.enumerable});return t};var _=(t,e,r)=>(r=t!=null?m(x(t)):{},s(e||!t||!t.__esModule?c(r,\"default\",{value:t,enumerable:!0}):r,t)),M=t=>s(c({},\"__esModule\",{value:!0}),t);var d=f((F,u)=>{u.exports=_jsx_runtime});var T={};j(T,{default:()=>w,frontmatter:()=>D});var n=_(d());var o=MDXTestExamples;var h=[{input:[[\"numbers\",[0,7,1,9]],[\"target\",7]],output:[0,1],explanation:\"numbers[0] plus numbers[1] = 7 which is target\"},{input:[[\"numbers\",[4,9,2,1,7]],[\"target\",5]],output:[0,3],explanation:\"numbers[3] plus numbers[0] = 5 which is target\"},{input:[[\"numbers\",[4,4]],[\"target\",8]],output:[0,1]}];var D={title:\"Pair sum\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u7528\\u4E8E\\u67E5\\u627E\\u6574\\u6570\\u6570\\u7EC4\\u4E2D\\u4E24\\u4E2A\\u76F8\\u52A0\\u7B49\\u4E8E\\u76EE\\u6807\\u6574\\u6570\\u7684\\u6570\\u5B57\"};function a(t){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"numbers\"}),\"\\uFF0C\\u7F16\\u5199\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u8BE5\\u51FD\\u6570\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"numbers\"}),\" \\u6570\\u7EC4\\u4E2D\\u4E24\\u4E2A\\u6574\\u6570\\u7684\\u7D22\\u5F15\\uFF0C\\u8FD9\\u4E24\\u4E2A\\u6574\\u6570\\u7684\\u548C\\u7B49\\u4E8E\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"target\"}),\" \\u6574\\u6570\\u3002\\u8F83\\u5C0F\\u7684\\u7D22\\u5F15\\u5E94\\u9996\\u5148\\u51FA\\u73B0\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"numbers: number[]\"}),\": \\u6574\\u6570\\u6570\\u7EC4\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"target: number\"}),\": \\u4E00\\u4E2A\\u6574\\u6570\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u6CE8\\u610F\\u4E8B\\u9879\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u5BF9\\u4E8E\\u7ED9\\u5B9A\\u7684\\u8F93\\u5165\\uFF0C\\u5C06\\u59CB\\u7EC8\\u53EA\\u6709\\u4E00\\u4E2A\\u89E3\\u51B3\\u65B9\\u6848\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u4E0D\\u5E94\\u591A\\u6B21\\u4F7F\\u7528\\u540C\\u4E00\\u5143\\u7D20\"}),`\n`]}),`\n`,(0,n.jsx)(o,{testCases:h}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"2 <= \",(0,n.jsx)(e.code,{children:\"numbers.length\"}),\" <= 100\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"-1000 <= \",(0,n.jsx)(e.code,{children:\"numbers[i]\"}),\" <= 1000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"-1000 <= \",(0,n.jsx)(e.code,{children:\"target\"}),\" <= 1000\"]}),`\n`]})]})}function X(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(a,t)})):a(t)}var w=X;return M(T);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,用于查找整数数组中两个相加等于目标整数的数字", + "title": "Pair sum" + }, + "solution": "var Component=(()=>{var b=Object.create;var c=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var O=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports),S=(r,n)=>{for(var i in n)c(r,i,{get:n[i],enumerable:!0})},d=(r,n,i,t)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let l of f(n))!x.call(r,l)&&l!==i&&c(r,l,{get:()=>n[l],enumerable:!(t=g(n,l))||t.enumerable});return r};var y=(r,n,i)=>(i=r!=null?b(j(r)):{},d(n||!r||!r.__esModule?c(i,\"default\",{value:r,enumerable:!0}):i,r)),_=r=>d(c({},\"__esModule\",{value:!0}),r);var m=O((X,o)=>{o.exports=_jsx_runtime});var M={};S(M,{default:()=>F});var e=y(m());var h=MDXCodeBlock;var s=`export default function pairSum(numbers: number[], target: number): number[] {\n const hash: { [key: number]: number } = {};\n\n for (let i = 0; i < numbers.length; i++) {\n const complement = target - numbers[i];\n\n // Check if the complement exists (excluding the current element)\n if (hash.hasOwnProperty(complement) && hash[complement] !== i) {\n return [hash[complement], i];\n }\n\n // Store the number and its index in the hash map\n hash[numbers[i]] = i;\n }\n\n // No solution found\n return [];\n}\n`;var u=`export default function pairSum(numbers: number[], target: number): number[] {\n // Iterate through each element in the array\n for (let i = 0; i < numbers.length; i++) {\n // For each element, iterate through the elements that come after it\n for (let j = i + 1; j < numbers.length; j++) {\n // If the sum of the two elements equals the target, return their indices\n if (numbers[j] === target - numbers[i]) {\n return [i, j];\n }\n }\n }\n // Return an empty array if no solution is found\n return [];\n}\n`;var a=`export default function pairSum(numbers: number[], target: number): number[] {\n const hash: { [key: number]: number } = {};\n\n // First pass: Populate the hash table with numbers and their indices\n for (let i = 0; i < numbers.length; i++) {\n hash[numbers[i]] = i;\n }\n\n // Second pass: Check for the complement\n for (let i = 0; i < numbers.length; i++) {\n const complement = target - numbers[i];\n\n // Ensure complement exists and is not the same index as the current one\n if (complement in hash && hash[complement] !== i) {\n return [i, hash[complement]];\n }\n }\n\n // If no solution is found\n return [];\n}\n`;function p(r){let n=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},r.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"1. \\u66B4\\u529B\\u89E3\\u6CD5\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5BF9\\u548C\\u95EE\\u9898\\u6D89\\u53CA\\u8BC6\\u522B\\u6570\\u7EC4\\u4E2D\\u7684\\u4E24\\u4E2A\\u7D22\\u5F15\\uFF0C\\u4F7F\\u5F97\\u5B83\\u4EEC\\u7684\\u503C\\u76F8\\u52A0\\u7B49\\u4E8E\\u6307\\u5B9A\\u7684 target\\u3002\\u66B4\\u529B\\u89E3\\u6CD5\\u68C0\\u67E5\\u6570\\u7EC4\\u4E2D\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u5143\\u7D20\\u5BF9\\u3002\\u5BF9\\u4E8E\\u7D22\\u5F15 \",(0,e.jsx)(n.code,{children:\"i\"}),\" \\u5904\\u7684\\u6BCF\\u4E2A\\u5143\\u7D20\\uFF0C\\u68C0\\u67E5\\u7D22\\u5F15 \",(0,e.jsx)(n.code,{children:\"j > i\"}),\" \\u5904\\u7684\\u6240\\u6709\\u540E\\u7EED\\u5143\\u7D20\\uFF0C\\u4EE5\\u786E\\u5B9A\\u5B83\\u4EEC\\u7684\\u603B\\u548C\\u662F\\u5426\\u4E0E target \\u5339\\u914D\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\\u8003\\u8651\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u5BF9\\uFF0C\\u4F7F\\u5F97\\u89E3\\u51B3\\u65B9\\u6848\\u76F4\\u63A5\\u4F46\\u5BF9\\u4E8E\\u5927\\u578B\\u6570\\u7EC4\\u6548\\u7387\\u4F4E\\u4E0B\\u3002\"]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528\\u7D22\\u5F15 \",(0,e.jsx)(n.code,{children:\"i\"}),\" \\u7684\\u5FAA\\u73AF\\u904D\\u5386 \",(0,e.jsx)(n.code,{children:\"numbers\"}),\" \\u6570\\u7EC4\\u7684\\u6BCF\\u4E2A\\u5143\\u7D20\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5BF9\\u4E8E\\u7D22\\u5F15 \",(0,e.jsx)(n.code,{children:\"i\"}),\" \\u5904\\u7684\\u6BCF\\u4E2A\\u5143\\u7D20\\uFF0C\\u4F7F\\u7528\\u53E6\\u4E00\\u4E2A\\u7D22\\u5F15\\u4E3A \",(0,e.jsx)(n.code,{children:\"j\"}),\" \\u7684\\u5FAA\\u73AF\\u904D\\u5386 \",(0,e.jsx)(n.code,{children:\"i\"}),\" \\u4E4B\\u540E\\u7684\\u5143\\u7D20 (\",(0,e.jsx)(n.code,{children:\"j > i\"}),\")\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u68C0\\u67E5 \",(0,e.jsx)(n.code,{children:\"numbers[i]\"}),\" \\u548C \",(0,e.jsx)(n.code,{children:\"numbers[j]\"}),\" \\u7684\\u603B\\u548C\\u662F\\u5426\\u7B49\\u4E8E \",(0,e.jsx)(n.code,{children:\"target\"}),\"\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5982\\u679C\\u6761\\u4EF6\\u4E3A\\u771F\\uFF0C\\u5219\\u8FD4\\u56DE\\u7D22\\u5F15 \",(0,e.jsx)(n.code,{children:\"[i, j]\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5982\\u679C\\u5728\\u68C0\\u67E5\\u6240\\u6709\\u5BF9\\u4E4B\\u540E\\u672A\\u627E\\u5230\\u8FD9\\u6837\\u7684\\u5BF9\\uFF0C\\u5219\\u8FD4\\u56DE\\u4E00\\u4E2A\\u7A7A\\u6570\\u7EC4\\u3002\"}),`\n`]}),`\n`,(0,e.jsx)(h,{children:u}),`\n`,(0,e.jsx)(n.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsxs)(n.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,e.jsx)(\"sup\",{children:\"2\"}),\")\"]}),\"\\u3002\\u5916\\u5FAA\\u73AF\\u8FD0\\u884C \",(0,e.jsx)(n.code,{children:\"n\"}),\" \\u6B21\\uFF0C\\u5E76\\u4E14\\u5BF9\\u4E8E\\u6BCF\\u6B21\\u8FED\\u4EE3\\uFF0C\\u5185\\u5FAA\\u73AF\\u6700\\u591A\\u8FD0\\u884C \",(0,e.jsx)(n.code,{children:\"n - 1\"}),\" \\u6B21\\uFF0C\\u5BFC\\u81F4\\u4E8C\\u6B21\\u65B9\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u6CA1\\u6709\\u4F7F\\u7528\\u989D\\u5916\\u7684\\u6570\\u636E\\u7ED3\\u6784\\uFF0C\\u7A7A\\u95F4\\u9700\\u6C42\\u662F\\u6052\\u5B9A\\u7684\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"2. \\u4F7F\\u7528\\u4E24\\u904D\\u54C8\\u5E0C\\u6620\\u5C04\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u4E4B\\u524D\\u7684\\u66B4\\u529B\\u89E3\\u6CD5\\u6D89\\u53CA\\u68C0\\u67E5\\u6240\\u6709\\u5143\\u7D20\\u5BF9\\uFF0C\\u7531\\u4E8E\\u91CD\\u590D\\u6BD4\\u8F83\\u5143\\u7D20\\u5BF9\\uFF0C\\u5BFC\\u81F4 O(n\",(0,e.jsx)(\"sup\",{children:\"2\"}),\") \\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u3002\\u56E0\\u6B64\\uFF0C\\u8FD9\\u79CD\\u65B9\\u6CD5\\u901A\\u8FC7\\u7528\\u9AD8\\u6548\\u7684 O(1) \\u54C8\\u5E0C\\u8868\\u67E5\\u627E\\u66FF\\u6362\\u5D4C\\u5957\\u5FAA\\u73AF\\u6765\\u6D88\\u9664\\u5197\\u4F59\\u5DE5\\u4F5C\\uFF0C\\u4ECE\\u800C\\u5C06\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u964D\\u4F4E\\u5230 O(n)\\u3002\"]}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u8FD9\\u79CD\\u4F18\\u5316\\u7684\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\",(0,e.jsx)(n.strong,{children:\"\\u4E24\\u904D\\u54C8\\u5E0C\\u6620\\u5C04\"}),\"\\u65B9\\u6CD5\\uFF1A\"]}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u7B2C\\u4E00\\u904D\\u6784\\u9020\\u4E00\\u4E2A\\u54C8\\u5E0C\\u8868\\uFF0C\\u5C06\\u6BCF\\u4E2A\\u5143\\u7D20\\u7684\\u503C\\u5B58\\u50A8\\u4E3A\\u952E\\uFF0C\\u5176\\u7D22\\u5F15\\u5B58\\u50A8\\u4E3A\\u503C\\u3002\"}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5728\\u7B2C\\u4E8C\\u904D\\u4E2D\\uFF0C\\u7B97\\u6CD5\\u68C0\\u67E5\\u5F53\\u524D\\u5143\\u7D20\\u7684\\u8865\\u6570\\uFF08\\u5373 \",(0,e.jsx)(n.code,{children:\"target - numbers[i]\"}),\"\\uFF09\\u662F\\u5426\\u5B58\\u5728\\u4E8E\\u54C8\\u5E0C\\u8868\\u4E2D\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u7A7A\\u54C8\\u5E0C\\u8868 \",(0,e.jsx)(n.code,{children:\"hash\"}),\" \\u4EE5\\u5B58\\u50A8\\u6570\\u5B57\\u53CA\\u5176\\u7D22\\u5F15\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u6267\\u884C\\u6570\\u7EC4\\u7684\\u7B2C\\u4E00\\u904D\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u5143\\u7D20 \",(0,e.jsx)(n.code,{children:\"numbers[i]\"}),\"\\uFF0C\\u5C06\\u5176\\u5B58\\u50A8\\u5728\\u54C8\\u5E0C\\u8868\\u4E2D\\uFF0C\\u5176\\u7D22\\u5F15\\u4F5C\\u4E3A\\u503C (\",(0,e.jsx)(n.code,{children:\"hash[numbers[i]] = i\"}),\")\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u6267\\u884C\\u6570\\u7EC4\\u7684\\u7B2C\\u4E8C\\u904D\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u8BA1\\u7B97 \",(0,e.jsx)(n.code,{children:\"complement\"}),\" \\u4F5C\\u4E3A \",(0,e.jsx)(n.code,{children:\"target - numbers[i]\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u68C0\\u67E5 \",(0,e.jsx)(n.code,{children:\"complement\"}),\" \\u662F\\u5426\\u5B58\\u5728\\u4E8E\\u54C8\\u5E0C\\u8868\\u4E2D\\uFF0C\\u5E76\\u786E\\u4FDD\\u5176\\u7D22\\u5F15\\u4E0E\\u5F53\\u524D\\u7D22\\u5F15\\u4E0D\\u540C\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5982\\u679C\\u6EE1\\u8DB3\\u6761\\u4EF6\\uFF0C\\u5219\\u8FD4\\u56DE\\u7D22\\u5F15 \",(0,e.jsx)(n.code,{children:\"[i, hash[complement]]\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5982\\u679C\\u672A\\u627E\\u5230\\u6709\\u6548\\u5BF9\\uFF0C\\u5219\\u8FD4\\u56DE\\u4E00\\u4E2A\\u7A7A\\u6570\\u7EC4\\u3002\"}),`\n`]}),`\n`,(0,e.jsx)(h,{children:a}),`\n`,(0,e.jsx)(n.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u904D\\u5386\\u6570\\u7EC4\\u4E24\\u6B21\\uFF0C\\u5E76\\u4E14\\u6BCF\\u4E2A\\u54C8\\u5E0C\\u8868\\u64CD\\u4F5C\\uFF08\\u63D2\\u5165\\u6216\\u67E5\\u627E\\uFF09\\u9700\\u8981 O(1) \\u65F6\\u95F4\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u5728\\u6700\\u574F\\u7684\\u60C5\\u51B5\\u4E0B\\uFF0C\\u6240\\u6709 \",(0,e.jsx)(n.code,{children:\"n\"}),\" \\u4E2A\\u5143\\u7D20\\u90FD\\u5B58\\u50A8\\u5728\\u54C8\\u5E0C\\u6620\\u5C04\\u4E2D\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"3. \\u4F7F\\u7528\\u4E00\\u904D\\u54C8\\u5E0C\\u6620\\u5C04\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u4E24\\u904D\\u89E3\\u6CD5\\u4E2D\\u4E0D\\u5FC5\\u8981\\u7684\\u5DE5\\u4F5C\\u662F\\u9700\\u8981\\u5BF9\\u6570\\u7EC4\\u8FDB\\u884C\\u4E24\\u6B21\\u8FED\\u4EE3\\u3002\\u4F18\\u5316\\u7684\\u5355\\u904D\\u54C8\\u5E0C\\u8868\\u65B9\\u6CD5\\u901A\\u8FC7\\u5C06\\u8FD9\\u4E24\\u4E2A\\u6B65\\u9AA4\\u5408\\u5E76\\u4E3A\\u5355\\u4E2A\\u8FED\\u4EE3\\u6765\\u6D88\\u9664\\u6B64\\u7F3A\\u70B9\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5728\\u8FED\\u4EE3\\u671F\\u95F4\\uFF0C\\u7B97\\u6CD5\\u8BA1\\u7B97\\u5F53\\u524D\\u6570\\u5B57\\u7684\\u8865\\u6570\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5982\\u679C\\u8865\\u6570\\u5DF2\\u5B58\\u5728\\u4E8E\\u54C8\\u5E0C\\u8868\\u4E2D\\uFF0C\\u5219\\u627E\\u5230\\u8BE5\\u5BF9\\uFF0C\\u5E76\\u8FD4\\u56DE\\u7D22\\u5F15\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5982\\u679C\\u4E0D\\u662F\\uFF0C\\u5219\\u5C06\\u5F53\\u524D\\u6570\\u5B57\\u53CA\\u5176\\u7D22\\u5F15\\u6DFB\\u52A0\\u5230\\u54C8\\u5E0C\\u8868\\u4E2D\\u4EE5\\u4F9B\\u5C06\\u6765\\u67E5\\u627E\\u3002\"}),`\n`]}),`\n`,(0,e.jsx)(n.p,{children:\"\\u8FD9\\u6D88\\u9664\\u4E86\\u5BF9\\u7B2C\\u4E8C\\u904D\\u7684\\u9700\\u6C42\\uFF0C\\u51CF\\u5C11\\u4E86\\u4E0D\\u5FC5\\u8981\\u7684\\u5DE5\\u4F5C\\u5E76\\u63D0\\u9AD8\\u4E86\\u8FD0\\u884C\\u65F6\\u6548\\u7387\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u7A7A\\u7684\\u54C8\\u5E0C\\u8868 \",(0,e.jsx)(n.code,{children:\"hash\"}),\" \\u6765\\u5B58\\u50A8\\u6570\\u5B57\\u53CA\\u5176\\u5BF9\\u5E94\\u7684\\u7D22\\u5F15\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u904D\\u5386\\u6570\\u7EC4 \",(0,e.jsx)(n.code,{children:\"numbers\"}),\":\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u8BA1\\u7B97 \",(0,e.jsx)(n.code,{children:\"complement\"}),\" \\u4E3A \",(0,e.jsx)(n.code,{children:\"target - numbers[i]\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u68C0\\u67E5 \",(0,e.jsx)(n.code,{children:\"complement\"}),\" \\u662F\\u5426\\u5B58\\u5728\\u4E8E\\u54C8\\u5E0C\\u8868\\u4E2D:\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5982\\u679C\\u5B58\\u5728\\uFF0C\\u5219\\u8FD4\\u56DE\\u7D22\\u5F15 \",(0,e.jsx)(n.code,{children:\"[hash[complement], i]\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5426\\u5219\\uFF0C\\u5C06\\u5F53\\u524D\\u6570\\u5B57\\u53CA\\u5176\\u7D22\\u5F15\\u6DFB\\u52A0\\u5230\\u54C8\\u5E0C\\u8868\\u4E2D\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5982\\u679C\\u672A\\u627E\\u5230\\u6709\\u6548\\u5BF9\\uFF0C\\u5219\\u8FD4\\u56DE\\u4E00\\u4E2A\\u7A7A\\u6570\\u7EC4\\u3002\"}),`\n`]}),`\n`,(0,e.jsxs)(h,{children:[\" \",s,\" \"]}),`\n`,(0,e.jsx)(n.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u4EC5\\u5904\\u7406\\u6570\\u7EC4\\u7684\\u6BCF\\u4E2A\\u5143\\u7D20\\u4E00\\u6B21\\uFF0C\\u5E76\\u4E14\\u54C8\\u5E0C\\u8868\\u4E2D\\u7684\\u6BCF\\u6B21\\u67E5\\u627E\\u6216\\u63D2\\u5165\\u90FD\\u9700\\u8981 O(1)\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u5728\\u6700\\u574F\\u7684\\u60C5\\u51B5\\u4E0B\\uFF0C\\u6240\\u6709 \",(0,e.jsx)(n.code,{children:\"n\"}),\" \\u4E2A\\u5143\\u7D20\\u90FD\\u5B58\\u50A8\\u5728\\u54C8\\u5E0C\\u6620\\u5C04\\u4E2D\\u3002\"]}),`\n`]})]})}function w(r={}){let{wrapper:n}=r.components||{};return n?(0,e.jsx)(n,Object.assign({},r,{children:(0,e.jsx)(p,r)})):p(r)}var F=w;return _(M);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/queue/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/queue/locales/zh-CN.json new file mode 100644 index 000000000..69f086496 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/queue/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var s=Object.create;var i=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var x=(c,e)=>()=>(e||c((e={exports:{}}).exports,e),e.exports),f=(c,e)=>{for(var u in e)i(c,u,{get:e[u],enumerable:!0})},l=(c,e,u,t)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of q(e))!m.call(c,r)&&r!==u&&i(c,r,{get:()=>e[r],enumerable:!(t=a(e,r))||t.enumerable});return c};var g=(c,e,u)=>(u=c!=null?s(p(c)):{},l(e||!c||!c.__esModule?i(u,\"default\",{value:c,enumerable:!0}):u,c)),j=c=>l(i({},\"__esModule\",{value:!0}),c);var o=x((E,d)=>{d.exports=_jsx_runtime});var y={};f(y,{default:()=>b,frontmatter:()=>O});var n=g(o()),O={title:\"\\u961F\\u5217\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u5305\\u542B\\u5E38\\u89C1\\u961F\\u5217\\u65B9\\u6CD5\\u7684\\u961F\\u5217\\u6570\\u636E\\u7ED3\\u6784\"};function h(c){let e=Object.assign({p:\"p\",ul:\"ul\",li:\"li\",code:\"code\",h2:\"h2\",pre:\"pre\"},c.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.p,{children:\"\\u7528 JavaScript \\u5B9E\\u73B0\\u4E00\\u4E2A\\u961F\\u5217\\u6570\\u636E\\u7ED3\\u6784\\uFF0C\\u5176\\u4E2D\\u5305\\u542B\\u4EE5\\u4E0B\\u64CD\\u4F5C\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"new Queue()\"}),\"\\uFF1A\\u521B\\u5EFA\\u4E00\\u4E2A\\u4E0D\\u5305\\u542B\\u4EFB\\u4F55\\u9879\\u76EE\\u7684 \",(0,n.jsx)(e.code,{children:\"Queue\"}),\" \\u7C7B\\u7684\\u5B9E\\u4F8B\\u3002\\u6784\\u9020\\u51FD\\u6570\\u4E0D\\u63A5\\u53D7\\u4EFB\\u4F55\\u53C2\\u6570\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"enqueue()\"}),\"\\uFF1A\\u5C06\\u4E00\\u4E2A\\u9879\\u76EE\\u6DFB\\u52A0\\u5230\\u961F\\u5217\\u7684\\u672B\\u5C3E\\u3002\\u6240\\u9700\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"dequeue()\"}),\"\\uFF1A\\u4ECE\\u961F\\u5217\\u7684\\u524D\\u9762\\u5220\\u9664\\u4E00\\u4E2A\\u9879\\u76EE\\u3002\\u6240\\u9700\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"isEmpty()\"}),\"\\uFF1A\\u786E\\u5B9A\\u961F\\u5217\\u662F\\u5426\\u4E3A\\u7A7A\\u3002\\u6240\\u9700\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"front()\"}),\"\\uFF1A\\u8FD4\\u56DE\\u961F\\u5217\\u524D\\u9762\\u7684\\u9879\\u76EE\\uFF0C\\u800C\\u4E0D\\u5C06\\u5176\\u4ECE\\u961F\\u5217\\u4E2D\\u5220\\u9664\\u3002\\u6240\\u9700\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"back()\"}),\"\\uFF1A\\u8FD4\\u56DE\\u961F\\u5217\\u540E\\u9762\\u7684\\u9879\\u76EE\\uFF0C\\u800C\\u4E0D\\u5C06\\u5176\\u4ECE\\u961F\\u5217\\u4E2D\\u5220\\u9664\\u3002\\u6240\\u9700\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"length()\"}),\"\\uFF1A\\u8FD4\\u56DE\\u961F\\u5217\\u4E2D\\u7684\\u9879\\u76EE\\u6570\\u3002\\u6240\\u9700\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"\\u4F8B\\u5B50\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`const queue = new Queue();\nqueue.isEmpty(); // true\nqueue.enqueue(1);\nqueue.enqueue(2);\nqueue.length(); // 2\nqueue.enqueue(3);\nqueue.front(); // 1\nqueue.back(); // 3\nqueue.dequeue(); // 1\nqueue.isEmpty(); // false\n`})})]})}function _(c={}){let{wrapper:e}=c.components||{};return e?(0,n.jsx)(e,Object.assign({},c,{children:(0,n.jsx)(h,c)})):h(c)}var b=_;return j(y);})();\n;return Component;", + "info": { + "excerpt": "实现一个包含常见队列方法的队列数据结构", + "title": "队列" + }, + "solution": "var Component=(()=>{var p=Object.create;var d=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var v=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),g=(n,e)=>{for(var u in e)d(n,u,{get:e[u],enumerable:!0})},h=(n,e,u,r)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of _(e))!y.call(n,i)&&i!==u&&d(n,i,{get:()=>e[i],enumerable:!(r=f(e,i))||r.enumerable});return n};var T=(n,e,u)=>(u=n!=null?p(q(n)):{},h(e||!n||!n.__esModule?d(u,\"default\",{value:n,enumerable:!0}):u,n)),x=n=>h(d({},\"__esModule\",{value:!0}),n);var m=v((j,o)=>{o.exports=_jsx_runtime});var k={};g(k,{default:()=>N});var t=T(m());var s=MDXCodeBlock;var l=`class Node {\n constructor(value) {\n this.value = value;\n this.next = null;\n this.prev = null;\n }\n}\n\nexport default class Queue {\n constructor() {\n this._dummyHead = new Node();\n this._dummyTail = new Node();\n this._dummyHead.prev = this._dummyTail;\n this._dummyTail.next = this._dummyHead;\n this._length = 0;\n }\n\n /**\n * Adds an item to the back of the queue.\n * @param {*} item The item to be pushed onto the queue.\n * @return {number} The new length of the queue.\n */\n enqueue(item) {\n const node = new Node(item);\n const prevLast = this._dummyTail.next;\n prevLast.prev = node;\n\n node.next = prevLast;\n node.prev = this._dummyTail;\n this._dummyTail.next = node;\n this._length++;\n return this._length;\n }\n\n /**\n * Remove an item from the front of the queue.\n * @return {*} The item at the front of the queue if it is not empty, \\`undefined\\` otherwise.\n */\n dequeue() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n const node = this._dummyHead.prev;\n const newFirst = node.prev;\n this._dummyHead.prev = newFirst;\n newFirst.next = this._dummyHead;\n // Unlink the node to be dequeued.\n node.prev = null;\n node.next = null;\n this._length--;\n return node.value;\n }\n\n /**\n * Determines if the queue is empty.\n * @return {boolean} \\`true\\` if the queue has no items, \\`false\\` otherwise.\n */\n isEmpty() {\n return this._length === 0;\n }\n\n /**\n * Returns the item at the front of the queue without removing it from the queue.\n * @return {*} The item at the front of the queue if it is not empty, \\`undefined\\` otherwise.\n */\n front() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n return this._dummyHead.prev.value;\n }\n\n /**\n * Returns the item at the back of the queue without removing it from the queue it.\n * @return {*} The item at the back of the queue if it is not empty, \\`undefined\\` otherwise.\n */\n back() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n return this._dummyTail.next.value;\n }\n\n /**\n * Returns the number of items in the queue.\n * @return {number} The number of items in the queue.\n */\n length() {\n return this._length;\n }\n}\n`;var c=`class Node {\n value: T | undefined;\n next: Node | null;\n prev: Node | null;\n\n constructor(value?: T) {\n this.value = value;\n this.next = null;\n this.prev = null;\n }\n}\n\nexport default class Queue {\n _dummyHead: Node;\n _dummyTail: Node;\n _length: number;\n\n constructor() {\n this._dummyHead = new Node();\n this._dummyTail = new Node();\n this._dummyHead.prev = this._dummyTail;\n this._dummyTail.next = this._dummyHead;\n this._length = 0;\n }\n\n /**\n * Adds an item to the back of the queue.\n */\n enqueue(item: T) {\n const node = new Node(item);\n const prevLast = this._dummyTail.next;\n prevLast!.prev = node;\n\n node.next = prevLast;\n node.prev = this._dummyTail;\n this._dummyTail.next = node;\n this._length++;\n return this._length;\n }\n\n /**\n * Remove an item from the front of the queue.\n */\n dequeue(): T | undefined {\n if (this.isEmpty()) {\n return undefined;\n }\n\n const node = this._dummyHead.prev;\n const newFirst = node!.prev;\n this._dummyHead.prev = newFirst;\n newFirst!.next = this._dummyHead;\n // Unlink the node to be dequeued.\n node!.prev = null;\n node!.next = null;\n this._length--;\n return node!.value;\n }\n\n /**\n * Determines if the queue is empty.\n */\n isEmpty(): boolean {\n return this._length === 0;\n }\n\n /**\n * Returns the item at the front of the queue without removing it from the queue.\n */\n front(): T | undefined {\n if (this.isEmpty()) {\n return undefined;\n }\n\n return this._dummyHead.prev!.value;\n }\n\n /**\n * Returns the item at the back of the queue without removing it from the queue it.\n */\n back(): T | undefined {\n if (this.isEmpty()) {\n return undefined;\n }\n\n return this._dummyTail.next!.value;\n }\n\n /**\n * Returns the number of items in the queue.\n * @return {number} The number of items in the queue.\n */\n length(): number {\n return this._length;\n }\n}\n`;function a(n){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",img:\"img\",ul:\"ul\",li:\"li\"},n.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(e.h2,{children:\"\\u89E3\\u51B3\\u65B9\\u6848\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"\\u961F\\u5217\\u5E94\\u8BE5\\u7528\\u94FE\\u8868\\u6765\\u5B9E\\u73B0\\uFF0C\\u94FE\\u8868\\u672C\\u8D28\\u4E0A\\u662F\\u4E00\\u7CFB\\u5217\\u8FDE\\u63A5\\u7684\\u8282\\u70B9\\u3002\\u4E3A\\u4E86\\u7B80\\u5316\\u7A7A\\u961F\\u5217\\u7684\\u94FE\\u8868\\u64CD\\u4F5C\\uFF0C\\u6211\\u4EEC\\u4F7F\\u7528\\u53CC\\u5411\\u94FE\\u8868\\uFF08\\u8282\\u70B9\\u540C\\u65F6\\u5177\\u6709 \",(0,t.jsx)(e.code,{children:\"prev\"}),\" \\u548C \",(0,t.jsx)(e.code,{children:\"next\"}),\" \\u6307\\u9488\\uFF09\\u548C\\u865A\\u62DF/\\u54E8\\u5175\\u5934/\\u5C3E\\u8282\\u70B9\\u3002\\u901A\\u8FC7\\u4F7F\\u7528\\u865A\\u62DF\\u8282\\u70B9\\uFF0C\\u94FE\\u8868\\u5C06\\u6C38\\u8FDC\\u4E0D\\u4F1A\\u662F\\u201C\\u7A7A\\u7684\\u201D\\uFF0C\\u6211\\u4EEC\\u4E0D\\u5FC5\\u5355\\u72EC\\u5904\\u7406\\u5165\\u961F\\u5230\\u7A7A\\u961F\\u5217\\u548C\\u51FA\\u961F\\u53EA\\u6709\\u4E00\\u4E2A\\u9879\\u76EE\\u7684\\u961F\\u5217\\u7684\\u60C5\\u51B5\\u3002\"]}),`\n`,(0,t.jsx)(e.p,{children:(0,t.jsx)(e.img,{src:\"/img/questions/queue/empty-queue.png\",alt:\"Empty Queue\"})}),`\n`,(0,t.jsxs)(e.p,{children:[(0,t.jsx)(e.code,{children:\"enqueue()\"}),\" \\u6D89\\u53CA\\u521B\\u5EFA\\u4E00\\u4E2A\\u65B0\\u7684 \",(0,t.jsx)(e.code,{children:\"Node\"}),\" \\u5E76\\u5728 \",(0,t.jsx)(e.code,{children:\"_dummyTail\"}),\" \\u8282\\u70B9\\u548C \",(0,t.jsx)(e.code,{children:\"_dummyTail.next\"}),\"\\uFF08\\u5728\\u7A7A\\u961F\\u5217\\u7684\\u60C5\\u51B5\\u4E0B\\u662F \",(0,t.jsx)(e.code,{children:\"_dummyHead\"}),\"\\uFF09\\u4E4B\\u95F4\\u6DFB\\u52A0\\u5B83\\u3002\"]}),`\n`,(0,t.jsx)(e.p,{children:(0,t.jsx)(e.img,{src:\"/img/questions/queue/enqueue-a.png\",alt:\"Enqueue one item\"})}),`\n`,(0,t.jsx)(e.p,{children:(0,t.jsx)(e.img,{src:\"/img/questions/queue/enqueue-b.png\",alt:\"Enqueue second item\"})}),`\n`,(0,t.jsxs)(e.p,{children:[(0,t.jsx)(e.code,{children:\"dequeue()\"}),\" \\u6D89\\u53CA\\u5220\\u9664 \",(0,t.jsx)(e.code,{children:\"_dummyHead\"}),\" \\u8282\\u70B9\\u548C \",(0,t.jsx)(e.code,{children:\"_dummyHead.prev\"}),\" \\u4E4B\\u95F4\\u7684\\u8282\\u70B9\\u3002\\u5982\\u679C\\u961F\\u5217\\u4E3A\\u7A7A\\uFF0C\\u5219\\u8FD9\\u5E94\\u8BE5\\u662F\\u4E00\\u4E2A no-op\\uFF0C\\u5426\\u5219 \",(0,t.jsx)(e.code,{children:\"_dummyTail\"}),\" \\u5C06\\u88AB\\u51FA\\u961F\\u3002\"]}),`\n`,(0,t.jsx)(e.p,{children:(0,t.jsx)(e.img,{src:\"/img/questions/queue/dequeue.png\",alt:\"Dequeue\"})}),`\n`,(0,t.jsxs)(e.p,{children:[\"\\u7531\\u4E8E \",(0,t.jsx)(e.code,{children:\"length()\"}),\" \\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u5FC5\\u987B\\u662F O(1)\\uFF0C\\u5E76\\u4E14\\u8BA1\\u7B97\\u94FE\\u8868\\u4E2D\\u9879\\u76EE\\u7684\\u6570\\u91CF\\u5C06\\u9700\\u8981 O(n)\\uFF0C\\u56E0\\u6B64\\u6211\\u4EEC\\u9700\\u8981\\u4F7F\\u7528 \",(0,t.jsx)(e.code,{children:\"_length\"}),\" \\u5B9E\\u4F8B\\u5C5E\\u6027\\u5355\\u72EC\\u8DDF\\u8E2A\\u5217\\u8868\\u4E2D\\u9879\\u76EE\\u7684\\u6570\\u91CF\\uFF0C\\u5E76\\u5728 \",(0,t.jsx)(e.code,{children:\"enqueue()\"}),\" \\u548C \",(0,t.jsx)(e.code,{children:\"dequeue()\"}),\" \\u65B9\\u6CD5\\u4E2D\\u66F4\\u65B0\\u5B83\\u3002\"]}),`\n`,(0,t.jsxs)(e.p,{children:[\"\\u8BF7\\u6CE8\\u610F\\uFF0C\\u81EA\\u52A8\\u8BC4\\u5206\\u5668\\u4E0D\\u4F1A\\u68C0\\u67E5\\u4F60\\u7684 \",(0,t.jsx)(e.code,{children:\"enqueue()\"}),\" \\u548C \",(0,t.jsx)(e.code,{children:\"dequeue()\"}),\" \\u64CD\\u4F5C\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u662F\\u5426\\u4E3A O(1)\\uFF0C\\u4F46\\u5982\\u679C\\u4F60\\u53EA\\u4F7F\\u7528\\u5355\\u4E2A JavaScript \\u6570\\u7EC4\\u6765\\u89E3\\u51B3\\u8FD9\\u4E2A\\u95EE\\u9898\\uFF0C\\u90A3\\u4E48\\u5B83\\u51E0\\u4E4E\\u80AF\\u5B9A\\u65E0\\u6CD5\\u5B9E\\u73B0\\u8FD9\\u4E24\\u4E2A\\u64CD\\u4F5C\\u7684 O(1) \\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u3002\"]}),`\n`,(0,t.jsx)(s,{languages:{jsx:l,tsx:c}}),`\n`,(0,t.jsx)(e.h2,{children:\"\\u8FB9\\u7F18\\u60C5\\u51B5\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[\"\\u5728\\u7A7A\\u6808\\u4E0A\\u8C03\\u7528 \",(0,t.jsx)(e.code,{children:\"dequeue()\"}),\"\\u3002\"]}),`\n`,(0,t.jsxs)(e.li,{children:[\"\\u5728\\u7A7A\\u6808\\u4E0A\\u8C03\\u7528 \",(0,t.jsx)(e.code,{children:\"front()\"}),\"\\u3002\"]}),`\n`,(0,t.jsxs)(e.li,{children:[\"\\u5728\\u7A7A\\u6808\\u4E0A\\u8C03\\u7528 \",(0,t.jsx)(e.code,{children:\"back()\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,t.jsx)(e.h2,{children:\"\\u6280\\u672F\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsx)(e.li,{children:\"\\u9762\\u5411\\u5BF9\\u8C61\\u7F16\\u7A0B\\u3002\"}),`\n`,(0,t.jsx)(e.li,{children:\"\\u94FE\\u8868\\u64CD\\u4F5C\\u3002\"}),`\n`]})]})}function H(n={}){let{wrapper:e}=n.components||{};return e?(0,t.jsx)(e,Object.assign({},n,{children:(0,t.jsx)(a,n)})):a(n)}var N=H;return x(k);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/quick-sort/locales/en-US.json b/apps/web/src/__generated__/questions/algo/quick-sort/locales/en-US.json index faeff1716..33fcdd05b 100644 --- a/apps/web/src/__generated__/questions/algo/quick-sort/locales/en-US.json +++ b/apps/web/src/__generated__/questions/algo/quick-sort/locales/en-US.json @@ -1,8 +1,8 @@ { - "description": "var Component=(()=>{var d=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var b=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),g=(t,e)=>{for(var r in e)i(t,r,{get:e[r],enumerable:!0})},o=(t,e,r,s)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let a of u(e))!f.call(t,a)&&a!==r&&i(t,a,{get:()=>e[a],enumerable:!(s=p(e,a))||s.enumerable});return t};var v=(t,e,r)=>(r=t!=null?d(m(t)):{},o(e||!t||!t.__esModule?i(r,\"default\",{value:t,enumerable:!0}):r,t)),x=t=>o(i({},\"__esModule\",{value:!0}),t);var h=b((w,c)=>{c.exports=_jsx_runtime});var _={};g(_,{default:()=>j,frontmatter:()=>y});var n=v(h()),y={title:\"Quick Sort\",excerpt:\"Implement a function that performs a recursive quick sort\"};function l(t){let e=Object.assign({p:\"p\",h2:\"h2\",pre:\"pre\",code:\"code\",ol:\"ol\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.p,{children:\"Implement a function that performs a recursive quick sort. The function should take in an array of integers. The output should be an array with the input sorted in ascending order.\"}),`\n`,(0,n.jsx)(e.h2,{children:\"Examples\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`quickSort([9, 3, 6, 2, 1, 11]); // [1, 2, 3, 6, 9, 11]\nquickSort([12, 16, 14, 1, 2, 3]); // [1, 2, 3, 12, 14, 16]\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"Recap\"}),`\n`,(0,n.jsx)(e.p,{children:'Quick sort is an efficient, in-place, recursive sorting algorithm that selects a \"pivot\" element and partitions all other elements into 2 subarrays:'}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"Elements that are smaller than the pivot are added in 1 subarray that is placed before the pivot.\"}),`\n`,(0,n.jsx)(e.li,{children:\"Elements that are larger than the pivot are added in 1 subarray that is placed after the pivot.\"}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"The quick sort is then recursively applied to each subarray. and once the subarrays are sorted they are then merged back with the pivot element between them as per above.\"})]})}function k(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(l,t)})):l(t)}var j=k;return x(_);})();\n;return Component;", + "description": "var Component=(()=>{var d=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var g=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),b=(t,e)=>{for(var r in e)i(t,r,{get:e[r],enumerable:!0})},o=(t,e,r,s)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let a of u(e))!f.call(t,a)&&a!==r&&i(t,a,{get:()=>e[a],enumerable:!(s=p(e,a))||s.enumerable});return t};var v=(t,e,r)=>(r=t!=null?d(m(t)):{},o(e||!t||!t.__esModule?i(r,\"default\",{value:t,enumerable:!0}):r,t)),x=t=>o(i({},\"__esModule\",{value:!0}),t);var h=g((w,c)=>{c.exports=_jsx_runtime});var _={};b(_,{default:()=>j,frontmatter:()=>y});var n=v(h()),y={title:\"Quick Sort\",excerpt:\"Implement a function that performs a recursive quick sort\"};function l(t){let e=Object.assign({p:\"p\",strong:\"strong\",h2:\"h2\",pre:\"pre\",code:\"code\",ol:\"ol\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"Implement a function that performs a \",(0,n.jsx)(e.strong,{children:\"recursive, in-place\"}),\" quick sort. The function should take in an array of integers. The output should be an array with the input sorted in ascending order.\"]}),`\n`,(0,n.jsx)(e.h2,{children:\"Examples\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`quickSort([9, 3, 6, 2, 1, 11]); // [1, 2, 3, 6, 9, 11]\nquickSort([12, 16, 14, 1, 2, 3]); // [1, 2, 3, 12, 14, 16]\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"Recap\"}),`\n`,(0,n.jsx)(e.p,{children:'Quick sort is an efficient, in-place, recursive sorting algorithm that selects a \"pivot\" element and partitions all other elements into 2 subarrays:'}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"Elements that are smaller than the pivot are added in 1 subarray that is placed before the pivot.\"}),`\n`,(0,n.jsx)(e.li,{children:\"Elements that are larger than the pivot are added in 1 subarray that is placed after the pivot.\"}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"The quick sort is then recursively applied to each subarray. and once the subarrays are sorted they are then merged back with the pivot element between them as per above.\"})]})}function k(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(l,t)})):l(t)}var j=k;return x(_);})();\n;return Component;", "info": { "excerpt": "Implement a function that performs a recursive quick sort", "title": "Quick Sort" }, - "solution": "var Component=(()=>{var m=Object.create;var a=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var v=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),w=(t,e)=>{for(var n in e)a(t,n,{get:e[n],enumerable:!0})},s=(t,e,n,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of y(e))!b.call(t,i)&&i!==n&&a(t,i,{get:()=>e[i],enumerable:!(o=f(e,i))||o.enumerable});return t};var x=(t,e,n)=>(n=t!=null?m(g(t)):{},s(e||!t||!t.__esModule?a(n,\"default\",{value:t,enumerable:!0}):n,t)),k=t=>s(a({},\"__esModule\",{value:!0}),t);var c=v((A,l)=>{l.exports=_jsx_runtime});var I={};w(I,{default:()=>j});var r=x(c());var h=MDXCodeBlock;var u=`/**\n * Partitions an array into two parts according to a pivot.\n * @param {Array} arr The array to be sorted.\n * @param {number} lo Starting index of the array to partition\n * @param {number} hi Ending index (inclusive) of the array to partition\n * @return {number} The pivot index that was chosen.\n */\nfunction partition(arr, lo, hi) {\n const pivot = arr[hi];\n let i = lo - 1;\n\n for (let j = lo; j < hi; j++) {\n if (arr[j] < pivot) {\n i++;\n [arr[i], arr[j]] = [arr[j], arr[i]];\n }\n }\n\n if (arr[hi] < arr[i + 1]) {\n [arr[i + 1], arr[hi]] = [arr[hi], arr[i + 1]];\n }\n\n return i + 1;\n}\n\n/**\n * Sorts an array of elements in-place.\n * @param {Array} arr The array to be sorted\n * @param {number} lo Starting index of the array to sort\n * @param {number} hi Ending index (inclusive) of the array to sort\n */\nfunction quickSortImpl(arr, lo, hi) {\n if (lo >= hi) {\n return;\n }\n\n const pivot = partition(arr, lo, hi);\n quickSortImpl(arr, lo, pivot - 1);\n quickSortImpl(arr, pivot + 1, hi);\n}\n\n/**\n * Sorts an array of elements\n * @param {number[]} arr The array to be sorted.\n * @return {number[]}\n */\nexport default function quickSort(arr) {\n quickSortImpl(arr, 0, arr.length - 1);\n return arr;\n}\n`;var d=`/**\n * Partitions an array into two parts according to a pivot.\n * @param {Array} arr The array to be sorted.\n * @param {number} lo Starting index of the array to partition\n * @param {number} hi Ending index (inclusive) of the array to partition\n * @return {number} The pivot index that was chosen.\n */\nfunction partition(arr: Array, lo: number, hi: number): number {\n const pivot = arr[hi];\n let i = lo - 1;\n\n for (let j = lo; j < hi; j++) {\n if (arr[j] < pivot) {\n i++;\n [arr[i], arr[j]] = [arr[j], arr[i]];\n }\n }\n\n if (arr[hi] < arr[i + 1]) {\n [arr[i + 1], arr[hi]] = [arr[hi], arr[i + 1]];\n }\n\n return i + 1;\n}\n\n/**\n * Sorts an array of elements in-place.\n * @param {Array} arr The array to be sorted\n * @param {number} lo Starting index of the array to sort\n * @param {number} hi Ending index (inclusive) of the array to sort\n */\nfunction quickSortImpl(arr: Array, lo: number, hi: number) {\n if (lo >= hi) {\n return;\n }\n\n const pivot = partition(arr, lo, hi);\n quickSortImpl(arr, lo, pivot - 1);\n quickSortImpl(arr, pivot + 1, hi);\n}\n\n/**\n * Sorts an array of elements\n * @param {Array} arr The array to be sorted.\n * @return {Array}\n */\nexport default function quickSort(arr: Array) {\n quickSortImpl(arr, 0, arr.length - 1);\n return arr;\n}\n`;function p(t){let e=Object.assign({p:\"p\",h2:\"h2\",ul:\"ul\",li:\"li\",h3:\"h3\",em:\"em\",ol:\"ol\",pre:\"pre\",code:\"code\"},t.components);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e.p,{children:\"Quick sort is generally regarded as the most efficient general-purpose sorting algorithm for any array size, being faster than merge sort on average. The standard form of quick sort is generally done recursively and in-place. However, it is an unstable sort and hence merge sort could be preferred in cases where stability is important.\"}),`\n`,(0,r.jsx)(e.h2,{children:\"Clarification questions\"}),`\n`,(0,r.jsx)(e.p,{children:\"If unspecified:\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"Should the data be sorted in an ascending or descending order?\"}),`\n`,(0,r.jsx)(e.li,{children:\"Should the data be sorted in-place or is it acceptable to use additional data structures?\"}),`\n`,(0,r.jsxs)(e.li,{children:[\"What kinds of inputs do we need to handle?\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"Will it just be an array of integers or should we handle other data types?\"}),`\n`,(0,r.jsx)(e.li,{children:\"Are there a large number of duplicate elements?\"}),`\n`,(0,r.jsx)(e.li,{children:\"How should negative numbers be handled?\"}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,r.jsx)(e.h2,{children:\"Solution\"}),`\n`,(0,r.jsx)(e.p,{children:\"Note: This question tackles a standard quick sort which is recursive and in-place for an output in ascending order.\"}),`\n`,(0,r.jsx)(h,{languages:{jsx:u,tsx:d}}),`\n`,(0,r.jsx)(e.h2,{children:\"Edge cases\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"Non-integer element input: If the input array comprises of elements of different data types, you may need to return an error, settle for sorting on a best-effort basis, for e.g., only sorting a subset of the input data, or even define custom comparison functions for non-integers.\"}),`\n`,(0,r.jsx)(e.li,{children:\"Single element / Empty input: Either return the original data structure, raise an error, or clarify required handling.\"}),`\n`,(0,r.jsx)(e.li,{children:\"Already sorted input: You may want to detect sorting and return the input unchanged.\"}),`\n`,(0,r.jsx)(e.li,{children:\"Invalid input: If the input is not an array, consider throwing an error.\"}),`\n`]}),`\n`,(0,r.jsx)(e.h2,{children:\"Big-O analysis\"}),`\n`,(0,r.jsx)(e.p,{children:\"Let's analyze the algorithm's time and space complexity.\"}),`\n`,(0,r.jsx)(e.h3,{children:\"Time complexity\"}),`\n`,(0,r.jsxs)(e.p,{children:[\"In the case of quick sort, the best and average case time complexity is O(nlog(n)), while the worst case time complexity is O(n\",(0,r.jsx)(\"sup\",{children:\"2\"}),\"). Despite this, quick sort is generally faster than merge sort as the conditions for a worst or best case time complexity makes it extremely rare.\"]}),`\n`,(0,r.jsx)(e.p,{children:\"The time complexity of quick sort is dependent on the selection of the pivot element for every recursive call. The closer the pivot is to the median of the array or subarray, the faster the algorithm. This is because it affects the partitioning time for every recursive call, which refers to the time it takes to scan each subarray and place it in the smaller or larger subarray.\"}),`\n`,(0,r.jsxs)(e.p,{children:[\"In the worst case, for every recursive call, we happen to select the pivot element furthest away from the median - that is, the largest or smallest element in the array or subarrays. This means that the partitioning time is \",(0,r.jsx)(e.em,{children:\"c(n)\"}),\" (c for some constant) for the first recursive call, \",(0,r.jsx)(e.em,{children:\"c(n-1)\"}),\" for the second recursive call (after selecting 1 pivot element), and so on. When we total up the partitioning times for n recursive calls, it comes up to about O(n\",(0,r.jsx)(\"sup\",{children:\"2\"}),\") running time.\"]}),`\n`,(0,r.jsxs)(e.p,{children:[\"In the best case, the pivot element for every recursive call is very close to the median such that partitions are always as evenly balanced as possible. In this case, we expect every subarray to be evenly halved each time, meaning that we only need \",(0,r.jsx)(e.em,{children:\"2 * (n/2)\"}),\" partitioning time for every recursive call (where n refers to the size of the subarray to be partitioned). Given that there are also log(n) + 1 recursive calls to be made, we expect a total of cn(log(n) + 1) running time, which in big O notation is O(nlog(n)).\"]}),`\n`,(0,r.jsx)(e.p,{children:\"As we can see from above, the best and worst requires very specific conditions for them to happen.\"}),`\n`,(0,r.jsx)(e.p,{children:\"Meanwhile, the average case is more likely to occur for quick sort. The average case is derived from the fact that any split of constant proportionality will produce a recursion tree of depth O(log(n)), where the partitioning cost for every recursion level is O(log(n)). Hence, the time complexity tends to be O(nlog(n)).\"}),`\n`,(0,r.jsx)(e.p,{children:\"Using an example where we assume a partially unbalanced split in the ratio of (9:1):\"}),`\n`,(0,r.jsxs)(e.ol,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"The left subtree of the recurrence will decrease at a factor of 1/10, which puts its depth at log\",(0,r.jsx)(\"sub\",{children:\"10\"}),\"(n).\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"The right subtree of the recurrence will decrease at a factor of 9/10, which puts its depth at log\",(0,r.jsx)(\"sub\",{children:\"10/9\"}),\"(n) = O(log(n)).\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"The cost to partition at each level of recursion is around \",(0,r.jsx)(e.em,{children:\"c(n)\"}),\".\"]}),`\n`]}),`\n`,(0,r.jsx)(e.p,{children:\"With the above, we see that the cost is around O(nlog(n)).\"}),`\n`,(0,r.jsx)(e.h3,{children:\"Space complexity\"}),`\n`,(0,r.jsx)(e.p,{children:\"In terms of space complexity, although quick sort is an in-place algorithm, as a recursive function it still uses a call stack. The space complexity will therefore depend on the size of the recursion call stack, which is the height of the recursion tree.\"}),`\n`,(0,r.jsx)(e.p,{children:\"In the worst case, pivots are chosen badly in every recursive call and there is therefore only 1 call at each level of recursion. This causes the height of the recursion tree to be O(n).\"}),`\n`,(0,r.jsx)(e.p,{children:\"In the best case, the space complexity tends to be O(log(n)), whereby there are 2 recursive calls at every recursion level. This occurs when the pivot is always the median or close to it, such that the recursion tree is balanced.\"}),`\n`,(0,r.jsx)(e.p,{children:\"To avoid the worst case time or space complexity, we could use a better pivot selection strategy. An example of such a strategy is the random pivot selection strategy. By randomly selecting the pivot element, we can ensure that the pivot is not always the smallest or largest element in the array, which reduces the likelihood of the worst-case time complexity occurring.\"}),`\n`,(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:\"language-js\",children:`// Select a pivot element randomly\nconst pivotIndex = Math.floor(Math.random() * arr.length);\nconst pivot = arr[pivotIndex];\n`})})]})}function q(t={}){let{wrapper:e}=t.components||{};return e?(0,r.jsx)(e,Object.assign({},t,{children:(0,r.jsx)(p,t)})):p(t)}var j=q;return k(I);})();\n;return Component;" + "solution": "var Component=(()=>{var m=Object.create;var a=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var v=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),w=(t,e)=>{for(var n in e)a(t,n,{get:e[n],enumerable:!0})},s=(t,e,n,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of y(e))!b.call(t,i)&&i!==n&&a(t,i,{get:()=>e[i],enumerable:!(o=f(e,i))||o.enumerable});return t};var x=(t,e,n)=>(n=t!=null?m(g(t)):{},s(e||!t||!t.__esModule?a(n,\"default\",{value:t,enumerable:!0}):n,t)),k=t=>s(a({},\"__esModule\",{value:!0}),t);var c=v((A,l)=>{l.exports=_jsx_runtime});var I={};w(I,{default:()=>j});var r=x(c());var h=MDXCodeBlock;var u=`/**\n * Partitions an array into two parts according to a pivot.\n * @param {Array} arr The array to be sorted.\n * @param {number} lo Starting index of the array to partition\n * @param {number} hi Ending index (inclusive) of the array to partition\n * @return {number} The pivot index that was chosen.\n */\nfunction partition(arr, lo, hi) {\n const pivot = arr[hi];\n let i = lo - 1;\n\n for (let j = lo; j < hi; j++) {\n if (arr[j] < pivot) {\n i++;\n [arr[i], arr[j]] = [arr[j], arr[i]];\n }\n }\n\n if (arr[hi] < arr[i + 1]) {\n [arr[i + 1], arr[hi]] = [arr[hi], arr[i + 1]];\n }\n\n return i + 1;\n}\n\n/**\n * Sorts an array of elements in-place.\n * @param {Array} arr The array to be sorted\n * @param {number} lo Starting index of the array to sort\n * @param {number} hi Ending index (inclusive) of the array to sort\n */\nfunction quickSortImpl(arr, lo, hi) {\n if (lo >= hi) {\n return;\n }\n\n const pivot = partition(arr, lo, hi);\n quickSortImpl(arr, lo, pivot - 1);\n quickSortImpl(arr, pivot + 1, hi);\n}\n\n/**\n * Sorts an array of elements\n * @param {number[]} arr The array to be sorted.\n * @return {number[]}\n */\nexport default function quickSort(arr) {\n quickSortImpl(arr, 0, arr.length - 1);\n return arr;\n}\n`;var d=`/**\n * Partitions an array into two parts according to a pivot.\n * @param {Array} arr The array to be sorted.\n * @param {number} lo Starting index of the array to partition\n * @param {number} hi Ending index (inclusive) of the array to partition\n * @return {number} The pivot index that was chosen.\n */\nfunction partition(arr: Array, lo: number, hi: number): number {\n const pivot = arr[hi];\n let i = lo - 1;\n\n for (let j = lo; j < hi; j++) {\n if (arr[j] < pivot) {\n i++;\n [arr[i], arr[j]] = [arr[j], arr[i]];\n }\n }\n\n if (arr[hi] < arr[i + 1]) {\n [arr[i + 1], arr[hi]] = [arr[hi], arr[i + 1]];\n }\n\n return i + 1;\n}\n\n/**\n * Sorts an array of elements in-place.\n * @param {Array} arr The array to be sorted\n * @param {number} lo Starting index of the array to sort\n * @param {number} hi Ending index (inclusive) of the array to sort\n */\nfunction quickSortImpl(arr: Array, lo: number, hi: number) {\n if (lo >= hi) {\n return;\n }\n\n const pivot = partition(arr, lo, hi);\n quickSortImpl(arr, lo, pivot - 1);\n quickSortImpl(arr, pivot + 1, hi);\n}\n\n/**\n * Sorts an array of elements\n * @param {Array} arr The array to be sorted.\n * @return {Array}\n */\nexport default function quickSort(arr: Array) {\n quickSortImpl(arr, 0, arr.length - 1);\n return arr;\n}\n`;function p(t){let e=Object.assign({p:\"p\",strong:\"strong\",h2:\"h2\",ul:\"ul\",li:\"li\",h3:\"h3\",em:\"em\",ol:\"ol\",pre:\"pre\",code:\"code\"},t.components);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(e.p,{children:[\"Quick sort is generally regarded as the most efficient general-purpose sorting algorithm for any array size, being faster than merge sort on average. The standard form of quick sort is generally done \",(0,r.jsx)(e.strong,{children:\"recursively\"}),\" and \",(0,r.jsx)(e.strong,{children:\"in-place\"}),\". However, it is an unstable sort and hence merge sort could be preferred in cases where stability is important.\"]}),`\n`,(0,r.jsx)(e.h2,{children:\"Clarification questions\"}),`\n`,(0,r.jsx)(e.p,{children:\"If unspecified:\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"Should the data be sorted in an ascending or descending order?\"}),`\n`,(0,r.jsx)(e.li,{children:\"Should the data be sorted in-place or is it acceptable to use additional data structures?\"}),`\n`,(0,r.jsxs)(e.li,{children:[\"What kinds of inputs do we need to handle?\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"Will it just be an array of integers or should we handle other data types?\"}),`\n`,(0,r.jsx)(e.li,{children:\"Are there a large number of duplicate elements?\"}),`\n`,(0,r.jsx)(e.li,{children:\"How should negative numbers be handled?\"}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,r.jsx)(e.h2,{children:\"Solution\"}),`\n`,(0,r.jsx)(e.p,{children:\"Note: This question tackles a standard quick sort which is recursive and in-place for an output in ascending order.\"}),`\n`,(0,r.jsx)(h,{languages:{jsx:u,tsx:d}}),`\n`,(0,r.jsx)(e.h2,{children:\"Edge cases\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsx)(e.li,{children:\"Non-integer element input: If the input array comprises of elements of different data types, you may need to return an error, settle for sorting on a best-effort basis, for e.g., only sorting a subset of the input data, or even define custom comparison functions for non-integers.\"}),`\n`,(0,r.jsx)(e.li,{children:\"Single element / Empty input: Either return the original data structure, raise an error, or clarify required handling.\"}),`\n`,(0,r.jsx)(e.li,{children:\"Already sorted input: You may want to detect sorting and return the input unchanged.\"}),`\n`,(0,r.jsx)(e.li,{children:\"Invalid input: If the input is not an array, consider throwing an error.\"}),`\n`]}),`\n`,(0,r.jsx)(e.h2,{children:\"Big-O analysis\"}),`\n`,(0,r.jsx)(e.p,{children:\"Let's analyze the algorithm's time and space complexity.\"}),`\n`,(0,r.jsx)(e.h3,{children:\"Time complexity\"}),`\n`,(0,r.jsxs)(e.p,{children:[\"In the case of quick sort, the best and average case time complexity is O(nlog(n)), while the worst case time complexity is O(n\",(0,r.jsx)(\"sup\",{children:\"2\"}),\"). Despite this, quick sort is generally faster than merge sort as the conditions for a worst or best case time complexity makes it extremely rare.\"]}),`\n`,(0,r.jsx)(e.p,{children:\"The time complexity of quick sort is dependent on the selection of the pivot element for every recursive call. The closer the pivot is to the median of the array or subarray, the faster the algorithm. This is because it affects the partitioning time for every recursive call, which refers to the time it takes to scan each subarray and place it in the smaller or larger subarray.\"}),`\n`,(0,r.jsxs)(e.p,{children:[\"In the worst case, for every recursive call, we happen to select the pivot element furthest away from the median - that is, the largest or smallest element in the array or subarrays. This means that the partitioning time is \",(0,r.jsx)(e.em,{children:\"c(n)\"}),\" (c for some constant) for the first recursive call, \",(0,r.jsx)(e.em,{children:\"c(n-1)\"}),\" for the second recursive call (after selecting 1 pivot element), and so on. When we total up the partitioning times for n recursive calls, it comes up to about O(n\",(0,r.jsx)(\"sup\",{children:\"2\"}),\") running time.\"]}),`\n`,(0,r.jsxs)(e.p,{children:[\"In the best case, the pivot element for every recursive call is very close to the median such that partitions are always as evenly balanced as possible. In this case, we expect every subarray to be evenly halved each time, meaning that we only need \",(0,r.jsx)(e.em,{children:\"2 * (n/2)\"}),\" partitioning time for every recursive call (where n refers to the size of the subarray to be partitioned). Given that there are also log(n) + 1 recursive calls to be made, we expect a total of cn(log(n) + 1) running time, which in big O notation is O(nlog(n)).\"]}),`\n`,(0,r.jsx)(e.p,{children:\"As we can see from above, the best and worst requires very specific conditions for them to happen.\"}),`\n`,(0,r.jsx)(e.p,{children:\"Meanwhile, the average case is more likely to occur for quick sort. The average case is derived from the fact that any split of constant proportionality will produce a recursion tree of depth O(log(n)), where the partitioning cost for every recursion level is O(log(n)). Hence, the time complexity tends to be O(nlog(n)).\"}),`\n`,(0,r.jsx)(e.p,{children:\"Using an example where we assume a partially unbalanced split in the ratio of (9:1):\"}),`\n`,(0,r.jsxs)(e.ol,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"The left subtree of the recurrence will decrease at a factor of 1/10, which puts its depth at log\",(0,r.jsx)(\"sub\",{children:\"10\"}),\"(n).\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"The right subtree of the recurrence will decrease at a factor of 9/10, which puts its depth at log\",(0,r.jsx)(\"sub\",{children:\"10/9\"}),\"(n) = O(log(n)).\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"The cost to partition at each level of recursion is around \",(0,r.jsx)(e.em,{children:\"c(n)\"}),\".\"]}),`\n`]}),`\n`,(0,r.jsx)(e.p,{children:\"With the above, we see that the cost is around O(nlog(n)).\"}),`\n`,(0,r.jsx)(e.h3,{children:\"Space complexity\"}),`\n`,(0,r.jsx)(e.p,{children:\"In terms of space complexity, although quick sort is an in-place algorithm, as a recursive function it still uses a call stack. The space complexity will therefore depend on the size of the recursion call stack, which is the height of the recursion tree.\"}),`\n`,(0,r.jsx)(e.p,{children:\"In the worst case, pivots are chosen badly in every recursive call and there is therefore only 1 call at each level of recursion. This causes the height of the recursion tree to be O(n).\"}),`\n`,(0,r.jsx)(e.p,{children:\"In the best case, the space complexity tends to be O(log(n)), whereby there are 2 recursive calls at every recursion level. This occurs when the pivot is always the median or close to it, such that the recursion tree is balanced.\"}),`\n`,(0,r.jsx)(e.p,{children:\"To avoid the worst case time or space complexity, we could use a better pivot selection strategy. An example of such a strategy is the random pivot selection strategy. By randomly selecting the pivot element, we can ensure that the pivot is not always the smallest or largest element in the array, which reduces the likelihood of the worst-case time complexity occurring.\"}),`\n`,(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:\"language-js\",children:`// Select a pivot element randomly\nconst pivotIndex = Math.floor(Math.random() * arr.length);\nconst pivot = arr[pivotIndex];\n`})})]})}function q(t={}){let{wrapper:e}=t.components||{};return e?(0,r.jsx)(e,Object.assign({},t,{children:(0,r.jsx)(p,t)})):p(t)}var j=q;return k(I);})();\n;return Component;" } \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/quick-sort/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/quick-sort/locales/zh-CN.json new file mode 100644 index 000000000..0fe34078a --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/quick-sort/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var h=Object.create;var o=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var g=(e,n)=>()=>(n||e((n={exports:{}}).exports,n),n.exports),j=(e,n)=>{for(var r in n)o(e,r,{get:n[r],enumerable:!0})},s=(e,n,r,i)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let c of m(n))!x.call(e,c)&&c!==r&&o(e,c,{get:()=>n[c],enumerable:!(i=p(n,c))||i.enumerable});return e};var _=(e,n,r)=>(r=e!=null?h(u(e)):{},s(n||!e||!e.__esModule?o(r,\"default\",{value:e,enumerable:!0}):r,e)),f=e=>s(o({},\"__esModule\",{value:!0}),e);var d=g((D,l)=>{l.exports=_jsx_runtime});var q={};j(q,{default:()=>k,frontmatter:()=>M});var t=_(d()),M={title:\"\\u5FEB\\u901F\\u6392\\u5E8F\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u6267\\u884C\\u9012\\u5F52\\u5FEB\\u901F\\u6392\\u5E8F\\u7684\\u51FD\\u6570\"};function a(e){let n=Object.assign({p:\"p\",strong:\"strong\",h2:\"h2\",pre:\"pre\",code:\"code\",ol:\"ol\",li:\"li\"},e.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(n.p,{children:[\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u6267\\u884C\",(0,t.jsx)(n.strong,{children:\"\\u9012\\u5F52\\u3001\\u5C31\\u5730\"}),\"\\u5FEB\\u901F\\u6392\\u5E8F\\u7684\\u51FD\\u6570\\u3002\\u8BE5\\u51FD\\u6570\\u5E94\\u63A5\\u6536\\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4\\u3002\\u8F93\\u51FA\\u5E94\\u8BE5\\u662F\\u4E00\\u4E2A\\u6309\\u5347\\u5E8F\\u6392\\u5E8F\\u7684\\u6570\\u7EC4\\u3002\"]}),`\n`,(0,t.jsx)(n.h2,{children:\"\\u4F8B\\u5B50\"}),`\n`,(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:\"language-js\",children:`quickSort([9, 3, 6, 2, 1, 11]); // [1, 2, 3, 6, 9, 11]\nquickSort([12, 16, 14, 1, 2, 3]); // [1, 2, 3, 12, 14, 16]\n`})}),`\n`,(0,t.jsx)(n.h2,{children:\"\\u56DE\\u987E\"}),`\n`,(0,t.jsx)(n.p,{children:\"\\u5FEB\\u901F\\u6392\\u5E8F\\u662F\\u4E00\\u79CD\\u9AD8\\u6548\\u7684\\u3001\\u5C31\\u5730\\u7684\\u3001\\u9012\\u5F52\\u7684\\u6392\\u5E8F\\u7B97\\u6CD5\\uFF0C\\u5B83\\u9009\\u62E9\\u4E00\\u4E2A\\u201C\\u67A2\\u8F74\\u201D\\u5143\\u7D20\\uFF0C\\u5E76\\u5C06\\u6240\\u6709\\u5176\\u4ED6\\u5143\\u7D20\\u5206\\u6210 2 \\u4E2A\\u5B50\\u6570\\u7EC4\\uFF1A\"}),`\n`,(0,t.jsxs)(n.ol,{children:[`\n`,(0,t.jsx)(n.li,{children:\"\\u5C0F\\u4E8E\\u67A2\\u8F74\\u7684\\u5143\\u7D20\\u88AB\\u6DFB\\u52A0\\u5230\\u4F4D\\u4E8E\\u67A2\\u8F74\\u4E4B\\u524D\\u7684 1 \\u4E2A\\u5B50\\u6570\\u7EC4\\u4E2D\\u3002\"}),`\n`]}),`\n`,(0,t.jsx)(n.p,{children:\"\\u7136\\u540E\\u5C06\\u5FEB\\u901F\\u6392\\u5E8F\\u9012\\u5F52\\u5730\\u5E94\\u7528\\u4E8E\\u6BCF\\u4E2A\\u5B50\\u6570\\u7EC4\\u3002\\u4E00\\u65E6\\u5B50\\u6570\\u7EC4\\u88AB\\u6392\\u5E8F\\uFF0C\\u5B83\\u4EEC\\u5C31\\u4F1A\\u6309\\u7167\\u4E0A\\u8FF0\\u65B9\\u5F0F\\u4E0E\\u5B83\\u4EEC\\u4E4B\\u95F4\\u7684\\u67A2\\u8F74\\u5143\\u7D20\\u5408\\u5E76\\u3002\"})]})}function b(e={}){let{wrapper:n}=e.components||{};return n?(0,t.jsx)(n,Object.assign({},e,{children:(0,t.jsx)(a,e)})):a(e)}var k=b;return f(q);})();\n;return Component;", + "info": { + "excerpt": "实现一个执行递归快速排序的函数", + "title": "快速排序" + }, + "solution": "var Component=(()=>{var s=Object.create;var t=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var x=(i,r)=>()=>(r||i((r={exports:{}}).exports,r),r.exports),j=(i,r)=>{for(var e in r)t(i,e,{get:r[e],enumerable:!0})},l=(i,r,e,o)=>{if(r&&typeof r==\"object\"||typeof r==\"function\")for(let a of f(r))!y.call(i,a)&&a!==e&&t(i,a,{get:()=>r[a],enumerable:!(o=g(r,a))||o.enumerable});return i};var v=(i,r,e)=>(e=i!=null?s(b(i)):{},l(r||!i||!i.__esModule?t(e,\"default\",{value:i,enumerable:!0}):e,i)),S=i=>l(t({},\"__esModule\",{value:!0}),i);var c=x((M,h)=>{h.exports=_jsx_runtime});var A={};j(A,{default:()=>I});var n=v(c());var d=MDXCodeBlock;var p=`/**\n * Partitions an array into two parts according to a pivot.\n * @param {Array} arr The array to be sorted.\n * @param {number} lo Starting index of the array to partition\n * @param {number} hi Ending index (inclusive) of the array to partition\n * @return {number} The pivot index that was chosen.\n */\nfunction partition(arr, lo, hi) {\n const pivot = arr[hi];\n let i = lo - 1;\n\n for (let j = lo; j < hi; j++) {\n if (arr[j] < pivot) {\n i++;\n [arr[i], arr[j]] = [arr[j], arr[i]];\n }\n }\n\n if (arr[hi] < arr[i + 1]) {\n [arr[i + 1], arr[hi]] = [arr[hi], arr[i + 1]];\n }\n\n return i + 1;\n}\n\n/**\n * Sorts an array of elements in-place.\n * @param {Array} arr The array to be sorted\n * @param {number} lo Starting index of the array to sort\n * @param {number} hi Ending index (inclusive) of the array to sort\n */\nfunction quickSortImpl(arr, lo, hi) {\n if (lo >= hi) {\n return;\n }\n\n const pivot = partition(arr, lo, hi);\n quickSortImpl(arr, lo, pivot - 1);\n quickSortImpl(arr, pivot + 1, hi);\n}\n\n/**\n * Sorts an array of elements\n * @param {number[]} arr The array to be sorted.\n * @return {number[]}\n */\nexport default function quickSort(arr) {\n quickSortImpl(arr, 0, arr.length - 1);\n return arr;\n}\n`;var u=`/**\n * Partitions an array into two parts according to a pivot.\n * @param {Array} arr The array to be sorted.\n * @param {number} lo Starting index of the array to partition\n * @param {number} hi Ending index (inclusive) of the array to partition\n * @return {number} The pivot index that was chosen.\n */\nfunction partition(arr: Array, lo: number, hi: number): number {\n const pivot = arr[hi];\n let i = lo - 1;\n\n for (let j = lo; j < hi; j++) {\n if (arr[j] < pivot) {\n i++;\n [arr[i], arr[j]] = [arr[j], arr[i]];\n }\n }\n\n if (arr[hi] < arr[i + 1]) {\n [arr[i + 1], arr[hi]] = [arr[hi], arr[i + 1]];\n }\n\n return i + 1;\n}\n\n/**\n * Sorts an array of elements in-place.\n * @param {Array} arr The array to be sorted\n * @param {number} lo Starting index of the array to sort\n * @param {number} hi Ending index (inclusive) of the array to sort\n */\nfunction quickSortImpl(arr: Array, lo: number, hi: number) {\n if (lo >= hi) {\n return;\n }\n\n const pivot = partition(arr, lo, hi);\n quickSortImpl(arr, lo, pivot - 1);\n quickSortImpl(arr, pivot + 1, hi);\n}\n\n/**\n * Sorts an array of elements\n * @param {Array} arr The array to be sorted.\n * @return {Array}\n */\nexport default function quickSort(arr: Array) {\n quickSortImpl(arr, 0, arr.length - 1);\n return arr;\n}\n`;function m(i){let r=Object.assign({p:\"p\",strong:\"strong\",h2:\"h2\",ul:\"ul\",li:\"li\",h3:\"h3\",em:\"em\",ol:\"ol\",pre:\"pre\",code:\"code\"},i.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(r.p,{children:[\"\\u5FEB\\u901F\\u6392\\u5E8F\\u901A\\u5E38\\u88AB\\u8BA4\\u4E3A\\u662F\\u4EFB\\u4F55\\u6570\\u7EC4\\u5927\\u5C0F\\u6700\\u6709\\u6548\\u7684\\u901A\\u7528\\u6392\\u5E8F\\u7B97\\u6CD5\\uFF0C\\u5E73\\u5747\\u901F\\u5EA6\\u6BD4\\u5408\\u5E76\\u6392\\u5E8F\\u5FEB\\u3002\\u5FEB\\u901F\\u6392\\u5E8F\\u7684\\u6807\\u51C6\\u5F62\\u5F0F\\u901A\\u5E38\\u662F\",(0,n.jsx)(r.strong,{children:\"\\u9012\\u5F52\"}),\"\\u548C\",(0,n.jsx)(r.strong,{children:\"\\u5C31\\u5730\"}),\"\\u5B8C\\u6210\\u7684\\u3002\\u7136\\u800C\\uFF0C\\u5B83\\u662F\\u4E00\\u79CD\\u4E0D\\u7A33\\u5B9A\\u7684\\u6392\\u5E8F\\uFF0C\\u56E0\\u6B64\\u5728\\u7A33\\u5B9A\\u6027\\u5F88\\u91CD\\u8981\\u7684\\u60C5\\u51B5\\u4E0B\\uFF0C\\u53EF\\u80FD\\u66F4\\u559C\\u6B22\\u5408\\u5E76\\u6392\\u5E8F\\u3002\"]}),`\n`,(0,n.jsx)(r.h2,{children:\"\\u6F84\\u6E05\\u95EE\\u9898\"}),`\n`,(0,n.jsx)(r.p,{children:\"\\u5982\\u679C\\u672A\\u6307\\u5B9A\\uFF1A\"}),`\n`,(0,n.jsxs)(r.ul,{children:[`\n`,(0,n.jsx)(r.li,{children:\"\\u6570\\u636E\\u5E94\\u8BE5\\u6309\\u5347\\u5E8F\\u8FD8\\u662F\\u964D\\u5E8F\\u6392\\u5E8F\\uFF1F\"}),`\n`,(0,n.jsx)(r.li,{children:\"\\u6570\\u636E\\u5E94\\u8BE5\\u5C31\\u5730\\u6392\\u5E8F\\u8FD8\\u662F\\u53EF\\u4EE5\\u4F7F\\u7528\\u5176\\u4ED6\\u6570\\u636E\\u7ED3\\u6784\\uFF1F\"}),`\n`,(0,n.jsxs)(r.li,{children:[\"\\u6211\\u4EEC\\u9700\\u8981\\u5904\\u7406\\u4EC0\\u4E48\\u6837\\u7684\\u8F93\\u5165\\uFF1F\",`\n`,(0,n.jsxs)(r.ul,{children:[`\n`,(0,n.jsx)(r.li,{children:\"\\u5B83\\u53EA\\u662F\\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4\\uFF0C\\u8FD8\\u662F\\u6211\\u4EEC\\u5E94\\u8BE5\\u5904\\u7406\\u5176\\u4ED6\\u6570\\u636E\\u7C7B\\u578B\\uFF1F\"}),`\n`,(0,n.jsx)(r.li,{children:\"\\u662F\\u5426\\u5B58\\u5728\\u5927\\u91CF\\u91CD\\u590D\\u5143\\u7D20\\uFF1F\"}),`\n`,(0,n.jsx)(r.li,{children:\"\\u5E94\\u8BE5\\u5982\\u4F55\\u5904\\u7406\\u8D1F\\u6570\\uFF1F\"}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(r.h2,{children:\"\\u89E3\\u51B3\\u65B9\\u6848\"}),`\n`,(0,n.jsx)(r.p,{children:\"\\u6CE8\\u610F\\uFF1A\\u8FD9\\u4E2A\\u95EE\\u9898\\u5904\\u7406\\u7684\\u662F\\u4E00\\u4E2A\\u6807\\u51C6\\u7684\\u5FEB\\u901F\\u6392\\u5E8F\\uFF0C\\u5B83\\u5BF9\\u5347\\u5E8F\\u8F93\\u51FA\\u662F\\u9012\\u5F52\\u548C\\u5C31\\u5730\\u7684\\u3002\"}),`\n`,(0,n.jsx)(d,{languages:{jsx:p,tsx:u}}),`\n`,(0,n.jsx)(r.h2,{children:\"\\u8FB9\\u7F18\\u60C5\\u51B5\"}),`\n`,(0,n.jsxs)(r.ul,{children:[`\n`,(0,n.jsx)(r.li,{children:\"\\u975E\\u6574\\u6570\\u5143\\u7D20\\u8F93\\u5165\\uFF1A\\u5982\\u679C\\u8F93\\u5165\\u6570\\u7EC4\\u5305\\u542B\\u4E0D\\u540C\\u6570\\u636E\\u7C7B\\u578B\\u7684\\u5143\\u7D20\\uFF0C\\u60A8\\u53EF\\u80FD\\u9700\\u8981\\u8FD4\\u56DE\\u4E00\\u4E2A\\u9519\\u8BEF\\uFF0C\\u6EE1\\u8DB3\\u4E8E\\u5C3D\\u529B\\u6392\\u5E8F\\uFF0C\\u4F8B\\u5982\\uFF0C\\u4EC5\\u5BF9\\u8F93\\u5165\\u6570\\u636E\\u7684\\u5B50\\u96C6\\u8FDB\\u884C\\u6392\\u5E8F\\uFF0C\\u751A\\u81F3\\u4E3A\\u975E\\u6574\\u6570\\u5B9A\\u4E49\\u81EA\\u5B9A\\u4E49\\u6BD4\\u8F83\\u51FD\\u6570\\u3002\"}),`\n`,(0,n.jsx)(r.li,{children:\"\\u5355\\u4E2A\\u5143\\u7D20/\\u7A7A\\u8F93\\u5165\\uFF1A\\u8FD4\\u56DE\\u539F\\u59CB\\u6570\\u636E\\u7ED3\\u6784\\u3001\\u5F15\\u53D1\\u9519\\u8BEF\\u6216\\u6F84\\u6E05\\u6240\\u9700\\u5904\\u7406\\u3002\"}),`\n`,(0,n.jsx)(r.li,{children:\"\\u5DF2\\u7ECF\\u6392\\u5E8F\\u7684\\u8F93\\u5165\\uFF1A\\u60A8\\u53EF\\u80FD\\u9700\\u8981\\u68C0\\u6D4B\\u6392\\u5E8F\\u5E76\\u539F\\u6837\\u8FD4\\u56DE\\u8F93\\u5165\\u3002\"}),`\n`,(0,n.jsx)(r.li,{children:\"\\u65E0\\u6548\\u8F93\\u5165\\uFF1A\\u5982\\u679C\\u8F93\\u5165\\u4E0D\\u662F\\u6570\\u7EC4\\uFF0C\\u8BF7\\u8003\\u8651\\u629B\\u51FA\\u9519\\u8BEF\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(r.h2,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsx)(r.p,{children:\"\\u8BA9\\u6211\\u4EEC\\u5206\\u6790\\u4E00\\u4E0B\\u7B97\\u6CD5\\u7684\\u65F6\\u95F4\\u548C\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u3002\"}),`\n`,(0,n.jsx)(r.h3,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\"}),`\n`,(0,n.jsxs)(r.p,{children:[\"\\u5BF9\\u4E8E\\u5FEB\\u901F\\u6392\\u5E8F\\uFF0C\\u6700\\u4F73\\u548C\\u5E73\\u5747\\u60C5\\u51B5\\u4E0B\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(nlog(n))\\uFF0C\\u800C\\u6700\\u574F\\u60C5\\u51B5\\u4E0B\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(n\",(0,n.jsx)(\"sup\",{children:\"2\"}),\")\\u3002\\u5C3D\\u7BA1\\u5982\\u6B64\\uFF0C\\u5FEB\\u901F\\u6392\\u5E8F\\u901A\\u5E38\\u6BD4\\u5408\\u5E76\\u6392\\u5E8F\\u66F4\\u5FEB\\uFF0C\\u56E0\\u4E3A\\u6700\\u574F\\u6216\\u6700\\u4F73\\u60C5\\u51B5\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u7684\\u6761\\u4EF6\\u4F7F\\u5176\\u6781\\u5176\\u7F55\\u89C1\\u3002\"]}),`\n`,(0,n.jsx)(r.p,{children:\"\\u5FEB\\u901F\\u6392\\u5E8F\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u53D6\\u51B3\\u4E8E\\u6BCF\\u6B21\\u9012\\u5F52\\u8C03\\u7528\\u65F6\\u67A2\\u8F74\\u5143\\u7D20\\u7684\\u9009\\u62E9\\u3002\\u67A2\\u8F74\\u8D8A\\u63A5\\u8FD1\\u6570\\u7EC4\\u6216\\u5B50\\u6570\\u7EC4\\u7684\\u4E2D\\u4F4D\\u6570\\uFF0C\\u7B97\\u6CD5\\u5C31\\u8D8A\\u5FEB\\u3002\\u8FD9\\u662F\\u56E0\\u4E3A\\u5B83\\u4F1A\\u5F71\\u54CD\\u6BCF\\u6B21\\u9012\\u5F52\\u8C03\\u7528\\u7684\\u5206\\u533A\\u65F6\\u95F4\\uFF0C\\u6307\\u7684\\u662F\\u626B\\u63CF\\u6BCF\\u4E2A\\u5B50\\u6570\\u7EC4\\u5E76\\u5C06\\u5176\\u653E\\u7F6E\\u5728\\u8F83\\u5C0F\\u6216\\u8F83\\u5927\\u5B50\\u6570\\u7EC4\\u4E2D\\u7684\\u65F6\\u95F4\\u3002\"}),`\n`,(0,n.jsxs)(r.p,{children:[\"\\u5728\\u6700\\u574F\\u7684\\u60C5\\u51B5\\u4E0B\\uFF0C\\u5BF9\\u4E8E\\u6BCF\\u6B21\\u9012\\u5F52\\u8C03\\u7528\\uFF0C\\u6211\\u4EEC\\u6070\\u597D\\u9009\\u62E9\\u4E86\\u79BB\\u4E2D\\u4F4D\\u6570\\u6700\\u8FDC\\u7684\\u67A2\\u8F74\\u5143\\u7D20\\u2014\\u2014\\u5373\\u6570\\u7EC4\\u6216\\u5B50\\u6570\\u7EC4\\u4E2D\\u6700\\u5927\\u6216\\u6700\\u5C0F\\u7684\\u5143\\u7D20\\u3002\\u8FD9\\u610F\\u5473\\u7740\\u5206\\u533A\\u65F6\\u95F4\\u5BF9\\u4E8E\\u7B2C\\u4E00\\u6B21\\u9012\\u5F52\\u8C03\\u7528\\u662F\",(0,n.jsx)(r.em,{children:\"c(n)\"}),\"\\uFF08c\\u4E3A\\u67D0\\u4E2A\\u5E38\\u6570\\uFF09\\uFF0C\\u5BF9\\u4E8E\\u7B2C\\u4E8C\\u6B21\\u9012\\u5F52\\u8C03\\u7528\\u662F\",(0,n.jsx)(r.em,{children:\"c(n-1)\"}),\"\\uFF08\\u5728\\u9009\\u62E91\\u4E2A\\u67A2\\u8F74\\u5143\\u7D20\\u4E4B\\u540E\\uFF09\\uFF0C\\u4F9D\\u6B64\\u7C7B\\u63A8\\u3002\\u5F53\\u6211\\u4EEC\\u52A0\\u603Bn\\u6B21\\u9012\\u5F52\\u8C03\\u7528\\u7684\\u5206\\u533A\\u65F6\\u95F4\\u65F6\\uFF0C\\u5B83\\u5927\\u7EA6\\u4E3AO(n\",(0,n.jsx)(\"sup\",{children:\"2\"}),\")\\u7684\\u8FD0\\u884C\\u65F6\\u95F4\\u3002\"]}),`\n`,(0,n.jsx)(r.p,{children:\"\\u5728\\u6700\\u4F73\\u60C5\\u51B5\\u4E0B\\uFF0C\\u6BCF\\u6B21\\u9012\\u5F52\\u8C03\\u7528\\u7684\\u67A2\\u8F74\\u5143\\u7D20\\u975E\\u5E38\\u63A5\\u8FD1\\u4E2D\\u4F4D\\u6570\\uFF0C\\u56E0\\u6B64\\u5206\\u533A\\u59CB\\u7EC8\\u5C3D\\u53EF\\u80FD\\u5747\\u5300\\u5730\\u5E73\\u8861\\u3002\\u5728\\u8FD9\\u79CD\\u60C5\\u51B5\\u4E0B\\uFF0C\\u6211\\u4EEC\\u5E0C\\u671B\\u6BCF\\u6B21\\u5C06\\u6BCF\\u4E2A\\u5B50\\u6570\\u7EC4\\u5747\\u5300\\u5730\\u51CF\\u534A\\uFF0C\\u8FD9\\u610F\\u5473\\u7740\\u6211\\u4EEC\\u53EA\\u9700\\u8981*2 * (n/2)*\\u5206\\u533A\\u65F6\\u95F4\\u7528\\u4E8E\\u6BCF\\u6B21\\u9012\\u5F52\\u8C03\\u7528\\uFF08\\u5176\\u4E2Dn\\u6307\\u7684\\u662F\\u8981\\u5206\\u533A\\u7684\\u5B50\\u6570\\u7EC4\\u7684\\u5927\\u5C0F\\uFF09\\u3002\\u9274\\u4E8E\\u8FD8\\u9700\\u8981\\u8FDB\\u884Clog(n) + 1\\u6B21\\u9012\\u5F52\\u8C03\\u7528\\uFF0C\\u6211\\u4EEC\\u9884\\u8BA1\\u603B\\u5171\\u6709cn(log(n) + 1)\\u7684\\u8FD0\\u884C\\u65F6\\u95F4\\uFF0C\\u7528\\u5927O\\u8868\\u793A\\u6CD5\\u8868\\u793A\\u4E3AO(nlog(n))\\u3002\"}),`\n`,(0,n.jsx)(r.p,{children:\"\\u6B63\\u5982\\u6211\\u4EEC\\u4ECE\\u4E0A\\u9762\\u770B\\u5230\\u7684\\uFF0C\\u6700\\u4F73\\u548C\\u6700\\u574F\\u60C5\\u51B5\\u9700\\u8981\\u975E\\u5E38\\u5177\\u4F53\\u7684\\u6761\\u4EF6\\u624D\\u80FD\\u53D1\\u751F\\u3002\"}),`\n`,(0,n.jsx)(r.p,{children:\"\\u540C\\u65F6\\uFF0C\\u5E73\\u5747\\u60C5\\u51B5\\u66F4\\u6709\\u53EF\\u80FD\\u53D1\\u751F\\u5728\\u5FEB\\u901F\\u6392\\u5E8F\\u4E2D\\u3002\\u5E73\\u5747\\u60C5\\u51B5\\u6E90\\u4E8E\\u4EE5\\u4E0B\\u4E8B\\u5B9E\\uFF1A\\u4EFB\\u4F55\\u6052\\u5B9A\\u6BD4\\u4F8B\\u7684\\u5206\\u5272\\u90FD\\u4F1A\\u4EA7\\u751F\\u6DF1\\u5EA6\\u4E3AO(log(n))\\u7684\\u9012\\u5F52\\u6811\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u9012\\u5F52\\u7EA7\\u522B\\u7684\\u5206\\u533A\\u6210\\u672C\\u4E3AO(log(n))\\u3002\\u56E0\\u6B64\\uFF0C\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u5F80\\u5F80\\u4E3AO(nlog(n))\\u3002\"}),`\n`,(0,n.jsx)(r.p,{children:\"\\u4F7F\\u7528\\u4E00\\u4E2A\\u4F8B\\u5B50\\uFF0C\\u6211\\u4EEC\\u5047\\u8BBE\\u90E8\\u5206\\u4E0D\\u5E73\\u8861\\u7684\\u5206\\u5272\\u6BD4\\u4F8B\\u4E3A (9:1):\"}),`\n`,(0,n.jsxs)(r.ol,{children:[`\n`,(0,n.jsxs)(r.li,{children:[\"\\u9012\\u5F52\\u7684\\u5DE6\\u5B50\\u6811\\u5C06\\u4EE5 1/10 \\u7684\\u56E0\\u5B50\\u9012\\u51CF\\uFF0C\\u8FD9\\u4F7F\\u5F97\\u5B83\\u7684\\u6DF1\\u5EA6\\u4E3A log\",(0,n.jsx)(\"sub\",{children:\"10\"}),\"(n)\\u3002\"]}),`\n`,(0,n.jsxs)(r.li,{children:[\"\\u9012\\u5F52\\u7684\\u53F3\\u5B50\\u6811\\u5C06\\u4EE5 9/10 \\u7684\\u56E0\\u5B50\\u9012\\u51CF\\uFF0C\\u8FD9\\u4F7F\\u5F97\\u5B83\\u7684\\u6DF1\\u5EA6\\u4E3A log\",(0,n.jsx)(\"sub\",{children:\"10/9\"}),\"(n) = O(log(n))\\u3002\"]}),`\n`,(0,n.jsxs)(r.li,{children:[\"\\u5728\\u9012\\u5F52\\u7684\\u6BCF\\u4E00\\u5C42\\u8FDB\\u884C\\u5206\\u533A\\u7684\\u6210\\u672C\\u5927\\u7EA6\\u4E3A \",(0,n.jsx)(r.em,{children:\"c(n)\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(r.p,{children:\"\\u7EFC\\u4E0A\\u6240\\u8FF0\\uFF0C\\u6211\\u4EEC\\u770B\\u5230\\u6210\\u672C\\u5927\\u7EA6\\u4E3A O(nlog(n))\\u3002\"}),`\n`,(0,n.jsx)(r.h3,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\"}),`\n`,(0,n.jsx)(r.p,{children:\"\\u5728\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u65B9\\u9762\\uFF0C\\u5C3D\\u7BA1\\u5FEB\\u901F\\u6392\\u5E8F\\u662F\\u4E00\\u79CD\\u539F\\u5730\\u7B97\\u6CD5\\uFF0C\\u4F46\\u4F5C\\u4E3A\\u9012\\u5F52\\u51FD\\u6570\\uFF0C\\u5B83\\u4ECD\\u7136\\u4F7F\\u7528\\u8C03\\u7528\\u6808\\u3002\\u56E0\\u6B64\\uFF0C\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u5C06\\u53D6\\u51B3\\u4E8E\\u9012\\u5F52\\u8C03\\u7528\\u6808\\u7684\\u5927\\u5C0F\\uFF0C\\u4E5F\\u5C31\\u662F\\u9012\\u5F52\\u6811\\u7684\\u9AD8\\u5EA6\\u3002\"}),`\n`,(0,n.jsx)(r.p,{children:\"\\u5728\\u6700\\u574F\\u7684\\u60C5\\u51B5\\u4E0B\\uFF0C\\u6BCF\\u6B21\\u9012\\u5F52\\u8C03\\u7528\\u4E2D\\u67A2\\u8F74\\u7684\\u9009\\u62E9\\u90FD\\u5F88\\u7CDF\\u7CD5\\uFF0C\\u56E0\\u6B64\\u5728\\u9012\\u5F52\\u7684\\u6BCF\\u4E00\\u5C42\\u53EA\\u6709 1 \\u4E2A\\u8C03\\u7528\\u3002\\u8FD9\\u5BFC\\u81F4\\u9012\\u5F52\\u6811\\u7684\\u9AD8\\u5EA6\\u4E3A O(n)\\u3002\"}),`\n`,(0,n.jsx)(r.p,{children:\"\\u5728\\u6700\\u597D\\u7684\\u60C5\\u51B5\\u4E0B\\uFF0C\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u5F80\\u5F80\\u662F O(log(n))\\uFF0C\\u5728\\u6BCF\\u4E2A\\u9012\\u5F52\\u7EA7\\u522B\\u90FD\\u6709 2 \\u4E2A\\u9012\\u5F52\\u8C03\\u7528\\u3002\\u5F53\\u67A2\\u8F74\\u59CB\\u7EC8\\u662F\\u4E2D\\u4F4D\\u6570\\u6216\\u63A5\\u8FD1\\u4E2D\\u4F4D\\u6570\\u65F6\\uFF0C\\u5C31\\u4F1A\\u53D1\\u751F\\u8FD9\\u79CD\\u60C5\\u51B5\\uFF0C\\u8FD9\\u6837\\u9012\\u5F52\\u6811\\u662F\\u5E73\\u8861\\u7684\\u3002\"}),`\n`,(0,n.jsx)(r.p,{children:\"\\u4E3A\\u4E86\\u907F\\u514D\\u6700\\u574F\\u60C5\\u51B5\\u4E0B\\u7684\\u65F6\\u95F4\\u548C\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF0C\\u6211\\u4EEC\\u53EF\\u4EE5\\u4F7F\\u7528\\u66F4\\u597D\\u7684\\u67A2\\u8F74\\u9009\\u62E9\\u7B56\\u7565\\u3002\\u8FD9\\u79CD\\u7B56\\u7565\\u7684\\u4E00\\u4E2A\\u4F8B\\u5B50\\u662F\\u968F\\u673A\\u67A2\\u8F74\\u9009\\u62E9\\u7B56\\u7565\\u3002\\u901A\\u8FC7\\u968F\\u673A\\u9009\\u62E9\\u67A2\\u8F74\\u5143\\u7D20\\uFF0C\\u6211\\u4EEC\\u53EF\\u4EE5\\u786E\\u4FDD\\u67A2\\u8F74\\u5E76\\u4E0D\\u603B\\u662F\\u5728\\u6570\\u7EC4\\u4E2D\\u6700\\u5C0F\\u6216\\u6700\\u5927\\u7684\\u5143\\u7D20\\uFF0C\\u8FD9\\u964D\\u4F4E\\u4E86\\u6700\\u574F\\u60C5\\u51B5\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u53D1\\u751F\\u7684\\u53EF\\u80FD\\u6027\\u3002\"}),`\n`,(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:\"language-js\",children:`// \\u968F\\u673A\\u9009\\u62E9\\u4E00\\u4E2A\\u67A2\\u8F74\\u5143\\u7D20\nconst pivotIndex = Math.floor(Math.random() * arr.length);\nconst pivot = arr[pivotIndex];\n`})})]})}function q(i={}){let{wrapper:r}=i.components||{};return r?(0,n.jsx)(r,Object.assign({},i,{children:(0,n.jsx)(m,i)})):m(i)}var I=q;return S(A);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/selection-sort/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/selection-sort/locales/zh-CN.json new file mode 100644 index 000000000..eb7e52867 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/selection-sort/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var r=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var x=(t,n)=>()=>(n||t((n={exports:{}}).exports,n),n.exports),j=(t,n)=>{for(var i in n)r(t,i,{get:n[i],enumerable:!0})},l=(t,n,i,c)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let o of m(n))!g.call(t,o)&&o!==i&&r(t,o,{get:()=>n[o],enumerable:!(c=h(n,o))||c.enumerable});return t};var _=(t,n,i)=>(i=t!=null?p(u(t)):{},l(n||!t||!t.__esModule?r(i,\"default\",{value:t,enumerable:!0}):i,t)),S=t=>l(r({},\"__esModule\",{value:!0}),t);var d=x((D,s)=>{s.exports=_jsx_runtime});var q={};j(q,{default:()=>b,frontmatter:()=>f});var e=_(d()),f={title:\"\\u9009\\u62E9\\u6392\\u5E8F\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u6267\\u884C\\u9009\\u62E9\\u6392\\u5E8F\\u7684\\u51FD\\u6570\"};function a(t){let n=Object.assign({p:\"p\",img:\"img\",h2:\"h2\",pre:\"pre\",code:\"code\",ol:\"ol\",li:\"li\"},t.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.p,{children:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u6267\\u884C\\u9009\\u62E9\\u6392\\u5E8F\\u7684\\u51FD\\u6570\\u3002\\u8BE5\\u51FD\\u6570\\u5E94\\u63A5\\u6536\\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4\\uFF0C\\u5E76\\u8FD4\\u56DE\\u4E00\\u4E2A\\u6309\\u5347\\u5E8F\\u6392\\u5E8F\\u7684\\u6574\\u6570\\u6570\\u7EC4\\u3002\"}),`\n`,(0,e.jsx)(n.p,{children:(0,e.jsx)(n.img,{src:\"/img/questions/selection-sort/selection-sort-input-output.png\",alt:\"Selection Sort expected input and output\"})}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u4F8B\\u5B50\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-js\",children:`selectionSort([9, 3, 6, 2, 1, 11]); // [1, 2, 3, 6, 9, 11]\nselectionSort([12, 16, 14, 1, 2, 3]); // [1, 2, 3, 12, 14, 16]\n`})}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u56DE\\u987E\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u9009\\u62E9\\u6392\\u5E8F\\u662F\\u4E00\\u79CD\\u6392\\u5E8F\\u7B97\\u6CD5\\uFF0C\\u5B83\\u91CD\\u590D\\u626B\\u63CF\\u4E00\\u4E2A\\u672A\\u6392\\u5E8F\\u7684\\u6570\\u7EC4\\uFF0C\\u5E76\\u5728\\u6BCF\\u6B21\\u8FED\\u4EE3\\u4E2D\\u627E\\u5230\\u6700\\u5C0F\\u7684\\u5143\\u7D20\\u6765\\u6784\\u5EFA\\u4E00\\u4E2A\\u5DF2\\u6392\\u5E8F\\u7684\\u6570\\u7EC4\\u3002\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u4EE5\\u4E0B\\u662F\\u9009\\u62E9\\u6392\\u5E8F\\u80CC\\u540E\\u7684\\u57FA\\u672C\\u601D\\u60F3\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5728\\u6570\\u7EC4\\u4E2D\\u627E\\u5230\\u6700\\u5C0F\\u7684\\u5143\\u7D20\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5C06\\u5176\\u4E0E\\u7B2C\\u4E00\\u4E2A\\u4F4D\\u7F6E\\u7684\\u5143\\u7D20\\u4EA4\\u6362\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5728\\u6570\\u7EC4\\u4E2D\\u627E\\u5230\\u7B2C\\u4E8C\\u4E2A\\u6700\\u5C0F\\u7684\\u5143\\u7D20\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5C06\\u5176\\u4E0E\\u7B2C\\u4E8C\\u4E2A\\u4F4D\\u7F6E\\u7684\\u5143\\u7D20\\u4EA4\\u6362\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u91CD\\u590D\\u6B64\\u8FC7\\u7A0B\\uFF0C\\u76F4\\u5230\\u6574\\u4E2A\\u6570\\u7EC4\\u6392\\u5E8F\\u5B8C\\u6BD5\\u3002\"}),`\n`]}),`\n`,(0,e.jsx)(n.p,{children:(0,e.jsx)(n.img,{src:\"/img/questions/selection-sort/selection-sort-explanation.png\",alt:\"Selection Sort explanation\"})})]})}function M(t={}){let{wrapper:n}=t.components||{};return n?(0,e.jsx)(n,Object.assign({},t,{children:(0,e.jsx)(a,t)})):a(t)}var b=M;return S(q);})();\n;return Component;", + "info": { + "excerpt": "实现一个执行选择排序的函数", + "title": "选择排序" + }, + "solution": "var Component=(()=>{var f=Object.create;var l=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var g=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports),y=(r,n)=>{for(var i in n)l(r,i,{get:n[i],enumerable:!0})},d=(r,n,i,o)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let t of x(n))!I.call(r,t)&&t!==i&&l(r,t,{get:()=>n[t],enumerable:!(o=p(n,t))||o.enumerable});return r};var O=(r,n,i)=>(i=r!=null?f(j(r)):{},d(n||!r||!r.__esModule?l(i,\"default\",{value:r,enumerable:!0}):i,r)),b=r=>d(l({},\"__esModule\",{value:!0}),r);var c=g((C,h)=>{h.exports=_jsx_runtime});var M={};y(M,{default:()=>B});var e=O(c());var a=MDXCodeBlock;var s=`/**\n * @param {Array} arr The input integer array to be sorted.\n * @return {Array}\n */\nexport default function selectionSort(arr) {\n // Iterate through the unsorted portion of the array.\n for (let i = 0; i < arr.length; i++) {\n // Initialize index of min element to the start\n // of the unsorted section.\n let minIndex = i;\n // Find the min element.\n for (let j = i + 1; j < arr.length; j++) {\n if (arr[j] < arr[minIndex]) {\n minIndex = j;\n }\n }\n\n // Swap the found min element with the first element of the\n // unsorted section.\n [arr[i], arr[minIndex]] = [arr[minIndex], arr[i]];\n\n // By the end of each outer loop iteration,\n // [0, i] are sorted.\n }\n\n return arr;\n}\n`;var m=`export default function selectionSort(arr: Array): Array {\n // Iterate through the unsorted portion of the array.\n for (let i = 0; i < arr.length; i++) {\n // Initialize index of min element to the start\n // of the unsorted section.\n let minIndex = i;\n // Find the min element.\n for (let j = i + 1; j < arr.length; j++) {\n if (arr[j] < arr[minIndex]) {\n minIndex = j;\n }\n }\n\n // Swap the found min element with the first element of the\n // unsorted section.\n [arr[i], arr[minIndex]] = [arr[minIndex], arr[i]];\n\n // By the end of each outer loop iteration,\n // [0, i] are sorted.\n }\n\n return arr;\n}\n`;function u(r){let n=Object.assign({p:\"p\",h2:\"h2\",ul:\"ul\",li:\"li\",code:\"code\",pre:\"pre\",h3:\"h3\"},r.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.p,{children:\"\\u9009\\u62E9\\u6392\\u5E8F\\u662F\\u4E00\\u79CD\\u6392\\u5E8F\\u7B97\\u6CD5\\uFF0C\\u975E\\u5E38\\u9002\\u7528\\u4E8E\\u5C0F\\u578B\\u6570\\u7EC4\\u6216\\u5DF2\\u7ECF\\u57FA\\u672C\\u6392\\u5E8F\\u7684\\u6570\\u7EC4\\u3002\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5B83\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(n\",(0,e.jsx)(\"sup\",{children:\"2\"}),\")\\uFF0C\\u8FD9\\u610F\\u5473\\u7740\\u4E0D\\u5EFA\\u8BAE\\u4F7F\\u7528\\u5B83\\u6765\\u5BF9\\u5927\\u578B\\u6570\\u7EC4\\u8FDB\\u884C\\u6392\\u5E8F\\u3002\\u5B83\\u901A\\u5E38\\u4E0D\\u7528\\u4E8E\\u5B9E\\u8DF5\\u4E2D\\u3002\"]}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u6F84\\u6E05\\u95EE\\u9898\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5982\\u679C\\u672A\\u6307\\u5B9A\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u6570\\u636E\\u5E94\\u8BE5\\u6309\\u5347\\u5E8F\\u8FD8\\u662F\\u964D\\u5E8F\\u6392\\u5E8F\\uFF1F\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u6570\\u636E\\u5E94\\u8BE5\\u5C31\\u5730\\u6392\\u5E8F\\u8FD8\\u662F\\u53EF\\u4EE5\\u4F7F\\u7528\\u5176\\u4ED6\\u6570\\u636E\\u7ED3\\u6784\\uFF1F\"}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u6211\\u4EEC\\u9700\\u8981\\u5904\\u7406\\u4EC0\\u4E48\\u6837\\u7684\\u8F93\\u5165\\uFF1F\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5B83\\u53EA\\u662F\\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4\\uFF0C\\u8FD8\\u662F\\u6211\\u4EEC\\u5E94\\u8BE5\\u5904\\u7406\\u5176\\u4ED6\\u6570\\u636E\\u7C7B\\u578B\\uFF1F\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u662F\\u5426\\u5B58\\u5728\\u5927\\u91CF\\u91CD\\u590D\\u5143\\u7D20\\uFF1F\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5E94\\u8BE5\\u5982\\u4F55\\u5904\\u7406\\u8D1F\\u6570\\uFF1F\"}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u89E3\\u51B3\\u65B9\\u6848\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u6CE8\\u610F\\uFF1A\\u6B64\\u95EE\\u9898\\u5904\\u7406\\u7684\\u662F\\u6309\\u5347\\u5E8F\\u8F93\\u51FA\\u7684\\u6392\\u5E8F\\u3002\\u8BF7\\u53C2\\u9605\\u4E0B\\u9762\\u7684\\u201C\\u6CE8\\u91CA\\u201D\\u90E8\\u5206\\uFF0C\\u4E86\\u89E3\\u5982\\u4F55\\u5904\\u7406\\u5176\\u4ED6\\u60C5\\u51B5\\u3002\"}),`\n`,(0,e.jsx)(a,{languages:{jsx:s,tsx:m}}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u8FB9\\u7F18\\u60C5\\u51B5\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u975E\\u6574\\u6570\\u5143\\u7D20\\u8F93\\u5165\\uFF1A\\u5982\\u679C\\u8F93\\u5165\\u6570\\u7EC4\\u5305\\u542B\\u4E0D\\u540C\\u6570\\u636E\\u7C7B\\u578B\\u7684\\u5143\\u7D20\\uFF0C\\u60A8\\u53EF\\u80FD\\u9700\\u8981\\u8FD4\\u56DE\\u4E00\\u4E2A\\u9519\\u8BEF\\uFF0C\\u5C1D\\u8BD5\\u8FDB\\u884C\\u6700\\u4F73\\u6392\\u5E8F\\uFF0C\\u4F8B\\u5982\\uFF0C\\u4EC5\\u5BF9\\u8F93\\u5165\\u6570\\u636E\\u7684\\u5B50\\u96C6\\u8FDB\\u884C\\u6392\\u5E8F\\uFF0C\\u751A\\u81F3\\u4E3A\\u975E\\u6574\\u6570\\u5B9A\\u4E49\\u81EA\\u5B9A\\u4E49\\u6BD4\\u8F83\\u51FD\\u6570\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5355\\u4E2A\\u5143\\u7D20/\\u7A7A\\u8F93\\u5165\\uFF1A\\u8FD4\\u56DE\\u539F\\u59CB\\u6570\\u636E\\u7ED3\\u6784\\u3001\\u5F15\\u53D1\\u9519\\u8BEF\\u6216\\u6F84\\u6E05\\u6240\\u9700\\u5904\\u7406\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5DF2\\u7ECF\\u6392\\u5E8F\\u7684\\u8F93\\u5165\\uFF1A\\u60A8\\u53EF\\u80FD\\u9700\\u8981\\u68C0\\u6D4B\\u6392\\u5E8F\\u5E76\\u539F\\u6837\\u8FD4\\u56DE\\u8F93\\u5165\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u91CD\\u590D\\u5143\\u7D20\\uFF1A\\u7279\\u522B\\u662F\\u5982\\u679C\\u6570\\u7EC4\\u6709\\u5927\\u91CF\\u91CD\\u590D\\u5143\\u7D20\\uFF0C\\u60A8\\u53EF\\u80FD\\u9700\\u8981\\u8FDB\\u4E00\\u6B65\\u4F18\\u5316\\u60A8\\u7684\\u5B9E\\u73B0\\u4EE5\\u907F\\u514D\\u4E0D\\u5FC5\\u8981\\u7684\\u6BD4\\u8F83\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u65E0\\u6548\\u8F93\\u5165\\uFF1A\\u5982\\u679C\\u8F93\\u5165\\u4E0D\\u662F\\u6570\\u7EC4\\uFF0C\\u8BF7\\u8003\\u8651\\u629B\\u51FA\\u9519\\u8BEF\\u3002\"}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u7B14\\u8BB0\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5982\\u679C\\u8981\\u6C42\\u6309\\u964D\\u5E8F\\u6392\\u5E8F\\uFF0C\\u8BF7\\u66F4\\u6539\\u6BD4\\u8F83\\u4EE5\\u627E\\u5230 \",(0,e.jsx)(n.code,{children:\"maxIndex\"}),\" \\u800C\\u4E0D\\u662F \",(0,e.jsx)(n.code,{children:\"minIndex\"}),\"\\uFF0C\\u65B9\\u6CD5\\u662F\\u5728\\u76F8\\u5173\\u6BD4\\u8F83\\u4E2D\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\">=\"}),\" \\u800C\\u4E0D\\u662F \",(0,e.jsx)(n.code,{children:\"<\"}),\"\\uFF0C\\u5982\\u4E0B\\u6240\\u793A\\uFF1A\"]}),`\n`]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-js\",children:`if (arr[j] >= arr[maxIndex]) {\n maxIndex = j;\n}\n`})}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5982\\u679C\\u8981\\u6C42\\u4F7F\\u7528\\u5176\\u4ED6\\u6570\\u636E\\u7ED3\\u6784\\u6216\\u7F16\\u5199\\u7EAF\\u51FD\\u6570\\u800C\\u4E0D\\u662F\\u5C31\\u5730\\u6392\\u5E8F\\u6570\\u636E\\uFF0C\\u8BF7\\u4F7F\\u7528\\u6269\\u5C55\\u8FD0\\u7B97\\u7B26\\u5728\\u5E94\\u7528\\u6392\\u5E8F\\u4E4B\\u524D\\u521B\\u5EFA\\u4E00\\u4E2A\\u65B0\\u6570\\u7EC4\\u3002\"}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u8BA9\\u6211\\u4EEC\\u5206\\u6790\\u4E00\\u4E0B\\u7B97\\u6CD5\\u7684\\u65F6\\u95F4\\u548C\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u9009\\u62E9\\u6392\\u5E8F\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(n\",(0,e.jsx)(\"sup\",{children:\"2\"}),\") - \\u5728\\u6240\\u6709\\u60C5\\u51B5\\u4E0B\\u90FD\\u76F8\\u540C\\u3002\\u8FD9\\u53EF\\u4EE5\\u901A\\u8FC7\\u89C2\\u5BDF\\u5FAA\\u73AF\\u6B21\\u6570\\u6765\\u63A8\\u5BFC\\u3002\\u6709 2 \\u4E2A\\u5FAA\\u73AF\\uFF0C\\u56E0\\u6B64\\u590D\\u6742\\u5EA6\\u4E3A O(n\",(0,e.jsx)(\"sup\",{children:\"2\"}),\")\\u3002\"]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u9009\\u62E9\\u6392\\u5E8F\\u7684\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(1)\\uFF0C\\u5F53\\u5B83\\u5728\\u539F\\u4F4D\\u6267\\u884C\\u65F6\\uFF0C\\u56E0\\u4E3A\\u5B83\\u53EA\\u9700\\u8981\\u5E38\\u91CF\\u5927\\u5C0F\\u7684\\u989D\\u5916\\u7A7A\\u95F4\\u6765\\u5B58\\u50A8\\u53D8\\u91CF\\u3002\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u4F46\\u662F\\uFF0C\\u5982\\u679C\\u6392\\u5E8F\\u7B97\\u6CD5\\u4E0D\\u662F\\u5728\\u539F\\u4F4D\\u6267\\u884C\\u7684\\uFF0C\\u90A3\\u4E48\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u5C06\\u662F O(n)\\uFF0C\\u56E0\\u4E3A\\u9700\\u8981\\u989D\\u5916\\u7684\\u5185\\u5B58\\u6765\\u5B58\\u50A8\\u5DF2\\u6392\\u5E8F\\u7684\\u5143\\u7D20\\u3002\"})]})}function w(r={}){let{wrapper:n}=r.components||{};return n?(0,e.jsx)(n,Object.assign({},r,{children:(0,e.jsx)(u,r)})):u(r)}var B=w;return b(M);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/stack/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/stack/locales/zh-CN.json new file mode 100644 index 000000000..27d1fca86 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/stack/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var h=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var k=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var x=(c,n)=>()=>(n||c((n={exports:{}}).exports,n),n.exports),g=(c,n)=>{for(var t in n)i(c,t,{get:n[t],enumerable:!0})},l=(c,n,t,s)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let r of u(n))!m.call(c,r)&&r!==t&&i(c,r,{get:()=>n[r],enumerable:!(s=p(n,r))||s.enumerable});return c};var j=(c,n,t)=>(t=c!=null?h(k(c)):{},l(n||!c||!c.__esModule?i(t,\"default\",{value:c,enumerable:!0}):t,c)),O=c=>l(i({},\"__esModule\",{value:!0}),c);var a=x((E,d)=>{d.exports=_jsx_runtime});var S={};g(S,{default:()=>y,frontmatter:()=>_});var e=j(a()),_={title:\"\\u6808\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u5305\\u542B\\u5E38\\u89C1\\u6808\\u65B9\\u6CD5\\u7684\\u6808\\u6570\\u636E\\u7ED3\\u6784\"};function o(c){let n=Object.assign({p:\"p\",ul:\"ul\",li:\"li\",code:\"code\",h2:\"h2\",pre:\"pre\"},c.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.p,{children:\"\\u7528 JavaScript \\u5B9E\\u73B0\\u4E00\\u4E2A\\u6808\\u6570\\u636E\\u7ED3\\u6784\\uFF0C\\u5B83\\u5305\\u542B\\u4EE5\\u4E0B\\u64CD\\u4F5C\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"new Stack()\"}),\"\\uFF1A\\u521B\\u5EFA\\u4E00\\u4E2A\\u4E0D\\u5305\\u542B\\u4EFB\\u4F55\\u9879\\u76EE\\u7684 \",(0,e.jsx)(n.code,{children:\"Stack\"}),\" \\u7C7B\\u7684\\u5B9E\\u4F8B\\u3002\\u6784\\u9020\\u51FD\\u6570\\u4E0D\\u63A5\\u53D7\\u4EFB\\u4F55\\u53C2\\u6570\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"push()\"}),\"\\uFF1A\\u5C06\\u4E00\\u4E2A\\u9879\\u76EE\\u63A8\\u5230\\u6808\\u7684\\u9876\\u90E8\\uFF0C\\u5E76\\u8FD4\\u56DE\\u6808\\u7684\\u65B0\\u957F\\u5EA6\\u3002\\u6240\\u9700\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"pop()\"}),\"\\uFF1A\\u79FB\\u9664\\u6808\\u9876\\u7684\\u4E00\\u4E2A\\u9879\\u76EE\\u5E76\\u8FD4\\u56DE\\u8BE5\\u9879\\u76EE\\u3002\\u6240\\u9700\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"isEmpty()\"}),\"\\uFF1A\\u786E\\u5B9A\\u6808\\u662F\\u5426\\u4E3A\\u7A7A\\u3002\\u6240\\u9700\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"peek()\"}),\"\\uFF1A\\u8FD4\\u56DE\\u6808\\u9876\\u7684\\u9879\\u76EE\\uFF0C\\u800C\\u4E0D\\u5C06\\u5176\\u4ECE\\u6808\\u4E2D\\u79FB\\u9664\\u3002\\u6240\\u9700\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"length()\"}),\"\\uFF1A\\u8FD4\\u56DE\\u6808\\u4E2D\\u9879\\u76EE\\u7684\\u6570\\u91CF\\u3002\\u6240\\u9700\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u4F8B\\u5B50\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-js\",children:`const stack = new Stack();\nstack.isEmpty(); // true\nstack.push(1);\nstack.push(2);\nstack.length(); // 2\nstack.push(3);\nstack.peek(); // 3\nstack.pop(); // 3\nstack.isEmpty(); // false\n`})})]})}function f(c={}){let{wrapper:n}=c.components||{};return n?(0,e.jsx)(n,Object.assign({},c,{children:(0,e.jsx)(o,c)})):o(c)}var y=f;return O(S);})();\n;return Component;", + "info": { + "excerpt": "实现一个包含常见栈方法的栈数据结构", + "title": "栈" + }, + "solution": "var Component=(()=>{var f=Object.create;var r=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var y=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),b=(n,e)=>{for(var i in e)r(n,i,{get:e[i],enumerable:!0})},c=(n,e,i,s)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let h of _(e))!v.call(n,h)&&h!==i&&r(n,h,{get:()=>e[h],enumerable:!(s=k(e,h))||s.enumerable});return n};var T=(n,e,i)=>(i=n!=null?f(g(n)):{},c(e||!n||!n.__esModule?r(i,\"default\",{value:n,enumerable:!0}):i,n)),x=n=>c(r({},\"__esModule\",{value:!0}),n);var a=y((O,d)=>{d.exports=_jsx_runtime});var E={};b(E,{default:()=>D});var t=T(a());var o=MDXCodeBlock;var u=`export default class Stack {\n constructor() {\n this._items = [];\n }\n\n /**\n * Pushes an item onto the top of the stack.\n * @param {*} item The item to be pushed onto the stack.\n * @return {number} The new length of the stack.\n */\n push(item) {\n return this._items.push(item);\n }\n\n /**\n * Remove an item at the top of the stack.\n * @return {*} The item at the top of the stack if it is not empty, \\`undefined\\` otherwise.\n */\n pop() {\n return this._items.pop();\n }\n\n /**\n * Determines if the stack is empty.\n * @return {boolean} \\`true\\` if the stack has no items, \\`false\\` otherwise.\n */\n isEmpty() {\n return this.length() === 0;\n }\n\n /**\n * Returns the item at the top of the stack without removing it from the stack.\n * @return {*} The item at the top of the stack if it is not empty, \\`undefined\\` otherwise.\n */\n peek() {\n return this.isEmpty() ? undefined : this._items[this.length() - 1];\n }\n\n /**\n * Returns the number of items in the stack.\n * @return {number} The number of items in the stack.\n */\n length() {\n return this._items.length;\n }\n}\n`;var l=`export default class Stack {\n _items: Array;\n\n constructor() {\n this._items = [];\n }\n\n /**\n * Pushes an item onto the top of the stack.\n */\n push(item: T): number {\n return this._items.push(item);\n }\n\n /**\n * Remove an item at the top of the stack.\n */\n pop(): T | undefined {\n return this._items.pop();\n }\n\n /**\n * Determines if the stack is empty.\n */\n isEmpty(): boolean {\n return this.length() === 0;\n }\n\n /**\n * Returns the item at the top of the stack without removing it from the stack.\n */\n peek(): T | undefined {\n return this.isEmpty() ? undefined : this._items[this.length() - 1];\n }\n\n /**\n * Returns the number of items in the stack.\n */\n length(): number {\n return this._items.length;\n }\n}\n`;var m=`class Node {\n constructor(value) {\n this.value = value;\n this.prev = null;\n }\n}\n\nexport default class Stack {\n constructor() {\n this._top = null;\n this._length = 0;\n }\n\n /**\n * Pushes an item onto the top of the stack.\n * @param {*} item The item to be pushed onto the stack.\n * @return {number} The new length of the stack.\n */\n push(item) {\n const node = new Node(item);\n node.prev = this._top;\n this._top = node;\n this._length++;\n return this._length;\n }\n\n /**\n * Remove an item at the top of the stack.\n * @return {*} The item at the top of the stack if it is not empty, \\`undefined\\` otherwise.\n */\n pop() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n const node = this._top;\n this._top = node.prev;\n node.prev = null;\n this._length--;\n return node.value;\n }\n\n /**\n * Determines if the stack is empty.\n * @return {boolean} \\`true\\` if the stack has no items, \\`false\\` otherwise.\n */\n isEmpty() {\n return this._length === 0;\n }\n\n /**\n * Returns the item at the top of the stack without removing it from the stack.\n * @return {*} The item at the top of the stack if it is not empty, \\`undefined\\` otherwise.\n */\n peek() {\n return this.isEmpty() ? undefined : this._top.value;\n }\n\n /**\n * Returns the number of items in the stack.\n * @return {number} The number of items in the stack.\n */\n length() {\n return this._length;\n }\n}\n`;function p(n){let e=Object.assign({h2:\"h2\",h3:\"h3\",p:\"p\",code:\"code\",ul:\"ul\",li:\"li\"},n.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(e.h2,{children:\"\\u89E3\\u51B3\\u65B9\\u6848\"}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u57FA\\u4E8E\\u6570\\u7EC4\\u7684\\u89E3\\u51B3\\u65B9\\u6848\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"\\u6808\\u62BD\\u8C61\\u6570\\u636E\\u7C7B\\u578B\\u53EF\\u4EE5\\u7528 JavaScript \",(0,t.jsx)(e.code,{children:\"Array\"}),\" \\u8F7B\\u677E\\u5730\\u5728 JavaScript \\u4E2D\\u5B9E\\u73B0\\u3002\\u5728\\u5B9E\\u73B0\\u6808\\u65F6\\u9700\\u8981\\u6CE8\\u610F\\u7684\\u4E3B\\u8981\\u4E8B\\u9879\\u662F\\uFF0C\\u8FD9\\u4E9B\\u64CD\\u4F5C\\u5E94\\u8BE5\\u662F O(1)\\u3002\\u503C\\u5F97\\u5E86\\u5E78\\u7684\\u662F\\uFF0CJavaScript \",(0,t.jsx)(e.code,{children:\"Array\"}),\" \\u7684 \",(0,t.jsx)(e.code,{children:\"push()\"}),\" \\u548C \",(0,t.jsx)(e.code,{children:\"pop()\"}),\" \\u64CD\\u4F5C\\u662F O(1)\\uFF0C\\u5E76\\u4E14\\u65B9\\u6CD5\\u7B7E\\u540D\\u4E0E \",(0,t.jsx)(e.code,{children:\"Stack\"}),\" \\u7684\\u5339\\u914D\\u3002\\u8BB8\\u591A\\u65B9\\u6CD5\\u53EA\\u662F\\u56F4\\u7ED5 \",(0,t.jsx)(e.code,{children:\"Array\"}),\" \\u65B9\\u6CD5\\u7684\\u7B80\\u5355\\u5305\\u88C5\\u5668\\u3002\"]}),`\n`,(0,t.jsx)(o,{languages:{jsx:u,tsx:l}}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u57FA\\u4E8E\\u94FE\\u8868\\u7684\\u89E3\\u51B3\\u65B9\\u6848\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"\\u6808\\u4E5F\\u53EF\\u4EE5\\u7528\\u5355\\u94FE\\u8868\\u6765\\u5B9E\\u73B0\\uFF0C\\u5355\\u94FE\\u8868\\u672C\\u8D28\\u4E0A\\u662F\\u4E00\\u7CFB\\u5217\\u8FDE\\u63A5\\u7684\\u8282\\u70B9\\u3002\\u4E3A\\u6B64\\uFF0C\\u6211\\u4EEC\\u9700\\u8981\\u521B\\u5EFA\\u4E00\\u4E2A \",(0,t.jsx)(e.code,{children:\"Node\"}),\" \\u7C7B\\uFF0C\\u8BE5\\u7C7B\\u5177\\u6709\\u4E00\\u4E2A \",(0,t.jsx)(e.code,{children:\"prev\"}),\" \\u6307\\u9488\\uFF0C\\u5982\\u679C\\u5B83\\u4E0D\\u662F\\u6808\\u7684\\u5E95\\u90E8\\u9879\\uFF0C\\u5219\\u5F15\\u7528\\u4E0B\\u9762\\u7684 \",(0,t.jsx)(e.code,{children:\"Node\"}),\"\\u3002\"]}),`\n`,(0,t.jsxs)(e.p,{children:[(0,t.jsx)(e.code,{children:\"push()\"}),\" \\u6D89\\u53CA\\u521B\\u5EFA\\u4E00\\u4E2A\\u65B0\\u7684 \",(0,t.jsx)(e.code,{children:\"Node\"}),\"\\uFF0C\\u5E76\\u5C06\\u6808\\u7684\\u5F53\\u524D\\u9876\\u90E8\\u6307\\u5411\\u8BE5\\u65B0 \",(0,t.jsx)(e.code,{children:\"Node\"}),\" \\u7684 \",(0,t.jsx)(e.code,{children:\"prev\"}),\" \\u5B57\\u6BB5\\uFF0C\\u5E76\\u66F4\\u65B0\\u5BF9\\u6808\\u7684\\u65B0\\u9876\\u90E8\\u7684\\u5F15\\u7528\\u3002\",(0,t.jsx)(e.code,{children:\"pop()\"}),\" \\u4E0E\\u4E4B\\u76F8\\u53CD\\uFF0C\\u6211\\u4EEC\\u5728\\u5176\\u4E2D\\u627E\\u5230\\u5F53\\u524D\\u9876\\u90E8\\u7684 \",(0,t.jsx)(e.code,{children:\"prev\"}),\" \\u8282\\u70B9\\uFF0C\\u5E76\\u5C06\\u5176\\u8BBE\\u7F6E\\u4E3A\\u6808\\u7684\\u65B0\\u9876\\u90E8\\u3002\"]}),`\n`,(0,t.jsxs)(e.p,{children:[\"\\u7531\\u4E8E \",(0,t.jsx)(e.code,{children:\"length()\"}),\" \\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u5FC5\\u987B\\u4E3A O(1)\\uFF0C\\u5E76\\u4E14\\u8BA1\\u7B97\\u94FE\\u8868\\u4E2D\\u9879\\u76EE\\u7684\\u6570\\u91CF\\u5C06\\u9700\\u8981 O(n)\\uFF0C\\u56E0\\u6B64\\u6211\\u4EEC\\u9700\\u8981\\u4F7F\\u7528 \",(0,t.jsx)(e.code,{children:\"_length\"}),\" \\u5B9E\\u4F8B\\u5C5E\\u6027\\u5355\\u72EC\\u8DDF\\u8E2A\\u5217\\u8868\\u4E2D\\u9879\\u76EE\\u7684\\u6570\\u91CF\\uFF0C\\u5E76\\u5728 \",(0,t.jsx)(e.code,{children:\"push()\"}),\" \\u548C \",(0,t.jsx)(e.code,{children:\"pop()\"}),\" \\u65B9\\u6CD5\\u4E2D\\u66F4\\u65B0\\u5B83\\u3002\"]}),`\n`,(0,t.jsx)(o,{children:m}),`\n`,(0,t.jsx)(e.h2,{children:\"\\u8FB9\\u7F18\\u60C5\\u51B5\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[\"\\u5728\\u7A7A\\u6808\\u4E0A\\u8C03\\u7528 \",(0,t.jsx)(e.code,{children:\"pop()\"}),\"\\u3002\"]}),`\n`,(0,t.jsxs)(e.li,{children:[\"\\u5728\\u7A7A\\u6808\\u4E0A\\u8C03\\u7528 \",(0,t.jsx)(e.code,{children:\"peek()\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,t.jsx)(e.h2,{children:\"\\u6280\\u672F\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsx)(e.li,{children:\"\\u719F\\u6089 JavaScript \\u6570\\u7EC4\\u3002\"}),`\n`,(0,t.jsx)(e.li,{children:\"\\u9762\\u5411\\u5BF9\\u8C61\\u7F16\\u7A0B\\u3002\"}),`\n`]})]})}function j(n={}){let{wrapper:e}=n.components||{};return e?(0,t.jsx)(e,Object.assign({},n,{children:(0,t.jsx)(p,n)})):p(n)}var D=j;return x(E);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/staircase-climbing-combinations/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/staircase-climbing-combinations/locales/zh-CN.json new file mode 100644 index 000000000..4bd40d294 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/staircase-climbing-combinations/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var d=Object.create;var o=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var _=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),w=(t,e)=>{for(var s in e)o(t,s,{get:e[s],enumerable:!0})},p=(t,e,s,i)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of x(e))!j.call(t,r)&&r!==s&&o(t,r,{get:()=>e[r],enumerable:!(i=m(e,r))||i.enumerable});return t};var T=(t,e,s)=>(s=t!=null?d(f(t)):{},p(e||!t||!t.__esModule?o(s,\"default\",{value:t,enumerable:!0}):s,t)),y=t=>p(o({},\"__esModule\",{value:!0}),t);var c=_((k,a)=>{a.exports=_jsx_runtime});var X={};w(X,{default:()=>D,frontmatter:()=>g});var n=T(c());var l=MDXTestExamples;var h=[{input:[[\"steps\",1]],output:1,explanation:\"There is only one way i.e take 1-step\"},{input:[[\"steps\",2]],output:2,explanation:\"There are two ways, either take two 1-step or take one 2-step\"},{input:[[\"steps\",3]],output:3,explanation:\"There are three ways: 1-step three times, 1-step then 2-step, 2-step then 1-step\"}];var g={title:\"\\u722C\\u697C\\u68AF\\u7EC4\\u5408\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u627E\\u5230\\u5230\\u8FBE\\u697C\\u68AF\\u9876\\u90E8\\u7684\\u4E0D\\u540C\\u65B9\\u5F0F\\u7684\\u6570\\u91CF\"};function u(t){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u957F\\u5EA6\\u4E3A \",(0,n.jsx)(e.code,{children:\"steps\"}),\" \\u7684\\u697C\\u68AF\\uFF0C\\u60A8\\u6BCF\\u6B21\\u53EF\\u4EE5\\u8D70 1 \\u6B65\\u6216 2 \\u6B65\\uFF0C\\u627E\\u5230\\u4ECE\\u697C\\u68AF\\u5E95\\u90E8\\u5230\\u8FBE\\u697C\\u68AF\\u9876\\u90E8\\u7684\\u4E0D\\u540C\\u7EC4\\u5408\\u7684\\u6570\\u91CF\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"steps: number\"}),\": \\u4E00\\u4E2A\\u6574\\u6570\"]}),`\n`]}),`\n`,(0,n.jsx)(l,{testCases:h}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"steps\"}),\" <= 45\"]}),`\n`]})]})}function C(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(u,t)})):u(t)}var D=C;return y(X);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,找到到达楼梯顶部的不同方式的数量", + "title": "爬楼梯组合" + }, + "solution": "var Component=(()=>{var u=Object.create;var l=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var y=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),C=(i,e)=>{for(var r in e)l(i,r,{get:e[r],enumerable:!0})},o=(i,e,r,t)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let c of f(e))!g.call(i,c)&&c!==r&&l(i,c,{get:()=>e[c],enumerable:!(t=b(e,c))||t.enumerable});return i};var w=(i,e,r)=>(r=i!=null?u(S(i)):{},o(e||!i||!i.__esModule?l(r,\"default\",{value:i,enumerable:!0}):r,i)),x=i=>o(l({},\"__esModule\",{value:!0}),i);var s=y((M,h)=>{h.exports=_jsx_runtime});var B={};C(B,{default:()=>_});var n=w(s());var d=MDXCodeBlock;var p=`export default function staircaseClimbingCombinations(steps: number): number {\n // Create an array 'dp' of size n+1 initialized with -1\n // This array will store the number of distinct ways to reach each step\n const dp: number[] = new Array(steps + 1).fill(-1);\n\n // Base cases\n // There is 1 way to reach step 0 (do nothing)\n dp[0] = 1;\n // There is 1 way to reach step 1 (a single step)\n dp[1] = 1;\n\n // Fill the dp array using the recurrence relation\n // dp[i] = dp[i-1] + dp[i-2]\n // This relation comes from the fact that you can reach step i either from step i-1 or step i-2\n for (let i = 2; i <= steps; i++) {\n dp[i] = dp[i - 1] + dp[i - 2];\n }\n\n // The value at dp[n] will be the number of distinct ways to reach the top of the staircase\n return dp[steps];\n}\n`;var a=`export default function staircaseClimbingCombinations(steps: number): number {\n return climbFromStep(0, steps);\n}\n\n// Helper function using recursion to find the number of ways from step i to n\nfunction climbFromStep(currentStep: number, totalSteps: number): number {\n // If current step exceeds total steps, no valid way\n if (currentStep > totalSteps) {\n return 0;\n }\n // If current step equals total steps, one valid way found\n if (currentStep === totalSteps) {\n return 1;\n }\n // Sum of ways by taking 1 step or 2 steps\n return (\n climbFromStep(currentStep + 1, totalSteps) +\n climbFromStep(currentStep + 2, totalSteps)\n );\n}\n`;function m(i){let e=Object.assign({h2:\"h2\",p:\"p\",ol:\"ol\",li:\"li\",h3:\"h3\",code:\"code\",ul:\"ul\",strong:\"strong\"},i.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u66B4\\u529B\\u89E3\\u6CD5\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u9012\\u5F52\\u8BA1\\u7B97\\u722C\\u697C\\u68AF\\u7684\\u4E0D\\u540C\\u65B9\\u5F0F\\u7684\\u6570\\u91CF\\uFF0C\\u7ED9\\u5B9A\\u697C\\u68AF\\u7684\\u6B65\\u6570\\u3002\\u5728\\u6BCF\\u4E00\\u6B65\\uFF0C\\u722C\\u697C\\u68AF\\u7684\\u4EBA\\u53EF\\u4EE5\\u9009\\u62E9\\u8D70 1 \\u6B65\\u6216 2 \\u6B65\\u3002\\u901A\\u8FC7\\u9012\\u5F52\\u8BA1\\u7B97\\u4ECE\\u5F53\\u524D\\u6B65\\u6570\\u5230\\u8FBE\\u9876\\u90E8\\u7684\\u603B\\u65B9\\u5F0F\\u6570\\u6765\\u89E3\\u51B3\\u8BE5\\u95EE\\u9898\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BE5\\u7B97\\u6CD5\\u4F7F\\u7528\\u4E00\\u4E2A\\u8F85\\u52A9\\u51FD\\u6570\\u6765\\u63A2\\u7D22\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u6B65\\u6570\\u7EC4\\u5408\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u5F53\\u524D\\u6B65\\u6570\\u8D85\\u8FC7\\u603B\\u6B65\\u6570\\uFF0C\\u5219\\u8DEF\\u5F84\\u65E0\\u6548\\uFF0C\\u56E0\\u6B64\\u8FD4\\u56DE 0\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u5F53\\u524D\\u6B65\\u6570\\u7B49\\u4E8E\\u603B\\u6B65\\u6570\\uFF0C\\u5219\\u8868\\u793A\\u6709\\u6548\\u8DEF\\u5F84\\uFF0C\\u56E0\\u6B64\\u8FD4\\u56DE 1\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5BF9\\u4E8E\\u6240\\u6709\\u5176\\u4ED6\\u60C5\\u51B5\\uFF0C\\u5B83\\u901A\\u8FC7\\u4ECE\\u5F53\\u524D\\u6B65\\u6570\\u8D70 1 \\u6B65\\u6216 2 \\u6B65\\u6765\\u9012\\u5F52\\u8BA1\\u7B97\\u5230\\u8FBE\\u9876\\u90E8\\u7684\\u603B\\u65B9\\u5F0F\\u6570\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8FD9\\u79CD\\u66B4\\u529B\\u65B9\\u6CD5\\u63A2\\u7D22\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u8DEF\\u5F84\\u4EE5\\u627E\\u5230\\u7EC4\\u5408\\u7684\\u603B\\u6570\\u3002\\u4F46\\u662F\\uFF0C\\u5B83\\u4F1A\\u8FDB\\u884C\\u5197\\u4F59\\u8BA1\\u7B97\\uFF0C\\u56E0\\u4E3A\\u591A\\u6B21\\u89E3\\u51B3\\u76F8\\u540C\\u7684\\u5B50\\u95EE\\u9898\\uFF0C\\u8FD9\\u4F1A\\u589E\\u52A0\\u5176\\u8BA1\\u7B97\\u6210\\u672C\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u51FD\\u6570 \",(0,n.jsx)(e.code,{children:\"staircaseClimbingCombinations\"}),\"\\uFF0C\\u8BE5\\u51FD\\u6570\\u4ECE\\u7B2C \",(0,n.jsx)(e.code,{children:\"0\"}),\" \\u6B65\\u5F00\\u59CB\\u8C03\\u7528\\u8F85\\u52A9\\u51FD\\u6570 \",(0,n.jsx)(e.code,{children:\"climbFromStep\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8F85\\u52A9\\u51FD\\u6570 \",(0,n.jsx)(e.code,{children:\"climbFromStep\"}),\" \\u5C06\\u5F53\\u524D\\u6B65\\u6570\\u548C\\u603B\\u6B65\\u6570\\u4F5C\\u4E3A\\u8F93\\u5165\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5F53\\u524D\\u6B65\\u6570\\u8D85\\u8FC7\\u603B\\u6B65\\u6570\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\uFF0C\\u56E0\\u4E3A\\u5B83\\u65E0\\u6548\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5F53\\u524D\\u6B65\\u6570\\u7B49\\u4E8E\\u603B\\u6B65\\u6570\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"1\"}),\"\\uFF0C\\u56E0\\u4E3A\\u5B83\\u8868\\u793A\\u6709\\u6548\\u8DEF\\u5F84\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u6C42\\u548C\\u9012\\u5F52\\u8BA1\\u7B97\\u603B\\u65B9\\u5F0F\\u6570\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8D70 1 \\u6B65\\u7684\\u7ED3\\u679C (\",(0,n.jsx)(e.code,{children:\"climbFromStep(currentStep + 1, totalSteps)\"}),\")\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8D70 2 \\u6B65\\u7684\\u7ED3\\u679C (\",(0,n.jsx)(e.code,{children:\"climbFromStep(currentStep + 2, totalSteps)\"}),\")\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8FD4\\u56DE\\u8F85\\u52A9\\u51FD\\u6570\\u7684\\u7ED3\\u679C\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(d,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(2\",(0,n.jsx)(\"sup\",{children:\"n\"}),\")\"]}),\"\\u3002\\u6BCF\\u4E00\\u6B65\\u90FD\\u5206\\u652F\\u4E3A\\u4E24\\u4E2A\\u9012\\u5F52\\u8C03\\u7528\\uFF0C\\u5BFC\\u81F4\\u6307\\u6570\\u7EA7\\u7684\\u51FD\\u6570\\u8C03\\u7528\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u9012\\u5F52\\u5806\\u6808\\u6700\\u591A\\u53EF\\u4EE5\\u589E\\u957F\\u5230 \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u7684\\u6DF1\\u5EA6\\uFF0C\\u5176\\u4E2D \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u662F\\u603B\\u6B65\\u6570\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u52A8\\u6001\\u89C4\\u5212\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u52A8\\u6001\\u89C4\\u5212 (DP) \\u8BA1\\u7B97\\u722C\\u697C\\u68AF\\u7684\\u4E0D\\u540C\\u65B9\\u5F0F\\u7684\\u6570\\u91CF\\uFF0C\\u7ED9\\u5B9A\\u697C\\u68AF\\u7684\\u6B65\\u6570\\u3002\\u901A\\u8FC7\\u5C06\\u5176\\u5206\\u89E3\\u4E3A\\u8F83\\u5C0F\\u7684\\u5B50\\u95EE\\u9898\\u5E76\\u5C06\\u8FD9\\u4E9B\\u5B50\\u95EE\\u9898\\u7684\\u7ED3\\u679C\\u5B58\\u50A8\\u5728 \",(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u6570\\u7EC4\\u4E2D\\u4EE5\\u907F\\u514D\\u5197\\u4F59\\u8BA1\\u7B97\\u6765\\u89E3\\u51B3\\u8BE5\\u95EE\\u9898\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u76F4\\u89C9\\u662F\\uFF0C\\u8981\\u5230\\u8FBE\\u7B2C \",(0,n.jsx)(e.code,{children:\"i\"}),\" \\u6B65\\uFF0C\\u6709\\u4E24\\u79CD\\u53EF\\u80FD\\u7684\\u65B9\\u5F0F\\uFF1A\"]}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u7B2C \",(0,n.jsx)(e.code,{children:\"i-1\"}),\" \\u6B65\\u8D70\\u4E00\\u6B65\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u7B2C \",(0,n.jsx)(e.code,{children:\"i-2\"}),\" \\u6B65\\u8D70\\u4E24\\u6B65\\u3002\"]}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8FD9\\u79CD\\u5173\\u7CFB\\u5BFC\\u81F4\\u4E86\\u9012\\u5F52\\u516C\\u5F0F\\uFF1A\",(0,n.jsx)(e.code,{children:\"dp[i] = dp[i-1] + dp[i-2]\"}),\"\\u3002\\u4F7F\\u7528\\u6B64\\u516C\\u5F0F\\uFF0C\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u8FED\\u4EE3\\u5730\\u6784\\u5EFA \",(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u6570\\u7EC4\\uFF0C\\u4ECE\\u57FA\\u672C\\u60C5\\u51B5\\u5F00\\u59CB\\uFF1A\"]}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u505C\\u7559\\u5728\\u7B2C \",(0,n.jsx)(e.code,{children:\"0\"}),\" \\u6B65\\u53EA\\u6709 1 \\u79CD\\u65B9\\u5F0F\\uFF08\\u4EC0\\u4E48\\u90FD\\u4E0D\\u505A\\uFF09\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5230\\u8FBE\\u7B2C \",(0,n.jsx)(e.code,{children:\"1\"}),\" \\u6B65\\u53EA\\u6709 1 \\u79CD\\u65B9\\u5F0F\\uFF08\\u4E00\\u6B65\\uFF09\\u3002\"]}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:\"dp[steps]\"}),\" \\u4E2D\\u7684\\u6700\\u7EC8\\u503C\\u7ED9\\u51FA\\u4E86\\u5230\\u8FBE\\u697C\\u68AF\\u9876\\u90E8\\u7684\\u603B\\u65B9\\u5F0F\\u6570\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521B\\u5EFA\\u4E00\\u4E2A\\u5927\\u5C0F\\u4E3A \",(0,n.jsx)(e.code,{children:\"steps + 1\"}),\" \\u7684 \",(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u6570\\u7EC4\\uFF0C\\u521D\\u59CB\\u5316\\u4E3A \",(0,n.jsx)(e.code,{children:\"-1\"}),\"\\uFF0C\\u7528\\u4E8E\\u5B58\\u50A8\\u5230\\u8FBE\\u6BCF\\u4E00\\u6B65\\u7684\\u65B9\\u5F0F\\u6570\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u57FA\\u672C\\u60C5\\u51B5\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8BBE\\u7F6E \",(0,n.jsx)(e.code,{children:\"dp[0] = 1\"}),\"\\uFF0C\\u56E0\\u4E3A\\u505C\\u7559\\u5728\\u7B2C \",(0,n.jsx)(e.code,{children:\"0\"}),\" \\u6B65\\u6709\\u4E00\\u79CD\\u65B9\\u5F0F\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8BBE\\u7F6E \",(0,n.jsx)(e.code,{children:\"dp[1] = 1\"}),\"\\uFF0C\\u56E0\\u4E3A\\u5230\\u8FBE\\u7B2C \",(0,n.jsx)(e.code,{children:\"1\"}),\" \\u6B65\\u6709\\u4E00\\u79CD\\u65B9\\u5F0F\\uFF08\\u4E00\\u6B65\\uFF09\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u5FAA\\u73AF\\u4ECE\\u7B2C \",(0,n.jsx)(e.code,{children:\"2\"}),\" \\u6B65\\u5230 \",(0,n.jsx)(e.code,{children:\"steps\"}),\" \\u586B\\u5145 \",(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u6570\\u7EC4\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E00\\u6B65 \",(0,n.jsx)(e.code,{children:\"i\"}),\"\\uFF0C\\u5C06 \",(0,n.jsx)(e.code,{children:\"dp[i]\"}),\" \\u8BA1\\u7B97\\u4E3A \",(0,n.jsx)(e.code,{children:\"dp[i-1]\"}),\"\\uFF08\\u4ECE\\u524D\\u4E00\\u6B65\\u5230\\u8FBE\\u7684\\u65B9\\u5F0F\\uFF09\\u548C \",(0,n.jsx)(e.code,{children:\"dp[i-2]\"}),\"\\uFF08\\u4ECE\\u524D\\u4E24\\u6B65\\u5230\\u8FBE\\u7684\\u65B9\\u5F0F\\uFF09\\u7684\\u603B\\u548C\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"dp[steps]\"}),\" \\u4E2D\\u7684\\u503C\\uFF0C\\u4F5C\\u4E3A\\u5230\\u8FBE\\u697C\\u68AF\\u9876\\u90E8\\u7684\\u4E0D\\u540C\\u65B9\\u5F0F\\u7684\\u603B\\u6570\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(d,{children:p}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\",(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u6570\\u7EC4\\u5728\\u4ECE \",(0,n.jsx)(e.code,{children:\"0\"}),\" \\u5230 \",(0,n.jsx)(e.code,{children:\"steps\"}),\" \\u7684\\u5355\\u6B21\\u904D\\u5386\\u4E2D\\u88AB\\u586B\\u5145\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\",(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u6570\\u7EC4\\u9700\\u8981\\u989D\\u5916\\u7684\\u7A7A\\u95F4\\uFF0C\\u4E0E\\u6B65\\u6570\\u6210\\u6B63\\u6BD4\\u3002\"]}),`\n`]})]})}function j(i={}){let{wrapper:e}=i.components||{};return e?(0,n.jsx)(e,Object.assign({},i,{children:(0,n.jsx)(m,i)})):m(i)}var _=j;return x(B);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/string-anagram-groups/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/string-anagram-groups/locales/zh-CN.json new file mode 100644 index 000000000..e2e9fc66b --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/string-anagram-groups/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var u=Object.create;var c=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var j=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports),y=(n,t)=>{for(var e in t)c(n,e,{get:t[e],enumerable:!0})},i=(n,t,e,s)=>{if(t&&typeof t==\"object\"||typeof t==\"function\")for(let a of m(t))!g.call(n,a)&&a!==e&&c(n,a,{get:()=>t[a],enumerable:!(s=x(t,a))||s.enumerable});return n};var f=(n,t,e)=>(e=n!=null?u(b(n)):{},i(t||!n||!n.__esModule?c(e,\"default\",{value:n,enumerable:!0}):e,n)),_=n=>i(c({},\"__esModule\",{value:!0}),n);var o=j((D,l)=>{l.exports=_jsx_runtime});var v={};y(v,{default:()=>T,frontmatter:()=>z});var r=f(o());var d=MDXTestExamples;var h=[{input:[[\"strs\",[\"abc\",\"bca\",\"cab\",\"xyz\",\"zyx\"]]],output:[[\"abc\",\"bca\",\"cab\"],[\"xyz\",\"zyx\"]],explanation:\"Two anagram groups: 'abc'-'bca'-'cab' and 'xyz'-'zyx'.\"},{input:[[\"strs\",[\"rat\",\"tar\",\"art\",\"car\",\"arc\"]]],output:[[\"arc\",\"car\"],[\"art\",\"rat\",\"tar\"]],explanation:\"Two anagram groups: 'car'-'arc' and 'rat'-'tar'-'art'.\"},{input:[[\"strs\",[\"kxac\",\"swavb\",\"lmq\",\"lvhc\",\"sjey\"]]],output:[[\"kxac\"],[\"lmq\"],[\"lvhc\"],[\"sjey\"],[\"swavb\"]],explanation:\"Each word has no anagram in the list.\"}];var z={title:\"\\u5B57\\u7B26\\u4E32\\u5F02\\u4F4D\\u8BCD\\u5206\\u7EC4\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u5C06\\u5B57\\u7B26\\u4E32\\u6570\\u7EC4\\u5206\\u7EC4\\u4E3A\\u5F02\\u4F4D\\u8BCD\"};function p(n){let t=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},n.components);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u5B57\\u7B26\\u4E32\\u6570\\u7EC4\",(0,r.jsx)(t.code,{children:\"strs\"}),\"\\uFF0C\\u5C06\\u5F7C\\u6B64\\u4E92\\u4E3A\\u5F02\\u4F4D\\u8BCD\\u7684\\u5B57\\u7B26\\u4E32\\u5206\\u7EC4\\u3002\\u7ED3\\u679C\\u53EF\\u4EE5\\u6309\\u4EFB\\u4F55\\u987A\\u5E8F\\u8FD4\\u56DE\\u3002\"]}),`\n`,(0,r.jsx)(t.p,{children:\"\\u5F02\\u4F4D\\u8BCD\\u662F\\u7531\\u53E6\\u4E00\\u4E2A\\u5355\\u8BCD\\u6216\\u77ED\\u8BED\\u7684\\u5B57\\u6BCD\\u91CD\\u65B0\\u6392\\u5217\\u800C\\u6210\\u7684\\u5355\\u8BCD\\u6216\\u77ED\\u8BED\\uFF0C\\u4F7F\\u7528\\u6240\\u6709\\u539F\\u59CB\\u5B57\\u6BCD\\u4E14\\u4EC5\\u4F7F\\u7528\\u4E00\\u6B21\\u3002\"}),`\n`,(0,r.jsx)(t.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,r.jsxs)(t.ul,{children:[`\n`,(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:\"strs: string[]\"}),\": \\u5B57\\u7B26\\u4E32\\u6570\\u7EC4\"]}),`\n`]}),`\n`,(0,r.jsx)(d,{testCases:h}),`\n`,(0,r.jsx)(t.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,r.jsxs)(t.ul,{children:[`\n`,(0,r.jsxs)(t.li,{children:[\"1 <= \",(0,r.jsx)(t.code,{children:\"strs.length\"}),\" <= 1000\"]}),`\n`,(0,r.jsxs)(t.li,{children:[\"1 <= \",(0,r.jsx)(t.code,{children:\"strs[i].length\"}),\" <= 100\"]}),`\n`,(0,r.jsxs)(t.li,{children:[\"\\u6BCF\\u4E2A\\u5B57\\u7B26\\u4E32\",(0,r.jsx)(t.code,{children:\"strs[i]\"}),\"\\u4EC5\\u5305\\u542B\\u5C0F\\u5199\\u82F1\\u6587\\u5B57\\u6BCD\"]}),`\n`]})]})}function M(n={}){let{wrapper:t}=n.components||{};return t?(0,r.jsx)(t,Object.assign({},n,{children:(0,r.jsx)(p,n)})):p(n)}var T=M;return _(v);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,将字符串数组分组为异位词", + "title": "字符串异位词分组" + }, + "solution": "var Component=(()=>{var g=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var x=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports),v=(r,n)=>{for(var t in n)i(r,t,{get:n[t],enumerable:!0})},c=(r,n,t,h)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let a of y(n))!k.call(r,a)&&a!==t&&i(r,a,{get:()=>n[a],enumerable:!(h=p(n,a))||h.enumerable});return r};var C=(r,n,t)=>(t=r!=null?g(f(r)):{},c(n||!r||!r.__esModule?i(t,\"default\",{value:r,enumerable:!0}):t,r)),M=r=>c(i({},\"__esModule\",{value:!0}),r);var s=x((_,o)=>{o.exports=_jsx_runtime});var w={};v(w,{default:()=>A});var e=C(s());var l=MDXCodeBlock;var d=`export default function anagramGroups(strs: string[]): string[][] {\n // Create a map to store the anagrams.\n // The keys are the sorted versions of the strings,\n // and the values are arrays containing the original strings (anagrams).\n let map = new Map();\n\n // Iterate over each string in the input array\n for (let str of strs) {\n // Convert the string to a character array and sort it alphabetically\n let chars = Array.from(str);\n chars.sort();\n\n // Join the sorted characters to form a key\n // This key will be the same for all anagrams\n let key = chars.join('');\n\n // If the key doesn't exist in the map, add it with an empty array as the value\n if (!map.has(key)) map.set(key, []);\n\n // Add the original string to the array of anagrams for this key\n map.get(key)!.push(str);\n }\n\n // Convert the map's values to an array and return it.\n // Each element in the array is a group of anagrams.\n return Array.from(map.values());\n}\n`;var u=`export default function anagramGroups(strs: string[]): string[][] {\n // If the input array is empty, return an empty array\n if (strs.length === 0) return [];\n\n // Initialize an object to store groups of anagrams\n // The keys are unique representations of the character counts\n // The values are arrays of strings that match the key's character count\n let ans: { [key: string]: string[] } = {};\n\n // Iterate over each string in the input array\n for (let s of strs) {\n // Create an array to count occurrences of each character (26 letters of the alphabet)\n let count: number[] = Array(26).fill(0);\n\n // Increment the corresponding index in the count array for each character in the string\n for (let c of s) count[c.charCodeAt(0) - 'a'.charCodeAt(0)]++;\n\n // Create a key string based on the character counts\n // The key is formatted as a series of \"#count\" for each character\n let key = '';\n for (let i = 0; i < 26; i++) {\n key += '#';\n key += count[i];\n }\n\n // If the key doesn't exist in the map, initialize it with an empty array\n if (!ans[key]) ans[key] = [];\n\n // Add the original string to the array associated with the key\n ans[key].push(s);\n }\n\n // Return the values of the map, which are the groups of anagrams\n return Object.values(ans);\n}\n`;function m(r){let n=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},r.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"1. \\u4F7F\\u7528\\u6392\\u5E8F\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u4E00\\u79CD\\u6734\\u7D20\\u7684\\u65B9\\u6CD5\\u53EF\\u80FD\\u6D89\\u53CA\\u68C0\\u67E5\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u5B57\\u7B26\\u4E32\\u5BF9\\uFF0C\\u8FD9\\u5C06\\u662F\\u4F4E\\u6548\\u7684\\u3002\\u7136\\u800C\\uFF0C\\u8FD9\\u79CD\\u4F18\\u5316\\u7684\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u6BCF\\u4E2A\\u5B57\\u7B26\\u4E32\\u7684\\u6392\\u5E8F\\u7248\\u672C\\u4F5C\\u4E3A\\u5206\\u7EC4\\u7684\\u552F\\u4E00\\u952E\\u3002\\u6392\\u5E8F\\u786E\\u4FDD\\u6240\\u6709\\u5B57\\u8C1C\\u4EA7\\u751F\\u76F8\\u540C\\u7684\\u952E\\uFF0C\\u7B80\\u5316\\u4E86\\u7EC4\\u7684\\u8BC6\\u522B\\u3002\\u5BF9\\u6BCF\\u4E2A\\u5B57\\u7B26\\u4E32\\u8FDB\\u884C\\u6392\\u5E8F\\u5C06\\u95EE\\u9898\\u7B80\\u5316\\u4E3A\\u952E\\u751F\\u6210\\uFF0C\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"Map\"}),\" \\u5904\\u7406\\u8D77\\u6765\\u5F88\\u7B80\\u5355\\u3002\"]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u7A7A\\u7684 \",(0,e.jsx)(n.code,{children:\"Map\"}),\" \\u6765\\u5B58\\u50A8\\u5B57\\u8C1C\\u7EC4\\u3002\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u952E\\u8868\\u793A\\u5B57\\u7B26\\u4E32\\u7684\\u6392\\u5E8F\\u7248\\u672C\\uFF0C\\u503C\\u662F\\u539F\\u59CB\\u5B57\\u7B26\\u4E32\\u7684\\u6570\\u7EC4\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u904D\\u5386\\u5B57\\u7B26\\u4E32\\u7684\\u8F93\\u5165\\u6570\\u7EC4\\u3002\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u5B57\\u7B26\\u4E32\\uFF0C\\u5C06\\u5176\\u8F6C\\u6362\\u4E3A\\u5B57\\u7B26\\u6570\\u7EC4\\u5E76\\u6309\\u5B57\\u6BCD\\u987A\\u5E8F\\u6392\\u5E8F\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u8FDE\\u63A5\\u6392\\u5E8F\\u540E\\u7684\\u5B57\\u7B26\\u4EE5\\u521B\\u5EFA\\u952E\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u68C0\\u67E5\\u952E\\u662F\\u5426\\u5DF2\\u5B58\\u5728\\u4E8E \",(0,e.jsx)(n.code,{children:\"Map\"}),\" \\u4E2D\\u3002\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5982\\u679C\\u952E\\u4E0D\\u5B58\\u5728\\uFF0C\\u5219\\u4F7F\\u7528\\u4E00\\u4E2A\\u7A7A\\u6570\\u7EC4\\u5BF9\\u5176\\u8FDB\\u884C\\u521D\\u59CB\\u5316\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5C06\\u539F\\u59CB\\u5B57\\u7B26\\u4E32\\u9644\\u52A0\\u5230\\u4E0E\\u952E\\u5BF9\\u5E94\\u7684\\u6570\\u7EC4\\u4E2D\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5C06 \",(0,e.jsx)(n.code,{children:\"Map\"}),\" \\u7684\\u503C\\u8F6C\\u6362\\u4E3A\\u6570\\u7EC4\\u7684\\u6570\\u7EC4\\u5E76\\u8FD4\\u56DE\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(l,{children:d}),`\n`,(0,e.jsx)(n.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n.m log m)\"}),\"\\u3002\\u5BF9\\u957F\\u5EA6\\u4E3A \",(0,e.jsx)(n.code,{children:\"m\"}),\" \\u7684\\u6BCF\\u4E2A\\u5B57\\u7B26\\u4E32\\u8FDB\\u884C\\u6392\\u5E8F\\u9700\\u8981 O(m log m)\\uFF0C\\u5E76\\u4E14\\u6709 \",(0,e.jsx)(n.code,{children:\"n\"}),\" \\u4E2A\\u5B57\\u7B26\\u4E32\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n.m)\"}),\"\\u3002\",(0,e.jsx)(n.code,{children:\"Map\"}),\" \\u5B58\\u50A8\\u6240\\u6709\\u5B57\\u7B26\\u4E32\\uFF0C\\u952E\\u548C\\u503C\\u6240\\u9700\\u7684\\u7A7A\\u95F4\\u53D6\\u51B3\\u4E8E\\u8F93\\u5165\\u4E2D\\u7684\\u603B\\u5B57\\u7B26\\u6570\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"2. \\u4F7F\\u7528\\u9891\\u7387\\u8BA1\\u6570\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u4E0E\\u5BF9\\u5B57\\u7B26\\u4E32\\u8FDB\\u884C\\u6392\\u5E8F\\u4EE5\\u751F\\u6210\\u952E\\uFF08\\u5982\\u4E4B\\u524D\\u7684\\u89E3\\u51B3\\u65B9\\u6848\\uFF09\\u4E0D\\u540C\\uFF0C\\u4F7F\\u7528\\u56FA\\u5B9A\\u5927\\u5C0F\\u7684\\u9891\\u7387\\u6570\\u7EC4\\uFF08\\u5BF9\\u4E8E\\u82F1\\u6587\\u5B57\\u6BCD\\u4E3A 26\\uFF09\\u6765\\u8BA1\\u7B97\\u6BCF\\u4E2A\\u5B57\\u7B26\\u7684\\u51FA\\u73B0\\u6B21\\u6570\\u3002\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u901A\\u8FC7\\u4F7F\\u7528\\u5176\\u5B57\\u7B26\\u9891\\u7387\\u8BA1\\u6570\\u6765\\u8868\\u793A\\u6BCF\\u4E2A\\u5B57\\u7B26\\u4E32\\uFF0C\\u4ECE\\u800C\\u4F18\\u5316\\u4E86\\u8BE5\\u8FC7\\u7A0B\\u3002\\u8FD9\\u6D88\\u9664\\u4E86\\u5BF9\\u6392\\u5E8F\\u7684\\u9700\\u8981\\uFF0C\\u800C\\u6392\\u5E8F\\u662F\\u57FA\\u4E8E\\u6392\\u5E8F\\u7684\\u65B9\\u6CD5\\u4E2D\\u7684\\u74F6\\u9888\\u3002\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u6BCF\\u4E2A\\u7EC4\\u7684\\u952E\\u662F\\u4ECE\\u9891\\u7387\\u8BA1\\u6570\\u6D3E\\u751F\\u7684\\uFF0C\\u683C\\u5F0F\\u5316\\u4E3A\\u5305\\u542B\\u6240\\u6709\\u5B57\\u7B26\\u8BA1\\u6570\\u7684\\u8FDE\\u63A5\\u5B57\\u7B26\\u4E32\\u3002\\u8FD9\\u786E\\u4FDD\\u6240\\u6709\\u5B57\\u8C1C\\u90FD\\u6620\\u5C04\\u5230\\u76F8\\u540C\\u7684\\u952E\\uFF0C\\u540C\\u65F6\\u907F\\u514D\\u4E86\\u6392\\u5E8F\\u5F00\\u9500\\uFF0C\\u63D0\\u9AD8\\u4E86\\u89E3\\u51B3\\u65B9\\u6848\\u7684\\u6548\\u7387\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u68C0\\u67E5\\u8F93\\u5165\\u6570\\u7EC4\\u662F\\u5426\\u4E3A\\u7A7A\\u3002\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5982\\u679C\\u6570\\u7EC4\\u4E3A\\u7A7A\\uFF0C\\u5219\\u8FD4\\u56DE\\u4E00\\u4E2A\\u7A7A\\u6570\\u7EC4\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u7A7A\\u5BF9\\u8C61\\u6765\\u5B58\\u50A8\\u5B57\\u8C1C\\u7EC4\\u3002\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u952E\\u8868\\u793A\\u5B57\\u7B26\\u8BA1\\u6570\\u6A21\\u5F0F\\uFF0C\\u503C\\u662F\\u4E0E\\u8BE5\\u6A21\\u5F0F\\u5339\\u914D\\u7684\\u5B57\\u7B26\\u4E32\\u6570\\u7EC4\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u904D\\u5386\\u8F93\\u5165\\u6570\\u7EC4\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5B57\\u7B26\\u4E32\\u3002\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u5927\\u5C0F\\u4E3A 26 \\u7684\\u8BA1\\u6570\\u6570\\u7EC4\\u6765\\u8868\\u793A\\u5B57\\u7B26\\u9891\\u7387\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5BF9\\u4E8E\\u5B57\\u7B26\\u4E32\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5B57\\u7B26\\uFF0C\\u9012\\u589E\\u8BA1\\u6570\\u6570\\u7EC4\\u4E2D\\u5BF9\\u5E94\\u7684\\u7D22\\u5F15\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4ECE\\u8BA1\\u6570\\u6570\\u7EC4\\u751F\\u6210\\u4E00\\u4E2A\\u952E\\u5B57\\u7B26\\u4E32\\u3002\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u8FDE\\u63A5 \",(0,e.jsx)(n.code,{children:\"#\"}),\" \\u548C\\u6BCF\\u4E2A\\u5B57\\u7B26\\u7684\\u8BA1\\u6570\\u4EE5\\u5F62\\u6210\\u952E\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u68C0\\u67E5\\u8BE5\\u952E\\u662F\\u5426\\u5B58\\u5728\\u4E8E\\u5BF9\\u8C61\\u4E2D\\u3002\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5982\\u679C\\u8BE5\\u952E\\u4E0D\\u5B58\\u5728\\uFF0C\\u5219\\u4F7F\\u7528\\u4E00\\u4E2A\\u7A7A\\u6570\\u7EC4\\u5BF9\\u5176\\u8FDB\\u884C\\u521D\\u59CB\\u5316\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5C06\\u5B57\\u7B26\\u4E32\\u9644\\u52A0\\u5230\\u4E0E\\u8BE5\\u952E\\u5BF9\\u5E94\\u7684\\u6570\\u7EC4\\u4E2D\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5C06\\u5BF9\\u8C61\\u7684\\u503C\\u4F5C\\u4E3A\\u5B57\\u8C1C\\u7EC4\\u7684\\u6570\\u7EC4\\u8FD4\\u56DE\\u3002\"}),`\n`]}),`\n`,(0,e.jsx)(l,{children:u}),`\n`,(0,e.jsx)(n.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n.m)\"}),\"\\u3002\\u8BA1\\u7B97\\u6BCF\\u4E2A\\u957F\\u5EA6\\u4E3A \",(0,e.jsx)(n.code,{children:\"m\"}),\" \\u7684\\u5B57\\u7B26\\u4E32\\u7684\\u5B57\\u7B26\\u9700\\u8981 O(m)\\uFF0C\\u5E76\\u4E14\\u6709 \",(0,e.jsx)(n.code,{children:\"n\"}),\" \\u4E2A\\u5B57\\u7B26\\u4E32\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n.m)\"}),\"\\u3002\\u5BF9\\u8C61\\u5B58\\u50A8\\u6240\\u6709\\u5B57\\u7B26\\u4E32\\uFF0C\\u5E76\\u4E3A\\u5B57\\u7B26\\u8BA1\\u6570\\u548C\\u952E\\u4F7F\\u7528\\u989D\\u5916\\u7684\\u7A7A\\u95F4\\u3002\"]}),`\n`]})]})}function b(r={}){let{wrapper:n}=r.components||{};return n?(0,e.jsx)(n,Object.assign({},r,{children:(0,e.jsx)(m,r)})):m(r)}var A=b;return M(w);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/string-anagram/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/string-anagram/locales/zh-CN.json new file mode 100644 index 000000000..85f5009a6 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/string-anagram/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var s=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var j=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),_=(n,e)=>{for(var r in e)s(n,r,{get:e[r],enumerable:!0})},l=(n,e,r,i)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let c of f(e))!g.call(n,c)&&c!==r&&s(n,c,{get:()=>e[c],enumerable:!(i=m(e,c))||i.enumerable});return n};var b=(n,e,r)=>(r=n!=null?p(x(n)):{},l(e||!n||!n.__esModule?s(r,\"default\",{value:n,enumerable:!0}):r,n)),M=n=>l(s({},\"__esModule\",{value:!0}),n);var d=j((q,o)=>{o.exports=_jsx_runtime});var w={};_(w,{default:()=>X,frontmatter:()=>D});var t=b(d());var h=MDXTestExamples;var a=[{input:[[\"str1\",\"abcd\"],[\"str2\",\"dcba\"]],output:!0,explanation:\"Both strings contain the same characters with the same frequency in different orders.\"},{input:[[\"str1\",\"hello\"],[\"str2\",\"bello\"]],output:!1,explanation:\"The strings do not contain the same characters.\"},{input:[[\"str1\",\"listen\"],[\"str2\",\"silent\"]],output:!0,explanation:\"Both strings contain the same characters with the same frequency in different orders.\"}];var D={title:\"\\u5B57\\u7B26\\u4E32\\u5F02\\u4F4D\\u8BCD\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u786E\\u5B9A\\u4E24\\u4E2A\\u5B57\\u7B26\\u4E32\\u662F\\u5426\\u4E92\\u4E3A\\u5F02\\u4F4D\\u8BCD\"};function u(n){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},n.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E24\\u4E2A\\u5B57\\u7B26\\u4E32\",(0,t.jsx)(e.code,{children:\"str1\"}),\"\\u548C\",(0,t.jsx)(e.code,{children:\"str2\"}),\"\\uFF0C\\u786E\\u5B9A\",(0,t.jsx)(e.code,{children:\"str2\"}),\"\\u662F\\u5426\\u662F\",(0,t.jsx)(e.code,{children:\"str1\"}),\"\\u7684\\u5F02\\u4F4D\\u8BCD\\uFF0C\\u5982\\u679C\\u662F\\u5219\\u8FD4\\u56DE\",(0,t.jsx)(e.code,{children:\"true\"}),\"\\uFF0C\\u5426\\u5219\\u8FD4\\u56DE\",(0,t.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`,(0,t.jsxs)(e.p,{children:[\"\\u5F02\\u4F4D\\u8BCD\\u662F\\u6307\\u901A\\u8FC7\\u91CD\\u65B0\\u6392\\u5217\\u53E6\\u4E00\\u4E2A\\u5355\\u8BCD\\u6216\\u77ED\\u8BED\\u7684\\u5B57\\u6BCD\\u800C\\u5F62\\u6210\\u7684\\u5355\\u8BCD\\u6216\\u77ED\\u8BED\\uFF0C\\u4F7F\\u7528\\u6240\\u6709\\u539F\\u59CB\\u5B57\\u6BCD\\u4E14\\u4EC5\\u4F7F\\u7528\\u4E00\\u6B21\\u3002\\u4F8B\\u5982\\uFF0C\\u5355\\u8BCD\",(0,t.jsx)(e.code,{children:\"listen\"}),\"\\u548C\",(0,t.jsx)(e.code,{children:\"silent\"}),\"\\u662F\\u5F02\\u4F4D\\u8BCD\\uFF0C\\u56E0\\u4E3A\\u5B83\\u4EEC\\u4F7F\\u7528\\u76F8\\u540C\\u7684\\u5B57\\u6BCD\\uFF0C\\u5177\\u6709\\u76F8\\u540C\\u7684\\u9891\\u7387\\uFF0C\\u4F46\\u987A\\u5E8F\\u4E0D\\u540C\\u3002\"]}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.code,{children:\"str1\"}),\"\\uFF1A\\u4E00\\u4E2A\\u5B57\\u7B26\\u4E32\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.code,{children:\"str2\"}),\"\\uFF1A\\u4E00\\u4E2A\\u5B57\\u7B26\\u4E32\"]}),`\n`]}),`\n`,(0,t.jsx)(h,{testCases:a}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[\"1 <= \",(0,t.jsx)(e.code,{children:\"str1.length\"}),\"\\uFF0C\",(0,t.jsx)(e.code,{children:\"str2.length\"}),\" <= 1000\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.code,{children:\"str1\"}),\"\\u548C\",(0,t.jsx)(e.code,{children:\"str2\"}),\"\\u4EC5\\u7531\\u5C0F\\u5199\\u82F1\\u6587\\u5B57\\u6BCD\\u7EC4\\u6210\"]}),`\n`]})]})}function T(n={}){let{wrapper:e}=n.components||{};return e?(0,t.jsx)(e,Object.assign({},n,{children:(0,t.jsx)(u,n)})):u(n)}var X=T;return M(w);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来确定两个字符串是否互为异位词", + "title": "字符串异位词" + }, + "solution": "var Component=(()=>{var f=Object.create;var l=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var A=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var C=(e,n)=>()=>(n||e((n={exports:{}}).exports,n),n.exports),b=(e,n)=>{for(var t in n)l(e,t,{get:n[t],enumerable:!0})},h=(e,n,t,a)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let i of p(n))!y.call(e,i)&&i!==t&&l(e,i,{get:()=>n[i],enumerable:!(a=m(n,i))||a.enumerable});return e};var x=(e,n,t)=>(t=e!=null?f(A(e)):{},h(n||!e||!e.__esModule?l(t,\"default\",{value:e,enumerable:!0}):t,e)),O=e=>h(l({},\"__esModule\",{value:!0}),e);var o=C((k,s)=>{s.exports=_jsx_runtime});var D={};b(D,{default:()=>q});var r=x(o());var c=MDXCodeBlock;var d=`export default function isStringAnagram(str1: string, str2: string): boolean {\n // If the lengths of the two strings are not equal, they cannot be anagrams\n if (str1.length !== str2.length) {\n return false;\n }\n\n // Convert the strings into character arrays\n let str1Array: string[] = str1.split('');\n let str2Array: string[] = str2.split('');\n\n // Sort the character arrays\n str1Array.sort();\n str2Array.sort();\n\n // Check if the sorted character arrays are equal\n for (let i = 0; i < str1Array.length; i++) {\n if (str1Array[i] !== str2Array[i]) {\n return false;\n }\n }\n\n // If all checks pass, the strings are anagrams\n return true;\n}\n`;var g=`export default function isAnagram(str1: string, str2: string): boolean {\n // If the lengths of the two strings are not equal, they cannot be anagrams\n if (str1.length !== str2.length) {\n return false;\n }\n\n // Create an array to count the frequency of each character in the alphabet\n const table: number[] = new Array(26).fill(0);\n\n // Increment the count for each character in string s\n for (let i = 0; i < str1.length; i++) {\n table[str1.charCodeAt(i) - 'a'.charCodeAt(0)]++;\n }\n\n // Decrement the count for each character in string t\n for (let i = 0; i < str2.length; i++) {\n table[str2.charCodeAt(i) - 'a'.charCodeAt(0)]--;\n // If count goes negative, strings are not anagrams\n if (table[str2.charCodeAt(i) - 'a'.charCodeAt(0)] < 0) {\n return false;\n }\n }\n\n // If all counts are zero, strings are anagrams\n return true;\n}\n`;function u(e){let n=Object.assign({h2:\"h2\",p:\"p\",h3:\"h3\",ol:\"ol\",li:\"li\",code:\"code\",ul:\"ul\",strong:\"strong\"},e.components);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.h2,{children:\"1. \\u4F7F\\u7528\\u6392\\u5E8F\"}),`\n`,(0,r.jsx)(n.p,{children:\"\\u95EE\\u9898\\u662F\\u786E\\u5B9A\\u4E24\\u4E2A\\u5B57\\u7B26\\u4E32\\u662F\\u5426\\u4E92\\u4E3A\\u5B57\\u8C1C\\u3002\\u5982\\u679C\\u4E24\\u4E2A\\u5B57\\u7B26\\u4E32\\u5305\\u542B\\u76F8\\u540C\\u5B57\\u7B26\\uFF0C\\u4E14\\u6BCF\\u4E2A\\u5B57\\u7B26\\u7684\\u51FA\\u73B0\\u9891\\u7387\\u4E5F\\u76F8\\u540C\\uFF0C\\u4F46\\u987A\\u5E8F\\u53EF\\u4EE5\\u4E0D\\u540C\\uFF0C\\u5219\\u5B83\\u4EEC\\u4E92\\u4E3A\\u5B57\\u8C1C\\u3002\\u8FD9\\u79CD\\u65B9\\u6CD5\\u7684\\u6838\\u5FC3\\u5728\\u4E8E\\uFF0C\\u5BF9\\u4E24\\u4E2A\\u5B57\\u7B26\\u4E32\\u8FDB\\u884C\\u6392\\u5E8F\\u540E\\uFF0C\\u5982\\u679C\\u5B83\\u4EEC\\u662F\\u5B57\\u8C1C\\uFF0C\\u5219\\u4F1A\\u6309\\u7167\\u76F8\\u540C\\u7684\\u987A\\u5E8F\\u91CD\\u65B0\\u6392\\u5217\\u5B57\\u7B26\\u3002\\u6392\\u5E8F\\u540E\\uFF0C\\u7B80\\u5355\\u5730\\u6BD4\\u8F83\\u4E24\\u4E2A\\u5DF2\\u6392\\u5E8F\\u7684\\u6570\\u7EC4\\u5C31\\u53EF\\u4EE5\\u786E\\u5B9A\\u8FD9\\u4E9B\\u5B57\\u7B26\\u4E32\\u662F\\u5426\\u4E92\\u4E3A\\u5B57\\u8C1C\\u3002\"}),`\n`,(0,r.jsx)(n.p,{children:\"\\u6392\\u5E8F\\u63D0\\u4F9B\\u4E86\\u4E00\\u79CD\\u76F4\\u63A5\\u7684\\u65B9\\u5F0F\\u6765\\u5BF9\\u9F50\\u4E24\\u4E2A\\u5B57\\u7B26\\u4E32\\u4E2D\\u7684\\u5B57\\u7B26\\uFF0C\\u4ECE\\u800C\\u4FBF\\u4E8E\\u68C0\\u67E5\\u662F\\u5426\\u76F8\\u7B49\\u3002\"}),`\n`,(0,r.jsx)(n.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,r.jsxs)(n.ol,{children:[`\n`,(0,r.jsxs)(n.li,{children:[\"\\u68C0\\u67E5 \",(0,r.jsx)(n.code,{children:\"str1\"}),\" \\u548C \",(0,r.jsx)(n.code,{children:\"str2\"}),\" \\u7684\\u957F\\u5EA6\\u662F\\u5426\\u4E0D\\u540C\\u3002\\u5982\\u679C\\u4E0D\\u540C\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,r.jsx)(n.code,{children:\"false\"}),\"\\uFF0C\\u56E0\\u4E3A\\u957F\\u5EA6\\u4E0D\\u540C\\u7684\\u5B57\\u7B26\\u4E32\\u4E0D\\u53EF\\u80FD\\u4E92\\u4E3A\\u5B57\\u8C1C\\u3002\"]}),`\n`,(0,r.jsxs)(n.li,{children:[\"\\u4F7F\\u7528 \",(0,r.jsx)(n.code,{children:\"split\"}),\" \\u65B9\\u6CD5\\u5C06 \",(0,r.jsx)(n.code,{children:\"str1\"}),\" \\u548C \",(0,r.jsx)(n.code,{children:\"str2\"}),\" \\u5206\\u5272\\u6210\\u5B57\\u7B26\\u6570\\u7EC4\\u3002\"]}),`\n`,(0,r.jsxs)(n.li,{children:[\"\\u4F7F\\u7528 \",(0,r.jsx)(n.code,{children:\"sort\"}),\" \\u65B9\\u6CD5\\u5BF9\\u5B57\\u7B26\\u6570\\u7EC4\\u8FDB\\u884C\\u6392\\u5E8F\\u3002\"]}),`\n`,(0,r.jsxs)(n.li,{children:[\"\\u904D\\u5386\\u5DF2\\u6392\\u5E8F\\u7684\\u6570\\u7EC4\\uFF0C\\u5E76\\u6BD4\\u8F83\\u6BCF\\u4E2A\\u7D22\\u5F15\\u5904\\u7684\\u5B57\\u7B26\\u3002\",`\n`,(0,r.jsxs)(n.ul,{children:[`\n`,(0,r.jsxs)(n.li,{children:[\"\\u5982\\u679C\\u4E24\\u4E2A\\u6570\\u7EC4\\u4E2D\\u7684\\u4EFB\\u4F55\\u5B57\\u7B26\\u4E0D\\u5339\\u914D\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,r.jsx)(n.code,{children:\"false\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,r.jsxs)(n.li,{children:[\"\\u5982\\u679C\\u6240\\u6709\\u5B57\\u7B26\\u90FD\\u5339\\u914D\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,r.jsx)(n.code,{children:\"true\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,r.jsx)(c,{children:d}),`\n`,(0,r.jsx)(n.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,r.jsxs)(n.ul,{children:[`\n`,(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n log n)\"}),\"\\u3002\\u5BF9\\u5B57\\u7B26\\u6570\\u7EC4\\u8FDB\\u884C\\u6392\\u5E8F\\u662F\\u6700\\u6602\\u8D35\\u7684\\u64CD\\u4F5C\\uFF0C\\u5E76\\u4E14\\u5728\\u8FD0\\u884C\\u65F6\\u5360\\u636E\\u4E3B\\u5BFC\\u5730\\u4F4D\\u3002\"]}),`\n`,(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u9700\\u8981\\u7A7A\\u95F4\\u6765\\u5B58\\u50A8\\u4ECE\\u8F93\\u5165\\u5B57\\u7B26\\u4E32\\u521B\\u5EFA\\u7684\\u5B57\\u7B26\\u6570\\u7EC4\\u3002\"]}),`\n`]}),`\n`,(0,r.jsx)(n.h2,{children:\"2. \\u4F7F\\u7528\\u9891\\u7387\\u8BA1\\u6570\"}),`\n`,(0,r.jsx)(n.p,{children:\"\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u901A\\u8FC7\\u4F7F\\u7528\\u9891\\u7387\\u8BA1\\u6570\\u65B9\\u6CD5\\u6765\\u4F18\\u5316\\u5B57\\u8C1C\\u68C0\\u67E5\\u8FC7\\u7A0B\\u3002\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u6CA1\\u6709\\u5BF9\\u5B57\\u7B26\\u4E32\\u8FDB\\u884C\\u6392\\u5E8F\\uFF08\\u9700\\u8981 O(n log n) \\u65F6\\u95F4\\uFF09\\uFF0C\\u800C\\u662F\\u4F7F\\u7528\\u56FA\\u5B9A\\u5927\\u5C0F\\u7684\\u6570\\u7EC4\\uFF08\\u5BF9\\u4E8E\\u82F1\\u6587\\u5B57\\u6BCD\\uFF0C\\u5927\\u5C0F\\u4E3A 26\\uFF09\\u6765\\u8BA1\\u7B97\\u5B57\\u7B26\\u7684\\u51FA\\u73B0\\u6B21\\u6570\\u3002\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u5B57\\u7B26\\u4E32\\uFF0C\\u90FD\\u4F1A\\u66F4\\u65B0\\u9891\\u7387\\u8868\\uFF1A\\u4E00\\u4E2A\\u5B57\\u7B26\\u4E32\\u9012\\u589E\\uFF0C\\u53E6\\u4E00\\u4E2A\\u5B57\\u7B26\\u4E32\\u9012\\u51CF\\u3002\\u5982\\u679C\\u6700\\u540E\\u6240\\u6709\\u5B57\\u7B26\\u7684\\u8BA1\\u6570\\u90FD\\u4E3A\\u96F6\\uFF0C\\u5219\\u8FD9\\u4E9B\\u5B57\\u7B26\\u4E32\\u4E92\\u4E3A\\u5B57\\u8C1C\\u3002\"}),`\n`,(0,r.jsx)(n.p,{children:\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u907F\\u514D\\u4E86\\u4E0D\\u5FC5\\u8981\\u7684\\u6392\\u5E8F\\uFF0C\\u5E76\\u76F4\\u63A5\\u9488\\u5BF9\\u524D\\u4E00\\u4E2A\\u89E3\\u51B3\\u65B9\\u6848\\u4E2D\\u7684\\u6392\\u5E8F\\u74F6\\u9888\\uFF0C\\u4ECE\\u800C\\u5C06\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4ECE O(n log n) \\u964D\\u4F4E\\u5230 O(n)\\u3002\"}),`\n`,(0,r.jsx)(n.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,r.jsxs)(n.ol,{children:[`\n`,(0,r.jsxs)(n.li,{children:[\"\\u68C0\\u67E5\\u4E24\\u4E2A\\u5B57\\u7B26\\u4E32\\u7684\\u957F\\u5EA6\\u662F\\u5426\\u4E0D\\u540C\\u3002\",`\n`,(0,r.jsxs)(n.ul,{children:[`\n`,(0,r.jsxs)(n.li,{children:[\"\\u5982\\u679C\\u4E0D\\u540C\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,r.jsx)(n.code,{children:\"false\"}),\"\\uFF0C\\u56E0\\u4E3A\\u8FD9\\u4E9B\\u5B57\\u7B26\\u4E32\\u4E0D\\u53EF\\u80FD\\u4E92\\u4E3A\\u5B57\\u8C1C\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,r.jsx)(n.li,{children:\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u5927\\u5C0F\\u4E3A 26 \\u7684\\u6570\\u7EC4\\uFF0C\\u5E76\\u5C06\\u6240\\u6709\\u5143\\u7D20\\u8BBE\\u7F6E\\u4E3A 0\\uFF0C\\u4EE5\\u5145\\u5F53\\u9891\\u7387\\u8868\\u3002\"}),`\n`,(0,r.jsxs)(n.li,{children:[\"\\u904D\\u5386\\u7B2C\\u4E00\\u4E2A\\u5B57\\u7B26\\u4E32\\u3002\",`\n`,(0,r.jsxs)(n.ul,{children:[`\n`,(0,r.jsx)(n.li,{children:\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u5B57\\u7B26\\uFF0C\\u9012\\u589E\\u5176\\u5728\\u9891\\u7387\\u8868\\u4E2D\\u7684\\u76F8\\u5E94\\u4F4D\\u7F6E\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,r.jsxs)(n.li,{children:[\"\\u904D\\u5386\\u7B2C\\u4E8C\\u4E2A\\u5B57\\u7B26\\u4E32\\u3002\",`\n`,(0,r.jsxs)(n.ul,{children:[`\n`,(0,r.jsx)(n.li,{children:\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u5B57\\u7B26\\uFF0C\\u9012\\u51CF\\u5176\\u5728\\u9891\\u7387\\u8868\\u4E2D\\u7684\\u76F8\\u5E94\\u4F4D\\u7F6E\\u3002\"}),`\n`,(0,r.jsxs)(n.li,{children:[\"\\u5982\\u679C\\u8868\\u4E2D\\u4EFB\\u4F55\\u8BA1\\u6570\\u53D8\\u4E3A\\u8D1F\\u6570\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,r.jsx)(n.code,{children:\"false\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,r.jsxs)(n.li,{children:[\"\\u5728\\u4E24\\u6B21\\u8FED\\u4EE3\\u4E4B\\u540E\\uFF0C\\u5982\\u679C\\u6CA1\\u6709\\u8BA1\\u6570\\u4E3A\\u8D1F\\u6570\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,r.jsx)(n.code,{children:\"true\"}),\"\\uFF0C\\u56E0\\u4E3A\\u8FD9\\u4E9B\\u5B57\\u7B26\\u4E32\\u4E92\\u4E3A\\u5B57\\u8C1C\\u3002\"]}),`\n`]}),`\n`,(0,r.jsx)(c,{children:g}),`\n`,(0,r.jsx)(n.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,r.jsxs)(n.ul,{children:[`\n`,(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u6070\\u597D\\u904D\\u5386\\u4E24\\u4E2A\\u5B57\\u7B26\\u4E32\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u9891\\u7387\\u8868\\u7684\\u5927\\u5C0F\\u662F\\u56FA\\u5B9A\\u7684\\uFF0826\\uFF09\\uFF0C\\u4E0E\\u8F93\\u5165\\u5927\\u5C0F\\u65E0\\u5173\\u3002\"]}),`\n`]})]})}function I(e={}){let{wrapper:n}=e.components||{};return n?(0,r.jsx)(n,Object.assign({},e,{children:(0,r.jsx)(u,e)})):u(e)}var q=I;return O(D);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/string-decode-message/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/string-decode-message/locales/zh-CN.json new file mode 100644 index 000000000..20914e107 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/string-decode-message/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var c=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var j=(t,n)=>()=>(n||t((n={exports:{}}).exports,n),n.exports),B=(t,n)=>{for(var i in n)c(t,i,{get:n[i],enumerable:!0})},d=(t,n,i,l)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let r of m(n))!g.call(t,r)&&r!==i&&c(t,r,{get:()=>n[r],enumerable:!(l=x(n,r))||l.enumerable});return t};var _=(t,n,i)=>(i=t!=null?p(f(t)):{},d(n||!t||!t.__esModule?c(i,\"default\",{value:t,enumerable:!0}):i,t)),b=t=>d(c({},\"__esModule\",{value:!0}),t);var s=j((X,o)=>{o.exports=_jsx_runtime});var E={};B(E,{default:()=>D,frontmatter:()=>M});var e=_(s());var a=MDXTestExamples;var h=[{input:[[\"str\",\"225\"]],output:3,explanation:\"'225' can be decoded as 'BY' (2 26), 'VE' (22 5), or 'BBE' (2 2 5).\"},{input:[[\"str\",\"10\"]],output:1,explanation:\"'10' can be decoded as 'J' (10).\"},{input:[[\"str\",\"1106\"]],output:1,explanation:\"'1106' can be decoded as 'AJF' (1 10 6). The grouping (11 06) is invalid because '06' is not a valid code.\"}];var M={title:\"\\u89E3\\u7801\\u6D88\\u606F\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u8BA1\\u7B97\\u89E3\\u7801\\u6570\\u5B57\\u5B57\\u7B26\\u4E32\\u7684\\u65B9\\u6CD5\"};function u(t){let n=Object.assign({p:\"p\",code:\"code\",ul:\"ul\",li:\"li\",h3:\"h3\"},t.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.p,{children:\"\\u4E00\\u4E2A\\u79D8\\u5BC6\\u6D88\\u606F\\u88AB\\u7F16\\u7801\\u4E3A\\u4E00\\u4E32\\u6570\\u5B57\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u6570\\u5B57\\u6216\\u4E00\\u5BF9\\u6570\\u5B57\\u4EE3\\u8868\\u4E00\\u4E2A\\u5B57\\u6BCD\\uFF0C\\u6839\\u636E\\u4EE5\\u4E0B\\u6620\\u5C04\\uFF1A\"}),`\n`,(0,e.jsx)(n.p,{children:(0,e.jsx)(n.code,{children:\"'1' \\u2192 'A', '2' \\u2192 'B', ..., '26' \\u2192 'Z'\"})}),`\n`,(0,e.jsx)(n.p,{children:\"\\u6D88\\u606F\\u53EF\\u4EE5\\u6839\\u636E\\u6570\\u5B57\\u7684\\u5206\\u7EC4\\u65B9\\u5F0F\\u4EE5\\u591A\\u79CD\\u65B9\\u5F0F\\u89E3\\u7801\\u3002\\u4F8B\\u5982\\uFF0C\\u5B57\\u7B26\\u4E32\\u201C226\\u201D\\u53EF\\u4EE5\\u89E3\\u91CA\\u4E3A\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:`\"2 26\" \\u2192 'BZ'`}),`\n`,(0,e.jsx)(n.li,{children:`\"22 6\" \\u2192 'VF'`}),`\n`,(0,e.jsx)(n.li,{children:`\"2 2 6\" \\u2192 'BBF'`}),`\n`]}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u53EA\\u5305\\u542B\\u6570\\u5B57\\u7684\\u5B57\\u7B26\\u4E32\",(0,e.jsx)(n.code,{children:\"str\"}),\"\\uFF0C\\u627E\\u51FA\\u5B83\\u53EF\\u4EE5\\u88AB\\u89E3\\u7801\\u7684\\u65B9\\u5F0F\\u6709\\u591A\\u5C11\\u79CD\\u3002\\u5982\\u679C\\u5B57\\u7B26\\u4E32\\u65E0\\u6CD5\\u4EE5\\u4EFB\\u4F55\\u6709\\u6548\\u65B9\\u5F0F\\u89E3\\u7801\\uFF0C\\u5219\\u8FD4\\u56DE\",(0,e.jsx)(n.code,{children:\"0\"}),\"\\u3002\"]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"str: string\"}),\": \\u4EC5\\u7531\\u8981\\u89E3\\u7801\\u7684\\u6570\\u5B57\\u7EC4\\u6210\\u7684\\u5B57\\u7B26\\u4E32\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u6CE8\\u610F\\u4E8B\\u9879\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u6D4B\\u8BD5\\u7528\\u4F8B\\u7684\\u8BBE\\u8BA1\\u4F7F\\u5F97\\u7B54\\u6848\\u9002\\u5408 32 \\u4F4D\\u6574\\u6570\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u53EF\\u80FD\\u5B58\\u5728\\u65E0\\u6CD5\\u89E3\\u7801\\u7684\\u5B57\\u7B26\\u4E32\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5E76\\u975E\\u6240\\u6709\\u6570\\u5B57\\u5206\\u7EC4\\u90FD\\u6709\\u6548\\u3002\\u4F8B\\u5982\\uFF0C\\u201C06\\u201D\\u65E0\\u6548\\uFF0C\\u56E0\\u4E3A\\u6570\\u5B57\\u4E0D\\u80FD\\u6709\\u524D\\u5BFC\\u96F6\"}),`\n`]}),`\n`,(0,e.jsx)(a,{testCases:h}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"1 <= \",(0,e.jsx)(n.code,{children:\"str.length\"}),\" <= 100\"]}),`\n`]})]})}function C(t={}){let{wrapper:n}=t.components||{};return n?(0,e.jsx)(n,Object.assign({},t,{children:(0,e.jsx)(u,t)})):u(t)}var D=C;return b(E);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来计算解码数字字符串的方法", + "title": "解码消息" + }, + "solution": "var Component=(()=>{var g=Object.create;var c=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,M=Object.prototype.hasOwnProperty;var v=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),w=(r,e)=>{for(var i in e)c(r,i,{get:e[i],enumerable:!0})},o=(r,e,i,t)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let d of x(e))!M.call(r,d)&&d!==i&&c(r,d,{get:()=>e[d],enumerable:!(t=f(e,d))||t.enumerable});return r};var y=(r,e,i)=>(i=r!=null?g(b(r)):{},o(e||!r||!r.__esModule?c(i,\"default\",{value:r,enumerable:!0}):i,r)),D=r=>o(c({},\"__esModule\",{value:!0}),r);var s=v((_,h)=>{h.exports=_jsx_runtime});var k={};w(k,{default:()=>j});var n=y(s());var l=MDXCodeBlock;var u=`export default function decodeMessage(str: string): number {\n // DP array to store the subproblem results\n const dp: number[] = new Array(str.length + 1).fill(0);\n\n // Base case: There's one way to decode an empty string\n dp[0] = 1;\n\n // Ways to decode a string of size 1 is 1, unless the string is '0'\n dp[1] = str[0] === '0' ? 0 : 1;\n\n // Iterate through the string to fill the DP array\n for (let i = 2; i <= str.length; i++) {\n // Check if successful single digit decode is possible\n if (str[i - 1] !== '0') {\n dp[i] += dp[i - 1];\n }\n\n // Check if successful two-digit decode is possible\n const twoDigit = parseInt(str.substring(i - 2, i), 10);\n if (twoDigit >= 10 && twoDigit <= 26) {\n dp[i] += dp[i - 2];\n }\n }\n\n // The last element in the DP array contains the number of ways to decode the entire string\n return dp[str.length];\n}\n`;var a=`// Recursive function with memoization to count the number of ways to decode a string\nfunction recursiveWithMemo(\n index: number, // Current index in the string\n str: string, // The input string to decode\n memo: Map, // Memoization map to store previously computed results\n): number {\n // If the result for the current index is already computed, return it from the memo\n if (memo.has(index)) {\n return memo.get(index)!;\n }\n // If the current index has reached the end of the string, return 1 (valid decode)\n if (index === str.length) {\n return 1;\n }\n // If the current character is '0', return 0 (no valid decode)\n if (str.charAt(index) === '0') {\n return 0;\n }\n // If the current index is the last character, return 1 (single valid decode)\n if (index === str.length - 1) {\n return 1;\n }\n\n // Initialize the answer by decoding one character\n let ans = recursiveWithMemo(index + 1, str, memo);\n\n // Check if the next two characters form a valid number <= 26 and decode it\n if (parseInt(str.substring(index, index + 2)) <= 26) {\n ans += recursiveWithMemo(index + 2, str, memo);\n }\n\n // Store the computed result in the memo map\n memo.set(index, ans);\n return ans;\n}\n\nexport default function decodeMessage(str: string): number {\n let memo = new Map();\n return recursiveWithMemo(0, str, memo);\n}\n`;var p=`export default function decodeMessage(str: string): number {\n // Handle edge case: empty string\n if (str.length === 0) return 0;\n\n // Variables to store the last two results\n let prev = 1; // Represents dp[i-2], initialized for empty string\n let curr = str[0] === '0' ? 0 : 1; // Represents dp[i-1]\n\n // Iterate through the string\n for (let i = 2; i <= str.length; i++) {\n let temp = 0; // Temporarily store the current dp[i]\n\n // Check if successful single-digit decode is possible\n if (str[i - 1] !== '0') {\n temp += curr;\n }\n\n // Check if successful two-digit decode is possible\n const twoDigit = parseInt(str.substring(i - 2, i), 10);\n if (twoDigit >= 10 && twoDigit <= 26) {\n temp += prev;\n }\n\n // Update prev and curr for the next iteration\n prev = curr;\n curr = temp;\n }\n\n // The last value of curr contains the result\n return curr;\n}\n`;function m(r){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u81EA\\u9876\\u5411\\u4E0B\\u52A8\\u6001\\u89C4\\u5212\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5C06\\u5B57\\u7B26\\u4E32\\u89E3\\u7801\\u6210\\u53EF\\u80FD\\u7684\\u5B57\\u6BCD\\u7EC4\\u5408\\u7684\\u95EE\\u9898\\u53EF\\u4EE5\\u88AB\\u53EF\\u89C6\\u5316\\u4E3A\\u5BFC\\u822A\\u51B3\\u7B56\\u6811\\u3002\\u5B57\\u7B26\\u4E32\\u4E2D\\u7684\\u6BCF\\u4E00\\u6B65\\u90FD\\u63D0\\u4F9B\\u4E24\\u79CD\\u9009\\u62E9\\uFF1A\\u89E3\\u7801\\u5355\\u4E2A\\u5B57\\u7B26\\u6216\\u89E3\\u7801\\u4E24\\u4E2A\\u5B57\\u7B26\\uFF08\\u5982\\u679C\\u5B83\\u4EEC\\u6784\\u6210 \",(0,n.jsx)(e.code,{children:\"10\"}),\" \\u5230 \",(0,n.jsx)(e.code,{children:\"26\"}),\" \\u4E4B\\u95F4\\u7684\\u6709\\u6548\\u6570\\u5B57\\uFF09\\u3002\\u76EE\\u6807\\u662F\\u8BA1\\u7B97\\u4ECE\\u5B57\\u7B26\\u4E32\\u5F00\\u5934\\u5230\\u7ED3\\u5C3E\\u7684\\u6240\\u6709\\u6709\\u6548\\u89E3\\u7801\\u8DEF\\u5F84\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u4F7F\\u7528\\u86EE\\u529B\\u9012\\u5F52\\u65B9\\u6CD5\\u4F1A\\u5BFC\\u81F4\\u5197\\u4F59\\u8BA1\\u7B97\\uFF0C\\u56E0\\u4E3A\\u540C\\u4E00\\u4E2A\\u5B50\\u95EE\\u9898\\uFF08\\u4F8B\\u5982\\uFF0C\\u89E3\\u7801\\u4ECE\\u7279\\u5B9A\\u7D22\\u5F15\\u5F00\\u59CB\\u7684\\u5B50\\u5B57\\u7B26\\u4E32\\uFF09\\u4F1A\\u88AB\\u591A\\u6B21\\u89E3\\u51B3\\u3002\\u8FD9\\u79CD\\u5197\\u4F59\\u53EF\\u4EE5\\u901A\\u8FC7\\u5C06\\u5148\\u524D\\u8BA1\\u7B97\\u7684\\u5B50\\u95EE\\u9898\\u7684\\u7ED3\\u679C\\u5B58\\u50A8\\u5728\\u5907\\u5FD8\\u5F55\\u6620\\u5C04\\u4E2D\\u6765\\u907F\\u514D\\u3002\\u5907\\u5FD8\\u5F55\\u89E3\\u51B3\\u65B9\\u6848\\u4EE5\\u6700\\u4F73\\u65B9\\u5F0F\\u5BFC\\u822A\\u51B3\\u7B56\\u6811\\uFF0C\\u786E\\u4FDD\\u6BCF\\u4E2A\\u5B50\\u95EE\\u9898\\u53EA\\u89E3\\u51B3\\u4E00\\u6B21\\uFF0C\\u4ECE\\u800C\\u663E\\u7740\\u63D0\\u9AD8\\u6548\\u7387\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u9012\\u5F52\\u51FD\\u6570 \",(0,n.jsx)(e.code,{children:\"recursiveWithMemo\"}),\"\\uFF0C\\u5B83:\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u63A5\\u53D7\\u5F53\\u524D\\u7D22\\u5F15\\u3001\\u8F93\\u5165\\u5B57\\u7B26\\u4E32\\u548C\\u5907\\u5FD8\\u5F55\\u6620\\u5C04\\u4F5C\\u4E3A\\u53C2\\u6570\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u5F53\\u524D\\u7D22\\u5F15\\u7684\\u7ED3\\u679C\\u662F\\u5426\\u5B58\\u5728\\u4E8E \",(0,n.jsx)(e.code,{children:\"memo\"}),\" \\u4E2D\\uFF0C\\u5982\\u679C\\u627E\\u5230\\u5219\\u8FD4\\u56DE\\u5B83\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u7D22\\u5F15\\u5230\\u8FBE\\u5B57\\u7B26\\u4E32\\u7684\\u672B\\u5C3E\\uFF08\\u6709\\u6548\\u89E3\\u7801\\uFF09\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"1\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5F53\\u524D\\u5B57\\u7B26\\u662F \",(0,n.jsx)(e.code,{children:\"'0'\"}),\"\\uFF08\\u65E0\\u6548\\u89E3\\u7801\\uFF09\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5F53\\u524D\\u7D22\\u5F15\\u6307\\u5411\\u6700\\u540E\\u4E00\\u4E2A\\u5B57\\u7B26\\uFF08\\u6709\\u6548\\u89E3\\u7801\\uFF09\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"1\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"recursiveWithMemo\"}),\" \\u4EE5 \",(0,n.jsx)(e.code,{children:\"index + 1\"}),\" \\u8C03\\u7528\\uFF0C\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u53D8\\u91CF \",(0,n.jsx)(e.code,{children:\"ans\"}),\"\\uFF0C\\u7ED3\\u679C\\u662F\\u89E3\\u7801\\u5F53\\u524D\\u7D22\\u5F15\\u5904\\u7684\\u5355\\u4E2A\\u5B57\\u7B26\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u63A5\\u4E0B\\u6765\\u7684\\u4E24\\u4E2A\\u5B57\\u7B26\\u662F\\u5426\\u6784\\u6210 \",(0,n.jsx)(e.code,{children:\"10\"}),\" \\u5230 \",(0,n.jsx)(e.code,{children:\"26\"}),\" \\u4E4B\\u95F4\\u7684\\u6709\\u6548\\u6570\\u5B57:\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u6709\\u6548\\uFF0C\\u901A\\u8FC7\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"index + 2\"}),\" \\u8C03\\u7528 \",(0,n.jsx)(e.code,{children:\"recursiveWithMemo\"}),\" \\u6765\\u6DFB\\u52A0\\u89E3\\u7801\\u4E24\\u4E2A\\u5B57\\u7B26\\u7684\\u7ED3\\u679C\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u5F53\\u524D\\u7D22\\u5F15\\u7684\\u8BA1\\u7B97\\u7ED3\\u679C\\u5B58\\u50A8\\u5728 \",(0,n.jsx)(e.code,{children:\"memo\"}),\" \\u6620\\u5C04\\u4E2D\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE\\u5B58\\u50A8\\u5728 \",(0,n.jsx)(e.code,{children:\"memo\"}),\" \\u4E2D\\u5F53\\u524D\\u7D22\\u5F15\\u7684\\u503C\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u5305\\u88C5\\u51FD\\u6570 \",(0,n.jsx)(e.code,{children:\"decodeMessage\"}),\"\\uFF0C\\u5B83:\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u7A7A\\u7684 \",(0,n.jsx)(e.code,{children:\"Map\"}),\" \\u7528\\u4E8E\\u5907\\u5FD8\\u5F55\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u521D\\u59CB\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"0\"}),\" \\u548C\\u8F93\\u5165\\u5B57\\u7B26\\u4E32\\u8C03\\u7528 \",(0,n.jsx)(e.code,{children:\"recursiveWithMemo\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(l,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u7531\\u4E8E\\u5907\\u5FD8\\u5F55\\uFF0C\\u6BCF\\u4E2A\\u7D22\\u5F15\\u53EA\\u5904\\u7406\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\",(0,n.jsx)(e.code,{children:\"Map\"}),\" \\u6700\\u591A\\u5B58\\u50A8 \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u4E2A\\u6761\\u76EE\\uFF0C\\u5E76\\u4E14\\u9012\\u5F52\\u5806\\u6808\\u5728\\u6700\\u574F\\u60C5\\u51B5\\u4E0B\\u9700\\u8981 O(n) \\u7A7A\\u95F4\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u81EA\\u5E95\\u5411\\u4E0A\\u52A8\\u6001\\u89C4\\u5212\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u4E0D\\u662F\\u9012\\u5F52\\u5730\\u89E3\\u51B3\\u5B50\\u95EE\\u9898\\uFF0C\\u800C\\u662F\\u901A\\u8FC7\\u4F7F\\u7528\\u8F83\\u5C0F\\u5B50\\u5B57\\u7B26\\u4E32\\u7684\\u7ED3\\u679C\\u6765\\u8FED\\u4EE3\\u5730\\u8BA1\\u7B97\\u89E3\\u7801\\u5B57\\u7B26\\u4E32\\u7684\\u65B9\\u5F0F\\u7684\\u6570\\u91CF\\u3002\\u76F4\\u89C9\\u662F\\u7EF4\\u62A4\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u6570\\u7EC4\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u6761\\u76EE\\u8868\\u793A\\u89E3\\u7801\\u5230\\u8BE5\\u7D22\\u5F15\\u7684\\u5B50\\u5B57\\u7B26\\u4E32\\u7684\\u65B9\\u5F0F\\u7684\\u6570\\u91CF\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8FD9\\u79CD\\u65B9\\u6CD5\\u901A\\u8FC7\\u5728\\u5355\\u6B21\\u4F20\\u9012\\u4E2D\\u8FED\\u4EE3\\u5730\\u586B\\u5145 \",(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u6570\\u7EC4\\u6765\\u907F\\u514D\\u9012\\u5F52\\u548C\\u5907\\u5FD8\\u5F55\\u7684\\u5F00\\u9500\\u3002\\u8FED\\u4EE3\\u6027\\u8D28\\u786E\\u4FDD\\u6BCF\\u4E2A\\u5B50\\u95EE\\u9898\\u53EA\\u89E3\\u51B3\\u4E00\\u6B21\\uFF0C\\u4ECE\\u800C\\u663E\\u7740\\u4F18\\u5316\\u65F6\\u95F4\\u548C\\u7A7A\\u95F4\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u6240\\u6709\\u503C\\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\" \\u521D\\u59CB\\u5316\\u5927\\u5C0F\\u4E3A \",(0,n.jsx)(e.code,{children:\"str.length + 1\"}),\" \\u7684 \",(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u6570\\u7EC4\\u3002\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"dp[0]\"}),\" \\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"1\"}),\"\\uFF0C\\u56E0\\u4E3A\\u6709\\u4E00\\u79CD\\u65B9\\u6CD5\\u53EF\\u4EE5\\u89E3\\u7801\\u4E00\\u4E2A\\u7A7A\\u5B57\\u7B26\\u4E32\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u7B2C\\u4E00\\u4E2A\\u5B57\\u7B26\\u4E0D\\u662F \",(0,n.jsx)(e.code,{children:\"'0'\"}),\"\\uFF0C\\u5219\\u5C06 \",(0,n.jsx)(e.code,{children:\"dp[1]\"}),\" \\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"1\"}),\"\\uFF0C\\u5426\\u5219\\u5C06\\u5176\\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"2\"}),\" \\u8FED\\u4EE3\\u5230 \",(0,n.jsx)(e.code,{children:\"str.length\"}),\":\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5F53\\u524D\\u5B57\\u7B26\\u4E0D\\u662F \",(0,n.jsx)(e.code,{children:\"'0'\"}),\"\\uFF0C\\u5219\\u5C06 \",(0,n.jsx)(e.code,{children:\"dp[i - 1]\"}),\" \\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"dp[i]\"}),\" \\u4EE5\\u8FDB\\u884C\\u5355\\u6570\\u5B57\\u89E3\\u7801\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u63D0\\u53D6\\u6700\\u540E\\u4E24\\u4E2A\\u5B57\\u7B26\\u4F5C\\u4E3A\\u4E24\\u4F4D\\u6570\\u3002\\u5982\\u679C\\u5B83\\u5728 \",(0,n.jsx)(e.code,{children:\"10\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"26\"}),\" \\u4E4B\\u95F4\\uFF0C\\u5219\\u5C06 \",(0,n.jsx)(e.code,{children:\"dp[i - 2]\"}),\" \\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"dp[i]\"}),\" \\u4EE5\\u8FDB\\u884C\\u4E24\\u4F4D\\u6570\\u89E3\\u7801\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"dp[str.length]\"}),\" \\u4E2D\\u7684\\u503C\\uFF0C\\u5B83\\u8868\\u793A\\u89E3\\u7801\\u6574\\u4E2A\\u5B57\\u7B26\\u4E32\\u7684\\u65B9\\u5F0F\\u7684\\u6570\\u91CF\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(l,{children:u}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u904D\\u5386\\u5B57\\u7B26\\u4E32\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\",(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u6570\\u7EC4\\u5B58\\u50A8\\u5B57\\u7B26\\u4E32\\u6BCF\\u4E2A\\u7D22\\u5F15\\u7684\\u4E2D\\u95F4\\u7ED3\\u679C\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"3. \\u5177\\u6709\\u6052\\u5B9A\\u7A7A\\u95F4\\u7684\\u81EA\\u5E95\\u5411\\u4E0A\\u52A8\\u6001\\u89C4\\u5212\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u901A\\u8FC7\\u5C06\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u964D\\u4F4E\\u5230 O(1) \\u6765\\u6539\\u8FDB\\u81EA\\u5E95\\u5411\\u4E0A\\u7684\\u52A8\\u6001\\u89C4\\u5212\\u65B9\\u6CD5\\u3002\\u6B64\\u65B9\\u6CD5\\u4E0D\\u662F\\u7EF4\\u62A4\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u6570\\u7EC4\\u6765\\u5B58\\u50A8\\u6240\\u6709\\u7D22\\u5F15\\u7684\\u7ED3\\u679C\\uFF0C\\u800C\\u662F\\u4EC5\\u8DDF\\u8E2A\\u6700\\u540E\\u4E24\\u4E2A\\u7ED3\\u679C (\",(0,n.jsx)(e.code,{children:\"dp[i-2]\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"dp[i-1]\"}),\")\\u3002\\u8FD9\\u79CD\\u4F18\\u5316\\u662F\\u53EF\\u80FD\\u7684\\uFF0C\\u56E0\\u4E3A\\u5728\\u4EFB\\u4F55\\u4F4D\\u7F6E\\u89E3\\u7801\\u5B57\\u7B26\\u4E32\\u7684\\u65B9\\u5F0F\\u90FD\\u4EC5\\u53D6\\u51B3\\u4E8E\\u524D\\u4E24\\u4E2A\\u4F4D\\u7F6E\\u7684\\u7ED3\\u679C\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u4E4B\\u524D\\u7684\\u81EA\\u5E95\\u5411\\u4E0A\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u4E86\\u4E00\\u4E2A\\u9700\\u8981 O(n) \\u7A7A\\u95F4\\u7684\\u6570\\u7EC4\\u3002\\u901A\\u8FC7\\u7528\\u4E24\\u4E2A\\u53D8\\u91CF\\u66FF\\u6362\\u6570\\u7EC4\\uFF0C\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u51CF\\u5C11\\u4E86\\u7A7A\\u95F4\\u4F7F\\u7528\\uFF0C\\u800C\\u4E0D\\u4F1A\\u5F71\\u54CD\\u6B63\\u786E\\u6027\\u6216\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u3002\\u5F53\\u5904\\u7406\\u5927\\u578B\\u5B57\\u7B26\\u4E32\\u65F6\\uFF0C\\u6B64\\u6539\\u8FDB\\u7279\\u522B\\u6709\\u7528\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"0\"}),\" \\u6765\\u5904\\u7406\\u5B57\\u7B26\\u4E32\\u4E3A\\u7A7A\\u7684\\u8FB9\\u7F18\\u60C5\\u51B5\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E24\\u4E2A\\u53D8\\u91CF:\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"prev\"}),\" \\u8868\\u793A \",(0,n.jsx)(e.code,{children:\"dp[i-2]\"}),\"\\uFF0C\\u5BF9\\u4E8E\\u7A7A\\u5B57\\u7B26\\u4E32\\u7684\\u57FA\\u672C\\u60C5\\u51B5\\uFF0C\\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"1\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"curr\"}),\" \\u8868\\u793A \",(0,n.jsx)(e.code,{children:\"dp[i-1]\"}),\"\\uFF0C\\u5982\\u679C\\u7B2C\\u4E00\\u4E2A\\u5B57\\u7B26\\u4E0D\\u662F \",(0,n.jsx)(e.code,{children:\"'0'\"}),\"\\uFF0C\\u5219\\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"1\"}),\"\\uFF0C\\u5426\\u5219\\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"2\"}),\" \\u8FED\\u4EE3\\u5230 \",(0,n.jsx)(e.code,{children:\"str.length\"}),\":\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u4E34\\u65F6\\u53D8\\u91CF \",(0,n.jsx)(e.code,{children:\"temp\"}),\" \\u6765\\u5B58\\u50A8\\u5F53\\u524D\\u7ED3\\u679C\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5F53\\u524D\\u5B57\\u7B26\\u4E0D\\u662F \",(0,n.jsx)(e.code,{children:\"'0'\"}),\"\\uFF0C\\u5219\\u5C06 \",(0,n.jsx)(e.code,{children:\"curr\"}),\" \\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"temp\"}),\" \\u4EE5\\u8FDB\\u884C\\u5355\\u6570\\u5B57\\u89E3\\u7801\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u63D0\\u53D6\\u6700\\u540E\\u4E24\\u4E2A\\u5B57\\u7B26\\u4F5C\\u4E3A\\u4E24\\u4F4D\\u6570\\u3002\\u5982\\u679C\\u5B83\\u5728 \",(0,n.jsx)(e.code,{children:\"10\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"26\"}),\" \\u4E4B\\u95F4\\uFF0C\\u5219\\u5C06 \",(0,n.jsx)(e.code,{children:\"prev\"}),\" \\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"temp\"}),\" \\u4EE5\\u8FDB\\u884C\\u4E24\\u4F4D\\u6570\\u89E3\\u7801\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"prev\"}),\" \\u66F4\\u65B0\\u4E3A \",(0,n.jsx)(e.code,{children:\"curr\"}),\"\\uFF0C\\u5C06 \",(0,n.jsx)(e.code,{children:\"curr\"}),\" \\u66F4\\u65B0\\u4E3A \",(0,n.jsx)(e.code,{children:\"temp\"}),\" \\u4EE5\\u8FDB\\u884C\\u4E0B\\u4E00\\u6B21\\u8FED\\u4EE3\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"curr\"}),\" \\u7684\\u503C\\uFF0C\\u5176\\u4E2D\\u5305\\u542B\\u89E3\\u7801\\u6574\\u4E2A\\u5B57\\u7B26\\u4E32\\u7684\\u65B9\\u5F0F\\u7684\\u6570\\u91CF\\u3002\"]}),`\n`]}),`\n`,(0,n.jsxs)(l,{children:[\" \",p,\" \"]}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u904D\\u5386\\u5B57\\u7B26\\u4E32\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u4EC5\\u4F7F\\u7528\\u4E24\\u4E2A\\u53D8\\u91CF\\u6765\\u5B58\\u50A8\\u4E2D\\u95F4\\u7ED3\\u679C\\u3002\"]}),`\n`]})]})}function W(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(m,r)})):m(r)}var j=W;return D(k);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/string-palindrome/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/string-palindrome/locales/zh-CN.json new file mode 100644 index 000000000..629c320de --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/string-palindrome/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var u=Object.create;var i=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var w=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),b=(n,e)=>{for(var r in e)i(n,r,{get:e[r],enumerable:!0})},o=(n,e,r,c)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let a of x(e))!f.call(n,a)&&a!==r&&i(n,a,{get:()=>e[a],enumerable:!(c=m(e,a))||c.enumerable});return n};var j=(n,e,r)=>(r=n!=null?u(g(n)):{},o(e||!n||!n.__esModule?i(r,\"default\",{value:n,enumerable:!0}):r,n)),_=n=>o(i({},\"__esModule\",{value:!0}),n);var l=w((I,s)=>{s.exports=_jsx_runtime});var D={};b(D,{default:()=>A,frontmatter:()=>C});var t=j(l());var h=MDXTestExamples;var d=[{input:[[\"str\",\"No 'x' in Nixon\"]],output:!0,explanation:\"After removing non-alphanumeric characters and converting to lowercase, the string becomes 'noxinnixon', which is a palindrome.\"},{input:[[\"str\",\"Was it a car or a cat I saw?\"]],output:!0,explanation:\"After removing non-alphanumeric characters and converting to lowercase, the string becomes 'wasitacaroracatisaw', which is a palindrome.\"},{input:[[\"str\",\"tab a cat\"]],output:!1,explanation:\"After removing non-alphanumeric characters and converting to lowercase, the string becomes 'tabacat', which is not a palindrome.\"}];var C={title:\"\\u5B57\\u7B26\\u4E32\\u56DE\\u6587\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u786E\\u5B9A\\u4E00\\u4E2A\\u5B57\\u7B26\\u4E32\\u662F\\u5426\\u662F\\u56DE\\u6587\"};function p(n){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},n.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u5B57\\u7B26\\u4E32 \",(0,t.jsx)(e.code,{children:\"str\"}),\"\\uFF0C\\u786E\\u5B9A\\u5B83\\u662F\\u5426\\u662F\\u56DE\\u6587\\u3002\\u5982\\u679C\\u662F\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,t.jsx)(e.code,{children:\"true\"}),\"\\uFF0C\\u5426\\u5219\\u8FD4\\u56DE \",(0,t.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`,(0,t.jsx)(e.p,{children:\"\\u5982\\u679C\\u4E00\\u4E2A\\u5B57\\u7B26\\u4E32\\u5728\\u5C06\\u6240\\u6709\\u5927\\u5199\\u5B57\\u6BCD\\u66F4\\u6539\\u4E3A\\u5C0F\\u5199\\u5B57\\u6BCD\\u5E76\\u4E22\\u5F03\\u6240\\u6709\\u975E\\u5B57\\u6BCD\\u6570\\u5B57\\u5B57\\u7B26\\u540E\\uFF0C\\u6B63\\u5411\\u548C\\u53CD\\u5411\\u8BFB\\u53D6\\u65F6\\u4FDD\\u6301\\u76F8\\u540C\\uFF0C\\u5219\\u8BE5\\u5B57\\u7B26\\u4E32\\u662F\\u56DE\\u6587\\u3002\\u5B57\\u6BCD\\u6570\\u5B57\\u5B57\\u7B26\\u7531\\u5B57\\u6BCD\\u548C\\u6570\\u5B57\\u7EC4\\u6210\\u3002\"}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.code,{children:\"str: string\"}),\": \\u5B57\\u7B26\\u4E32\"]}),`\n`]}),`\n`,(0,t.jsx)(h,{testCases:d}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[\"1 <= \",(0,t.jsx)(e.code,{children:\"str.length\"}),\" <= 1000\"]}),`\n`,(0,t.jsxs)(e.li,{children:[\"\\u5B57\\u7B26\\u4E32 \",(0,t.jsx)(e.code,{children:\"str\"}),\" \\u4EC5\\u7531\\u53EF\\u6253\\u5370\\u7684 ASCII \\u5B57\\u7B26\\u7EC4\\u6210\"]}),`\n`]})]})}function M(n={}){let{wrapper:e}=n.components||{};return e?(0,t.jsx)(e,Object.assign({},n,{children:(0,t.jsx)(p,n)})):p(n)}var A=M;return _(D);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来确定一个字符串是否是回文", + "title": "字符串回文" + }, + "solution": "var Component=(()=>{var C=Object.create;var h=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var v=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),A=(t,e)=>{for(var i in e)h(t,i,{get:e[i],enumerable:!0})},d=(t,e,i,l)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let n of p(e))!j.call(t,n)&&n!==i&&h(t,n,{get:()=>e[n],enumerable:!(l=u(e,n))||l.enumerable});return t};var w=(t,e,i)=>(i=t!=null?C(m(t)):{},d(e||!t||!t.__esModule?h(i,\"default\",{value:t,enumerable:!0}):i,t)),O=t=>d(h({},\"__esModule\",{value:!0}),t);var a=v((z,o)=>{o.exports=_jsx_runtime});var _={};A(_,{default:()=>D});var r=w(a());var c=MDXCodeBlock;var s=`export default function isStringPalindrome(str: string): boolean {\n // Initialize an empty string to store filtered characters\n let filteredChars = '';\n\n // Iterate through each character in the input string\n for (let ch of str) {\n // Check if the character is alphanumeric (a-z, A-Z, 0-9)\n if (ch.match(/[a-z0-9]/i)) {\n // Convert the character to lowercase and add it to the filteredChars string\n filteredChars += ch.toLowerCase();\n }\n }\n\n // Reverse the filtered characters string\n const reversedChars = filteredChars.split('').reverse().join('');\n\n // Compare the original filtered string with the reversed string\n // If they are the same, it is a palindrome\n return filteredChars === reversedChars;\n}\n`;var f=`export default function isStringPalindrome(str: string): boolean {\n let i = 0; // Initialize the left pointer\n let j = str.length - 1; // Initialize the right pointer\n\n // Loop until the left pointer is less than the right pointer\n while (i < j) {\n // Move the left pointer to the right if the current character is not alphanumeric\n while (i < j && !isLetterOrDigit(str.charAt(i))) {\n i++;\n }\n\n // Move the right pointer to the left if the current character is not alphanumeric\n while (i < j && !isLetterOrDigit(str.charAt(j))) {\n j--;\n }\n\n // Compare the characters at the left and right pointers after converting to lowercase\n if (str.charAt(i).toLowerCase() !== str.charAt(j).toLowerCase()) {\n return false; // Return false if characters don't match\n }\n\n i++; // Move the left pointer to the right\n j--; // Move the right pointer to the left\n }\n\n return true; // Return true if all characters match\n}\n\nfunction isLetterOrDigit(character: string): boolean {\n const charCode = character.charCodeAt(0);\n return (\n (charCode >= 'a'.charCodeAt(0) && charCode <= 'z'.charCodeAt(0)) || // Check if character is a lowercase letter\n (charCode >= 'A'.charCodeAt(0) && charCode <= 'Z'.charCodeAt(0)) || // Check if character is an uppercase letter\n (charCode >= '0'.charCodeAt(0) && charCode <= '9'.charCodeAt(0)) // Check if character is a digit\n );\n}\n`;function g(t){let e=Object.assign({h2:\"h2\",p:\"p\",h3:\"h3\",ol:\"ol\",li:\"li\",code:\"code\",ul:\"ul\",strong:\"strong\"},t.components);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e.h2,{children:\"1. \\u6BD4\\u8F83\\u9006\\u5E8F\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u901A\\u8FC7\\u4EC5\\u5173\\u6CE8\\u5B57\\u7B26\\u4E32\\u7684\\u5B57\\u6BCD\\u6570\\u5B57\\u5B57\\u7B26\\u5E76\\u5FFD\\u7565\\u5927\\u5C0F\\u5199\\u654F\\u611F\\u5EA6\\u6765\\u786E\\u5B9A\\u5B57\\u7B26\\u4E32\\u662F\\u5426\\u4E3A\\u56DE\\u6587\\u3002\\u5173\\u952E\\u7684\\u76F4\\u89C9\\u662F\\uFF0C\\u56DE\\u6587\\u7684\\u5B57\\u7B26\\u5E8F\\u5217\\u5728\\u53CD\\u8F6C\\u65F6\\u5FC5\\u987B\\u76F8\\u540C\\u3002\\u56E0\\u6B64\\uFF0C\\u6B64\\u65B9\\u6CD5\\u5C06\\u53CD\\u8F6C\\u8F93\\u5165\\u5B57\\u7B26\\u4E32\\uFF0C\\u5E76\\u5C06\\u53CD\\u8F6C\\u540E\\u7684\\u5B57\\u7B26\\u4E32\\u4E0E\\u539F\\u59CB\\u5B57\\u7B26\\u4E32\\u8FDB\\u884C\\u6BD4\\u8F83\\uFF0C\\u4EE5\\u68C0\\u67E5\\u5B83\\u4EEC\\u662F\\u5426\\u76F8\\u4F3C\\u3002\\u4E3A\\u4E86\\u7B80\\u5316\\u6BD4\\u8F83\\uFF0C\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u901A\\u8FC7\\u8FC7\\u6EE4\\u6389\\u975E\\u5B57\\u6BCD\\u6570\\u5B57\\u5B57\\u7B26\\u5E76\\u5C06\\u5269\\u4F59\\u5B57\\u7B26\\u8F6C\\u6362\\u4E3A\\u5C0F\\u5199\\u6765\\u9884\\u5904\\u7406\\u5B57\\u7B26\\u4E32\\u3002\\u8FD9\\u521B\\u5EFA\\u4E86\\u5B57\\u7B26\\u4E32\\u7684\\u89C4\\u8303\\u5316\\u7248\\u672C\\uFF0C\\u4F7F\\u5F97\\u53CD\\u5411\\u6BD4\\u8F83\\u53D8\\u5F97\\u7B80\\u5355\\u3002\"}),`\n`,(0,r.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,r.jsxs)(e.ol,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u7A7A\\u5B57\\u7B26\\u4E32 \",(0,r.jsx)(e.code,{children:\"filteredChars\"}),\"\\uFF0C\\u7528\\u4E8E\\u5B58\\u50A8\\u5C0F\\u5199\\u7684\\u5B57\\u6BCD\\u6570\\u5B57\\u5B57\\u7B26\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u8F93\\u5165\\u5B57\\u7B26\\u4E32\\u7684\\u6BCF\\u4E2A\\u5B57\\u7B26\\uFF1A\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u8BE5\\u5B57\\u7B26\\u662F\\u5B57\\u6BCD\\u6570\\u5B57\\uFF0C\\u5219\\u5C06\\u5176\\u8F6C\\u6362\\u4E3A\\u5C0F\\u5199\\u5E76\\u8FFD\\u52A0\\u5230 \",(0,r.jsx)(e.code,{children:\"filteredChars\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u4F7F\\u7528 \",(0,r.jsx)(e.code,{children:\"split\"}),\"\\u3001\",(0,r.jsx)(e.code,{children:\"reverse\"}),\" \\u548C \",(0,r.jsx)(e.code,{children:\"join\"}),\" \\u53CD\\u8F6C \",(0,r.jsx)(e.code,{children:\"filteredChars\"}),\" \\u5B57\\u7B26\\u4E32\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5C06\\u539F\\u59CB\\u7684 \",(0,r.jsx)(e.code,{children:\"filteredChars\"}),\" \\u4E0E\\u53CD\\u8F6C\\u540E\\u7684\\u7248\\u672C\\u8FDB\\u884C\\u6BD4\\u8F83\\u3002\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5B83\\u4EEC\\u76F8\\u540C\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,r.jsx)(e.code,{children:\"true\"}),\"\\uFF0C\\u56E0\\u4E3A\\u8BE5\\u5B57\\u7B26\\u4E32\\u662F\\u56DE\\u6587\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5426\\u5219\\uFF0C\\u8FD4\\u56DE \",(0,r.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,r.jsx)(c,{children:s}),`\n`,(0,r.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u8FC7\\u6EE4\\u5B57\\u7B26\\u548C\\u53CD\\u8F6C\\u5B57\\u7B26\\u4E32\\u90FD\\u9700\\u8981\\u7EBF\\u6027\\u65F6\\u95F4\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\",(0,r.jsx)(e.code,{children:\"filteredChars\"}),\" \\u548C \",(0,r.jsx)(e.code,{children:\"reversedChars\"}),\" \\u5B57\\u7B26\\u4E32\\u90FD\\u9700\\u8981 O(n) \\u7A7A\\u95F4\\u3002\"]}),`\n`]}),`\n`,(0,r.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u53CC\\u6307\\u9488\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u901A\\u8FC7\\u907F\\u514D\\u521B\\u5EFA\\u53CD\\u8F6C\\u5B57\\u7B26\\u4E32\\u6765\\u6539\\u8FDB\\u524D\\u4E00\\u4E2A\\u89E3\\u51B3\\u65B9\\u6848\\uFF0C\\u8FD9\\u9700\\u8981\\u989D\\u5916\\u7684\\u65F6\\u95F4\\u548C\\u7A7A\\u95F4\\u3002\\u53CC\\u6307\\u9488\\u65B9\\u6CD5\\u901A\\u8FC7\\u4F7F\\u7528\\u4E24\\u4E2A\\u7D22\\u5F15\\uFF08\\u4E00\\u4E2A\\u4ECE\\u5B57\\u7B26\\u4E32\\u7684\\u5F00\\u5934\\u5F00\\u59CB\\uFF0C\\u53E6\\u4E00\\u4E2A\\u4ECE\\u7ED3\\u5C3E\\u5F00\\u59CB\\uFF0C\\u5E76\\u5411\\u4E2D\\u5FC3\\u79FB\\u52A8\\uFF09\\u6765\\u786E\\u5B9A\\u5B57\\u7B26\\u4E32\\u662F\\u5426\\u4E3A\\u56DE\\u6587\\u3002\\u8FD9\\u6D88\\u9664\\u4E86\\u53CD\\u8F6C\\u5B57\\u7B26\\u4E32\\u7684\\u9700\\u8981\\uFF0C\\u56E0\\u4E3A\\u53EF\\u4EE5\\u76F4\\u63A5\\u5728\\u5BF9\\u5E94\\u7684\\u5B57\\u7B26\\u4E4B\\u95F4\\u8FDB\\u884C\\u6BD4\\u8F83\\u3002\"}),`\n`,(0,r.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,r.jsxs)(e.ol,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E24\\u4E2A\\u6307\\u9488\\uFF1A\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u4E00\\u4E2A (\",(0,r.jsx)(e.code,{children:\"left\"}),\") \\u5728\\u5B57\\u7B26\\u4E32\\u7684\\u5F00\\u5934\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u53E6\\u4E00\\u4E2A (\",(0,r.jsx)(e.code,{children:\"right\"}),\") \\u5728\\u5B57\\u7B26\\u4E32\\u7684\\u7ED3\\u5C3E\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5F53 \",(0,r.jsx)(e.code,{children:\"left\"}),\" \\u5C0F\\u4E8E \",(0,r.jsx)(e.code,{children:\"right\"}),\" \\u65F6\\uFF1A\",`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u5C06 \",(0,r.jsx)(e.code,{children:\"left\"}),\" \\u5411\\u524D\\u79FB\\u52A8\\u5E76\\u5C06 \",(0,r.jsx)(e.code,{children:\"right\"}),\" \\u5411\\u540E\\u79FB\\u52A8\\uFF0C\\u8DF3\\u8FC7\\u975E\\u5B57\\u6BCD\\u6570\\u5B57\\u5B57\\u7B26\\uFF0C\\u76F4\\u5230\\u627E\\u5230\\u6709\\u6548\\u7684\\u5B57\\u7B26\\u3002\"]}),`\n`,(0,r.jsx)(e.li,{children:\"\\u5C06\\u4E24\\u4E2A\\u5B57\\u7B26\\u8F6C\\u6362\\u4E3A\\u5C0F\\u5199\\uFF0C\\u4EE5\\u8FDB\\u884C\\u4E0D\\u533A\\u5206\\u5927\\u5C0F\\u5199\\u7684\\u6BD4\\u8F83\\u3002\"}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,r.jsx)(e.code,{children:\"left\"}),\" \\u548C \",(0,r.jsx)(e.code,{children:\"right\"}),\" \\u7684\\u5B57\\u7B26\\u4E0D\\u76F8\\u7B49\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,r.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5426\\u5219\\uFF0C\\u5C06 \",(0,r.jsx)(e.code,{children:\"left\"}),\" \\u5411\\u524D\\u79FB\\u52A8\\u5E76\\u5C06 \",(0,r.jsx)(e.code,{children:\"right\"}),\" \\u5411\\u540E\\u79FB\\u52A8\\u4EE5\\u7EE7\\u7EED\\u6BD4\\u8F83\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u6240\\u6709\\u5B57\\u7B26\\u90FD\\u5339\\u914D\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,r.jsx)(e.code,{children:\"true\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,r.jsx)(c,{children:f}),`\n`,(0,r.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002\\u5B57\\u7B26\\u4E32\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5B57\\u7B26\\u90FD\\u4F1A\\u88AB\\u5904\\u7406\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u53CC\\u6307\\u9488\\u65B9\\u6CD5\\u4F7F\\u7528\\u5E38\\u91CF\\u989D\\u5916\\u7A7A\\u95F4\\u7528\\u4E8E\\u53D8\\u91CF\\u3002\"]}),`\n`]})]})}function L(t={}){let{wrapper:e}=t.components||{};return e?(0,r.jsx)(e,Object.assign({},t,{children:(0,r.jsx)(g,t)})):g(t)}var D=L;return O(_);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/string-palindromic-substrings/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/string-palindromic-substrings/locales/zh-CN.json new file mode 100644 index 000000000..942d8b1b7 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/string-palindromic-substrings/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var u=Object.create;var i=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var f=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),j=(r,e)=>{for(var c in e)i(r,c,{get:e[c],enumerable:!0})},o=(r,e,c,d)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let t of m(e))!g.call(r,t)&&t!==c&&i(r,t,{get:()=>e[t],enumerable:!(d=b(e,t))||d.enumerable});return r};var _=(r,e,c)=>(c=r!=null?u(x(r)):{},o(e||!r||!r.__esModule?i(c,\"default\",{value:r,enumerable:!0}):c,r)),T=r=>o(i({},\"__esModule\",{value:!0}),r);var a=f((O,s)=>{s.exports=_jsx_runtime});var E={};j(E,{default:()=>X,frontmatter:()=>C});var n=_(a());var l=MDXTestExamples;var h=[{input:[[\"str\",\"cat\"]],output:3,explanation:\"The palindromic substrings are 'c', 'a', and 't'.\"},{input:[[\"str\",\"racecar\"]],output:10,explanation:\"The palindromic substrings are 'r', 'a', 'c', 'e', 'c', 'a', 'r', 'cec', 'aceca', and 'racecar'.\"},{input:[[\"str\",\"bbb\"]],output:6,explanation:\"The palindromic substrings are 'b', 'b', 'b', 'bb', 'bb', and 'bbb'.\"}];var C={title:\"\\u56DE\\u6587\\u5B50\\u4E32\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u8BA1\\u7B97\\u5B57\\u7B26\\u4E32\\u4E2D\\u6240\\u6709\\u56DE\\u6587\\u5B50\\u4E32\\u7684\\u6570\\u91CF\"};function p(r){let e=Object.assign({p:\"p\",code:\"code\",strong:\"strong\",h3:\"h3\",ul:\"ul\",li:\"li\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u5B57\\u7B26\\u4E32\",(0,n.jsx)(e.code,{children:\"str\"}),\"\\uFF0C\\u786E\\u5B9A\\u4F5C\\u4E3A\\u56DE\\u6587\\u7684\\u5B50\\u4E32\\u7684\\u603B\\u6570\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A\",(0,n.jsx)(e.strong,{children:\"\\u56DE\\u6587\"}),\"\\u662F\\u6307\\u4ECE\\u524D\\u5F80\\u540E\\u548C\\u4ECE\\u540E\\u5F80\\u524D\\u8BFB\\u90FD\\u4E00\\u6837\\u7684\\u5B57\\u7B26\\u5E8F\\u5217\\uFF08\\u4F8B\\u5982\\uFF0C\",(0,n.jsx)(e.code,{children:\"racecar\"}),\"\\uFF09\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A\",(0,n.jsx)(e.strong,{children:\"\\u5B50\\u4E32\"}),\"\\u662F\\u5B57\\u7B26\\u4E32\\u4E2D\\u4EFB\\u4F55\\u8FDE\\u7EED\\u7684\\u5B57\\u7B26\\u5E8F\\u5217\\u3002\\u4F8B\\u5982\\uFF0C\\u5B57\\u7B26\\u4E32\",(0,n.jsx)(e.code,{children:\"abc\"}),\"\\u7684\\u5B50\\u4E32\\u662F\",(0,n.jsx)(e.code,{children:\"a\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"b\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"c\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"ab\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"bc\"}),\"\\u548C\",(0,n.jsx)(e.code,{children:\"abc\"}),\"\\u3002\\u5B50\\u4E32\\u662F\\u901A\\u8FC7\\u9009\\u62E9\\u4E00\\u4E2A\\u8D77\\u59CB\\u70B9\\u548C\\u4E00\\u4E2A\\u7ED3\\u675F\\u70B9\\u5F62\\u6210\\u7684\\uFF0C\\u4E2D\\u95F4\\u6CA1\\u6709\\u8DF3\\u8FC7\\u5B57\\u7B26\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"str: string\"}),\": \\u5B57\\u7B26\\u4E32\"]}),`\n`]}),`\n`,(0,n.jsx)(l,{testCases:h}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"str.length\"}),\" <= 1000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"str\"}),\" \\u4EC5\\u5305\\u542B\\u5C0F\\u5199\\u82F1\\u6587\\u5B57\\u6BCD\"]}),`\n`]})]})}function D(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(p,r)})):p(r)}var X=D;return T(E);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来计算字符串中所有回文子串的数量", + "title": "回文子串" + }, + "solution": "var Component=(()=>{var m=Object.create;var d=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var x=(i,n)=>()=>(n||i((n={exports:{}}).exports,n),n.exports),C=(i,n)=>{for(var r in n)d(i,r,{get:n[r],enumerable:!0})},o=(i,n,r,h)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let l of w(n))!j.call(i,l)&&l!==r&&d(i,l,{get:()=>n[l],enumerable:!(h=f(n,l))||h.enumerable});return i};var O=(i,n,r)=>(r=i!=null?m(b(i)):{},o(n||!i||!i.__esModule?d(r,\"default\",{value:i,enumerable:!0}):r,i)),P=i=>o(d({},\"__esModule\",{value:!0}),i);var s=x((D,t)=>{t.exports=_jsx_runtime});var k={};C(k,{default:()=>_});var e=O(s());var c=MDXCodeBlock;var a=`export default function countPalindromicSubstrings(str: string): number {\n let ans = 0;\n\n // Iterate through each character in the string\n for (let i = 0; i < str.length; i++) {\n // Count odd-length palindromes with a single character center\n ans += countPalindromesAroundCenter(str, i, i);\n\n // Count even-length palindromes with consecutive characters as the center\n ans += countPalindromesAroundCenter(str, i, i + 1);\n }\n\n return ans;\n}\n\nfunction countPalindromesAroundCenter(\n str: string,\n low: number,\n high: number,\n): number {\n let ans = 0;\n\n // Expand around the center as long as the characters at the edges match\n while (low >= 0 && high < str.length) {\n if (str[low] !== str[high]) {\n break; // Stop if characters don't match\n }\n\n // Expand the window outward\n low--;\n high++;\n\n // Increment the palindrome count\n ans++;\n }\n\n return ans;\n}\n`;var u=`export default function countPalindromicSubstrings(str: string): number {\n const n = str.length;\n let ans = 0;\n\n // If the string is empty, return 0\n if (n === 0) {\n return 0;\n }\n\n // Initialize a 2D array (dp) to store whether substrings are palindromic\n const dp: boolean[][] = Array.from({ length: n }, () => Array(n).fill(false));\n\n // Base case: single letter substrings are always palindromes\n for (let i = 0; i < n; i++) {\n dp[i][i] = true;\n ans++; // Count single letter palindromes\n }\n\n // Base case: check double letter substrings\n for (let i = 0; i < n - 1; i++) {\n dp[i][i + 1] = str[i] === str[i + 1];\n ans += dp[i][i + 1] ? 1 : 0; // Count double letter palindromes\n }\n\n // Check all other substrings of length 3 to n\n for (let len = 3; len <= n; len++) {\n for (let i = 0; i <= n - len; i++) {\n const j = i + len - 1; // Ending index of the substring\n dp[i][j] = dp[i + 1][j - 1] && str[i] === str[j];\n ans += dp[i][j] ? 1 : 0; // Count palindromes of length len\n }\n }\n\n return ans;\n}\n`;var g=`function isPalindrome(str: string, low: number, high: number): boolean {\n // Continue checking as long as the left index is less than the right index\n while (low < high) {\n // If characters at low and high do not match, it's not a palindrome\n if (str[low] !== str[high]) {\n return false;\n }\n // Move towards the center\n low++;\n high--;\n }\n // If all characters matched, it's a palindrome\n return true;\n}\n\nexport default function countPalindromicSubstrings(str: string): number {\n let ans = 0;\n\n // Iterate over all possible starting points of substrings\n for (let low = 0; low < str.length; low++) {\n // Iterate over all possible ending points of substrings starting at low\n for (let high = low; high < str.length; high++) {\n // Increment ans if the substring s[low...high] is a palindrome\n ans += isPalindrome(str, low, high) ? 1 : 0;\n }\n }\n\n return ans;\n}\n`;function p(i){let n=Object.assign({h2:\"h2\",p:\"p\",h3:\"h3\",ol:\"ol\",li:\"li\",code:\"code\",ul:\"ul\",strong:\"strong\",h4:\"h4\"},i.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"1. \\u4F7F\\u7528\\u66B4\\u529B\\u65B9\\u6CD5\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u66B4\\u529B\\u65B9\\u6CD5\\u4F1A\\u68C0\\u67E5\\u6BCF\\u4E2A\\u53EF\\u80FD\\u7684\\u5B50\\u4E32\\uFF0C\\u4EE5\\u786E\\u5B9A\\u5B83\\u662F\\u5426\\u662F\\u56DE\\u6587\\u3002\\u8FD9\\u662F\\u901A\\u8FC7\\u904D\\u5386\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u5B50\\u4E32\\u7684\\u8D77\\u59CB\\u548C\\u7ED3\\u675F\\u7D22\\u5F15\\uFF0C\\u5E76\\u4F7F\\u7528\\u8F85\\u52A9\\u51FD\\u6570\\u6765\\u9A8C\\u8BC1\\u5B50\\u4E32\\u662F\\u5426\\u662F\\u56DE\\u6587\\u6765\\u5B9E\\u73B0\\u7684\\u3002\\u5982\\u679C\\u5B50\\u4E32\\u6B63\\u5411\\u548C\\u53CD\\u5411\\u8BFB\\u53D6\\u76F8\\u540C\\uFF0C\\u5219\\u8BE5\\u5B50\\u4E32\\u662F\\u56DE\\u6587\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5B9A\\u4E49\\u4E00\\u4E2A\\u8F85\\u52A9\\u51FD\\u6570 \",(0,e.jsx)(n.code,{children:\"isPalindrome\"}),\"\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u63A5\\u53D7\\u5B57\\u7B26\\u4E32 \",(0,e.jsx)(n.code,{children:\"str\"}),\"\\u3001\\u8D77\\u59CB\\u7D22\\u5F15 \",(0,e.jsx)(n.code,{children:\"low\"}),\" \\u548C\\u7ED3\\u675F\\u7D22\\u5F15 \",(0,e.jsx)(n.code,{children:\"high\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"while\"}),\" \\u5FAA\\u73AF\\u6BD4\\u8F83 \",(0,e.jsx)(n.code,{children:\"low\"}),\" \\u548C \",(0,e.jsx)(n.code,{children:\"high\"}),\" \\u5904\\u7684\\u5B57\\u7B26\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5982\\u679C\\u5B57\\u7B26\\u4E0D\\u5339\\u914D\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,e.jsx)(n.code,{children:\"false\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u9012\\u589E \",(0,e.jsx)(n.code,{children:\"low\"}),\" \\u5E76\\u9012\\u51CF \",(0,e.jsx)(n.code,{children:\"high\"}),\" \\u4EE5\\u5411\\u4E2D\\u5FC3\\u79FB\\u52A8\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5982\\u679C\\u6240\\u6709\\u5B57\\u7B26\\u90FD\\u5339\\u914D\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,e.jsx)(n.code,{children:\"true\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u53D8\\u91CF \",(0,e.jsx)(n.code,{children:\"ans\"}),\" \\u6765\\u5B58\\u50A8\\u56DE\\u6587\\u5B50\\u4E32\\u7684\\u8BA1\\u6570\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528\\u5D4C\\u5957\\u5FAA\\u73AF\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5916\\u5FAA\\u73AF\\u904D\\u5386\\u5B50\\u4E32\\u7684\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u8D77\\u59CB\\u7D22\\u5F15 \",(0,e.jsx)(n.code,{children:\"low\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5185\\u5FAA\\u73AF\\u904D\\u5386\\u5F53\\u524D\\u8D77\\u59CB\\u7D22\\u5F15\\u7684\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u7ED3\\u675F\\u7D22\\u5F15 \",(0,e.jsx)(n.code,{children:\"high\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E00\\u5BF9\\u7D22\\u5F15\\uFF0C\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"isPalindrome\"}),\" \\u51FD\\u6570\\u68C0\\u67E5\\u5B50\\u4E32\\u662F\\u5426\\u662F\\u56DE\\u6587\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5982\\u679C\\u5B50\\u4E32\\u662F\\u56DE\\u6587\\uFF0C\\u5219\\u5C06 \",(0,e.jsx)(n.code,{children:\"ans\"}),\" \\u589E\\u52A0 \",(0,e.jsx)(n.code,{children:\"1\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5C06 \",(0,e.jsx)(n.code,{children:\"ans\"}),\" \\u7684\\u503C\\u4F5C\\u4E3A\\u56DE\\u6587\\u5B50\\u4E32\\u7684\\u603B\\u6570\\u8FD4\\u56DE\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(c,{children:g}),`\n`,(0,e.jsx)(n.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsxs)(n.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,e.jsx)(\"sup\",{children:\"3\"}),\")\"]}),\"\\u3002\\u6709 O(n\",(0,e.jsx)(\"sup\",{children:\"2\"}),\") \\u4E2A\\u5B50\\u4E32\\uFF0C\\u5E76\\u4E14\\u68C0\\u67E5\\u6BCF\\u4E2A\\u5B50\\u4E32\\u662F\\u5426\\u4E3A\\u56DE\\u6587\\u9700\\u8981 O(n) \\u65F6\\u95F4\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u9664\\u4E86\\u8F93\\u5165\\u5B57\\u7B26\\u4E32\\u548C\\u5FAA\\u73AF\\u53D8\\u91CF\\u5916\\uFF0C\\u8BE5\\u7B97\\u6CD5\\u4F7F\\u7528\\u6052\\u5B9A\\u7A7A\\u95F4\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"2. \\u4F7F\\u7528\\u52A8\\u6001\\u89C4\\u5212\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u52A8\\u6001\\u89C4\\u5212\\u65B9\\u6CD5\\u901A\\u8FC7\\u907F\\u514D\\u91CD\\u590D\\u68C0\\u67E5\\u91CD\\u53E0\\u7684\\u5B50\\u4E32\\u6765\\u6539\\u8FDB\\u6734\\u7D20\\u7684\\u66B4\\u529B\\u65B9\\u6CD5\\u3002\\u5173\\u952E\\u7684\\u76F4\\u89C9\\u662F\\uFF0C\\u5982\\u679C\\u4E00\\u4E2A\\u5B50\\u4E32\\u7684\\u4E24\\u4E2A\\u6700\\u5916\\u9762\\u7684\\u5B57\\u7B26\\u76F8\\u540C\\uFF0C\\u5E76\\u4E14\\u5185\\u90E8\\u5B50\\u4E32\\uFF08\\u4E0D\\u5305\\u62EC\\u5916\\u90E8\\u5B57\\u7B26\\uFF09\\u4E5F\\u662F\\u56DE\\u6587\\uFF0C\\u5219\\u8BE5\\u5B50\\u4E32\\u662F\\u56DE\\u6587\\u3002\\u4F7F\\u7528\\u52A8\\u6001\\u89C4\\u5212\\u8868\\u53EF\\u4EE5\\u6709\\u6548\\u5730\\u6355\\u83B7\\u6B64\\u9012\\u5F52\\u5C5E\\u6027\\u3002\"}),`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.code,{children:\"dp\"}),\" \\u8868\\u5B58\\u50A8\\u4E86\\u4EE5\\u7D22\\u5F15 \",(0,e.jsx)(n.code,{children:\"i\"}),\" \\u5F00\\u5934\\u5E76\\u4EE5\\u7D22\\u5F15 \",(0,e.jsx)(n.code,{children:\"j\"}),\" \\u7ED3\\u5C3E\\u7684\\u5B50\\u4E32\\u662F\\u5426\\u662F\\u56DE\\u6587\\u3002\\u8FD9\\u901A\\u8FC7\\u4ECE\\u8F83\\u5C0F\\u7684\\u5B50\\u4E32\\u5F00\\u59CB\\u5E76\\u4F7F\\u7528\\u5B83\\u4EEC\\u7684\\u7ED3\\u679C\\u6765\\u6C42\\u89E3\\u8F83\\u5927\\u7684\\u5B50\\u4E32\\uFF0C\\u4ECE\\u800C\\u6D88\\u9664\\u4E86\\u5197\\u4F59\\u7684\\u91CD\\u65B0\\u8BA1\\u7B97\\u3002\"]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u901A\\u8FC7\\u8FD4\\u56DE \",(0,e.jsx)(n.code,{children:\"0\"}),\" \\u6765\\u5904\\u7406\\u7A7A\\u5B57\\u7B26\\u4E32\\u7684\\u57FA\\u672C\\u60C5\\u51B5\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u5927\\u5C0F\\u4E3A \",(0,e.jsx)(n.code,{children:\"n x n\"}),\" \\u7684\\u4E8C\\u7EF4\\u6570\\u7EC4 \",(0,e.jsx)(n.code,{children:\"dp\"}),\"\\uFF0C\\u5E76\\u5C06\\u6240\\u6709\\u503C\\u8BBE\\u7F6E\\u4E3A \",(0,e.jsx)(n.code,{children:\"false\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u904D\\u5386\\u957F\\u5EA6\\u4E3A \",(0,e.jsx)(n.code,{children:\"1\"}),\" \\u7684\\u5B50\\u4E32\\u7684\\u5B57\\u7B26\\u4E32\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5BF9\\u4E8E\\u6240\\u6709\\u7D22\\u5F15 \",(0,e.jsx)(n.code,{children:\"i\"}),\"\\uFF0C\\u5C06 \",(0,e.jsx)(n.code,{children:\"dp[i][i]\"}),\" \\u8BBE\\u7F6E\\u4E3A \",(0,e.jsx)(n.code,{children:\"true\"}),\"\\uFF0C\\u56E0\\u4E3A\\u5355\\u5B57\\u7B26\\u5B50\\u4E32\\u59CB\\u7EC8\\u662F\\u56DE\\u6587\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u589E\\u52A0\\u6BCF\\u4E2A\\u5355\\u5B57\\u7B26\\u56DE\\u6587\\u7684\\u8BA1\\u6570 \",(0,e.jsx)(n.code,{children:\"ans\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u904D\\u5386\\u957F\\u5EA6\\u4E3A \",(0,e.jsx)(n.code,{children:\"2\"}),\" \\u7684\\u5B50\\u4E32\\u7684\\u5B57\\u7B26\\u4E32\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5982\\u679C\\u7D22\\u5F15 \",(0,e.jsx)(n.code,{children:\"i\"}),\" \\u548C \",(0,e.jsx)(n.code,{children:\"i + 1\"}),\" \\u5904\\u7684\\u4E24\\u4E2A\\u5B57\\u7B26\\u76F8\\u7B49\\uFF0C\\u5219\\u5C06 \",(0,e.jsx)(n.code,{children:\"dp[i][i + 1]\"}),\" \\u8BBE\\u7F6E\\u4E3A \",(0,e.jsx)(n.code,{children:\"true\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u589E\\u52A0\\u6BCF\\u4E2A\\u53CC\\u5B57\\u7B26\\u56DE\\u6587\\u7684\\u8BA1\\u6570 \",(0,e.jsx)(n.code,{children:\"ans\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528\\u5D4C\\u5957\\u5FAA\\u73AF\\u6765\\u8BC4\\u4F30\\u957F\\u5EA6\\u4E3A \",(0,e.jsx)(n.code,{children:\"3\"}),\" \\u6216\\u66F4\\u5927\\u7684\\u5B50\\u4E32\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5BF9\\u4E8E\\u4EE5\\u7D22\\u5F15 \",(0,e.jsx)(n.code,{children:\"i\"}),\" \\u5F00\\u5934\\u5E76\\u4EE5\\u7D22\\u5F15 \",(0,e.jsx)(n.code,{children:\"j\"}),\" \\u7ED3\\u5C3E\\u7684\\u6BCF\\u4E2A\\u5B50\\u4E32\\uFF0C\\u5982\\u679C\\u6EE1\\u8DB3\\u4EE5\\u4E0B\\u6761\\u4EF6\\uFF0C\\u5219\\u5C06 \",(0,e.jsx)(n.code,{children:\"dp[i][j]\"}),\" \\u8BBE\\u7F6E\\u4E3A \",(0,e.jsx)(n.code,{children:\"true\"}),\"\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"i\"}),\" \\u548C \",(0,e.jsx)(n.code,{children:\"j\"}),\" \\u5904\\u7684\\u5B57\\u7B26\\u76F8\\u540C\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"i\"}),\" \\u548C \",(0,e.jsx)(n.code,{children:\"j\"}),\" \\u4E4B\\u95F4\\u7684\\u5B50\\u4E32 (\",(0,e.jsx)(n.code,{children:\"dp[i + 1][j - 1]\"}),\") \\u4E5F\\u662F\\u56DE\\u6587\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u589E\\u52A0\\u627E\\u5230\\u7684\\u6BCF\\u4E2A\\u56DE\\u6587\\u7684\\u8BA1\\u6570 \",(0,e.jsx)(n.code,{children:\"ans\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5C06 \",(0,e.jsx)(n.code,{children:\"ans\"}),\" \\u4F5C\\u4E3A\\u56DE\\u6587\\u5B50\\u4E32\\u7684\\u603B\\u6570\\u8FD4\\u56DE\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(c,{children:u}),`\n`,(0,e.jsx)(n.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsxs)(n.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,e.jsx)(\"sup\",{children:\"2\"}),\")\"]}),\"\\u3002\\u5916\\u5FAA\\u73AF\\u904D\\u5386\\u5B50\\u4E32\\u957F\\u5EA6\\uFF0C\\u5185\\u5FAA\\u73AF\\u904D\\u5386\\u5B50\\u4E32\\u7684\\u6240\\u6709\\u8D77\\u59CB\\u7D22\\u5F15\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsxs)(n.strong,{children:[\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,e.jsx)(\"sup\",{children:\"2\"}),\")\"]}),\"\\u3002\",(0,e.jsx)(n.code,{children:\"dp\"}),\" \\u8868\\u9700\\u8981 O(n\",(0,e.jsx)(\"sup\",{children:\"2\"}),\") \\u7A7A\\u95F4\\u6765\\u5B58\\u50A8\\u6240\\u6709\\u5B50\\u4E32\\u7684\\u7ED3\\u679C\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"3. \\u4F7F\\u7528\\u56DE\\u6587\\u7684\\u4E2D\\u5FC3\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u4ECE\\u4E2D\\u5FC3\\u6269\\u5C55\\u65B9\\u6CD5\\u901A\\u8FC7\\u5173\\u6CE8\\u56DE\\u6587\\u7684\\u6F5C\\u5728\\u4E2D\\u5FC3\\u6765\\u4F18\\u5316\\u67E5\\u627E\\u6240\\u6709\\u56DE\\u6587\\u5B50\\u4E32\\u7684\\u8FC7\\u7A0B\\u3002\\u5173\\u952E\\u7684\\u76F4\\u89C9\\u662F\\uFF0C\\u6BCF\\u4E2A\\u56DE\\u6587\\u90FD\\u53EF\\u4EE5\\u4ECE\\u5176\\u4E2D\\u5FC3\\u5411\\u5916\\u6269\\u5C55\\u3002\\u4E2D\\u5FC3\\u53EF\\u4EE5\\u662F\\u5355\\u4E2A\\u5B57\\u7B26\\uFF08\\u5BF9\\u4E8E\\u5947\\u6570\\u957F\\u5EA6\\u7684\\u56DE\\u6587\\uFF09\\u6216\\u4E00\\u5BF9\\u8FDE\\u7EED\\u5B57\\u7B26\\uFF08\\u5BF9\\u4E8E\\u5076\\u6570\\u957F\\u5EA6\\u7684\\u56DE\\u6587\\uFF09\\u3002\\u901A\\u8FC7\\u4ECE\\u6BCF\\u4E2A\\u4E2D\\u5FC3\\u8FED\\u4EE3\\u5730\\u6269\\u5C55\\uFF0C\\u8FD9\\u79CD\\u65B9\\u6CD5\\u907F\\u514D\\u4E86\\u5197\\u4F59\\u8BA1\\u7B97\\uFF0C\\u5E76\\u4E14\\u4E0D\\u9700\\u8981\\u4F7F\\u7528\\u989D\\u5916\\u7684\\u7A7A\\u95F4\\u6765\\u5B58\\u50A8\\u52A8\\u6001\\u89C4\\u5212\\u8868\\u3002\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u6B64\\u65B9\\u6CD5\\u901A\\u8FC7\\u51CF\\u5C11\\u7A7A\\u95F4\\u4F7F\\u7528\\u6765\\u6539\\u8FDB\\u5148\\u524D\\u52A8\\u6001\\u89C4\\u5212\\u65B9\\u6CD5\\u3002\\u5B83\\u6CA1\\u6709\\u9884\\u5148\\u8BA1\\u7B97\\u6240\\u6709\\u53EF\\u80FD\\u957F\\u5EA6\\u7684\\u56DE\\u6587\\u5B50\\u4E32\\uFF0C\\u800C\\u662F\\u5728\\u6269\\u5C55\\u8FC7\\u7A0B\\u4E2D\\u76F4\\u63A5\\u8BA1\\u7B97\\u56DE\\u6587\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u53D8\\u91CF \",(0,e.jsx)(n.code,{children:\"ans\"}),\" \\u6765\\u5B58\\u50A8\\u56DE\\u6587\\u5B50\\u4E32\\u7684\\u603B\\u6570\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u904D\\u5386\\u5B57\\u7B26\\u4E32\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5B57\\u7B26\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5C06\\u5F53\\u524D\\u7D22\\u5F15\\u5904\\u7684\\u5B57\\u7B26\\u89C6\\u4E3A\\u5947\\u6570\\u957F\\u5EA6\\u56DE\\u6587\\u7684\\u4E2D\\u5FC3\\uFF0C\\u5E76\\u4F7F\\u7528\\u76F8\\u540C\\u7684\\u8D77\\u59CB\\u548C\\u7ED3\\u675F\\u7D22\\u5F15\\u8C03\\u7528\\u8F85\\u52A9\\u51FD\\u6570 \",(0,e.jsx)(n.code,{children:\"countPalindromesAroundCenter\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5C06\\u5F53\\u524D\\u5B57\\u7B26\\u548C\\u4E0B\\u4E00\\u4E2A\\u5B57\\u7B26\\u89C6\\u4E3A\\u5076\\u6570\\u957F\\u5EA6\\u56DE\\u6587\\u7684\\u4E2D\\u5FC3\\uFF0C\\u5E76\\u4F7F\\u7528\\u8FDE\\u7EED\\u7D22\\u5F15\\u4F5C\\u4E3A\\u8D77\\u59CB\\u548C\\u7ED3\\u675F\\u70B9\\u8C03\\u7528\\u8F85\\u52A9\\u51FD\\u6570 \",(0,e.jsx)(n.code,{children:\"countPalindromesAroundCenter\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5C06 \",(0,e.jsx)(n.code,{children:\"ans\"}),\" \\u4F5C\\u4E3A\\u56DE\\u6587\\u5B50\\u4E32\\u7684\\u603B\\u6570\\u8FD4\\u56DE\\u3002\"]}),`\n`]}),`\n`,(0,e.jsxs)(n.h4,{children:[\"\\u8F85\\u52A9\\u51FD\\u6570\\uFF1A\",(0,e.jsx)(n.code,{children:\"countPalindromesAroundCenter\"})]}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u63A5\\u53D7\\u5B57\\u7B26\\u4E32\",(0,e.jsx)(n.code,{children:\"str\"}),\"\\u3001\\u8D77\\u59CB\\u7D22\\u5F15\",(0,e.jsx)(n.code,{children:\"low\"}),\"\\u548C\\u7ED3\\u675F\\u7D22\\u5F15\",(0,e.jsx)(n.code,{children:\"high\"}),\"\\u4F5C\\u4E3A\\u8F93\\u5165\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u53D8\\u91CF\",(0,e.jsx)(n.code,{children:\"ans\"}),\"\\uFF0C\\u7528\\u4E8E\\u5B58\\u50A8\\u6269\\u5C55\\u8FC7\\u7A0B\\u4E2D\\u627E\\u5230\\u7684\\u56DE\\u6587\\u4E32\\u7684\\u8BA1\\u6570\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4F7F\\u7528\",(0,e.jsx)(n.code,{children:\"while\"}),\"\\u5FAA\\u73AF\\u5411\\u5916\\u6269\\u5C55\\uFF0C\\u53EA\\u8981\\uFF1A\",`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"\\u7D22\\u5F15\",(0,e.jsx)(n.code,{children:\"low\"}),\"\\u548C\",(0,e.jsx)(n.code,{children:\"high\"}),\"\\u5728\\u5B57\\u7B26\\u4E32\\u7684\\u8303\\u56F4\\u5185\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"low\"}),\"\\u548C\",(0,e.jsx)(n.code,{children:\"high\"}),\"\\u5904\\u7684\\u5B57\\u7B26\\u5339\\u914D\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u6709\\u6548\\u56DE\\u6587\\u4E32\\uFF0C\\u9012\\u589E\",(0,e.jsx)(n.code,{children:\"ans\"}),\"\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u9012\\u51CF\",(0,e.jsx)(n.code,{children:\"low\"}),\"\\u5E76\\u9012\\u589E\",(0,e.jsx)(n.code,{children:\"high\"}),\"\\u4EE5\\u7EE7\\u7EED\\u6269\\u5C55\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u8FD4\\u56DE\\u8BA1\\u6570\",(0,e.jsx)(n.code,{children:\"ans\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,e.jsxs)(c,{children:[\" \",a,\" \"]}),`\n`,(0,e.jsx)(n.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsxs)(n.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,e.jsx)(\"sup\",{children:\"2\"}),\")\"]}),\"\\u3002\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u5B57\\u7B26\\uFF0C\\u6269\\u5C55\\u5728\\u6700\\u574F\\u7684\\u60C5\\u51B5\\u4E0B\\u53EF\\u4EE5\\u8DE8\\u8D8A\\u6574\\u4E2A\\u5B57\\u7B26\\u4E32\\uFF0C\\u5BFC\\u81F4O(n)\\u4E2A\\u4E2D\\u5FC3\\u6709O(n)\\u6B21\\u6269\\u5C55\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002\\u8BE5\\u7B97\\u6CD5\\u4F7F\\u7528\\u5E38\\u91CF\\u989D\\u5916\\u7A7A\\u95F4\\u7528\\u4E8E\\u53D8\\u91CF\\uFF0C\\u4E0D\\u9700\\u8981\\u989D\\u5916\\u7684\\u6570\\u636E\\u7ED3\\u6784\\u3002\"]}),`\n`]})]})}function S(i={}){let{wrapper:n}=i.components||{};return n?(0,e.jsx)(n,Object.assign({},i,{children:(0,e.jsx)(p,i)})):p(i)}var _=S;return P(k);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/string-segment-words/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/string-segment-words/locales/zh-CN.json new file mode 100644 index 000000000..bf5bd4d6c --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/string-segment-words/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var i=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var b=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),j=(t,e)=>{for(var c in e)i(t,c,{get:e[c],enumerable:!0})},l=(t,e,c,d)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of m(e))!f.call(t,r)&&r!==c&&i(t,r,{get:()=>e[r],enumerable:!(d=g(e,r))||d.enumerable});return t};var _=(t,e,c)=>(c=t!=null?p(x(t)):{},l(e||!t||!t.__esModule?i(c,\"default\",{value:t,enumerable:!0}):c,t)),T=t=>l(i({},\"__esModule\",{value:!0}),t);var s=b((E,o)=>{o.exports=_jsx_runtime});var w={};j(w,{default:()=>X,frontmatter:()=>C});var n=_(s());var a=MDXTestExamples;var h=[{input:[[\"str\",\"greatfrontendgreat\"],[\"dict\",[\"frontend\",\"great\"]]],output:!0,explanation:\"The string can be segmented as 'great' + 'frontend' + 'great' as we can re-use 'great'.\"},{input:[[\"str\",\"abcd\"],[\"dict\",[\"a\",\"abc\",\"b\",\"cd\"]]],output:!0,explanation:\"The string can be segmented as 'a' + 'b' + 'cd'.\"},{input:[[\"str\",\"a\"],[\"dict\",[\"b\"]]],output:!1,explanation:\"The single character 'a' is not in the word dictionary.\"}];var C={title:\"\\u5355\\u8BCD\\u5206\\u5272\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u68C0\\u67E5\\u4E00\\u4E2A\\u5B57\\u7B26\\u4E32\\u662F\\u5426\\u53EF\\u4EE5\\u7531\\u5B57\\u5178\\u4E2D\\u7684\\u5355\\u8BCD\\u7EC4\\u6210\"};function u(t){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u5B57\\u7B26\\u4E32\",(0,n.jsx)(e.code,{children:\"str\"}),\"\\u548C\\u4E00\\u4E2A\\u5355\\u8BCD\\u5217\\u8868\",(0,n.jsx)(e.code,{children:\"dict\"}),\"\\uFF0C\\u786E\\u5B9A\",(0,n.jsx)(e.code,{children:\"str\"}),\"\\u662F\\u5426\\u53EF\\u4EE5\\u88AB\\u5206\\u5272\\u6210\\u6765\\u81EA\",(0,n.jsx)(e.code,{children:\"dict\"}),\"\\u7684\\u4E00\\u4E2A\\u6216\\u591A\\u4E2A\\u5355\\u8BCD\\u7684\\u5E8F\\u5217\\u3002\\u6765\\u81EA\",(0,n.jsx)(e.code,{children:\"dict\"}),\"\\u7684\\u5355\\u8BCD\\u53EF\\u4EE5\\u5728\\u5206\\u5272\\u4E2D\\u91CD\\u590D\\u4F7F\\u7528\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5982\\u679C\\u53EF\\u4EE5\\u5206\\u5272\",(0,n.jsx)(e.code,{children:\"str\"}),\"\\uFF0C\\u5219\\u8FD4\\u56DE\",(0,n.jsx)(e.code,{children:\"true\"}),\"\\uFF0C\\u5426\\u5219\\u8FD4\\u56DE\",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"str: string\"}),\": \\u4E00\\u4E2A\\u8868\\u793A\\u8981\\u5206\\u5272\\u7684\\u5B57\\u7B26\\u4E32\\u7684\\u5B57\\u7B26\\u4E32\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"dict: string[]\"}),\": \\u4E00\\u4E2A\\u8868\\u793A\\u53EF\\u7528\\u5355\\u8BCD\\u5B57\\u5178\\u7684\\u5B57\\u7B26\\u4E32\\u6570\\u7EC4\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u6CE8\\u610F\\u4E8B\\u9879\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u6765\\u81EA\",(0,n.jsx)(e.code,{children:\"dict\"}),\"\\u7684\\u5355\\u8BCD\\u53EF\\u4EE5\\u5728\\u5206\\u5272\\u4E2D\\u591A\\u6B21\\u4F7F\\u7528\"]}),`\n`]}),`\n`,(0,n.jsx)(a,{testCases:h}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"str.length\"}),\" <= 300\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"0 <= \",(0,n.jsx)(e.code,{children:\"dict.length\"}),\" <= 300\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"0 <= \",(0,n.jsx)(e.code,{children:\"dict[i].length\"}),\" <= 300\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"str\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"dict[i]\"}),\" \\u4EC5\\u7531\\u5C0F\\u5199\\u82F1\\u6587\\u5B57\\u6BCD\\u7EC4\\u6210\"]}),`\n`]})]})}function D(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(u,t)})):u(t)}var X=D;return T(w);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数来检查一个字符串是否可以由字典中的单词组成", + "title": "单词分割" + }, + "solution": "var Component=(()=>{var g=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var O=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),w=(r,e)=>{for(var d in e)i(r,d,{get:e[d],enumerable:!0})},s=(r,e,d,l)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let t of m(e))!k.call(r,t)&&t!==d&&i(r,t,{get:()=>e[t],enumerable:!(l=p(e,t))||l.enumerable});return r};var S=(r,e,d)=>(d=r!=null?g(b(r)):{},s(e||!r||!r.__esModule?i(d,\"default\",{value:r,enumerable:!0}):d,r)),x=r=>s(i({},\"__esModule\",{value:!0}),r);var h=O((j,o)=>{o.exports=_jsx_runtime});var F={};w(F,{default:()=>C});var n=S(h());var c=MDXCodeBlock;var a=`export default function segmentWords(str: string, dict: string[]): boolean {\n // Create a set from the word dictionary for quick lookup\n const dictSet = new Set(dict);\n\n // Create a DP array initialized to false, with an extra space for the base case\n const dp: boolean[] = new Array(str.length + 1).fill(false);\n dp[0] = true; // Base case: an empty string can always be segmented\n\n // Iterate over the end positions of the substring\n for (let end = 1; end <= str.length; end++) {\n // Iterate over the start positions of the substring\n for (let start = 0; start < end; start++) {\n // If the substring from start to end can be segmented\n if (dp[start] && dictSet.has(str.substring(start, end))) {\n dp[end] = true; // Mark the end position as true\n break; // No need to check further start positions for this end\n }\n }\n }\n\n // The last element in dp represents whether the entire string can be segmented\n return dp[str.length];\n}\n`;var u=`export default function segmentWords(str: string, dict: string[]): boolean {\n // Convert dict to a set for O(1) average time complexity lookups\n const words = new Set(dict);\n\n // Check for empty string as a base case\n if (str.length === 0) return true;\n\n // Initialize variables\n const queue: number[] = [0];\n const seen = new Set();\n\n // Breadth-first search loop\n while (queue.length !== 0) {\n // Check if queue is empty before dequeueing\n if (queue.length === 0) return false; // String cannot be formed from words\n\n const start = queue.shift()!; // Use non-null assertion after the check\n\n // If we reached the end of the string, return true\n if (start === str.length) return true;\n\n // Iterate over all possible end indices from start + 1 to end of string\n for (let end = start + 1; end <= str.length; end++) {\n // Skip already processed end indices\n if (seen.has(end)) continue;\n\n // Check if substring from start to end exists in dict\n if (words.has(str.substring(start, end))) {\n // If found, enqueue the end index and mark as visited\n queue.push(end);\n seen.add(end);\n }\n }\n }\n\n // If no segmentation found, return false\n return false;\n}\n`;function f(r){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u52A8\\u6001\\u89C4\\u5212\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u52A8\\u6001\\u89C4\\u5212\\u65B9\\u6CD5\\u901A\\u8FC7\\u5C06\\u5B57\\u7B26\\u4E32\\u5206\\u5272\\u6210\\u66F4\\u5C0F\\u7684\\u5B50\\u95EE\\u9898\\u6765\\u89E3\\u51B3\\u5C06\\u5B57\\u7B26\\u4E32\\u5206\\u5272\\u6210\\u7ED9\\u5B9A\\u5B57\\u5178\\u4E2D\\u7684\\u5355\\u8BCD\\u7684\\u95EE\\u9898\\u3002 \\u5173\\u952E\\u7684\\u76F4\\u89C9\\u662F\\uFF0C\\u5982\\u679C\\u5B57\\u7B26\\u4E32\\u7684\\u524D\\u7F00\\u53EF\\u4EE5\\u88AB\\u5206\\u5272\\uFF0C\\u5E76\\u4E14\\u5269\\u4F59\\u7684\\u5B50\\u5B57\\u7B26\\u4E32\\u5B58\\u5728\\u4E8E\\u5B57\\u5178\\u4E2D\\uFF0C\\u90A3\\u4E48\\u6574\\u4E2A\\u5B57\\u7B26\\u4E32\\u5C31\\u53EF\\u4EE5\\u88AB\\u5206\\u5272\\u3002 \\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u6570\\u7EC4\\u6765\\u5B58\\u50A8\\u4EE5\\u6BCF\\u4E2A\\u4F4D\\u7F6E\\u7ED3\\u5C3E\\u7684\\u5B50\\u5B57\\u7B26\\u4E32\\u662F\\u5426\\u53EF\\u4EE5\\u88AB\\u5206\\u5272\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:\"dp[i]\"}),\" \\u8868\\u793A\\u5B50\\u5B57\\u7B26\\u4E32 \",(0,n.jsx)(e.code,{children:\"str[0...i-1]\"}),\" \\u662F\\u5426\\u53EF\\u4EE5\\u88AB\\u5206\\u5272\\u6210\\u5B57\\u5178\\u4E2D\\u7684\\u6709\\u6548\\u5355\\u8BCD\\u3002 \\u8FD9\\u79CD\\u65B9\\u6CD5\\u786E\\u4FDD\\u4E86\\u91CD\\u53E0\\u7684\\u5B50\\u95EE\\u9898\\u53EA\\u88AB\\u89E3\\u51B3\\u4E00\\u6B21\\uFF0C\\u907F\\u514D\\u4E86\\u5197\\u4F59\\u7684\\u8BA1\\u7B97\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u5355\\u8BCD\\u5B57\\u5178\\u8F6C\\u6362\\u4E3A \",(0,n.jsx)(e.code,{children:\"Set\"}),\" \\u4EE5\\u4FBF\\u5FEB\\u901F\\u67E5\\u627E\\u5355\\u8BCD\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521B\\u5EFA\\u4E00\\u4E2A\\u5927\\u5C0F\\u4E3A \",(0,n.jsx)(e.code,{children:\"str.length + 1\"}),\" \\u7684 \",(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u6570\\u7EC4\\uFF0C\\u5E76\\u521D\\u59CB\\u5316\\u4E3A \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"dp[0]\"}),\" \\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\uFF0C\\u56E0\\u4E3A\\u7A7A\\u5B57\\u7B26\\u4E32\\u603B\\u662F\\u53EF\\u4EE5\\u88AB\\u5206\\u5272\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u5B57\\u7B26\\u4E32\\u4EE5\\u68C0\\u67E5\\u4EE5\\u6BCF\\u4E2A\\u4F4D\\u7F6E \",(0,n.jsx)(e.code,{children:\"end\"}),\" \\u7ED3\\u5C3E\\u7684\\u5B50\\u5B57\\u7B26\\u4E32\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A \",(0,n.jsx)(e.code,{children:\"end\"}),\"\\uFF0C\\u904D\\u5386\\u5B50\\u5B57\\u7B26\\u4E32\\u7684\\u53EF\\u80FD\\u8D77\\u59CB\\u4F4D\\u7F6E \",(0,n.jsx)(e.code,{children:\"start\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u5B50\\u5B57\\u7B26\\u4E32 \",(0,n.jsx)(e.code,{children:\"str[start...end-1]\"}),\" \\u662F\\u5426\\u5B58\\u5728\\u4E8E\\u5B57\\u5178\\u4E2D\\uFF0C\\u4EE5\\u53CA \",(0,n.jsx)(e.code,{children:\"dp[start]\"}),\" \\u662F\\u5426\\u4E3A \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u4E24\\u4E2A\\u6761\\u4EF6\\u90FD\\u6EE1\\u8DB3\\uFF0C\\u5219\\u5C06 \",(0,n.jsx)(e.code,{children:\"dp[end]\"}),\" \\u8BBE\\u7F6E\\u4E3A \",(0,n.jsx)(e.code,{children:\"true\"}),\" \\u5E76\\u8DF3\\u51FA\\u5185\\u5FAA\\u73AF\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"dp[str.length]\"}),\" \\u7684\\u503C\\uFF0C\\u8BE5\\u503C\\u6307\\u793A\\u6574\\u4E2A\\u5B57\\u7B26\\u4E32\\u662F\\u5426\\u53EF\\u4EE5\\u88AB\\u5206\\u5272\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(c,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n.m.k)\"}),\"\\u3002 \\u68C0\\u67E5\\u5B50\\u5B57\\u7B26\\u4E32\\u662F\\u5426\\u5B58\\u5728\\u4E8E\\u5B57\\u5178\\u4E2D\\u7684\\u6210\\u672C\\u4E3A O(m.k)\\uFF0C\\u5176\\u4E2D \",(0,n.jsx)(e.code,{children:\"m\"}),\" \\u662F\\u5B57\\u5178\\u7684\\u5927\\u5C0F\\uFF0C\",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u662F\\u5E73\\u5747\\u5355\\u8BCD\\u957F\\u5EA6\\u3002 \\u7531\\u4E8E\\u6709 O(n) \\u4E2A\\u72B6\\u6001\\u9700\\u8981\\u8BA1\\u7B97\\uFF0C\\u56E0\\u6B64\\u603B\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3A O(n.m.k)\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002 \",(0,n.jsx)(e.code,{children:\"dp\"}),\" \\u6570\\u7EC4\\u9700\\u8981 O(n) \\u7A7A\\u95F4\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528 BFS\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5E7F\\u5EA6\\u4F18\\u5148\\u641C\\u7D22 (BFS) \\u65B9\\u6CD5\\u901A\\u8FC7\\u5C06\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u5206\\u5272\\u4F5C\\u4E3A\\u56FE\\u4E2D\\u7684\\u5C42\\u6765\\u89E3\\u51B3\\u5B57\\u7B26\\u4E32\\u5206\\u5272\\u95EE\\u9898\\u3002 \\u5173\\u952E\\u7684\\u76F4\\u89C9\\u662F\\uFF0C\\u8BE5\\u95EE\\u9898\\u53EF\\u4EE5\\u8868\\u793A\\u4E3A\\u4ECE\\u5B57\\u7B26\\u4E32\\u7684\\u5F00\\u5934\\u5230\\u7ED3\\u5C3E\\u7684\\u5BFC\\u822A\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u6709\\u6548\\u7684\\u5B50\\u5B57\\u7B26\\u4E32\\u5BF9\\u5E94\\u4E8E\\u8FDE\\u63A5\\u4E24\\u4E2A\\u8282\\u70B9\\uFF08\\u7D22\\u5F15\\uFF09\\u7684\\u8FB9\\u3002 \\u4F7F\\u7528\\u961F\\u5217\\u6267\\u884C BFS\\uFF0C\\u4ECE\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"0\"}),\" \\u5F00\\u59CB\\uFF0C\\u5E76\\u63A2\\u7D22\\u5B57\\u5178\\u4E2D\\u5B58\\u5728\\u7684\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u5B50\\u5B57\\u7B26\\u4E32\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"BFS \\u7684\\u4F7F\\u7528\\u786E\\u4FDD\\u4E86\\u89E3\\u51B3\\u65B9\\u6848\\u7CFB\\u7EDF\\u5730\\u68C0\\u67E5\\u6240\\u6709\\u6709\\u6548\\u8DEF\\u5F84\\u3002 \\u4E3A\\u4E86\\u9632\\u6B62\\u5197\\u4F59\\u8BA1\\u7B97\\uFF0C\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"seen\"}),\" \\u96C6\\u5408\\u6765\\u8DDF\\u8E2A\\u5DF2\\u8BBF\\u95EE\\u7684\\u7D22\\u5F15\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u5B57\\u5178 \",(0,n.jsx)(e.code,{children:\"dict\"}),\" \\u8F6C\\u6362\\u4E3A \",(0,n.jsx)(e.code,{children:\"Set\"}),\"\\uFF0C\\u4EE5\\u5B9E\\u73B0 O(1) \\u5E73\\u5747\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u67E5\\u627E\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u5B57\\u7B26\\u4E32\\u4E3A\\u7A7A\\u7684\\u57FA\\u672C\\u60C5\\u51B5\\u3002 \\u5982\\u679C\\u5B57\\u7B26\\u4E32\\u4E3A\\u7A7A\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u8D77\\u59CB\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"0\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"seen\"}),\" \\u96C6\\u5408\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u961F\\u5217\\uFF0C\\u4EE5\\u8DDF\\u8E2A\\u5DF2\\u8BBF\\u95EE\\u7684\\u7D22\\u5F15\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u6267\\u884C BFS\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u51FA\\u961F\\u961F\\u5217\\u7684\\u524D\\u4E00\\u4E2A\\u5143\\u7D20\\uFF0C\\u8868\\u793A\\u5F53\\u524D\\u7684\\u8D77\\u59CB\\u7D22\\u5F15\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u8D77\\u59CB\\u7D22\\u5F15\\u7B49\\u4E8E\\u5B57\\u7B26\\u4E32\\u7684\\u957F\\u5EA6\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\uFF0C\\u56E0\\u4E3A\\u5B57\\u7B26\\u4E32\\u53EF\\u4EE5\\u88AB\\u5206\\u5272\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u4ECE \",(0,n.jsx)(e.code,{children:\"start + 1\"}),\" \\u5230 \",(0,n.jsx)(e.code,{children:\"str.length\"}),\" \\u7684\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u7ED3\\u675F\\u7D22\\u5F15\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8DF3\\u8FC7\\u5DF2\\u7ECF\\u5728 \",(0,n.jsx)(e.code,{children:\"seen\"}),\" \\u96C6\\u5408\\u4E2D\\u7684\\u7D22\\u5F15\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u4ECE \",(0,n.jsx)(e.code,{children:\"start\"}),\" \\u5230 \",(0,n.jsx)(e.code,{children:\"end\"}),\" \\u7684\\u5B50\\u5B57\\u7B26\\u4E32\\u5B58\\u5728\\u4E8E\\u5B57\\u5178\\u4E2D\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"end\"}),\" \\u7D22\\u5F15\\u6DFB\\u52A0\\u5230\\u961F\\u5217\\u4E2D\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"end\"}),\" \\u7D22\\u5F15\\u6807\\u8BB0\\u4E3A\\u5728 \",(0,n.jsx)(e.code,{children:\"seen\"}),\" \\u96C6\\u5408\\u4E2D\\u5DF2\\u8BBF\\u95EE\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u961F\\u5217\\u5DF2\\u8017\\u5C3D\\u4E14\\u672A\\u627E\\u5230\\u6709\\u6548\\u7684\\u5206\\u5272\\uFF0C\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(c,{children:u}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,n.jsx)(\"sup\",{children:\"3\"}),\" + m\\u22C5k)\"]}),\"\\u3002 \\u6709 O(n) \\u4E2A\\u8282\\u70B9\\uFF0C\\u5E76\\u4E14\\u7531\\u4E8E \",(0,n.jsx)(e.code,{children:\"seen\"}),\" \\u96C6\\u5408\\uFF0C\\u6BCF\\u4E2A\\u8282\\u70B9\\u6700\\u591A\\u8BBF\\u95EE\\u4E00\\u6B21\\u3002 \\u5728\\u6BCF\\u4E2A\\u8282\\u70B9\\uFF0C\\u7B97\\u6CD5\\u904D\\u5386\\u5F53\\u524D\\u8282\\u70B9\\u4E4B\\u524D\\u7684\\u8282\\u70B9 (O(n)) \\u5E76\\u521B\\u5EFA\\u5B50\\u5B57\\u7B26\\u4E32 (O(n))\\uFF0C\\u4ECE\\u800C\\u5BFC\\u81F4\\u6BCF\\u4E2A\\u8282\\u70B9 O(n\",(0,n.jsx)(\"sup\",{children:\"2\"}),\")\\u3002 \\u56E0\\u6B64\\uFF0CBFS \\u7684\\u6210\\u672C\\u4E3A O(n\",(0,n.jsx)(\"sup\",{children:\"3\"}),\")\\u3002 \\u6B64\\u5916\\uFF0C\\u4ECE\\u5B57\\u5178\\u521B\\u5EFA \",(0,n.jsx)(e.code,{children:\"words\"}),\" \\u96C6\\u5408\\u7684\\u6210\\u672C\\u4E3A O(m\\u22C5k)\\uFF0C\\u5176\\u4E2D \",(0,n.jsx)(e.code,{children:\"m\"}),\" \\u662F\\u5B57\\u5178\\u7684\\u5927\\u5C0F\\uFF0C\",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u662F\\u5E73\\u5747\\u5355\\u8BCD\\u957F\\u5EA6\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n + m\\u22C5k)\"}),\"\\u3002 \",(0,n.jsx)(e.code,{children:\"queue\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"seen\"}),\" \\u96C6\\u5408\\u9700\\u8981 O(n) \\u7A7A\\u95F4\\uFF0C\\u800C \",(0,n.jsx)(e.code,{children:\"words\"}),\" \\u96C6\\u5408\\u9700\\u8981 O(m\\u22C5k) \\u7A7A\\u95F4\\u3002\"]}),`\n`]})]})}function y(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(f,r)})):f(r)}var C=y;return x(F);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/string-shortest-substring-containing-characters/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/string-shortest-substring-containing-characters/locales/zh-CN.json new file mode 100644 index 000000000..76a5a5d48 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/string-shortest-substring-containing-characters/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var i=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var A=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty;var g=(t,n)=>()=>(n||t((n={exports:{}}).exports,n),n.exports),B=(t,n)=>{for(var r in n)i(t,r,{get:n[r],enumerable:!0})},d=(t,n,r,s)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let c of x(n))!C.call(t,c)&&c!==r&&i(t,c,{get:()=>n[c],enumerable:!(s=m(n,c))||s.enumerable});return t};var b=(t,n,r)=>(r=t!=null?p(A(t)):{},d(n||!t||!t.__esModule?i(r,\"default\",{value:t,enumerable:!0}):r,t)),f=t=>d(i({},\"__esModule\",{value:!0}),t);var o=g((v,l)=>{l.exports=_jsx_runtime});var T={};B(T,{default:()=>M,frontmatter:()=>_});var e=b(o());var h=MDXTestExamples;var a=[{input:[[\"str1\",\"ABCD\"],[\"str2\",\"AC\"]],output:\"ABC\",explanation:\"The substring 'ABC' contains both 'A' and 'C'\"},{input:[[\"str1\",\"AAABBBCCC\"],[\"str2\",\"ABC\"]],output:\"ABBBC\",explanation:\"The substring 'ABBBC' contains 'A', 'B', and 'C', making it the smallest valid substring.\"},{input:[[\"str1\",\"A\"],[\"str2\",\"AA\"]],output:\"\",explanation:\"str1 does not have enough 'A's to match the two required in str2, so the result is an empty string.\"}];var _={title:\"\\u5305\\u542B\\u5B57\\u7B26\\u7684\\u6700\\u77ED\\u5B50\\u5B57\\u7B26\\u4E32\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u8FD4\\u56DE\\u5305\\u542B\\u6765\\u81EA\\u53E6\\u4E00\\u4E2A\\u5B57\\u7B26\\u4E32\\u7684\\u6240\\u6709\\u5B57\\u7B26\\uFF08\\u5305\\u62EC\\u91CD\\u590D\\u5B57\\u7B26\\uFF09\\u7684\\u5B57\\u7B26\\u4E32\\u7684\\u6700\\u5C0F\\u5B50\\u5B57\\u7B26\\u4E32\"};function u(t){let n=Object.assign({p:\"p\",code:\"code\",strong:\"strong\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)(n.p,{children:[\"\\u7ED9\\u5B9A\\u4E24\\u4E2A\\u5B57\\u7B26\\u4E32\",(0,e.jsx)(n.code,{children:\"str1\"}),\"\\u548C\",(0,e.jsx)(n.code,{children:\"str2\"}),\"\\uFF0C\\u8FD4\\u56DE\",(0,e.jsx)(n.code,{children:\"str1\"}),\"\\u7684\\u6700\\u5C0F\\u5B50\\u5B57\\u7B26\\u4E32\\uFF0C\\u8BE5\\u5B50\\u5B57\\u7B26\\u4E32\\u5305\\u542B\",(0,e.jsx)(n.code,{children:\"str2\"}),\"\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5B57\\u7B26\\uFF08\\u5305\\u62EC\\u91CD\\u590D\\u5B57\\u7B26\\uFF09\\u3002\\u5982\\u679C\\u4E0D\\u5B58\\u5728\\u8FD9\\u6837\\u7684\\u5B50\\u5B57\\u7B26\\u4E32\\uFF0C\\u5219\\u8FD4\\u56DE\\u4E00\\u4E2A\\u7A7A\\u5B57\\u7B26\\u4E32\\u3002\"]}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u4E00\\u4E2A\",(0,e.jsx)(n.strong,{children:\"\\u5B50\\u5B57\\u7B26\\u4E32\"}),\"\\u662F\\u5B57\\u7B26\\u4E32\\u4E2D\\u4EFB\\u4F55\\u8FDE\\u7EED\\u7684\\u5B57\\u7B26\\u5E8F\\u5217\\u3002\\u4F8B\\u5982\\uFF0C\\u5B57\\u7B26\\u4E32\",(0,e.jsx)(n.code,{children:\"abc\"}),\"\\u7684\\u5B50\\u5B57\\u7B26\\u4E32\\u662F\",(0,e.jsx)(n.code,{children:\"a\"}),\"\\u3001\",(0,e.jsx)(n.code,{children:\"b\"}),\"\\u3001\",(0,e.jsx)(n.code,{children:\"c\"}),\"\\u3001\",(0,e.jsx)(n.code,{children:\"ab\"}),\"\\u3001\",(0,e.jsx)(n.code,{children:\"bc\"}),\"\\u548C\",(0,e.jsx)(n.code,{children:\"abc\"}),\"\\u3002\\u5B50\\u5B57\\u7B26\\u4E32\\u662F\\u901A\\u8FC7\\u9009\\u62E9\\u4E00\\u4E2A\\u8D77\\u59CB\\u70B9\\u548C\\u4E00\\u4E2A\\u7ED3\\u675F\\u70B9\\u5F62\\u6210\\u7684\\uFF0C\\u4E2D\\u95F4\\u6CA1\\u6709\\u8DF3\\u8FC7\\u5B57\\u7B26\\u3002\"]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"str1\"}),\"\\uFF1A\\u4E00\\u4E2A\\u5B57\\u7B26\\u4E32\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"str2\"}),\"\\uFF1A\\u4E00\\u4E2A\\u5B57\\u7B26\\u4E32\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u6CE8\\u610F\\u4E8B\\u9879\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5982\\u679C\\u5B58\\u5728\\u591A\\u4E2A\\u89E3\\u51B3\\u65B9\\u6848\\uFF0C\\u60A8\\u53EF\\u4EE5\\u8FD4\\u56DE\\u5176\\u4E2D\\u4EFB\\u4F55\\u4E00\\u4E2A\"}),`\n`]}),`\n`,(0,e.jsx)(h,{testCases:a}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"1 <= \",(0,e.jsx)(n.code,{children:\"str1.length\"}),\"\\uFF0C\",(0,e.jsx)(n.code,{children:\"str2.length\"}),\" <= 10,000\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"str1\"}),\"\\u548C\",(0,e.jsx)(n.code,{children:\"str2\"}),\"\\u4EC5\\u5305\\u542B\\u5927\\u5199\\u82F1\\u6587\\u5B57\\u6BCD\"]}),`\n`]})]})}function D(t={}){let{wrapper:n}=t.components||{};return n?(0,e.jsx)(n,Object.assign({},t,{children:(0,e.jsx)(u,t)})):u(t)}var M=D;return f(T);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,返回包含来自另一个字符串的所有字符(包括重复字符)的字符串的最小子字符串", + "title": "包含字符的最短子字符串" + }, + "solution": "var Component=(()=>{var f=Object.create;var c=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty;var T=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),b=(t,e)=>{for(var r in e)c(t,r,{get:e[r],enumerable:!0})},h=(t,e,r,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of m(e))!C.call(t,i)&&i!==r&&c(t,i,{get:()=>e[i],enumerable:!(o=g(e,i))||o.enumerable});return t};var y=(t,e,r)=>(r=t!=null?f(p(t)):{},h(e||!t||!t.__esModule?c(r,\"default\",{value:t,enumerable:!0}):r,t)),v=t=>h(c({},\"__esModule\",{value:!0}),t);var s=T((I,l)=>{l.exports=_jsx_runtime});var S={};b(S,{default:()=>O});var n=y(s());var d=MDXCodeBlock;var a=`export default function shortestSubstringContainingCharacters(\n str1: string,\n str2: string,\n): string {\n // Edge case: If either string is empty, return an empty string.\n if (str1.length === 0 || str2.length === 0) {\n return '';\n }\n\n // Dictionary to keep track of the frequency of each character in \\`str2\\`.\n let dictT: Map = new Map();\n for (let i = 0; i < str2.length; i++) {\n dictT.set(str2.charAt(i), (dictT.get(str2.charAt(i)) || 0) + 1);\n }\n\n // Number of unique characters in \\`str2\\` that must be present in the desired window.\n let required: number = dictT.size;\n\n // Pointers for the sliding window technique.\n let left = 0,\n right = 0;\n\n // \\`formed\\` tracks how many unique characters in the current window match the desired count.\n let formed: number = 0;\n\n // Dictionary to count the characters in the current window.\n let windowCounts: Map = new Map();\n\n // Result placeholder to store the smallest window found (length, left index, right index).\n let ans: number[] = [-1, 0, 0];\n\n // Expand the window by moving the right pointer (\\`right\\`) to the right.\n while (right < str1.length) {\n // Add the character at the right pointer to the window's counts.\n let c: string = str1.charAt(right);\n windowCounts.set(c, (windowCounts.get(c) || 0) + 1);\n\n // If the current character's count in the window matches its count in \\`str2\\`, increase \\`formed\\`.\n if (dictT.has(c) && windowCounts.get(c) === dictT.get(c)) {\n formed++;\n }\n\n // Try to contract the window by moving the left pointer (\\`left\\`) to the right.\n while (left <= right && formed === required) {\n c = str1.charAt(left);\n\n // Update the result if this window is smaller than the previously found smallest window.\n if (ans[0] === -1 || right - left + 1 < ans[0]) {\n ans[0] = right - left + 1;\n ans[1] = left;\n ans[2] = right;\n }\n\n // Remove the character at the left pointer from the window's counts.\n windowCounts.set(c, windowCounts.get(c)! - 1);\n\n // If the count of this character in the window falls below its count in \\`str2\\`, reduce \\`formed\\`.\n if (dictT.has(c) && windowCounts.get(c)! < dictT.get(c)!) {\n formed--;\n }\n\n // Move the left pointer to the right, contracting the window.\n left++;\n }\n\n // Move the right pointer to the right, expanding the window.\n right++;\n }\n\n // Return the smallest window found, or an empty string if no such window exists.\n return ans[0] === -1 ? '' : str1.substring(ans[1], ans[2] + 1);\n}\n`;var u=`export default function shortestSubstringContainingCharacters(\n str1: string,\n str2: string,\n): string {\n // If either input string is empty, return an empty string as there's no valid window\n if (str1.length === 0 || str2.length === 0) {\n return '';\n }\n\n // Build a frequency map of characters in \\`str2\\` (target string)\n const dictT: Record = {};\n for (let char of str2) {\n dictT[char] = (dictT[char] || 0) + 1; // Increment count of each character\n }\n\n // The number of unique characters in \\`str2\\` that must appear in the desired window\n const required = Object.keys(dictT).length;\n\n // Filter \\`str1\\` to include only characters present in \\`str2\\`\n // Store as tuples of [index, character]\n const filteredStr1: [number, string][] = [];\n for (let i = 0; i < str1.length; i++) {\n const char = str1[i];\n if (char in dictT) {\n filteredStr1.push([i, char]); // Keep only relevant characters with their indices\n }\n }\n\n // Initialize sliding window pointers\n let left = 0,\n right = 0;\n\n // Track how many characters from \\`dictT\\` have their required frequency in the current window\n let formed = 0;\n\n // A map to count characters in the current window\n const windowCounts: Record = {};\n\n // Result to store the smallest window found: [window length, left index, right index]\n let ans: [number, number, number] = [-1, 0, 0];\n\n // Expand the window by moving the \\`right\\` pointer\n while (right < filteredStr1.length) {\n // Character at the right pointer in the filtered string\n const char = filteredStr1[right][1];\n windowCounts[char] = (windowCounts[char] || 0) + 1; // Increment count in the window\n\n // If the current character's count matches the required count, increment \\`formed\\`\n if (dictT[char] && windowCounts[char] === dictT[char]) {\n formed++;\n }\n\n // Try contracting the window from the left as long as all required characters are present\n while (left <= right && formed === required) {\n // Get the actual indices of the current window from the filtered string\n const start = filteredStr1[left][0];\n const end = filteredStr1[right][0];\n\n // Update the result if the current window is smaller than the previously found one\n if (ans[0] === -1 || end - start + 1 < ans[0]) {\n ans = [end - start + 1, start, end];\n }\n\n // Character to be removed from the window as the left pointer moves\n const charToRemove = filteredStr1[left][1];\n windowCounts[charToRemove] -= 1; // Decrement count in the window\n\n // If the character's count falls below the required count, decrement \\`formed\\`\n if (\n dictT[charToRemove] &&\n windowCounts[charToRemove] < dictT[charToRemove]\n ) {\n formed--;\n }\n\n // Move the left pointer to shrink the window\n left++;\n }\n\n // Move the right pointer to expand the window\n right++;\n }\n\n // If no valid window is found, return an empty string\n return ans[0] === -1 ? '' : str1.substring(ans[1], ans[2] + 1);\n}\n`;function w(t){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u6ED1\\u52A8\\u7A97\\u53E3\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u6ED1\\u52A8\\u7A97\\u53E3\\u6280\\u672F\\u6765\\u67E5\\u627E \",(0,n.jsx)(e.code,{children:\"str1\"}),\" \\u4E2D\\u5305\\u542B \",(0,n.jsx)(e.code,{children:\"str2\"}),\" \\u6240\\u6709\\u5B57\\u7B26\\u7684\\u6700\\u77ED\\u5B50\\u5B57\\u7B26\\u4E32\\u3002 \\u5173\\u952E\\u7684\\u76F4\\u89C9\\u662F\\u7EF4\\u62A4\\u4E00\\u4E2A\\u52A8\\u6001\\u7A97\\u53E3\\uFF0C\\u8BE5\\u7A97\\u53E3\\u6839\\u636E\\u5176\\u662F\\u5426\\u6EE1\\u8DB3\\u5305\\u542B \",(0,n.jsx)(e.code,{children:\"str2\"}),\" \\u4E2D\\u6240\\u6709\\u5B57\\u7B26\\u53CA\\u5176\\u6B63\\u786E\\u9891\\u7387\\u7684\\u8981\\u6C42\\u6765\\u8C03\\u6574\\u5176\\u5927\\u5C0F\\u548C\\u4F4D\\u7F6E\\u3002 \\u8BE5\\u7B97\\u6CD5\\u52A8\\u6001\\u5730\\u6269\\u5C55\\u6216\\u7F29\\u5C0F\\u7A97\\u53E3\\u4EE5\\u627E\\u5230\\u6700\\u5C0F\\u7684\\u6709\\u6548\\u5B50\\u5B57\\u7B26\\u4E32\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5904\\u7406\\u8FB9\\u7F18\\u60C5\\u51B5\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u4EFB\\u4E00\\u5B57\\u7B26\\u4E32\\u4E3A\\u7A7A\\uFF0C\\u5219\\u8FD4\\u56DE\\u4E00\\u4E2A\\u7A7A\\u5B57\\u7B26\\u4E32\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521B\\u5EFA\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"Map\"}),\" \",(0,n.jsx)(e.code,{children:\"dictT\"}),\" \\u6765\\u5B58\\u50A8 \",(0,n.jsx)(e.code,{children:\"str2\"}),\" \\u4E2D\\u6BCF\\u4E2A\\u5B57\\u7B26\\u7684\\u9891\\u7387\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u53D8\\u91CF\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"required\"}),\" \\u7528\\u4E8E\\u5B58\\u50A8 \",(0,n.jsx)(e.code,{children:\"str2\"}),\" \\u4E2D\\u552F\\u4E00\\u5B57\\u7B26\\u7684\\u6570\\u91CF\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4E24\\u4E2A\\u6307\\u9488 \",(0,n.jsx)(e.code,{children:\"left\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"right\"}),\" \\u7528\\u4E8E\\u6ED1\\u52A8\\u7A97\\u53E3\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"formed\"}),\" \\u7528\\u4E8E\\u8DDF\\u8E2A\\u5F53\\u524D\\u7A97\\u53E3\\u4E2D\\u6EE1\\u8DB3\\u6240\\u9700\\u9891\\u7387\\u7684\\u552F\\u4E00\\u5B57\\u7B26\\u7684\\u6570\\u91CF\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"windowCounts\"}),\" \\u7528\\u4E8E\\u8DDF\\u8E2A\\u5F53\\u524D\\u7A97\\u53E3\\u4E2D\\u7684\\u5B57\\u7B26\\u8BA1\\u6570\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"ans\"}),\" \\u7528\\u4E8E\\u5B58\\u50A8\\u627E\\u5230\\u7684\\u6700\\u5C0F\\u6709\\u6548\\u7A97\\u53E3\\uFF0C\\u521D\\u59CB\\u5316\\u4E3A \",(0,n.jsx)(e.code,{children:\"[-1, 0, 0]\"}),\"\\uFF08\\u957F\\u5EA6\\u3001\\u5DE6\\u4FA7\\u7D22\\u5F15\\u3001\\u53F3\\u4FA7\\u7D22\\u5F15\\uFF09\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u9012\\u589E \",(0,n.jsx)(e.code,{children:\"right\"}),\" \\u6307\\u9488\\u6765\\u6269\\u5C55\\u7A97\\u53E3\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06 \",(0,n.jsx)(e.code,{children:\"right\"}),\" \\u5904\\u7684\\u5B57\\u7B26\\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"windowCounts\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5F53\\u524D\\u5B57\\u7B26\\u7684\\u8BA1\\u6570\\u4E0E\\u5176\\u5728 \",(0,n.jsx)(e.code,{children:\"dictT\"}),\" \\u4E2D\\u7684\\u8BA1\\u6570\\u5339\\u914D\\uFF0C\\u5219\\u9012\\u589E \",(0,n.jsx)(e.code,{children:\"formed\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5F53 \",(0,n.jsx)(e.code,{children:\"formed\"}),\" \\u7B49\\u4E8E \",(0,n.jsx)(e.code,{children:\"required\"}),\" \\u65F6\\uFF0C\\u901A\\u8FC7\\u9012\\u589E \",(0,n.jsx)(e.code,{children:\"left\"}),\" \\u6307\\u9488\\u6765\\u6536\\u7F29\\u7A97\\u53E3\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u68C0\\u67E5\\u5F53\\u524D\\u7A97\\u53E3\\u662F\\u5426\\u5C0F\\u4E8E\\u5148\\u524D\\u627E\\u5230\\u7684\\u6700\\u5C0F\\u7A97\\u53E3\\u3002 \\u5982\\u679C\\u662F\\uFF0C\\u5219\\u66F4\\u65B0 \",(0,n.jsx)(e.code,{children:\"ans\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4ECE \",(0,n.jsx)(e.code,{children:\"windowCounts\"}),\" \\u4E2D\\u5220\\u9664 \",(0,n.jsx)(e.code,{children:\"left\"}),\" \\u5904\\u7684\\u5B57\\u7B26\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5B57\\u7B26\\u7684\\u8BA1\\u6570\\u4F4E\\u4E8E\\u5176\\u5728 \",(0,n.jsx)(e.code,{children:\"dictT\"}),\" \\u4E2D\\u7684\\u8BA1\\u6570\\uFF0C\\u5219\\u9012\\u51CF \",(0,n.jsx)(e.code,{children:\"formed\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u7EE7\\u7EED\\u6269\\u5C55\\u548C\\u6536\\u7F29\\uFF0C\\u76F4\\u5230 \",(0,n.jsx)(e.code,{children:\"right\"}),\" \\u5230\\u8FBE \",(0,n.jsx)(e.code,{children:\"str1\"}),\" \\u7684\\u672B\\u5C3E\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE\\u4E0E \",(0,n.jsx)(e.code,{children:\"ans\"}),\" \\u4E2D\\u6700\\u5C0F\\u7A97\\u53E3\\u5BF9\\u5E94\\u7684\\u5B50\\u5B57\\u7B26\\u4E32\\uFF0C\\u5982\\u679C\\u4E0D\\u5B58\\u5728\\u6709\\u6548\\u7A97\\u53E3\\uFF0C\\u5219\\u8FD4\\u56DE\\u4E00\\u4E2A\\u7A7A\\u5B57\\u7B26\\u4E32\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(d,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n + m)\"}),\"\\u3002 \",(0,n.jsx)(e.code,{children:\"right\"}),\" \\u6307\\u9488\\u904D\\u5386 \",(0,n.jsx)(e.code,{children:\"str1\"}),\" (O(n))\\uFF0C\",(0,n.jsx)(e.code,{children:\"left\"}),\" \\u6307\\u9488\\u6839\\u636E\\u9700\\u8981\\u6536\\u7F29\\u7A97\\u53E3\\u3002 \",(0,n.jsx)(e.code,{children:\"Map\"}),\" \\u64CD\\u4F5C\\u7528\\u4E8E\\u68C0\\u67E5\\u548C\\u66F4\\u65B0\\u8BA1\\u6570\\uFF0C\\u5E73\\u5747\\u4E3A O(1)\\u3002 \\u6784\\u9020 \",(0,n.jsx)(e.code,{children:\"str2\"}),\" \\u7684\\u9891\\u7387\\u6620\\u5C04\\u9700\\u8981 O(m)\\uFF0C\\u5176\\u4E2D \",(0,n.jsx)(e.code,{children:\"m\"}),\" \\u662F \",(0,n.jsx)(e.code,{children:\"str2\"}),\" \\u7684\\u957F\\u5EA6\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n + m)\"}),\"\\u3002 \",(0,n.jsx)(e.code,{children:\"windowCounts\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"dictT\"}),\" \\u6620\\u5C04\\u9700\\u8981 O(n + m) \\u7A7A\\u95F4\\u6765\\u5B58\\u50A8\\u5B57\\u7B26\\u9891\\u7387\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u4F18\\u5316\\u7684\\u6ED1\\u52A8\\u7A97\\u53E3\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4F18\\u5316\\u7684\\u6ED1\\u52A8\\u7A97\\u53E3\\u65B9\\u6CD5\\u901A\\u8FC7\\u8FC7\\u6EE4 \",(0,n.jsx)(e.code,{children:\"str1\"}),\" \\u4EE5\\u4EC5\\u5305\\u542B \",(0,n.jsx)(e.code,{children:\"str2\"}),\" \\u4E2D\\u5B58\\u5728\\u7684\\u5B57\\u7B26\\u6765\\u63D0\\u9AD8\\u6548\\u7387\\u3002 \\u8FD9\\u51CF\\u5C11\\u4E86\\u6ED1\\u52A8\\u7A97\\u53E3\\u8FC7\\u7A0B\\u4E2D\\u6240\\u9700\\u7684\\u8FED\\u4EE3\\u548C\\u6BD4\\u8F83\\u6B21\\u6570\\u3002 \\u5173\\u952E\\u7684\\u76F4\\u89C9\\u662F\\uFF0C\\u53EF\\u4EE5\\u5FFD\\u7565 \",(0,n.jsx)(e.code,{children:\"str1\"}),\" \\u4E2D\\u4E0D\\u76F8\\u5173\\u7684\\u5B57\\u7B26\\uFF0C\\u56E0\\u4E3A\\u5B83\\u4EEC\\u4E0D\\u4F1A\\u6709\\u52A9\\u4E8E\\u5F62\\u6210\\u6240\\u9700\\u7684\\u5B50\\u5B57\\u7B26\\u4E32\\u3002 \\u901A\\u8FC7\\u4F7F\\u7528\\u8FC7\\u6EE4\\u540E\\u7684 \",(0,n.jsx)(e.code,{children:\"str1\"}),\" \\u7248\\u672C\\uFF0C\\u8BE5\\u7B97\\u6CD5\\u4EC5\\u5904\\u7406\\u76F8\\u5173\\u5B57\\u7B26\\uFF0C\\u8FD9\\u4F7F\\u5176\\u6BD4\\u4E4B\\u524D\\u7684\\u5B9E\\u73B0\\u66F4\\u5FEB\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8FD9\\u79CD\\u4F18\\u5316\\u5BF9\\u4E8E \",(0,n.jsx)(e.code,{children:\"str1\"}),\" \\u5305\\u542B\\u8BB8\\u591A \",(0,n.jsx)(e.code,{children:\"str2\"}),\" \\u4E2D\\u4E0D\\u5B58\\u5728\\u7684\\u5B57\\u7B26\\u7684\\u5927\\u578B\\u8F93\\u5165\\u5C24\\u5176\\u6709\\u5F71\\u54CD\\u3002 \\u6269\\u5C55\\u548C\\u6536\\u7F29\\u7A97\\u53E3\\u7684\\u903B\\u8F91\\u4FDD\\u6301\\u4E0D\\u53D8\\uFF0C\\u4F46\\u7531\\u4E8E\\u8FC7\\u6EE4\\uFF0C\\u64CD\\u4F5C\\u6B21\\u6570\\u51CF\\u5C11\\u4E86\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5904\\u7406\\u57FA\\u672C\\u60C5\\u51B5\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C \",(0,n.jsx)(e.code,{children:\"str1\"}),\" \\u6216 \",(0,n.jsx)(e.code,{children:\"str2\"}),\" \\u4E3A\\u7A7A\\uFF0C\\u5219\\u8FD4\\u56DE\\u4E00\\u4E2A\\u7A7A\\u5B57\\u7B26\\u4E32\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4E3A \",(0,n.jsx)(e.code,{children:\"str2\"}),\" \\u6784\\u5EFA\\u9891\\u7387\\u6620\\u5C04 \",(0,n.jsx)(e.code,{children:\"dictT\"}),\"\\uFF0C\\u4EE5\\u8DDF\\u8E2A\\u6BCF\\u4E2A\\u5B57\\u7B26\\u7684\\u6240\\u9700\\u8BA1\\u6570\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FC7\\u6EE4 \",(0,n.jsx)(e.code,{children:\"str1\"}),\" \\u4EE5\\u4EC5\\u5305\\u542B \",(0,n.jsx)(e.code,{children:\"str2\"}),\" \\u4E2D\\u5B58\\u5728\\u7684\\u5B57\\u7B26\\uFF0C\\u5C06\\u5B83\\u4EEC\\u5B58\\u50A8\\u4E3A\\u5B83\\u4EEC\\u7684\\u7D22\\u5F15\\u548C \",(0,n.jsx)(e.code,{children:\"filteredStr1\"}),\" \\u4E2D\\u7684\\u5B57\\u7B26\\u7684\\u5143\\u7EC4\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u6ED1\\u52A8\\u7A97\\u53E3\\u6307\\u9488 \",(0,n.jsx)(e.code,{children:\"left\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"right\"}),\"\\uFF0C\\u4E00\\u4E2A\\u53D8\\u91CF \",(0,n.jsx)(e.code,{children:\"formed\"}),\" \\u7528\\u4E8E\\u8DDF\\u8E2A\\u6EE1\\u8DB3\\u5176\\u6240\\u9700\\u9891\\u7387\\u7684\\u5B57\\u7B26\\uFF0C\\u4EE5\\u53CA\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"windowCounts\"}),\" \\u6620\\u5C04\\u4EE5\\u8BA1\\u7B97\\u5F53\\u524D\\u7A97\\u53E3\\u4E2D\\u7684\\u5B57\\u7B26\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u6ED1\\u52A8\\u7A97\\u53E3\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u9012\\u589E \",(0,n.jsx)(e.code,{children:\"right\"}),\" \\u6307\\u9488\\u6765\\u6269\\u5C55\\u7A97\\u53E3\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u66F4\\u65B0 \",(0,n.jsx)(e.code,{children:\"windowCounts\"}),\" \\u5E76\\u5728 \",(0,n.jsx)(e.code,{children:\"right\"}),\" \\u5904\\u7684\\u5B57\\u7B26\\u6EE1\\u8DB3 \",(0,n.jsx)(e.code,{children:\"dictT\"}),\" \\u4E2D\\u6240\\u9700\\u7684\\u8BA1\\u6570\\u65F6\\u9012\\u589E \",(0,n.jsx)(e.code,{children:\"formed\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u53EA\\u8981\\u5B58\\u5728\\u6240\\u6709\\u5FC5\\u9700\\u7684\\u5B57\\u7B26\\uFF0C\\u5C31\\u901A\\u8FC7\\u9012\\u589E \",(0,n.jsx)(e.code,{children:\"left\"}),\" \\u6307\\u9488\\u6765\\u6536\\u7F29\\u7A97\\u53E3\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u5F53\\u524D\\u7A97\\u53E3\\u5C0F\\u4E8E\\u5148\\u524D\\u627E\\u5230\\u7684\\u7A97\\u53E3\\uFF0C\\u5219\\u66F4\\u65B0\\u7ED3\\u679C\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u51CF\\u5C11\\u4ECE \",(0,n.jsx)(e.code,{children:\"windowCounts\"}),\" \\u4E2D\\u5220\\u9664\\u7684\\u5B57\\u7B26\\u7684\\u8BA1\\u6570\\uFF0C\\u5982\\u679C\\u5B83\\u4F4E\\u4E8E\\u6240\\u9700\\u8BA1\\u6570\\uFF0C\\u5219\\u9012\\u51CF \",(0,n.jsx)(e.code,{children:\"formed\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8FD4\\u56DE\\u4E0E\\u6700\\u5C0F\\u7A97\\u53E3\\u5BF9\\u5E94\\u7684\\u5B50\\u5B57\\u7B26\\u4E32\\uFF0C\\u5982\\u679C\\u672A\\u627E\\u5230\\u6709\\u6548\\u7A97\\u53E3\\uFF0C\\u5219\\u8FD4\\u56DE\\u4E00\\u4E2A\\u7A7A\\u5B57\\u7B26\\u4E32\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(d,{children:u}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n + m)\"}),\"\\u3002 \\u8FC7\\u6EE4 \",(0,n.jsx)(e.code,{children:\"str1\"}),\" \\u6240\\u9700\\u7684\\u65F6\\u95F4\\u4E0E \",(0,n.jsx)(e.code,{children:\"str1\"}),\" \\u7684\\u957F\\u5EA6\\u6210\\u6B63\\u6BD4\\uFF0C\\u6ED1\\u52A8\\u7A97\\u53E3\\u5728\\u8FC7\\u6EE4\\u540E\\u7684\\u5B57\\u7B26\\u4E32\\u4E0A\\u8FD0\\u884C\\uFF0C\\u5176\\u957F\\u5EA6\\u4E0E \",(0,n.jsx)(e.code,{children:\"str2\"}),\" \\u4E2D\\u7684\\u5B57\\u7B26\\u6570\\u6210\\u6B63\\u6BD4\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n + m)\"}),\"\\u3002 \\u7528\\u4E8E\\u9891\\u7387\\u6620\\u5C04\\u548C\\u7A97\\u53E3\\u8BA1\\u6570\\u7684\\u7A7A\\u95F4\\u4E0E \",(0,n.jsx)(e.code,{children:\"str2\"}),\" \\u4E2D\\u7684\\u5B57\\u7B26\\u6570\\u6210\\u6B63\\u6BD4\\uFF0C\\u800C\\u8FC7\\u6EE4\\u540E\\u7684 \",(0,n.jsx)(e.code,{children:\"str1\"}),\" \\u7248\\u672C\\u4F7F\\u7528\\u7684\\u7A7A\\u95F4\\u4E0E \",(0,n.jsx)(e.code,{children:\"str1\"}),\" \\u7684\\u957F\\u5EA6\\u6210\\u6B63\\u6BD4\\u3002\"]}),`\n`]})]})}function M(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(w,t)})):w(t)}var O=M;return v(S);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/sum-without-addition/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/sum-without-addition/locales/zh-CN.json new file mode 100644 index 000000000..affc8cf35 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/sum-without-addition/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var h=Object.create;var l=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var j=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),_=(t,e)=>{for(var c in e)l(t,c,{get:e[c],enumerable:!0})},r=(t,e,c,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of m(e))!f.call(t,i)&&i!==c&&l(t,i,{get:()=>e[i],enumerable:!(o=x(e,i))||o.enumerable});return t};var M=(t,e,c)=>(c=t!=null?h(b(t)):{},r(e||!t||!t.__esModule?l(c,\"default\",{value:t,enumerable:!0}):c,t)),g=t=>r(l({},\"__esModule\",{value:!0}),t);var u=j((E,s)=>{s.exports=_jsx_runtime});var q={};_(q,{default:()=>X,frontmatter:()=>C});var n=M(u());var a=MDXTestExamples;var d=[{input:[[\"a\",1],[\"b\",2]],output:3,explanation:\"a:=1 plus b:=2 equals 3 which is the expected output.\"},{input:[[\"a\",-1],[\"b\",-2]],output:-3,explanation:\"a:=-1 plus b:=-2 equals -3 which is the expected output.\"},{input:[[\"a\",0],[\"b\",0]],output:0,explanation:\"a:=0 plus b:=0 equals 0 which is the expected output.\"}];var C={title:\"\\u65E0\\u52A0\\u6CD5\\u6C42\\u548C\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u65E0\\u9700\\u4F7F\\u7528 + \\u548C - \\u8FD0\\u7B97\\u7B26\\u5373\\u53EF\\u627E\\u5230\\u4E24\\u4E2A\\u6574\\u6570\\u7684\\u548C\"};function p(t){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E24\\u4E2A\\u6574\\u6570 \",(0,n.jsx)(e.code,{children:\"a\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"b\"}),\"\\uFF0C\\u5728\\u4E0D\\u4F7F\\u7528\\u52A0\\u6CD5\\u6216\\u51CF\\u6CD5\\u8FD0\\u7B97\\u7B26\\u7684\\u60C5\\u51B5\\u4E0B\\u8BA1\\u7B97\\u5B83\\u4EEC\\u7684\\u548C\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"a: number\"}),\": \\u4E00\\u4E2A\\u6574\\u6570\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"b: number\"}),\": \\u4E00\\u4E2A\\u6574\\u6570\"]}),`\n`]}),`\n`,(0,n.jsx)(a,{testCases:d}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"-1000 <= \",(0,n.jsx)(e.code,{children:\"a\"}),\", \",(0,n.jsx)(e.code,{children:\"b\"}),\" <= 1000\"]}),`\n`]})]})}function D(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(p,t)})):p(t)}var X=D;return g(q);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,无需使用 + 和 - 运算符即可找到两个整数的和", + "title": "无加法求和" + }, + "solution": "var Component=(()=>{var u=Object.create;var d=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty;var g=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),x=(n,e)=>{for(var i in e)d(n,i,{get:e[i],enumerable:!0})},l=(n,e,i,t)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let c of y(e))!p.call(n,c)&&c!==i&&d(n,c,{get:()=>e[c],enumerable:!(t=m(e,c))||t.enumerable});return n};var O=(n,e,i)=>(i=n!=null?u(f(n)):{},l(e||!n||!n.__esModule?d(i,\"default\",{value:n,enumerable:!0}):i,n)),j=n=>l(d({},\"__esModule\",{value:!0}),n);var h=g((A,o)=>{o.exports=_jsx_runtime});var M={};x(M,{default:()=>D});var r=O(h());var a=MDXCodeBlock;var s=`export default function sumWithoutAddition(a: number, b: number): number {\n // Initialize a variable carry to hold the carry bits generated during each iteration\n let carry: number = 0;\n\n // Loop continues as long as there's a carry bit or bits to process in a or b\n while (b !== 0 || carry !== 0) {\n // Extract the carry bit from the AND operation of a and b\n carry = a & b;\n\n // Use the XOR operation to add a and b without the carry bit\n a = a ^ b;\n\n // Left shift the carry bit for the next iteration\n b = carry << 1;\n }\n\n // Return the final result, which is stored in 'a' after all carry bits have been processed\n return a;\n}\n`;function b(n){let e=Object.assign({h2:\"h2\",p:\"p\",ul:\"ul\",li:\"li\",code:\"code\",h3:\"h3\",ol:\"ol\",strong:\"strong\"},n.components);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u4F4D\\u8FD0\\u7B97\"}),`\n`,(0,r.jsx)(e.p,{children:\"\\u7ED9\\u5B9A\\u7684\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u4F4D\\u8FD0\\u7B97\\u6765\\u8BA1\\u7B97\\u4E24\\u4E2A\\u6570\\u5B57\\u7684\\u548C\\uFF0C\\u800C\\u4E0D\\u4F7F\\u7528\\u52A0\\u6CD5\\u8FD0\\u7B97\\u7B26\\u3002 \\u5173\\u952E\\u601D\\u60F3\\u4F9D\\u8D56\\u4E8E\\u7406\\u89E3\\u4E8C\\u8FDB\\u5236\\u52A0\\u6CD5\\u7684\\u539F\\u7406\\uFF1A\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"XOR \\u8FD0\\u7B97 (\",(0,r.jsx)(e.code,{children:\"^\"}),\") \\u6267\\u884C\\u52A0\\u6CD5\\uFF0C\\u4F46\\u4E0D\\u4EA7\\u751F\\u8FDB\\u4F4D\\u3002 \\u4F8B\\u5982\\uFF0C\\u5728\\u4E8C\\u8FDB\\u5236\\u4E2D \",(0,r.jsx)(e.code,{children:\"1 ^ 1 = 0\"}),\" \\u4E14 \",(0,r.jsx)(e.code,{children:\"0 ^ 1 = 1\"}),\"\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"AND \\u8FD0\\u7B97 (\",(0,r.jsx)(e.code,{children:\"&\"}),\") \\u786E\\u5B9A\\u4EA7\\u751F\\u8FDB\\u4F4D\\u4F4D\\u7684\\u4F4D\\u7F6E\\u3002 \\u4F8B\\u5982\\uFF0C\\u5728\\u4E8C\\u8FDB\\u5236\\u4E2D \",(0,r.jsx)(e.code,{children:\"1 & 1 = 1\"}),\" \\u4E14 \",(0,r.jsx)(e.code,{children:\"0 & 1 = 0\"}),\"\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5DE6\\u79FB\\u8FD0\\u7B97 (\",(0,r.jsx)(e.code,{children:\"<<\"}),\") \\u5C06\\u8FDB\\u4F4D\\u4F4D\\u79FB\\u52A8\\u5230\\u4E0B\\u4E00\\u4E2A\\u66F4\\u9AD8\\u7684\\u4F4D\\u7F6E\\uFF0C\\u4EE5\\u4FBF\\u5728\\u540E\\u7EED\\u8FED\\u4EE3\\u4E2D\\u8FDB\\u884C\\u52A0\\u6CD5\\u3002\"]}),`\n`]}),`\n`,(0,r.jsx)(e.p,{children:\"\\u901A\\u8FC7\\u8FED\\u4EE3\\u5730\\u5E94\\u7528\\u8FD9\\u4E9B\\u64CD\\u4F5C\\uFF0C\\u7B97\\u6CD5\\u5904\\u7406\\u8FDB\\u4F4D\\u4F4D\\uFF0C\\u76F4\\u5230\\u6CA1\\u6709\\u8FDB\\u4F4D\\uFF0C\\u4ECE\\u800C\\u5F97\\u5230\\u603B\\u548C\\u3002\"}),`\n`,(0,r.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,r.jsxs)(e.ol,{children:[`\n`,(0,r.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316 \",(0,r.jsx)(e.code,{children:\"carry\"}),\" \\u53D8\\u91CF\\u4EE5\\u4FDD\\u5B58\\u6BCF\\u6B21\\u8FED\\u4EE3\\u4E2D\\u4EA7\\u751F\\u7684\\u8FDB\\u4F4D\\u4F4D\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u53EA\\u8981 \",(0,r.jsx)(e.code,{children:\"b\"}),\" \\u4E2D\\u6709\\u8981\\u5904\\u7406\\u7684\\u4F4D\\u6216\\u6709\\u8FDB\\u4F4D\\u4F4D\\uFF0C\\u5C31\\u7EE7\\u7EED\\u5FAA\\u73AF\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u4F7F\\u7528 \",(0,r.jsx)(e.code,{children:\"a & b\"}),\" \\u8FD0\\u7B97\\u63D0\\u53D6\\u8FDB\\u4F4D\\u4F4D\\u5E76\\u5C06\\u7ED3\\u679C\\u5B58\\u50A8\\u5728 \",(0,r.jsx)(e.code,{children:\"carry\"}),\" \\u4E2D\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u4F7F\\u7528 XOR \\u8FD0\\u7B97 (\",(0,r.jsx)(e.code,{children:\"a ^ b\"}),\") \\u8BA1\\u7B97\\u548C\\uFF0C\\u4E0D\\u5E26\\u8FDB\\u4F4D\\u4F4D\\uFF0C\\u5E76\\u66F4\\u65B0 \",(0,r.jsx)(e.code,{children:\"a\"}),\"\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u5C06 \",(0,r.jsx)(e.code,{children:\"carry\"}),\" \\u5DE6\\u79FB\\u4E00\\u4F4D (\",(0,r.jsx)(e.code,{children:\"carry << 1\"}),\") \\u4EE5\\u4F7F\\u5176\\u4E0E\\u4E0B\\u4E00\\u4E2A\\u66F4\\u9AD8\\u7684\\u4F4D\\u5BF9\\u9F50\\uFF0C\\u5E76\\u5C06\\u7ED3\\u679C\\u5206\\u914D\\u7ED9 \",(0,r.jsx)(e.code,{children:\"b\"}),\"\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u91CD\\u590D\\u6B65\\u9AA4 3\\u20135\\uFF0C\\u76F4\\u5230 \",(0,r.jsx)(e.code,{children:\"b\"}),\" \\u548C \",(0,r.jsx)(e.code,{children:\"carry\"}),\" \\u90FD\\u4E3A\\u96F6\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE \",(0,r.jsx)(e.code,{children:\"a\"}),\"\\uFF0C\\u5B83\\u4FDD\\u5B58\\u6700\\u7EC8\\u7684\\u548C\\u3002\"]}),`\n`]}),`\n`,(0,r.jsx)(a,{children:s}),`\n`,(0,r.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,r.jsxs)(e.ul,{children:[`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002 \\u6BCF\\u4E2A\\u6574\\u6570\\u5305\\u542B 32 \\u4F4D\\u3002\"]}),`\n`,(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002 \\u7B97\\u6CD5\\u4F7F\\u7528\\u6052\\u5B9A\\u7A7A\\u95F4\\uFF0C\\u56E0\\u4E3A\\u5B83\\u76F4\\u63A5\\u5BF9\\u8F93\\u5165\\u53D8\\u91CF\\u8FDB\\u884C\\u64CD\\u4F5C\\u3002\"]}),`\n`]})]})}function _(n={}){let{wrapper:e}=n.components||{};return e?(0,r.jsx)(e,Object.assign({},n,{children:(0,r.jsx)(b,n)})):b(n)}var D=_;return j(M);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/task-coordination/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/task-coordination/locales/zh-CN.json new file mode 100644 index 000000000..0b2a3017a --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/task-coordination/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var a=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var k=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var B=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),x=(n,e)=>{for(var i in e)a(n,i,{get:e[i],enumerable:!0})},r=(n,e,i,l)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let s of A(e))!f.call(n,s)&&s!==i&&a(n,s,{get:()=>e[s],enumerable:!(l=m(e,s))||l.enumerable});return n};var g=(n,e,i)=>(i=n!=null?p(k(n)):{},r(e||!n||!n.__esModule?a(i,\"default\",{value:n,enumerable:!0}):i,n)),b=n=>r(a({},\"__esModule\",{value:!0}),n);var d=B((D,o)=>{o.exports=_jsx_runtime});var C={};x(C,{default:()=>j,frontmatter:()=>v});var t=g(d());var c=MDXTestExamples;var h=[{input:[[\"tasks\",[\"A\",\"A\",\"A\",\"B\",\"B\",\"B\"]],[\"n\",2]],output:8,explanation:\"Task 'A' appears 3 times and task 'B' appears 3 times. Since there is a cooldown of 2, we need to ensure that after every 'A' there are at least 2 other tasks or idle intervals before we can add another 'A'. The same applies to 'B'. A valid sequence might look like this: 'A' -> 'B' -> idle -> 'A' -> 'B' -> idle -> 'A' -> 'B'. Thus, the total number of intervals required is 8.\"},{input:[[\"tasks\",[\"A\",\"C\",\"A\",\"B\",\"D\",\"B\"]],[\"n\",1]],output:6,explanation:\"The tasks 'A', 'B', and 'C' appear multiple times, but the cooldown is only 1. After completing one 'A', we can immediately complete another 'A' after just one other task. A valid sequence could look like this: 'A' -> 'C' -> 'A' -> 'B' -> 'D' -> 'B'. Thus, the total number of intervals required is 6.\"},{input:[[\"tasks\",[\"A\",\"A\",\"A\",\"B\",\"B\",\"B\"]],[\"n\",3]],output:10,explanation:\"The cooldown is 3, meaning after completing a task, we must wait for 3 intervals before repeating the same task. A valid sequence could be: 'A' -> 'B' -> idle -> idle -> 'A' -> 'B' -> idle -> idle -> 'A' -> 'B'. Thus, the total number of intervals needed is 10.\"}];var v={title:\"\\u4EFB\\u52A1\\u534F\\u8C03\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u7528\\u4E8E\\u67E5\\u627E\\u5177\\u6709\\u51B7\\u5374\\u65F6\\u95F4\\u7684\\u4EFB\\u52A1\\u7684\\u6700\\u5C0F\\u95F4\\u9694\"};function u(n){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},n.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u4EFB\\u52A1\\u5217\\u8868\\uFF0C\\u6BCF\\u4E2A\\u4EFB\\u52A1\\u7531\\u4E00\\u4E2A\\u5B57\\u6BCD\\uFF08\\u4ECE A \\u5230 Z\\uFF09\\u8868\\u793A\\uFF0C\\u4EE5\\u53CA\\u4E00\\u4E2A\\u51B7\\u5374\\u65F6\\u95F4 \",(0,t.jsx)(e.code,{children:\"k\"}),\"\\u3002\\u51B7\\u5374\\u65F6\\u95F4\\u6307\\u5B9A\\u540C\\u4E00\\u4EFB\\u52A1\\u7684\\u4E24\\u6B21\\u6267\\u884C\\u4E4B\\u95F4\\u5FC5\\u987B\\u81F3\\u5C11\\u95F4\\u9694 \",(0,t.jsx)(e.code,{children:\"k\"}),\" \\u4E2A\\u65F6\\u95F4\\u5355\\u4F4D\\u3002\"]}),`\n`,(0,t.jsx)(e.p,{children:\"\\u786E\\u5B9A\\u5B8C\\u6210\\u6240\\u6709\\u4EFB\\u52A1\\u6240\\u9700\\u7684\\u6700\\u5C0F\\u95F4\\u9694\\u6570\\uFF0C\\u540C\\u65F6\\u786E\\u4FDD\\u5728\\u51B7\\u5374\\u671F\\u8FC7\\u53BB\\u4E4B\\u524D\\u4E0D\\u4F1A\\u518D\\u6B21\\u6267\\u884C\\u540C\\u4E00\\u4EFB\\u52A1\\u3002\"}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.code,{children:\"tasks: string[]\"}),\": \\u5B57\\u7B26\\u6570\\u7EC4\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u4EFB\\u52A1\\u7531\\u4E00\\u4E2A\\u5B57\\u6BCD (A-Z) \\u8868\\u793A\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.code,{children:\"k: number\"}),\": \\u4E00\\u4E2A\\u6574\\u6570\\uFF0C\\u8868\\u793A\\u51B7\\u5374\\u65F6\\u95F4\\uFF0C\\u5373\\u540C\\u4E00\\u4EFB\\u52A1\\u4E24\\u6B21\\u6267\\u884C\\u4E4B\\u95F4\\u7684\\u6700\\u5C0F\\u95F4\\u9694\\u6570\"]}),`\n`]}),`\n`,(0,t.jsx)(c,{testCases:h}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[\"1 <= \",(0,t.jsx)(e.code,{children:\"tasks.length\"}),\" <= 1000\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.code,{children:\"tasks[i]\"}),\" \\u662F\\u4E00\\u4E2A\\u5927\\u5199\\u82F1\\u6587\\u5B57\\u6BCD\"]}),`\n`,(0,t.jsxs)(e.li,{children:[\"0 <= \",(0,t.jsx)(e.code,{children:\"k\"}),\" <= 100\"]}),`\n`]})]})}function w(n={}){let{wrapper:e}=n.components||{};return e?(0,t.jsx)(e,Object.assign({},n,{children:(0,t.jsx)(u,n)})):u(n)}var j=w;return b(C);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,用于查找具有冷却时间的任务的最小间隔", + "title": "任务协调" + }, + "solution": "var Component=(()=>{var p=Object.create;var l=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var k=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var q=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),C=(t,e)=>{for(var r in e)l(t,r,{get:e[r],enumerable:!0})},d=(t,e,r,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of f(e))!g.call(t,i)&&i!==r&&l(t,i,{get:()=>e[i],enumerable:!(o=x(e,i))||o.enumerable});return t};var y=(t,e,r)=>(r=t!=null?p(k(t)):{},d(e||!t||!t.__esModule?l(r,\"default\",{value:t,enumerable:!0}):r,t)),b=t=>d(l({},\"__esModule\",{value:!0}),t);var a=q((_,h)=>{h.exports=_jsx_runtime});var w={};C(w,{default:()=>v});var n=y(a());var c=MDXCodeBlock;var s=`export default function taskCoordinator(tasks: string[], k: number): number {\n // Array to store the frequency of each task (26 letters, A-Z)\n const counter: number[] = new Array(26).fill(0);\n let maximum = 0; // Maximum frequency of any task\n let maxCount = 0; // Number of tasks with maximum frequency\n\n // Traverse through tasks to calculate task frequencies\n for (const task of tasks) {\n const index = task.charCodeAt(0) - 'A'.charCodeAt(0);\n counter[index]++;\n\n if (maximum === counter[index]) {\n maxCount++;\n } else if (maximum < counter[index]) {\n maximum = counter[index];\n maxCount = 1;\n }\n }\n\n // Calculate idle slots, available tasks, and idles needed\n const partCount = maximum - 1;\n const partLength = k - (maxCount - 1);\n const emptySlots = partCount * partLength;\n const availableTasks = tasks.length - maximum * maxCount;\n const idles = Math.max(0, emptySlots - availableTasks);\n\n // Return the total time required\n return tasks.length + idles;\n}\n`;var u=`export default function leastInterval(tasks: string[], n: number): number {\n // Building frequency map\n const freq: number[] = new Array(26).fill(0);\n for (const ch of tasks) {\n freq[ch.charCodeAt(0) - 'A'.charCodeAt(0)]++;\n }\n\n // Max heap to store frequencies\n const pq: number[] = [];\n\n // Helper function to maintain the max heap property\n function heapPush(value: number) {\n pq.push(value);\n let index = pq.length - 1;\n while (index > 0) {\n const parentIndex = Math.floor((index - 1) / 2);\n if (pq[index] > pq[parentIndex]) {\n [pq[index], pq[parentIndex]] = [pq[parentIndex], pq[index]];\n index = parentIndex;\n } else {\n break;\n }\n }\n }\n\n // Populate the max heap with frequencies\n for (const count of freq) {\n if (count > 0) {\n heapPush(count);\n }\n }\n\n let time = 0;\n // Process tasks until the heap is empty\n while (pq.length > 0) {\n let cycle = n + 1;\n const store: number[] = [];\n let taskCount = 0;\n\n // Execute tasks in each cycle\n while (cycle-- > 0 && pq.length > 0) {\n const top = pq[0];\n if (top > 1) {\n store.push(top - 1);\n }\n pq.shift(); // Remove the top element from the heap\n taskCount++;\n }\n\n // Restore updated frequencies to the heap\n for (const x of store) {\n heapPush(x);\n }\n\n // Add time for the completed cycle\n time += pq.length === 0 ? taskCount : n + 1;\n }\n\n return time;\n}\n`;function m(t){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528\\u8D2A\\u5FC3\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u6B64\\u89E3\\u51B3\\u65B9\\u6848\\u6700\\u5927\\u9650\\u5EA6\\u5730\\u51CF\\u5C11\\u4E86\\u4F7F\\u7528\\u51B7\\u5374\\u671F \",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u6267\\u884C\\u4E00\\u7CFB\\u5217\\u4EFB\\u52A1\\u6240\\u9700\\u7684\\u65F6\\u95F4\\uFF0C\\u786E\\u4FDD\\u5728 \",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u4E2A\\u95F4\\u9694\\u5185\\u4E0D\\u6267\\u884C\\u4E24\\u4E2A\\u76F8\\u540C\\u7684\\u4EFB\\u52A1\\u3002 \\u6838\\u5FC3\\u601D\\u60F3\\u662F\\u5173\\u6CE8\\u9891\\u7387\\u6700\\u9AD8\\u7684\\u4EFB\\u52A1\\uFF0C\\u56E0\\u4E3A\\u5B83\\u4EEC\\u5728\\u8C03\\u5EA6\\u8FC7\\u7A0B\\u4E2D\\u5360\\u4E3B\\u5BFC\\u5730\\u4F4D\\u3002 \\u8FD9\\u4E9B\\u4EFB\\u52A1\\u5FC5\\u987B\\u5C3D\\u53EF\\u80FD\\u5747\\u5300\\u5730\\u5206\\u5E03\\uFF0C\\u4ECE\\u800C\\u5728\\u8C03\\u5EA6\\u4E2D\\u521B\\u5EFA\\u201C\\u5206\\u533A\\u201D\\u3002 \\u5269\\u4F59\\u7684\\u4EFB\\u52A1\\u586B\\u8865\\u4E86\\u8FD9\\u4E9B\\u5206\\u533A\\u4E4B\\u95F4\\u7684\\u7A7A\\u767D\\uFF0C\\u51CF\\u5C11\\u4E86\\u7A7A\\u95F2\\u65F6\\u95F4\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u9891\\u7387\\u6700\\u9AD8\\u7684\\u4EFB\\u52A1\\u5B9A\\u4E49\\u4E86\\u8C03\\u5EA6\\u7684\\u6846\\u67B6\\uFF0C\\u56E0\\u4E3A\\u5B83\\u4EEC\\u7684\\u5206\\u5E03\\u51B3\\u5B9A\\u4E86\\u6240\\u6709\\u5176\\u4ED6\\u4EFB\\u52A1\\u7684\\u653E\\u7F6E\\u3002 \\u8FD9\\u4E9B\\u4EFB\\u52A1\\u7684\\u6BCF\\u6B21\\u51FA\\u73B0\\u81F3\\u5C11\\u95F4\\u9694 \",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u4E2A\\u95F4\\u9694\\u3002 \\u5982\\u679C\\u6709\\u5176\\u4ED6\\u4EFB\\u52A1\\u6765\\u586B\\u8865\\u8FD9\\u4E9B\\u7A7A\\u767D\\uFF0C\\u5219\\u7A7A\\u95F2\\u65F6\\u95F4\\u4F1A\\u51CF\\u5C11\\uFF1B\\u5426\\u5219\\uFF0C\\u7A7A\\u95F2\\u65F6\\u9699\\u4ECD\\u7136\\u5B58\\u5728\\uFF0C\\u4ECE\\u800C\\u589E\\u52A0\\u4E86\\u603B\\u65F6\\u95F4\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8D2A\\u5FC3\\u7B97\\u6CD5\\u786E\\u4FDD\\u8C03\\u5EA6\\u901A\\u8FC7\\u9996\\u5148\\u586B\\u8865\\u7531\\u6700\\u9891\\u7E41\\u7684\\u4EFB\\u52A1\\u521B\\u5EFA\\u7684\\u7A7A\\u767D\\u6765\\u538B\\u7F29\\u3002 \\u8FD9\\u907F\\u514D\\u4E86\\u4E0D\\u5FC5\\u8981\\u7684\\u7A7A\\u95F2\\u65F6\\u95F4\\uFF0C\\u5E76\\u786E\\u4FDD\\u8C03\\u5EA6\\u5728\\u4FDD\\u6301\\u5C3D\\u53EF\\u80FD\\u77ED\\u7684\\u540C\\u65F6\\u9075\\u5B88\\u51B7\\u5374\\u7EA6\\u675F\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u5927\\u5C0F\\u4E3A 26 \\u7684\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"counter\"}),\" \\u4EE5\\u8BA1\\u7B97\\u6BCF\\u4E2A\\u4EFB\\u52A1\\u7684\\u9891\\u7387\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u904D\\u5386 \",(0,n.jsx)(e.code,{children:\"tasks\"}),\" \\u6570\\u7EC4\\u4EE5\\u586B\\u5145 \",(0,n.jsx)(e.code,{children:\"counter\"}),\" \\u6570\\u7EC4\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u4EFB\\u52A1\\uFF0C\\u589E\\u52A0\\u5176\\u5728 \",(0,n.jsx)(e.code,{children:\"counter\"}),\" \\u4E2D\\u7684\\u9891\\u7387\\u8BA1\\u6570\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u66F4\\u65B0 \",(0,n.jsx)(e.code,{children:\"maximum\"}),\" \\u4EE5\\u8DDF\\u8E2A\\u4EFB\\u4F55\\u4EFB\\u52A1\\u7684\\u6700\\u9AD8\\u9891\\u7387\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u66F4\\u65B0 \",(0,n.jsx)(e.code,{children:\"maxCount\"}),\" \\u4EE5\\u8BA1\\u7B97\\u6709\\u591A\\u5C11\\u4EFB\\u52A1\\u5177\\u6709\\u6B64\\u6700\\u5927\\u9891\\u7387\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8BA1\\u7B97\\u5206\\u533A\\u6570\\uFF0C\\u5373 \",(0,n.jsx)(e.code,{children:\"maximum - 1\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8BA1\\u7B97\\u6BCF\\u4E2A\\u5206\\u533A\\u7684\\u957F\\u5EA6\\uFF0C\\u5373 \",(0,n.jsx)(e.code,{children:\"k - (maxCount - 1)\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8BA1\\u7B97\\u7A7A\\u69FD\\u603B\\u6570\\uFF0C\\u5373 \",(0,n.jsx)(e.code,{children:\"partCount * partLength\"}),\"\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8BA1\\u7B97\\u53EF\\u7528\\u4EFB\\u52A1\\u6570\\uFF0C\\u5373\\u4EFB\\u52A1\\u603B\\u6570\\u51CF\\u53BB\\u5177\\u6709\\u6700\\u5927\\u9891\\u7387\\u7684\\u4EFB\\u52A1\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8BA1\\u7B97\\u7A7A\\u95F2\\u69FD\\u6570\\uFF0C\\u5373 \",(0,n.jsx)(e.code,{children:\"Math.max(0, emptySlots - availableTasks)\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u6240\\u9700\\u603B\\u65F6\\u95F4\\u4F5C\\u4E3A \",(0,n.jsx)(e.code,{children:\"tasks.length + idles\"}),\" \\u8FD4\\u56DE\\u3002\"]}),`\n`]}),`\n`,(0,n.jsxs)(c,{children:[\" \",s,\" \"]}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n)\"}),\"\\u3002 \\u904D\\u5386 \",(0,n.jsx)(e.code,{children:\"tasks\"}),\" \\u6570\\u7EC4\\u548C\\u66F4\\u65B0 \",(0,n.jsx)(e.code,{children:\"counter\"}),\" \\u6570\\u7EC4\\u90FD\\u9700\\u8981\\u7EBF\\u6027\\u65F6\\u95F4\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002 \\u65E0\\u8BBA\\u8F93\\u5165\\u5927\\u5C0F\\u5982\\u4F55\\uFF0C\",(0,n.jsx)(e.code,{children:\"counter\"}),\" \\u6570\\u7EC4\\u7684\\u5927\\u5C0F\\u90FD\\u56FA\\u5B9A\\u4E3A 26\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u4F7F\\u7528\\u5806\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u5173\\u952E\\u601D\\u60F3\\u662F\\u901A\\u8FC7\\u59CB\\u7EC8\\u9996\\u5148\\u6267\\u884C\\u6700\\u9891\\u7E41\\u7684\\u4EFB\\u52A1\\u6765\\u6700\\u5927\\u9650\\u5EA6\\u5730\\u51CF\\u5C11\\u7A7A\\u95F2\\u65F6\\u95F4\\u3002 \\u4F7F\\u7528\\u6700\\u5927\\u5806\\u53EF\\u4EE5\\u6709\\u6548\\u5730\\u68C0\\u7D22\\u5269\\u4F59\\u9891\\u7387\\u6700\\u9AD8\\u7684\\u4EFB\\u52A1\\u3002 \\u8FD9\\u786E\\u4FDD\\u4E86\\u4EE5\\u66F4\\u9AD8\\u7684\\u9891\\u7387\\u6267\\u884C\\u4EFB\\u52A1\\uFF0C\\u4ECE\\u800C\\u51CF\\u5C11\\u4E86\\u7A7A\\u95F2\\u5468\\u671F\\u7684\\u53EF\\u80FD\\u6027\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u6784\\u5EFA\\u4E00\\u4E2A\\u9891\\u7387\\u6620\\u5C04\\u6765\\u8BA1\\u7B97\\u6BCF\\u4E2A\\u4EFB\\u52A1\\u7684\\u51FA\\u73B0\\u6B21\\u6570\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u4F7F\\u7528\\u4EFB\\u52A1\\u9891\\u7387\\u586B\\u5145\\u6700\\u5927\\u5806\\u3002\\u5806\\u7684\\u7ED3\\u6784\\u4F18\\u5148\\u8003\\u8651\\u6700\\u9AD8\\u9891\\u7387\\u7684\\u4EFB\\u52A1\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u603B\\u65F6\\u95F4\\u8BA1\\u6570\\u5668\\u521D\\u59CB\\u5316\\u4E3A \",(0,n.jsx)(e.code,{children:\"0\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5F53\\u5806\\u4E0D\\u4E3A\\u7A7A\\u65F6\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u6267\\u884C\\u4E00\\u4E2A\\u51B7\\u5374\\u5468\\u671F\\uFF08\",(0,n.jsx)(e.code,{children:\"n + 1\"}),\" \\u6B21\\uFF09\\u7684\\u4EFB\\u52A1\\uFF0C\\u6216\\u8005\\u76F4\\u5230\\u5806\\u4E3A\\u7A7A\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u51CF\\u5C11\\u5DF2\\u6267\\u884C\\u4EFB\\u52A1\\u7684\\u9891\\u7387\\u5E76\\u5B58\\u50A8\\u66F4\\u65B0\\u540E\\u7684\\u9891\\u7387\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5468\\u671F\\u7ED3\\u675F\\u540E\\uFF0C\\u5C06\\u66F4\\u65B0\\u540E\\u7684\\u4EFB\\u52A1\\u9891\\u7387\\u91CD\\u65B0\\u63D2\\u5165\\u5806\\u4E2D\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u66F4\\u65B0\\u603B\\u65F6\\u95F4\\u8BA1\\u6570\\u5668\\u3002\\u5982\\u679C\\u4E00\\u4E2A\\u5468\\u671F\\u540E\\u5806\\u4E3A\\u7A7A\\uFF0C\\u5219\\u4EC5\\u6DFB\\u52A0\\u8BE5\\u5468\\u671F\\u5185\\u6267\\u884C\\u7684\\u4EFB\\u52A1\\uFF1B\\u5426\\u5219\\uFF0C\\u6DFB\\u52A0 \",(0,n.jsx)(e.code,{children:\"n + 1\"}),\" \\u4E2A\\u65F6\\u95F4\\u5355\\u4F4D\\uFF0C\\u7528\\u4E8E\\u6574\\u4E2A\\u5468\\u671F\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5C06\\u603B\\u65F6\\u95F4\\u8BA1\\u6570\\u5668\\u4F5C\\u4E3A\\u7ED3\\u679C\\u8FD4\\u56DE\\u3002\"}),`\n`]}),`\n`,(0,n.jsxs)(c,{children:[\" \",u,\" \"]}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n log k)\"}),\"\\u3002 \\u8FED\\u4EE3 \",(0,n.jsx)(e.code,{children:\"tasks\"}),\" \\u6570\\u7EC4\\u5E76\\u6784\\u5EFA\\u9891\\u7387\\u6620\\u5C04\\u4E3A O(n)\\u3002 \\u5806\\u4E0A\\u7684\\u64CD\\u4F5C\\uFF08\\u63D2\\u5165\\u548C\\u5220\\u9664\\uFF09\\u4E3A O(log k)\\uFF0C\\u5176\\u4E2D \",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u662F\\u552F\\u4E00\\u4EFB\\u52A1\\u7684\\u6570\\u91CF\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(k)\"}),\"\\u3002 \\u5806\\u548C\\u9891\\u7387\\u6620\\u5C04\\u6240\\u9700\\u7684\\u5B58\\u50A8\\u7A7A\\u95F4\\u4E0E\\u552F\\u4E00\\u4EFB\\u52A1\\u7684\\u6570\\u91CF\\u6210\\u6B63\\u6BD4\\uFF0C\\u5373 \",(0,n.jsx)(e.code,{children:\"k\"}),\"\\u3002\"]}),`\n`]})]})}function O(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(m,t)})):m(t)}var v=O;return b(w);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/topological-sort/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/topological-sort/locales/zh-CN.json new file mode 100644 index 000000000..a8314ffd4 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/topological-sort/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var i=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var C=(l,n)=>()=>(n||l((n={exports:{}}).exports,n),n.exports),A=(l,n)=>{for(var r in n)i(l,r,{get:n[r],enumerable:!0})},t=(l,n,r,h)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let c of g(n))!u.call(l,c)&&c!==r&&i(l,c,{get:()=>n[c],enumerable:!(h=s(n,c))||h.enumerable});return l};var B=(l,n,r)=>(r=l!=null?p(D(l)):{},t(n||!l||!l.__esModule?i(r,\"default\",{value:l,enumerable:!0}):r,l)),F=l=>t(i({},\"__esModule\",{value:!0}),l);var d=C((f,o)=>{o.exports=_jsx_runtime});var j={};A(j,{default:()=>E,frontmatter:()=>m});var e=B(d()),m={title:\"\\u62D3\\u6251\\u6392\\u5E8F\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u6267\\u884C\\u62D3\\u6251\\u6392\\u5E8F\\u7684\\u51FD\\u6570\"};function a(l){let n=Object.assign({p:\"p\",h2:\"h2\",pre:\"pre\",code:\"code\",ol:\"ol\",li:\"li\",h3:\"h3\",ul:\"ul\"},l.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.p,{children:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u5BF9\\u6709\\u5411\\u56FE\\uFF08\\u90BB\\u63A5\\u8868\\u683C\\u5F0F\\uFF09\\u6267\\u884C\\u62D3\\u6251\\u6392\\u5E8F\\u7684\\u51FD\\u6570\\uFF0C\\u5176\\u4E2D\\u952E\\u8868\\u793A\\u8282\\u70B9\\uFF0C\\u503C\\u662F\\u5177\\u6709\\u6307\\u5411\\u5F53\\u524D\\u8282\\u70B9\\u7684\\u4F20\\u51FA\\u8FB9\\u7684\\u8282\\u70B9\\u6570\\u7EC4\\u3002\"}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u4F8B\\u5B50\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-js\",children:`const graph1 = {\n A: ['B', 'C'],\n B: ['C', 'D', 'E'],\n C: ['F'],\n D: [],\n E: ['F'],\n F: [],\n};\ntopologicalSort(graph1); // ['A', 'B', 'C', 'D', 'E', 'F']\n\nconst graph2 = {\n A: ['B', 'C'],\n B: ['C', 'D'],\n C: ['D'],\n D: ['E'],\n E: ['F'],\n F: [],\n};\ntopologicalSort(graph2); // ['A', 'B', 'C', 'D', 'E', 'F']\n\nconst graph3 = {\n A: [],\n B: ['A'],\n C: ['B'],\n D: ['C'],\n E: ['D'],\n F: ['E'],\n};\ntopologicalSort(graph3); // ['F', 'E', 'D', 'C', 'B', 'A']\n`})}),`\n`,(0,e.jsx)(n.p,{children:\"\\u8BF7\\u6CE8\\u610F\\uFF0C\\u5BF9\\u4E8E\\u6709\\u5411\\u56FE\\uFF0C\\u53EF\\u4EE5\\u6709\\u591A\\u4E2A\\u6709\\u6548\\u7684\\u62D3\\u6251\\u6392\\u5E8F\\uFF0C\\u4F46\\u5BF9\\u4E8E\\u6211\\u4EEC\\u7684\\u6D4B\\u8BD5\\u7528\\u4F8B\\uFF0C\\u53EA\\u6709\\u4E00\\u4E2A\\u6709\\u6548\\u7684\\u89E3\\u51B3\\u65B9\\u6848\\u3002\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5728\\u9AA8\\u67B6\\u4EE3\\u7801\\u7684\\u5E95\\u90E8\\u4E5F\\u4E3A\\u60A8\\u63D0\\u4F9B\\u4E86\\u4E00\\u4E2A \",(0,e.jsx)(n.code,{children:\"Queue\"}),\" \\u6570\\u636E\\u7ED3\\u6784\\u3002\"]}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u56DE\\u987E\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u62D3\\u6251\\u6392\\u5E8F\\u662F\\u4E00\\u79CD\\u7B97\\u6CD5\\uFF0C\\u7528\\u4E8E\\u4EE5\\u7EBF\\u6027\\u987A\\u5E8F\\u5BF9\\u6709\\u5411\\u65E0\\u73AF\\u56FE (DAG) \\u7684\\u5143\\u7D20\\u8FDB\\u884C\\u6392\\u5E8F\\uFF0C\\u4F7F\\u5F97\\u987A\\u5E8F\\u9075\\u5FAA\\u56FE\\u4E2D\\u8FB9\\u5B9A\\u4E49\\u7684\\u987A\\u5E8F\\u3002\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u7406\\u89E3\\u8FD9\\u4E00\\u70B9\\u7684\\u4E00\\u79CD\\u7B80\\u5355\\u65B9\\u6CD5\\u662F\\u5C06\\u56FE\\u7684\\u8282\\u70B9\\u89C6\\u4E3A\\u4EFB\\u52A1\\uFF0C\\u4ECE\\u8282\\u70B9 A \\u5230\\u8282\\u70B9 B \\u7684\\u8FB9\\u8868\\u793A\\u8282\\u70B9 B \\u4F9D\\u8D56\\u4E8E\\u8282\\u70B9 A\\u3002\\u62D3\\u6251\\u6392\\u5E8F\\u6240\\u505A\\u7684\\u662F\\u4ECE\\u56FE\\u4E2D\\u751F\\u6210\\u4E00\\u4E2A\\u8282\\u70B9\\u6570\\u7EC4\\uFF0C\\u4F7F\\u5F97\\u6570\\u7EC4\\u4E2D\\u8282\\u70B9\\u7684\\u987A\\u5E8F\\u9075\\u5FAA\\u56FE\\u4E2D\\u5B9A\\u4E49\\u7684\\u6240\\u6709\\u4F9D\\u8D56\\u5173\\u7CFB\\u3002\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u4E3A\\u4EC0\\u4E48\\u62D3\\u6251\\u6392\\u5E8F\\u53EA\\u9002\\u7528\\u4E8E DAG \\u800C\\u4E0D\\u662F\\u4EFB\\u4F55\\u56FE\\uFF1F\\u8FD9\\u662F\\u56E0\\u4E3A\\u56FE\\u5FC5\\u987B\\u5177\\u6709\\u6709\\u5411\\u8FB9\\u624D\\u80FD\\u8868\\u793A\\u4F9D\\u8D56\\u5173\\u7CFB\\uFF0C\\u5E76\\u4E14\\u662F\\u65E0\\u73AF\\u7684\\uFF08\\u65E0\\u73AF\\uFF09\\uFF0C\\u56E0\\u4E3A\\u4EFB\\u4F55\\u73AF\\u90FD\\u5C06\\u8868\\u793A\\u8282\\u70B9\\u4E4B\\u95F4\\u65E0\\u6CD5\\u89E3\\u6790\\u7684\\u4F9D\\u8D56\\u5173\\u7CFB\\u3002\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u62D3\\u6251\\u6392\\u5E8F\\u901A\\u5E38\\u7528\\u4E8E\\u8C03\\u5EA6\\u95EE\\u9898\\uFF0C\\u4F8B\\u5982\\u8C03\\u5EA6\\u5177\\u6709\\u4F9D\\u8D56\\u5173\\u7CFB\\u7684\\u4F5C\\u4E1A\\uFF0C\\u6216\\u5728\\u7F16\\u8BD1\\u4E2D\\uFF0C\\u7F16\\u8BD1\\u987A\\u5E8F\\u7531\\u6A21\\u5757\\u4E4B\\u95F4\\u7684\\u4F9D\\u8D56\\u5173\\u7CFB\\u51B3\\u5B9A\\u3002\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u6709\\u5F88\\u591A\\u65B9\\u6CD5\\u53EF\\u4EE5\\u5B9E\\u73B0\\u62D3\\u6251\\u6392\\u5E8F\\uFF0C\\u4F46\\u4E00\\u79CD\\u7B80\\u5355\\u76F4\\u89C2\\u7684\\u65B9\\u6CD5\\u662F\\u4F7F\\u7528 Kahn \\u7B97\\u6CD5\\uFF0C\\u5176\\u5DE5\\u4F5C\\u539F\\u7406\\u5982\\u4E0B\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u961F\\u5217\\u548C\\u4E00\\u4E2A\\u5217\\u8868\\u6765\\u5B58\\u50A8\\u6392\\u5E8F\\u540E\\u7684\\u8282\\u70B9\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5BF9\\u4E8E\\u56FE\\u4E2D\\u7684\\u6BCF\\u4E2A\\u8282\\u70B9\\uFF0C\\u5982\\u679C\\u5B83\\u6CA1\\u6709\\u5165\\u8FB9\\uFF0C\\u5219\\u5C06\\u5176\\u6DFB\\u52A0\\u5230\\u961F\\u5217\\u4E2D\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5F53\\u961F\\u5217\\u4E0D\\u4E3A\\u7A7A\\u65F6\\uFF1A\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u4ECE\\u961F\\u5217\\u7684\\u524D\\u9762\\u53D6\\u51FA\\u4E00\\u4E2A\\u8282\\u70B9\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5C06\\u6B64\\u8282\\u70B9\\u6DFB\\u52A0\\u5230\\u5DF2\\u6392\\u5E8F\\u8282\\u70B9\\u7684\\u5217\\u8868\\u4E2D\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5BF9\\u4E8E\\u6B64\\u8282\\u70B9\\u7684\\u6BCF\\u4E2A\\u5B50\\u8282\\u70B9\\uFF0C\\u5C06\\u5176\\u5165\\u5EA6\\uFF08\\u5165\\u8FB9\\u7684\\u6570\\u91CF\\uFF09\\u51CF 1\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5982\\u679C\\u5B50\\u8282\\u70B9\\u7684\\u5165\\u5EA6\\u53D8\\u4E3A 0\\uFF0C\\u5219\\u5C06\\u5176\\u6DFB\\u52A0\\u5230\\u961F\\u5217\\u4E2D\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5982\\u679C\\u6392\\u5E8F\\u5217\\u8868\\u7684\\u957F\\u5EA6\\u5C0F\\u4E8E\\u56FE\\u4E2D\\u7684\\u8282\\u70B9\\u6570\\uFF0C\\u8FD9\\u610F\\u5473\\u7740\\u56FE\\u4E2D\\u5B58\\u5728\\u4E00\\u4E2A\\u5FAA\\u73AF\\uFF0C\\u5E76\\u4E14\\u65E0\\u6CD5\\u8FDB\\u884C\\u62D3\\u6251\\u6392\\u5E8F\\u3002\"}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7B14\\u8BB0\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u4E25\\u683C\\u6765\\u8BF4\\uFF0C\\u6211\\u4EEC\\u4E5F\\u53EF\\u4EE5\\u4F7F\\u7528\\u4E00\\u4E2A\\u96C6\\u5408\\u800C\\u4E0D\\u662F\\u4E00\\u4E2A\\u961F\\u5217\\u3002\"}),`\n`]})]})}function x(l={}){let{wrapper:n}=l.components||{};return n?(0,e.jsx)(n,Object.assign({},l,{children:(0,e.jsx)(a,l)})):a(l)}var E=x;return F(j);})();\n;return Component;", + "info": { + "excerpt": "实现一个执行拓扑排序的函数", + "title": "拓扑排序" + }, + "solution": "var Component=(()=>{var p=Object.create;var i=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var v=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),q=(n,e)=>{for(var o in e)i(n,o,{get:e[o],enumerable:!0})},h=(n,e,o,u)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of f(e))!b.call(n,r)&&r!==o&&i(n,r,{get:()=>e[r],enumerable:!(u=g(e,r))||u.enumerable});return n};var _=(n,e,o)=>(o=n!=null?p(y(n)):{},h(e||!n||!n.__esModule?i(o,\"default\",{value:n,enumerable:!0}):o,n)),w=n=>h(i({},\"__esModule\",{value:!0}),n);var s=v((H,d)=>{d.exports=_jsx_runtime});var E={};q(E,{default:()=>k});var t=_(s());var a=MDXCodeBlock;var l=`/**\n * @param {Object} graph Node to array of neighboring nodes.\n * @return {Array} A topological traversal of nodes.\n */\nexport default function topologicalSort(graph) {\n // Initialize a Map object to store each node's incoming and outgoing edges,\n // an array to store the output topological sort order,\n // and a Queue object to store nodes to be processed\n const nodes = new Map();\n const queue = new Queue();\n const order = [];\n\n // Iterating over all the keys in the input graph object\n // add each key to the \"nodes\" Map object\n // with properties \"in\" with value 0\n // and \"out\" with the value of set of neighboring nodes.\n Object.keys(graph).forEach((node) => {\n nodes.set(node, { in: 0, out: new Set(graph[node]) });\n });\n\n // Set the Map with the correct \\`in\\` values.\n // Iterating over all the keys in the input graph object,\n // for each node increase the \\`in\\` property of its neighbor node by 1.\n Object.keys(graph).forEach((node) => {\n graph[node].forEach((neighbor) => {\n nodes.get(neighbor).in += 1;\n });\n });\n\n // Iterate over the nodes and add all the nodes with \\`in: 0\\` to the queue.\n nodes.forEach((value, node) => {\n if (value.in === 0) {\n queue.enqueue(node);\n }\n });\n\n // While queue is not empty.\n while (queue.length()) {\n // Dequeue a node from the front of the queue.\n const node = queue.dequeue();\n\n // For each neighbor of this dequeued node decrease its \\`in\\` property by 1,\n // if the \\`in\\` becomes 0, enqueue the neighbor node.\n nodes.get(node).out.forEach((neighbor) => {\n nodes.get(neighbor).in -= 1;\n if (nodes.get(neighbor).in === 0) {\n queue.enqueue(neighbor);\n }\n });\n\n // Add the dequeued node to the output array.\n order.push(node);\n }\n\n // Return topological-ordered array if it has the same length as\n // the number of keys in the graph, otherwise there is a cycle\n // and we return an empty array.\n return order.length === Object.keys(graph).length ? order : [];\n}\n\nclass Node {\n constructor(value) {\n this.value = value;\n this.next = null;\n this.prev = null;\n }\n}\n\nclass Queue {\n constructor() {\n this._dummyHead = new Node();\n this._dummyTail = new Node();\n this._dummyHead.prev = this._dummyTail;\n this._dummyTail.next = this._dummyHead;\n this._length = 0;\n }\n\n /**\n * Adds an item to the back of the queue.\n * @param {*} item The item to be pushed onto the queue.\n * @return {number} The new length of the queue.\n */\n enqueue(item) {\n const node = new Node(item);\n const prevLast = this._dummyTail.next;\n prevLast.prev = node;\n\n node.next = prevLast;\n node.prev = this._dummyTail;\n this._dummyTail.next = node;\n this._length++;\n return this._length;\n }\n\n /**\n * Remove an item from the front of the queue.\n * @return {*} The item at the front of the queue if it is not empty, \\`undefined\\` otherwise.\n */\n dequeue() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n const node = this._dummyHead.prev;\n const newFirst = node.prev;\n this._dummyHead.prev = newFirst;\n newFirst.next = this._dummyHead;\n // Unlink the node to be dequeued.\n node.prev = null;\n node.next = null;\n this._length--;\n return node.value;\n }\n\n /**\n * Determines if the queue is empty.\n * @return {boolean} \\`true\\` if the queue has no items, \\`false\\` otherwise.\n */\n isEmpty() {\n return this._length === 0;\n }\n\n /**\n * Returns the item at the front of the queue without removing it from the queue.\n * @return {*} The item at the front of the queue if it is not empty, \\`undefined\\` otherwise.\n */\n front() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n return this._dummyHead.prev.value;\n }\n\n /**\n * Returns the item at the back of the queue without removing it from the queue it.\n * @return {*} The item at the back of the queue if it is not empty, \\`undefined\\` otherwise.\n */\n back() {\n if (this.isEmpty()) {\n return undefined;\n }\n\n return this._dummyTail.next.value;\n }\n\n /**\n * Returns the number of items in the queue.\n * @return {number} The number of items in the queue.\n */\n length() {\n return this._length;\n }\n}\n`;var c=`export default function topologicalSort(\n graph: Record>,\n): Array {\n // Initialize a Map object to store each node's incoming and outgoing edges,\n // an array to store the output topological sort order,\n // and a Queue object to store nodes to be processed\n const nodes = new Map }>();\n const queue = new Queue();\n const order = [];\n\n // Iterating over all the keys in the input graph object\n // add each key to the \"nodes\" Map object\n // with properties \"in\" with value 0\n // and \"out\" with the value of set of neighboring nodes.\n Object.keys(graph).forEach((node) => {\n nodes.set(node, { in: 0, out: new Set(graph[node]) });\n });\n\n // Set the Map with the correct \\`in\\` values.\n // Iterating over all the keys in the input graph object,\n // for each node increase the \\`in\\` property of its neighbor node by 1.\n Object.keys(graph).forEach((node) => {\n graph[node].forEach((neighbor) => {\n nodes.get(neighbor)!.in += 1;\n });\n });\n\n // Iterate over the nodes and add all the nodes with \\`in: 0\\` to the queue.\n nodes.forEach((value, node) => {\n if (value.in === 0) {\n queue.enqueue(node);\n }\n });\n\n // While queue is not empty.\n while (queue.length()) {\n // Dequeue a node from the front of the queue.\n const node = queue.dequeue()!;\n\n // For each neighbor of this dequeued node decrease its \\`in\\` property by 1,\n // if the \\`in\\` becomes 0, enqueue the neighbor node.\n nodes.get(node)?.out.forEach((neighbor) => {\n nodes.get(neighbor)!.in -= 1;\n if (nodes.get(neighbor)!.in === 0) {\n queue.enqueue(neighbor);\n }\n });\n\n // Add the dequeued node to the output array.\n order.push(node);\n }\n\n // Return topological-ordered array if it has the same length as\n // the number of keys in the graph, otherwise there is a cycle\n // and we return an empty array.\n return order.length === Object.keys(graph).length ? order : [];\n}\n\nclass Node {\n value: T | undefined;\n next: Node | null;\n prev: Node | null;\n\n constructor(value?: T) {\n this.value = value;\n this.next = null;\n this.prev = null;\n }\n}\n\nclass Queue {\n _dummyHead: Node;\n _dummyTail: Node;\n _length: number;\n\n constructor() {\n this._dummyHead = new Node();\n this._dummyTail = new Node();\n this._dummyHead.prev = this._dummyTail;\n this._dummyTail.next = this._dummyHead;\n this._length = 0;\n }\n\n /**\n * Adds an item to the back of the queue.\n */\n enqueue(item: T) {\n const node = new Node(item);\n const prevLast = this._dummyTail.next;\n prevLast!.prev = node;\n\n node.next = prevLast;\n node.prev = this._dummyTail;\n this._dummyTail.next = node;\n this._length++;\n return this._length;\n }\n\n /**\n * Remove an item from the front of the queue.\n */\n dequeue(): T | undefined {\n if (this.isEmpty()) {\n return undefined;\n }\n\n const node = this._dummyHead.prev;\n const newFirst = node!.prev;\n this._dummyHead.prev = newFirst;\n newFirst!.next = this._dummyHead;\n // Unlink the node to be dequeued.\n node!.prev = null;\n node!.next = null;\n this._length--;\n return node!.value;\n }\n\n /**\n * Determines if the queue is empty.\n */\n isEmpty(): boolean {\n return this._length === 0;\n }\n\n /**\n * Returns the item at the front of the queue without removing it from the queue.\n */\n front(): T | undefined {\n if (this.isEmpty()) {\n return undefined;\n }\n\n return this._dummyHead.prev!.value;\n }\n\n /**\n * Returns the item at the back of the queue without removing it from the queue it.\n */\n back(): T | undefined {\n if (this.isEmpty()) {\n return undefined;\n }\n\n return this._dummyTail.next!.value;\n }\n\n /**\n * Returns the number of items in the queue.\n * @return {number} The number of items in the queue.\n */\n length(): number {\n return this._length;\n }\n}\n`;function m(n){let e=Object.assign({p:\"p\",h2:\"h2\",ul:\"ul\",li:\"li\",h3:\"h3\",code:\"code\"},n.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(e.p,{children:\"\\u62D3\\u6251\\u6392\\u5E8F\\u662F\\u4E00\\u79CD\\u7B97\\u6CD5\\uFF0C\\u5B83\\u4EA7\\u751F\\u6709\\u5411\\u65E0\\u73AF\\u56FE\\uFF08DAG\\uFF09\\u7684\\u9876\\u70B9\\u7684\\u7EBF\\u6027\\u6392\\u5E8F\\uFF0C\\u4F7F\\u5F97\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u6709\\u5411\\u8FB9\\uFF08u\\uFF0Cv\\uFF09\\uFF0C\\u9876\\u70B9u\\u5728\\u6392\\u5E8F\\u4E2D\\u4F4D\\u4E8E\\u9876\\u70B9v\\u4E4B\\u524D\\u3002\\u4F7F\\u7528Kahn\\u7B97\\u6CD5\\u5B9E\\u73B0\\u7684\\u62D3\\u6251\\u6392\\u5E8F\\u5177\\u6709\\u7EBF\\u6027\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF0C\\u8FD9\\u4F7F\\u5F97\\u5B83\\u5BF9\\u4E8E\\u5927\\u578B\\u56FE\\u76F8\\u5BF9\\u6709\\u6548\\u3002\"}),`\n`,(0,t.jsx)(e.h2,{children:\"\\u6F84\\u6E05\\u95EE\\u9898\"}),`\n`,(0,t.jsx)(e.p,{children:\"\\u5982\\u679C\\u672A\\u6307\\u5B9A\\uFF1A\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[\"\\u8F93\\u5165\\u548C\\u8F93\\u51FA\\u683C\\u5F0F\\uFF1A\",`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsx)(e.li,{children:\"\\u8F93\\u5165\\u56FE\\u5E94\\u8BE5\\u8868\\u793A\\u4E3A\\u90BB\\u63A5\\u77E9\\u9635\\u3001\\u90BB\\u63A5\\u8868\\u8FD8\\u662F\\u5176\\u4ED6\\u6570\\u636E\\u7ED3\\u6784\\uFF1F\"}),`\n`,(0,t.jsx)(e.li,{children:\"\\u8F93\\u51FA\\u5E94\\u8BE5\\u662F\\u62D3\\u6251\\u987A\\u5E8F\\u7684\\u8282\\u70B9\\u5217\\u8868\\u8FD8\\u662F\\u8868\\u793A\\u8282\\u70B9\\u62D3\\u6251\\u987A\\u5E8F\\u7684\\u6574\\u6570\\u6570\\u7EC4\\uFF1F\"}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,t.jsx)(e.h2,{children:\"\\u89E3\\u51B3\\u65B9\\u6848\"}),`\n`,(0,t.jsx)(a,{languages:{jsx:l,tsx:c}}),`\n`,(0,t.jsx)(e.h2,{children:\"\\u8FB9\\u7F18\\u60C5\\u51B5\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsx)(e.li,{children:\"\\u6CA1\\u6709\\u8FB9\\u7684\\u56FE\\uFF1A\\u8FD4\\u56DE\\u4E00\\u4E2A\\u7A7A\\u6570\\u7EC4\\u6216\\u9002\\u5F53\\u7684\\u9519\\u8BEF\\u6D88\\u606F\\u3002\"}),`\n`,(0,t.jsx)(e.li,{children:\"\\u5E26\\u6709\\u5FAA\\u73AF\\u7684\\u56FE\\uFF1A\\u8FD4\\u56DE\\u9519\\u8BEF\\u6216\\u7A7A\\u6570\\u7EC4\\u3002\"}),`\n`]}),`\n`,(0,t.jsx)(e.h2,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,t.jsx)(e.p,{children:\"\\u8BA9\\u6211\\u4EEC\\u5206\\u6790\\u4E00\\u4E0B\\u7B97\\u6CD5\\u7684\\u65F6\\u95F4\\u548C\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u3002\"}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\"}),`\n`,(0,t.jsx)(e.p,{children:\"\\u4F7F\\u7528Kahn\\u7B97\\u6CD5\\u5B9E\\u73B0\\u7684\\u62D3\\u6251\\u6392\\u5E8F\\u59CB\\u7EC8\\u4EE5O(V + E)\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u8FD0\\u884C\\uFF0C\\u5176\\u4E2DV\\u662F\\u56FE\\u4E2D\\u9876\\u70B9\\u7684\\u6570\\u91CF\\uFF08\\u6216\\u8282\\u70B9\\uFF09\\uFF0CE\\u662F\\u56FE\\u4E2D\\u8FB9\\u7684\\u6570\\u91CF\\u3002\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\",(0,t.jsx)(e.code,{children:\"Map\"}),\"\\u5BF9\\u8C61\\u4EE5\\u5B58\\u50A8\\u6BCF\\u4E2A\\u8282\\u70B9\\u7684\\u4F20\\u5165\\u548C\\u4F20\\u51FA\\u8FB9\\u7684\\u5FAA\\u73AF\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3AO(V)\\uFF0C\\u56E0\\u4E3A\\u5B83\\u8BBF\\u95EE\\u4E86\\u56FE\\u7684\\u6240\\u6709\\u9876\\u70B9\\uFF08\\u8282\\u70B9\\uFF09\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,t.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u8F93\\u5165\\u56FE\\u4E2D\\u7684\\u6240\\u6709\\u952E\\uFF0C\\u5E76\\u4E14\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u8282\\u70B9\\uFF0C\\u5C06\\u5176\\u90BB\\u5C45\\u8282\\u70B9\\u7684\",(0,t.jsx)(e.code,{children:\"in\"}),\"\\u5C5E\\u6027\\u589E\\u52A01\\u7684\\u5FAA\\u73AF\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3AO(E)\\uFF0C\\u56E0\\u4E3A\\u5B83\\u8BBF\\u95EE\\u4E86\\u56FE\\u7684\\u6240\\u6709\\u8FB9\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,t.jsxs)(e.li,{children:[\"\\u904D\\u5386\\u8282\\u70B9\\uFF0C\\u5C06\\u6240\\u6709\",(0,t.jsx)(e.code,{children:\"in: 0\"}),\"\\u7684\\u8282\\u70B9\\u6DFB\\u52A0\\u5230\\u961F\\u5217\\u4E2D\\u7684\\u5FAA\\u73AF\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E5F\\u4E3AO(V)\\uFF0C\\u56E0\\u4E3A\\u5B83\\u8BBF\\u95EE\\u4E86\\u56FE\\u7684\\u6240\\u6709\\u9876\\u70B9\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,t.jsx)(e.li,{children:\"while\\u5FAA\\u73AF\\u8FED\\u4EE3\\u76F4\\u5230\\u961F\\u5217\\u4E0D\\u4E3A\\u7A7A\\uFF0C\\u5176\\u6700\\u5927\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3AO(V + E)\\uFF0C\\u56E0\\u4E3A\\u5B83\\u6B63\\u5728\\u5904\\u7406\\u56FE\\u7684\\u6240\\u6709\\u9876\\u70B9\\u548C\\u8FB9\\u3002\"}),`\n`]}),`\n`,(0,t.jsx)(e.p,{children:\"\\u603B\\u7684\\u6765\\u8BF4\\uFF0CKahn\\u7B97\\u6CD5\\u5B9E\\u73B0\\u7684\\u7684\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3AO(V + E)\\u3002\"}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\"}),`\n`,(0,t.jsx)(e.p,{children:\"\\u4F7F\\u7528Kahn\\u7B97\\u6CD5\\u5B9E\\u73B0\\u7684\\u62D3\\u6251\\u6392\\u5E8F\\u7684\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u4E3AO(V)\\uFF0C\\u5176\\u4E2DV\\u662F\\u56FE\\u4E2D\\u9876\\u70B9\\u7684\\u6570\\u91CF\\uFF08\\u6216\\u8282\\u70B9\\uFF09\\u3002\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsx)(e.li,{children:\"Map\\u6570\\u636E\\u7ED3\\u6784\\u201Cnodes\\u201D\\u5B58\\u50A8\\u6BCF\\u4E2A\\u8282\\u70B9\\u7684\\u5C5E\\u6027\\uFF0C\\u5E76\\u5360\\u7528O(V)\\u7A7A\\u95F4\\u3002\"}),`\n`,(0,t.jsx)(e.li,{children:\"\\u8F93\\u51FA\\u6570\\u7EC4\\u201Corder\\u201D\\u5360\\u7528O(V)\\u7A7A\\u95F4\\uFF0C\\u56E0\\u4E3A\\u5B83\\u5B58\\u50A8\\u6240\\u6709\\u8282\\u70B9\\u7684\\u62D3\\u6251\\u987A\\u5E8F\\u3002\"}),`\n`,(0,t.jsx)(e.li,{children:\"\\u961F\\u5217\\u6570\\u636E\\u7ED3\\u6784\\u201Cqueue\\u201D\\u5B58\\u50A8\\u5165\\u5EA6\\u7B49\\u4E8E0\\u7684\\u8282\\u70B9\\uFF0C\\u8FD9\\u9700\\u8981\\u4E0E\\u8F93\\u5165\\u6570\\u636E\\u6210\\u7EBF\\u6027\\u5173\\u7CFB\\u7684\\u7A7A\\u95F4\\uFF0C\\u56E0\\u6B64\\u5360\\u7528O(V)\\u7A7A\\u95F4\\u3002\"}),`\n`]}),`\n`,(0,t.jsx)(e.p,{children:\"\\u56E0\\u6B64\\uFF0C\\u8BE5\\u7B97\\u6CD5\\u7684\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u4E3AO(V)\\u3002\"})]})}function j(n={}){let{wrapper:e}=n.components||{};return e?(0,t.jsx)(e,Object.assign({},n,{children:(0,t.jsx)(m,n)})):m(n)}var k=j;return w(E);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/trie-prefix-tree/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/trie-prefix-tree/locales/zh-CN.json new file mode 100644 index 000000000..f7ca88498 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/trie-prefix-tree/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var u=Object.create;var d=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var x=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),W=(r,e)=>{for(var t in e)d(r,t,{get:e[t],enumerable:!0})},a=(r,e,t,s)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of m(e))!b.call(r,i)&&i!==t&&d(r,i,{get:()=>e[i],enumerable:!(s=f(e,i))||s.enumerable});return r};var T=(r,e,t)=>(t=r!=null?u(g(r)):{},a(e||!r||!r.__esModule?d(t,\"default\",{value:r,enumerable:!0}):t,r)),w=r=>a(d({},\"__esModule\",{value:!0}),r);var o=x((k,c)=>{c.exports=_jsx_runtime});var D={};W(D,{default:()=>C,frontmatter:()=>_});var n=T(o());var l=MDXTestExamples;var h=[{input:[[\"methods\",[\"insert\",\"insert\",\"search\",\"startsWith\",\"insert\",\"search\",\"startsWith\"]],[\"params\",[\"car\",\"care\",\"car\",\"cap\",\"card\",\"cast\",\"car\"]]],output:[null,null,1,0,null,0,1],explanation:\"The words 'car' and 'care' are inserted. 'search' for 'car' finds it, and 'startsWith' for 'cap' returns 0. 'card' is then inserted. 'search' for 'cast' does not find it. 'startsWith' finds 'car'\"},{input:[[\"methods\",[\"insert\",\"insert\",\"search\",\"startsWith\",\"insert\",\"search\",\"startsWith\"]],[\"params\",[\"dog\",\"doge\",\"dog\",\"do\",\"door\",\"doge\",\"doc\"]]],output:[null,null,1,1,null,1,0],explanation:\"Words 'dog' and 'doge' are inserted. 'search' finds 'dog' and 'startsWith' finds 'do'. After 'door' is inserted, 'search' finds 'doge'.'startsWith' do not finds 'doc'\"},{input:[[\"methods\",[\"insert\",\"insert\",\"startsWith\",\"insert\",\"search\",\"search\",\"startsWith\"]],[\"params\",[\"banana\",\"band\",\"ban\",\"bandit\",\"band\",\"banana\",\"ban\"]]],output:[null,null,1,null,1,1,1],explanation:\"'banana' and 'band' are inserted. 'startsWith' finds 'ban'. After 'bandit' is inserted, both 'band' and 'banana' can be found. 'startsWith' finds 'ban'.\"}];var _={title:\"Trie\\uFF08\\u524D\\u7F00\\u6811\\uFF09\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u5177\\u6709\\u63D2\\u5165\\u3001\\u641C\\u7D22\\u548C\\u4EE5...\\u5F00\\u5934\\u529F\\u80FD\\u7684 trie \\u524D\\u7F00\\u6811\"};function p(r){let e=Object.assign({p:\"p\",a:\"a\",code:\"code\",ul:\"ul\",li:\"li\",h3:\"h3\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u4E00\\u4E2A \",(0,n.jsx)(e.a,{href:\"https://en.wikipedia.org/wiki/Trie\",children:\"trie\"}),\"\\uFF08\\u53D1\\u97F3\\u4E3A\\u201Ctry\\u201D\\uFF09\\uFF0C\\u4E5F\\u79F0\\u4E3A\\u524D\\u7F00\\u6811\\uFF0C\\u662F\\u4E00\\u79CD\\u6811\\u72B6\\u6570\\u636E\\u7ED3\\u6784\\uFF0C\\u65E8\\u5728\\u6709\\u6548\\u5730\\u7BA1\\u7406\\u548C\\u67E5\\u8BE2\\u5B57\\u7B26\\u4E32\\u3002\\u5B83\\u5BF9\\u4E8E\\u81EA\\u52A8\\u5B8C\\u6210\\u548C\\u62FC\\u5199\\u68C0\\u67E5\\u7B49\\u4EFB\\u52A1\\u7279\\u522B\\u6709\\u7528\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u5177\\u6709\\u4EE5\\u4E0B\\u65B9\\u6CD5\\u7684 \",(0,n.jsx)(e.code,{children:\"Trie\"}),\" \\u7C7B\\uFF1A\"]}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"insert(word: string): void\"}),\": \\u5C06\\u7ED9\\u5B9A\\u7684\\u5355\\u8BCD\\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"Trie\"})]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"search(word: string): boolean\"}),\": \\u68C0\\u67E5\\u6307\\u5B9A\\u7684\\u5355\\u8BCD\\u662F\\u5426\\u5B58\\u5728\\u4E8E trie \\u4E2D\\uFF0C\\u5982\\u679C\\u5B58\\u5728\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\uFF0C\\u5426\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"})]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"startsWith(prefix: string): boolean\"}),\": \\u68C0\\u67E5 Trie \\u4E2D\\u662F\\u5426\\u6709\\u4EE5\\u7ED9\\u5B9A\\u524D\\u7F00\\u5F00\\u5934\\u7684\\u5355\\u8BCD\\uFF0C\\u5982\\u679C\\u5B58\\u5728\\u8FD9\\u6837\\u7684\\u5355\\u8BCD\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"true\"}),\"\\uFF0C\\u5426\\u5219\\u8FD4\\u56DE \",(0,n.jsx)(e.code,{children:\"false\"})]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:\"Trie\"}),\" \\u5B9E\\u4F8B\\u5C06\\u6839\\u636E\\u8FD9\\u4E9B\\u53C2\\u6570\\u8C03\\u7528\\u5176\\u65B9\\u6CD5\\uFF1A\"]}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"methods: string[]\"}),\": \",(0,n.jsx)(e.code,{children:\"Trie\"}),\" \\u65B9\\u6CD5\\u540D\\u79F0\\u7684\\u6570\\u7EC4\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"params: string[]\"}),\": \\u5B57\\u7B26\\u4E32\\u6570\\u7EC4\"]}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:\"methods[i]\"}),\" \\u5C06\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"params[i]\"}),\" \\u8C03\\u7528\\u3002\"]}),`\n`,(0,n.jsx)(l,{testCases:h}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"word.length\"}),\" <= 100\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"prefix.length\"}),\" <= 100\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"word\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"prefix\"}),\" \\u4EC5\\u5305\\u542B\\u5C0F\\u5199\\u82F1\\u6587\\u5B57\\u6BCD\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"1 <= \",(0,n.jsx)(e.code,{children:\"methods.length\"}),\" <= 1000\"]}),`\n`]})]})}function M(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(p,r)})):p(r)}var C=M;return w(D);})();\n;return Component;", + "info": { + "excerpt": "实现一个具有插入、搜索和以...开头功能的 trie 前缀树", + "title": "Trie(前缀树)" + }, + "solution": "var Component=(()=>{var f=Object.create;var o=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var T=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var N=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),x=(i,e)=>{for(var r in e)o(i,r,{get:e[r],enumerable:!0})},c=(i,e,r,d)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let t of g(e))!w.call(i,t)&&t!==r&&o(i,t,{get:()=>e[t],enumerable:!(d=p(e,t))||d.enumerable});return i};var m=(i,e,r)=>(r=i!=null?f(T(i)):{},c(e||!i||!i.__esModule?o(r,\"default\",{value:i,enumerable:!0}):r,i)),b=i=>c(o({},\"__esModule\",{value:!0}),i);var h=N((E,l)=>{l.exports=_jsx_runtime});var v={};x(v,{default:()=>k});var n=m(h());var s=MDXCodeBlock;var a=`class TrieNode {\n // Array to hold child nodes\n private links: TrieNode[] = [];\n private static readonly NUM_ALPHABETS = 26; // Number of possible links (a-z)\n private isEnd: boolean = false; // Indicates if this node is the end of a word\n\n constructor() {\n this.links = new Array(TrieNode.NUM_ALPHABETS); // Initialize the array with 26 slots\n }\n\n // Check if a child node for the given character exists\n public containsKey(ch: string): boolean {\n return this.links[ch.charCodeAt(0) - 'a'.charCodeAt(0)] !== undefined;\n }\n\n // Get the child node for the given character\n public get(ch: string): TrieNode | undefined {\n return this.links[ch.charCodeAt(0) - 'a'.charCodeAt(0)];\n }\n\n // Put a child node for the given character\n public put(ch: string, node: TrieNode): void {\n this.links[ch.charCodeAt(0) - 'a'.charCodeAt(0)] = node;\n }\n\n // Set this node as the end of a word\n public setEnd(): void {\n this.isEnd = true;\n }\n\n // Check if this node is the end of a word\n public isEndNode(): boolean {\n return this.isEnd;\n }\n}\n\nexport default class Trie {\n private root: TrieNode = new TrieNode();\n\n constructor() {\n this.root = new TrieNode();\n }\n\n // Inserts a word into the trie\n public insert(word: string): void {\n let node: TrieNode = this.root;\n\n for (let i = 0; i < word.length; i++) {\n const currentChar: string = word.charAt(i);\n if (!node.containsKey(currentChar)) {\n node.put(currentChar, new TrieNode());\n }\n node = node.get(currentChar)!; // Non-null assertion since containsKey checks existence\n }\n\n node.setEnd();\n }\n\n // Search for the prefix or whole key in the trie\n private searchPrefix(word: string): TrieNode | null {\n let node: TrieNode = this.root;\n for (let i = 0; i < word.length; i++) {\n const curLetter: string = word.charAt(i);\n if (node.containsKey(curLetter)) {\n node = node.get(curLetter)!; // Non-null assertion since containsKey checks existence\n } else {\n return null;\n }\n }\n return node;\n }\n\n // Returns if the word is in the trie\n public search(word: string): boolean {\n const node: TrieNode | null = this.searchPrefix(word);\n return node !== null && node.isEndNode();\n }\n\n // Returns if there is any word in the trie that starts with the given prefix\n public startsWith(prefix: string): boolean {\n const node: TrieNode | null = this.searchPrefix(prefix);\n return node !== null;\n }\n}\n`;function u(i){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",strong:\"strong\",ul:\"ul\"},i.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528 Trie \\u6570\\u636E\\u7ED3\\u6784\"}),`\n`,(0,n.jsx)(e.p,{children:\"Trie\\uFF08\\u524D\\u7F00\\u6811\\uFF09\\u662F\\u4E00\\u79CD\\u6811\\u72B6\\u6570\\u636E\\u7ED3\\u6784\\uFF0C\\u7528\\u4E8E\\u9AD8\\u6548\\u5B58\\u50A8\\u548C\\u68C0\\u7D22\\u5B57\\u7B26\\u4E32\\uFF0C\\u5C24\\u5176\\u662F\\u5728\\u5904\\u7406\\u524D\\u7F00\\u65F6\\u3002Trie \\u4E2D\\u7684\\u6BCF\\u4E2A\\u8282\\u70B9\\u4EE3\\u8868\\u4E00\\u4E2A\\u5B57\\u7B26\\uFF0C\\u5E76\\u5B58\\u50A8\\u5BF9\\u5176\\u5B50\\u8282\\u70B9\\u7684\\u5F15\\u7528\\u3002\\u8FD9\\u79CD\\u7ED3\\u6784\\u53EF\\u4EE5\\u5B9E\\u73B0\\u5FEB\\u901F\\u64CD\\u4F5C\\uFF0C\\u4F8B\\u5982\\u63D2\\u5165\\u5355\\u8BCD\\u3001\\u641C\\u7D22\\u5355\\u8BCD\\u4EE5\\u53CA\\u68C0\\u67E5\\u4EFB\\u4F55\\u5355\\u8BCD\\u662F\\u5426\\u4EE5\\u7ED9\\u5B9A\\u524D\\u7F00\\u5F00\\u5934\\u3002\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"Trie \\u4F7F\\u7528\\u5177\\u6709\\u6307\\u5411\\u5176\\u5B50\\u8282\\u70B9\\u7684\\u94FE\\u63A5\\u7684\\u6839\\u8282\\u70B9\\u8FDB\\u884C\\u521D\\u59CB\\u5316\\u3002\\u6BCF\\u4E2A\\u94FE\\u63A5\\u5BF9\\u5E94\\u4E8E\\u4ECE 'a' \\u5230 'z' \\u7684\\u4E00\\u4E2A\\u5B57\\u7B26\\u3002\\u5355\\u8BCD\\u9010\\u4E2A\\u5B57\\u7B26\\u5730\\u63D2\\u5165\\u5230 Trie \\u4E2D\\uFF0C\\u5982\\u679C\\u5B57\\u7B26\\u4E0D\\u5B58\\u5728\\uFF0C\\u5219\\u521B\\u5EFA\\u65B0\\u7684\\u5B50\\u8282\\u70B9\\u3002\\u641C\\u7D22\\u64CD\\u4F5C\\u904D\\u5386 Trie \\u4EE5\\u68C0\\u67E5\\u5355\\u8BCD\\u6216\\u524D\\u7F00\\u7684\\u6240\\u6709\\u5B57\\u7B26\\u662F\\u5426\\u5B58\\u5728\\uFF0C\\u800C\\u6BCF\\u4E2A\\u8282\\u70B9\\u7684 \",(0,n.jsx)(e.code,{children:\"isEnd\"}),\" \\u6807\\u5FD7\\u6307\\u793A\\u8BE5\\u8282\\u70B9\\u662F\\u5426\\u6807\\u8BB0\\u5355\\u8BCD\\u7684\\u7ED3\\u5C3E\\u3002\\u8BE5\\u8BBE\\u8BA1\\u6709\\u6548\\u5730\\u5904\\u7406\\u6D89\\u53CA\\u524D\\u7F00\\u7684\\u64CD\\u4F5C\\uFF0C\\u56E0\\u4E3A\\u5171\\u4EAB\\u524D\\u7F00\\u4EC5\\u5B58\\u50A8\\u4E00\\u6B21\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.strong,{children:\"\\u63D2\\u5165\"}),\"\\uFF1A\"]}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u4ECE\\u6839\\u8282\\u70B9\\u5F00\\u59CB\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5BF9\\u4E8E\\u5355\\u8BCD\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5B57\\u7B26\\uFF0C\\u68C0\\u67E5\\u8282\\u70B9\\u662F\\u5426\\u5305\\u542B\\u8BE5\\u5B57\\u7B26\\u7684\\u94FE\\u63A5\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u6CA1\\u6709\\uFF0C\\u521B\\u5EFA\\u4E00\\u4E2A\\u65B0\\u8282\\u70B9\\u5E76\\u5C06\\u5176\\u6DFB\\u52A0\\u4E3A\\u5B50\\u8282\\u70B9\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u79FB\\u52A8\\u5230\\u5B50\\u8282\\u70B9\\uFF0C\\u5E76\\u5BF9\\u6240\\u6709\\u5B57\\u7B26\\u91CD\\u590D\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"isEnd\"}),\" \\u6807\\u5FD7\\u5C06\\u6700\\u540E\\u4E00\\u4E2A\\u8282\\u70B9\\u6807\\u8BB0\\u4E3A\\u5355\\u8BCD\\u7684\\u7ED3\\u5C3E\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.strong,{children:\"\\u641C\\u7D22\"}),\"\\uFF1A\"]}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u4F7F\\u7528\\u5355\\u8BCD\\u7684\\u5B57\\u7B26\\u904D\\u5386 Trie\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u672A\\u627E\\u5230\\u4EFB\\u4F55\\u5B57\\u7B26\\uFF0C\\u5219\\u8BE5\\u5355\\u8BCD\\u4E0D\\u5B58\\u5728\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u68C0\\u67E5\\u6700\\u540E\\u4E00\\u4E2A\\u8282\\u70B9\\u662F\\u5426\\u4EE3\\u8868\\u5355\\u8BCD\\u7684\\u7ED3\\u5C3E\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.strong,{children:\"StartsWith\"}),\"\\uFF1A\"]}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u4F7F\\u7528\\u524D\\u7F00\\u7684\\u5B57\\u7B26\\u904D\\u5386 Trie\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5982\\u679C\\u627E\\u5230\\u6240\\u6709\\u5B57\\u7B26\\uFF0C\\u5219\\u524D\\u7F00\\u5B58\\u5728\\u4E8E Trie \\u4E2D\\u3002\"}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(s,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\"}),\"\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u63D2\\u5165\\uFF1AO(m)\\uFF0C\\u5176\\u4E2D \",(0,n.jsx)(e.code,{children:\"m\"}),\" \\u662F\\u8981\\u63D2\\u5165\\u7684\\u5355\\u8BCD\\u7684\\u957F\\u5EA6\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u641C\\u7D22\\uFF1AO(m)\\uFF0C\\u5176\\u4E2D \",(0,n.jsx)(e.code,{children:\"m\"}),\" \\u662F\\u8981\\u641C\\u7D22\\u7684\\u5355\\u8BCD\\u7684\\u957F\\u5EA6\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"StartsWith\\uFF1AO(m)\\uFF0C\\u5176\\u4E2D \",(0,n.jsx)(e.code,{children:\"m\"}),\" \\u662F\\u524D\\u7F00\\u7684\\u957F\\u5EA6\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\"}),\"\\uFF1AO(n)\\uFF0C\\u5176\\u4E2D \",(0,n.jsx)(e.code,{children:\"n\"}),\" \\u662F\\u6240\\u6709\\u63D2\\u5165\\u5355\\u8BCD\\u4E2D\\u7684\\u5B57\\u7B26\\u603B\\u6570\\u3002\\u6BCF\\u4E2A\\u5B57\\u7B26\\u90FD\\u9700\\u8981\\u5728 Trie \\u4E2D\\u6709\\u4E00\\u4E2A\\u8282\\u70B9\\uFF0C\\u5E76\\u4E14\\u5171\\u4EAB\\u524D\\u7F00\\u53EF\\u4EE5\\u51CF\\u5C11\\u5197\\u4F59\\u3002\"]}),`\n`]})]})}function A(i={}){let{wrapper:e}=i.components||{};return e?(0,n.jsx)(e,Object.assign({},i,{children:(0,n.jsx)(u,i)})):u(i)}var k=A;return b(v);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/triplet-sum/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/triplet-sum/locales/zh-CN.json new file mode 100644 index 000000000..93e9d5889 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/triplet-sum/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var p=Object.create;var i=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var f=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),_=(r,e)=>{for(var t in e)i(r,t,{get:e[t],enumerable:!0})},o=(r,e,t,l)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let s of b(e))!j.call(r,s)&&s!==t&&i(r,s,{get:()=>e[s],enumerable:!(l=a(e,s))||l.enumerable});return r};var T=(r,e,t)=>(t=r!=null?p(x(r)):{},o(e||!r||!r.__esModule?i(t,\"default\",{value:r,enumerable:!0}):t,r)),g=r=>o(i({},\"__esModule\",{value:!0}),r);var c=f((E,u)=>{u.exports=_jsx_runtime});var y={};_(y,{default:()=>X,frontmatter:()=>C});var n=T(c());var d=MDXTestExamples;var m=[{input:[[\"numbers\",[-1,0,1,2,-1,-4]]],output:[[-1,-1,2],[-1,0,1]],explanation:\"numbers[0] + numbers[1] + numbers[2] = (-1) + 0 + 1 = 0. numbers[1] + numbers[2] + numbers[4] = 0 + 1 + (-1) = 0. numbers[0] + numbers[3] + numbers[4] = (-1) + 2 + (-1) = 0. The distinct triplets are [-1,0,1] and [-1,-1,2]\"},{input:[[\"numbers\",[0,0,0]]],output:[[0,0,0]],explanation:\"The only possible triplet adds up to 0\"},{input:[[\"numbers\",[1,0,0]]],output:[],explanation:\"The only possible triplet does not add up to 0\"}];var C={title:\"\\u4E09\\u5143\\u7EC4\\u4E4B\\u548C\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u51FD\\u6570\\uFF0C\\u627E\\u5230\\u6240\\u6709\\u548C\\u4E3A 0 \\u4E14\\u7D22\\u5F15\\u4E0D\\u540C\\u7684\\u552F\\u4E00\\u4E09\\u5143\\u7EC4\\u3002\"};function h(r){let e=Object.assign({p:\"p\",code:\"code\",h3:\"h3\",ul:\"ul\",li:\"li\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(e.p,{children:[\"\\u7ED9\\u5B9A\\u4E00\\u4E2A\\u6574\\u6570\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"numbers\"}),\"\\uFF0C\\u8FD4\\u56DE\\u6240\\u6709\\u4E09\\u5143\\u7EC4 \",(0,n.jsx)(e.code,{children:\"[numbers[i], numbers[j], numbers[k]]\"}),\"\\uFF0C\\u4F7F\\u5F97 \",(0,n.jsx)(e.code,{children:\"i\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"j\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u662F\\u4E0D\\u540C\\u7684\\u7D22\\u5F15\\uFF0C\\u5E76\\u4E14\\u5B83\\u4EEC\\u7684\\u503C\\u603B\\u548C\\u4E3A 0\\u3002\\u786E\\u4FDD\\u89E3\\u96C6\\u4E2D\\u4E0D\\u5305\\u542B\\u91CD\\u590D\\u7684\\u4E09\\u5143\\u7EC4\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"numbers: number[]\"}),\": \\u6574\\u6570\\u6570\\u7EC4\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u6CE8\\u610F\\u4E8B\\u9879\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u8F93\\u51FA\\u5E94\\u6309\\u6392\\u5E8F\\u987A\\u5E8F\\u6392\\u5217\"}),`\n`]}),`\n`,(0,n.jsx)(d,{testCases:m}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"3 <= \",(0,n.jsx)(e.code,{children:\"numbers.length\"}),\" <= 1000\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"-10,000 <= \",(0,n.jsx)(e.code,{children:\"numbers[i]\"}),\" <= 10,000\"]}),`\n`]})]})}function D(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(h,r)})):h(r)}var X=D;return g(y);})();\n;return Component;", + "info": { + "excerpt": "实现一个函数,找到所有和为 0 且索引不同的唯一三元组。", + "title": "三元组之和" + }, + "solution": "var Component=(()=>{var b=Object.create;var t=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var g=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),S=(r,e)=>{for(var i in e)t(r,i,{get:e[i],enumerable:!0})},o=(r,e,i,d)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let l of f(e))!k.call(r,l)&&l!==i&&t(r,l,{get:()=>e[l],enumerable:!(d=p(e,l))||d.enumerable});return r};var O=(r,e,i)=>(i=r!=null?b(j(r)):{},o(e||!r||!r.__esModule?t(i,\"default\",{value:r,enumerable:!0}):i,r)),x=r=>o(t({},\"__esModule\",{value:!0}),r);var s=g((q,h)=>{h.exports=_jsx_runtime});var y={};S(y,{default:()=>v});var n=O(s());var c=MDXCodeBlock;var u=`export default function tripletSum(numbers: number[]): number[][] {\n const ans: number[][] = [];\n\n // Sort the input array for efficient two-pointer search\n numbers.sort((a, b) => a - b);\n\n for (let i = 0; i < numbers.length - 2; i++) {\n // Skip duplicates: only consider unique starting elements (i)\n if (i > 0 && numbers[i] === numbers[i - 1]) continue;\n\n // Two-pointer approach for remaining elements (j & k)\n let j = i + 1;\n let k = numbers.length - 1;\n\n while (j < k) {\n const sum = numbers[i] + numbers[j] + numbers[k];\n\n if (sum === 0) {\n // Found a triplet, add it to the answer\n ans.push([numbers[i], numbers[j], numbers[k]]);\n\n // Move pointers to skip duplicates\n do {\n j++;\n } while (j < k && numbers[j] === numbers[j - 1]);\n do {\n k--;\n } while (j < k && numbers[k] === numbers[k + 1]);\n } else if (sum < 0) {\n // Move j forward to search for a larger positive number\n j++;\n } else {\n // Move k backward to search for a smaller negative number\n k--;\n }\n }\n }\n\n return ans;\n}\n`;var m=`export default function tripletSum(numbers: number[]): number[][] {\n // Set to store unique triplets\n const uniqueTriplets = new Set();\n const n = numbers.length;\n\n // Iterate through the array to find triplets\n for (let i = 0; i < n; i++) {\n for (let j = i + 1; j < n; j++) {\n for (let k = j + 1; k < n; k++) {\n // Check if the sum of three numbers is zero\n if (numbers[i] + numbers[j] + numbers[k] === 0) {\n // Sort the triplet to maintain order\n const triplet = [numbers[i], numbers[j], numbers[k]].sort(\n (a, b) => a - b,\n );\n // Convert to string for set storage\n uniqueTriplets.add(JSON.stringify(triplet));\n }\n }\n }\n }\n // result should be in sorted order as mentioned in the description.\n const result: number[][] = Array.from(uniqueTriplets)\n .map((triplet) => JSON.parse(triplet))\n .sort((a, b) => a[0] - b[0] || a[1] - b[1] || a[2] - b[2]);\n\n return result;\n}\n`;function a(r){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",ul:\"ul\",strong:\"strong\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u66B4\\u529B\\u89E3\\u6CD5\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u76EE\\u6807\\u662F\\u5728\\u4E00\\u4E2A\\u6570\\u7EC4\\u4E2D\\u627E\\u5230\\u6240\\u6709\\u548C\\u4E3A\\u96F6\\u7684\\u552F\\u4E00\\u4E09\\u5143\\u7EC4\\u3002 \\u8FD9\\u79CD\\u65B9\\u6CD5\\u662F\\u4F7F\\u7528\\u4E09\\u4E2A\\u5D4C\\u5957\\u5FAA\\u73AF\\u6765\\u63A2\\u7D22\\u4E09\\u4E2A\\u6570\\u5B57\\u7684\\u6BCF\\u4E00\\u79CD\\u7EC4\\u5408\\u3002 \\u68C0\\u67E5\\u6BCF\\u4E2A\\u7EC4\\u5408\\u662F\\u5426\\u603B\\u548C\\u4E3A\\u96F6\\u3002 \\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"Set\"}),\" \\u901A\\u8FC7\\u5C06\\u5B83\\u4EEC\\u8F6C\\u6362\\u4E3A\\u5B57\\u7B26\\u4E32\\u6765\\u5B58\\u50A8\\u552F\\u4E00\\u7684\\u4E09\\u5143\\u7EC4\\uFF0C\\u786E\\u4FDD\\u907F\\u514D\\u91CD\\u590D\\u3002 \\u5BF9\\u4E09\\u5143\\u7EC4\\u8FDB\\u884C\\u6392\\u5E8F\\u6709\\u52A9\\u4E8E\\u4FDD\\u6301\\u987A\\u5E8F\\uFF0C\\u5E76\\u786E\\u4FDD\\u5728\\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"Set\"}),\" \\u65F6\\u6B63\\u786E\\u68C0\\u6D4B\\u5230\\u91CD\\u590D\\u9879\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"Set\"}),\" \\u6765\\u5B58\\u50A8\\u552F\\u4E00\\u7684\\u4E09\\u5143\\u7EC4\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u4E09\\u4E2A\\u5D4C\\u5957\\u5FAA\\u73AF\\u904D\\u5386\\u6570\\u7EC4\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u6700\\u5916\\u5C42\\u5FAA\\u73AF\\u56FA\\u5B9A\\u4E09\\u5143\\u7EC4\\u7684\\u7B2C\\u4E00\\u4E2A\\u6570\\u5B57\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u7B2C\\u4E8C\\u4E2A\\u5FAA\\u73AF\\u56FA\\u5B9A\\u4E09\\u5143\\u7EC4\\u7684\\u7B2C\\u4E8C\\u4E2A\\u6570\\u5B57\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u6700\\u5185\\u5C42\\u5FAA\\u73AF\\u9009\\u62E9\\u4E09\\u5143\\u7EC4\\u7684\\u7B2C\\u4E09\\u4E2A\\u6570\\u5B57\\u3002\"}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5BF9\\u4E8E\\u6BCF\\u4E00\\u79CD\\u4E09\\u4E2A\\u6570\\u5B57\\u7684\\u7EC4\\u5408\\uFF0C\\u68C0\\u67E5\\u5B83\\u4EEC\\u7684\\u603B\\u548C\\u662F\\u5426\\u7B49\\u4E8E\\u96F6\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u603B\\u548C\\u4E3A\\u96F6\\uFF0C\\u5BF9\\u4E09\\u5143\\u7EC4\\u8FDB\\u884C\\u6392\\u5E8F\\u4EE5\\u4FDD\\u6301\\u987A\\u5E8F\\uFF0C\\u5E76\\u5C06\\u5176\\u8F6C\\u6362\\u4E3A\\u5B57\\u7B26\\u4E32\\u4EE5\\u5B58\\u50A8\\u5728 \",(0,n.jsx)(e.code,{children:\"Set\"}),\" \\u4E2D\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5B8C\\u6210\\u8FED\\u4EE3\\u540E\\uFF0C\\u901A\\u8FC7\\u89E3\\u6790\\u5B58\\u50A8\\u7684\\u5B57\\u7B26\\u4E32\\u5C06 \",(0,n.jsx)(e.code,{children:\"Set\"}),\" \\u8F6C\\u6362\\u56DE\\u6570\\u7EC4\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u5BF9\\u751F\\u6210\\u7684\\u4E09\\u5143\\u7EC4\\u6570\\u7EC4\\u8FDB\\u884C\\u6392\\u5E8F\\uFF0C\\u4EE5\\u6EE1\\u8DB3\\u6709\\u5E8F\\u7ED3\\u679C\\u7684\\u8981\\u6C42\\u3002\"}),`\n`,(0,n.jsx)(e.li,{children:\"\\u8FD4\\u56DE\\u5DF2\\u6392\\u5E8F\\u7684\\u4E09\\u5143\\u7EC4\\u6570\\u7EC4\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(c,{children:m}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,n.jsx)(\"sup\",{children:\"3\"}),\")\"]}),\"\\u3002 \\u4E09\\u4E2A\\u5D4C\\u5957\\u5FAA\\u73AF\\u904D\\u5386\\u6570\\u7EC4\\u4E2D\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u4E09\\u4E2A\\u6570\\u5B57\\u7684\\u7EC4\\u5408\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(k)\"}),\"\\u3002 \\u7528\\u4E8E\\u5B58\\u50A8\\u552F\\u4E00\\u4E09\\u5143\\u7EC4\\u7684 \",(0,n.jsx)(e.code,{children:\"Set\"}),\" \\u548C\\u751F\\u6210\\u7684\\u6570\\u7EC4\\u6240\\u9700\\u7684\\u7A7A\\u95F4\\u4E0E\\u552F\\u4E00\\u4E09\\u5143\\u7EC4\\u7684\\u6570\\u91CF\\u6210\\u6B63\\u6BD4\\uFF0C\\u5373 \",(0,n.jsx)(e.code,{children:\"k\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"2. \\u53CC\\u6307\\u9488\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u53CC\\u6307\\u9488\\u65B9\\u6CD5\\u901A\\u8FC7\\u51CF\\u5C11\\u4E0D\\u5FC5\\u8981\\u7684\\u8BA1\\u7B97\\u6765\\u6539\\u8FDB\\u66B4\\u529B\\u89E3\\u6CD5\\u3002 \\u5BF9\\u6570\\u7EC4\\u8FDB\\u884C\\u6392\\u5E8F\\u53EF\\u4EE5\\u901A\\u8FC7\\u4F7F\\u7528\\u4E24\\u4E2A\\u6307\\u9488\\uFF08\",(0,n.jsx)(e.code,{children:\"j\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"k\"}),\"\\uFF09\\u6839\\u636E\\u5F53\\u524D\\u603B\\u548C\\u76F8\\u4E92\\u79FB\\u52A8\\u6765\\u6709\\u6548\\u5730\\u641C\\u7D22\\u603B\\u548C\\u4E3A\\u96F6\\u7684\\u4E09\\u5143\\u7EC4\\u3002 \\u8FD9\\u6D88\\u9664\\u4E86\\u5BF9\\u7B2C\\u4E09\\u4E2A\\u5D4C\\u5957\\u5FAA\\u73AF\\u7684\\u9700\\u6C42\\uFF0C\\u5E76\\u901A\\u8FC7\\u8DF3\\u8FC7\\u91CD\\u590D\\u9879\\u6765\\u907F\\u514D\\u5197\\u4F59\\u68C0\\u67E5\\u3002 \\u901A\\u8FC7\\u4E13\\u6CE8\\u4E8E\\u8865\\u5145\\u56FA\\u5B9A\\u8D77\\u59CB\\u5143\\u7D20\\uFF08\",(0,n.jsx)(e.code,{children:\"i\"}),\"\\uFF09\\u7684\\u6570\\u5B57\\u5BF9\\uFF0C\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u663E\\u7740\\u964D\\u4F4E\\u4E86\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u5BF9\\u8F93\\u5165\\u6570\\u7EC4\\u8FDB\\u884C\\u5347\\u5E8F\\u6392\\u5E8F\\uFF0C\\u4EE5\\u5141\\u8BB8\\u6709\\u6548\\u7684\\u53CC\\u6307\\u9488\\u904D\\u5386\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u521D\\u59CB\\u5316\\u4E00\\u4E2A\\u7A7A\\u6570\\u7EC4 \",(0,n.jsx)(e.code,{children:\"ans\"}),\" \\u6765\\u5B58\\u50A8\\u4E09\\u5143\\u7EC4\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u7D22\\u5F15 \",(0,n.jsx)(e.code,{children:\"i\"}),\" \\u904D\\u5386\\u6392\\u5E8F\\u540E\\u7684\\u6570\\u7EC4\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u8DF3\\u8FC7\\u91CD\\u590D\\u5143\\u7D20\\uFF0C\\u4EE5\\u786E\\u4FDD\\u6BCF\\u4E2A\\u8D77\\u59CB\\u5143\\u7D20\\u90FD\\u662F\\u552F\\u4E00\\u7684\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8BBE\\u7F6E\\u4E24\\u4E2A\\u6307\\u9488\\uFF1A\",(0,n.jsx)(e.code,{children:\"j\"}),\" \\u5728 \",(0,n.jsx)(e.code,{children:\"i\"}),\" \\u4E4B\\u540E\\u7684\\u7D22\\u5F15\\u5904\\uFF0C\",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u5728\\u6570\\u7EC4\\u7684\\u6700\\u540E\\u4E00\\u4E2A\\u7D22\\u5F15\\u5904\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5F53 \",(0,n.jsx)(e.code,{children:\"j\"}),\" \\u5C0F\\u4E8E \",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u65F6\\uFF1A\",`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8BA1\\u7B97 \",(0,n.jsx)(e.code,{children:\"numbers[i]\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"numbers[j]\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"numbers[k]\"}),\" \\u7684\\u603B\\u548C\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u603B\\u548C\\u7B49\\u4E8E\\u96F6\\uFF1A\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5C06\\u4E09\\u5143\\u7EC4 \",(0,n.jsx)(e.code,{children:\"[numbers[i], numbers[j], numbers[k]]\"}),\" \\u6DFB\\u52A0\\u5230 \",(0,n.jsx)(e.code,{children:\"ans\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u79FB\\u52A8 \",(0,n.jsx)(e.code,{children:\"j\"}),\" \\u5411\\u524D\\uFF0C\\u79FB\\u52A8 \",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u5411\\u540E\\uFF0C\\u8DF3\\u8FC7\\u91CD\\u590D\\u5143\\u7D20\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u603B\\u548C\\u5C0F\\u4E8E\\u96F6\\uFF0C\\u5219\\u9012\\u589E \",(0,n.jsx)(e.code,{children:\"j\"}),\" \\u4EE5\\u589E\\u52A0\\u603B\\u548C\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u603B\\u548C\\u5927\\u4E8E\\u96F6\\uFF0C\\u5219\\u9012\\u51CF \",(0,n.jsx)(e.code,{children:\"k\"}),\" \\u4EE5\\u51CF\\u5C11\\u603B\\u548C\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u8FD4\\u56DE\\u5305\\u542B\\u6240\\u6709\\u552F\\u4E00\\u4E09\\u5143\\u7EC4\\u7684 \",(0,n.jsx)(e.code,{children:\"ans\"}),\" \\u6570\\u7EC4\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(c,{children:u}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(n\",(0,n.jsx)(\"sup\",{children:\"2\"}),\")\"]}),\"\\u3002 \\u5BF9\\u6570\\u7EC4\\u8FDB\\u884C\\u6392\\u5E8F\\u9700\\u8981 O(n log n)\\uFF0C\\u5E76\\u4E14\\u5BF9\\u6BCF\\u4E2A\\u5143\\u7D20\\u8FDB\\u884C\\u53CC\\u6307\\u9488\\u904D\\u5386\\u9700\\u8981 O(n)\\uFF0C\\u7ED3\\u679C\\u4E3A O(n\",(0,n.jsx)(\"sup\",{children:\"2\"}),\")\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\uFF1AO(1)\"}),\"\\u3002 \\u9664\\u4E86\\u8F93\\u51FA\\u6570\\u7EC4\\u4E4B\\u5916\\uFF0C\\u8BE5\\u89E3\\u51B3\\u65B9\\u6848\\u4F7F\\u7528\\u6052\\u5B9A\\u91CF\\u7684\\u989D\\u5916\\u7A7A\\u95F4\\u3002\"]}),`\n`]})]})}function _(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(a,r)})):a(r)}var v=_;return x(y);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/algo/word-finder/locales/zh-CN.json b/apps/web/src/__generated__/questions/algo/word-finder/locales/zh-CN.json new file mode 100644 index 000000000..e245cbdb2 --- /dev/null +++ b/apps/web/src/__generated__/questions/algo/word-finder/locales/zh-CN.json @@ -0,0 +1,8 @@ +{ + "description": "var Component=(()=>{var m=Object.create;var a=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,W=Object.prototype.hasOwnProperty;var g=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),f=(r,e)=>{for(var l in e)a(r,l,{get:e[l],enumerable:!0})},o=(r,e,l,t)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let n of b(e))!W.call(r,n)&&n!==l&&a(r,n,{get:()=>e[n],enumerable:!(t=p(e,n))||t.enumerable});return r};var w=(r,e,l)=>(l=r!=null?m(x(r)):{},o(e||!r||!r.__esModule?a(l,\"default\",{value:r,enumerable:!0}):l,r)),j=r=>o(a({},\"__esModule\",{value:!0}),r);var h=g((T,c)=>{c.exports=_jsx_runtime});var D={};f(D,{default:()=>C,frontmatter:()=>M});var d=w(h());var s=MDXTestExamples;var i=[{input:[[\"methods\",[\"addWord\",\"addWord\",\"search\",\"addWord\",\"search\",\"search\",\"search\"]],[\"params\",[\"car\",\"cat\",\"c.r\",\"dog\",\"d.g\",\"cat\",\"c..\"]]],output:[null,null,!0,null,!0,!0,!0],explanation:\"Words 'car' and 'cat' are added, 'c.r' matches 'car', 'dog' and 'd.g' match, 'c..' matches both 'car' and 'cat'.\"},{input:[[\"methods\",[\"addWord\",\"addWord\",\"addWord\",\"search\",\"search\",\"addWord\",\"search\"]],[\"params\",[\"hello\",\"hollow\",\"hollow\",\"hell\",\"hel.o\",\"hero\",\"h.o.\"]]],output:[null,null,null,!1,!0,null,!1],explanation:\"The words 'hello', 'hollow' are added, 'hell' doesn't exist, 'hel.o' matches 'hello', 'hero' is added, 'h.o.' does not match with any other word.\"},{input:[[\"methods\",[\"addWord\",\"search\",\"addWord\",\"search\",\"addWord\",\"search\",\"search\"]],[\"params\",[\"bat\",\"b.t\",\"ball\",\"ba.l\",\"bat\",\"b.ll\",\"ball\"]]],output:[null,!0,null,!0,null,!0,!0],explanation:\"Words 'bat' and 'ball' are added, 'b.t' matches 'bat', 'ba.l', 'b.ll' and 'ball' match 'ball'.\"}];var M={title:\"\\u5355\\u8BCD\\u67E5\\u627E\\u5668\",excerpt:\"\\u5B9E\\u73B0\\u4E00\\u4E2A\\u53EF\\u4EE5\\u6DFB\\u52A0\\u5355\\u8BCD\\u5E76\\u652F\\u6301\\u901A\\u914D\\u7B26\\u641C\\u7D22\\u7684\\u6570\\u636E\\u7ED3\\u6784\"};function u(r){let e=Object.assign({p:\"p\",code:\"code\",ul:\"ul\",li:\"li\",h3:\"h3\"},r.components);return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(e.p,{children:[\"\\u5B9E\\u73B0\\u5141\\u8BB8\\u6DFB\\u52A0\\u5355\\u8BCD\\u548C\\u641C\\u7D22\\u5355\\u8BCD\\u7684 \",(0,d.jsx)(e.code,{children:\"WordFinder\"}),\" \\u7C7B\\u3002\\u5B83\\u5177\\u6709\\u4EE5\\u4E0B\\u65B9\\u6CD5\\uFF1A\"]}),`\n`,(0,d.jsxs)(e.ul,{children:[`\n`,(0,d.jsxs)(e.li,{children:[(0,d.jsx)(e.code,{children:\"addWord(word: string)\"}),\": \\u5C06\\u4E00\\u4E2A\\u5355\\u8BCD\\u6DFB\\u52A0\\u5230\\u6570\\u636E\\u7ED3\\u6784\\u4E2D\"]}),`\n`,(0,d.jsxs)(e.li,{children:[(0,d.jsx)(e.code,{children:\"search(query: string)\"}),\": \\u68C0\\u67E5\\u4EFB\\u4F55\\u5DF2\\u6DFB\\u52A0\\u7684\\u5355\\u8BCD\\u662F\\u5426\\u4E0E\\u7ED9\\u5B9A\\u7684\\u5355\\u8BCD\\u5339\\u914D\\u3002\",(0,d.jsx)(e.code,{children:\"query\"}),\" \\u53EF\\u4EE5\\u5305\\u542B\\u70B9 \",(0,d.jsx)(e.code,{children:\".\"}),\"\\uFF0C\\u5B83\\u53EF\\u4EE5\\u5339\\u914D\\u4EFB\\u4F55\\u5B57\\u6BCD\"]}),`\n`]}),`\n`,(0,d.jsx)(e.h3,{children:\"\\u8F93\\u5165\"}),`\n`,(0,d.jsxs)(e.p,{children:[(0,d.jsx)(e.code,{children:\"WordFinder\"}),\" \\u5B9E\\u4F8B\\u5C06\\u6839\\u636E\\u4EE5\\u4E0B\\u5185\\u5BB9\\u4F7F\\u7528\\u5404\\u79CD\\u53C2\\u6570\\u8C03\\u7528\\u5176\\u65B9\\u6CD5\\uFF1A\"]}),`\n`,(0,d.jsxs)(e.ul,{children:[`\n`,(0,d.jsxs)(e.li,{children:[(0,d.jsx)(e.code,{children:\"methods: string[]\"}),\": \\u65B9\\u6CD5\\u540D\\u79F0\\u6570\\u7EC4\"]}),`\n`,(0,d.jsxs)(e.li,{children:[(0,d.jsx)(e.code,{children:\"params: string[]\"}),\": \\u5B57\\u7B26\\u4E32\\u6570\\u7EC4\"]}),`\n`]}),`\n`,(0,d.jsxs)(e.p,{children:[(0,d.jsx)(e.code,{children:\"methods[i]\"}),\" \\u5C06\\u4F7F\\u7528 \",(0,d.jsx)(e.code,{children:\"params[i]\"}),\" \\u8C03\\u7528\\u3002\"]}),`\n`,(0,d.jsx)(s,{testCases:i}),`\n`,(0,d.jsx)(e.h3,{children:\"\\u7EA6\\u675F\"}),`\n`,(0,d.jsxs)(e.ul,{children:[`\n`,(0,d.jsxs)(e.li,{children:[\"1 <= \",(0,d.jsx)(e.code,{children:\"word.length\"}),\" <= 25\"]}),`\n`,(0,d.jsxs)(e.li,{children:[\"1 <= \",(0,d.jsx)(e.code,{children:\"methods.length\"}),\" <= 1000\"]}),`\n`,(0,d.jsxs)(e.li,{children:[\"\\u641C\\u7D22\\u67E5\\u8BE2\\u53EF\\u80FD\\u5305\\u542B \",(0,d.jsx)(e.code,{children:\".\"}),\" \\u548C\\u5C0F\\u5199\\u82F1\\u6587\\u5B57\\u6BCD\\uFF0C\\u6BCF\\u4E2A\\u67E5\\u8BE2\\u6700\\u591A 2 \\u4E2A\\u70B9\"]}),`\n`,(0,d.jsx)(e.li,{children:\"\\u6BCF\\u4E2A\\u5355\\u8BCD\\u4EC5\\u5305\\u542B\\u5C0F\\u5199\\u82F1\\u6587\\u5B57\\u6BCD\"}),`\n`]})]})}function y(r={}){let{wrapper:e}=r.components||{};return e?(0,d.jsx)(e,Object.assign({},r,{children:(0,d.jsx)(u,r)})):u(r)}var C=y;return j(D);})();\n;return Component;", + "info": { + "excerpt": "实现一个可以添加单词并支持通配符搜索的数据结构", + "title": "单词查找器" + }, + "solution": "var Component=(()=>{var f=Object.create;var o=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty;var T=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),x=(r,e)=>{for(var d in e)o(r,d,{get:e[d],enumerable:!0})},h=(r,e,d,c)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of m(e))!p.call(r,i)&&i!==d&&o(r,i,{get:()=>e[i],enumerable:!(c=g(e,i))||c.enumerable});return r};var N=(r,e,d)=>(d=r!=null?f(w(r)):{},h(e||!r||!r.__esModule?o(d,\"default\",{value:r,enumerable:!0}):d,r)),I=r=>h(o({},\"__esModule\",{value:!0}),r);var t=T((_,l)=>{l.exports=_jsx_runtime});var j={};x(j,{default:()=>b});var n=N(t());var s=MDXCodeBlock;var a=`class TrieNode {\n // A map to hold child nodes\n children: Map = new Map();\n // Indicates whether this node is the end of a word\n word: boolean = false;\n}\n\nexport default class WordFinder {\n private trie: TrieNode;\n\n constructor() {\n // Initialize the root of the trie\n this.trie = new TrieNode();\n }\n\n addWord(word: string): void {\n let node = this.trie;\n\n for (const ch of word) {\n // If the character is not already a child node, add it\n if (!node.children.has(ch)) {\n node.children.set(ch, new TrieNode());\n }\n // Move to the next node in the trie\n node = node.children.get(ch)!;\n }\n // Mark the end of the word\n node.word = true;\n }\n\n private searchInNode(word: string, node: TrieNode): boolean {\n for (let i = 0; i < word.length; i++) {\n const ch = word[i];\n // If the character is not found, check if it's a '.'\n if (!node.children.has(ch)) {\n if (ch === '.') {\n // Iterate over all children nodes using forEach\n let found = false;\n node.children.forEach((child) => {\n // Recursively search for the remaining substring in each child node\n if (this.searchInNode(word.substring(i + 1), child)) {\n found = true;\n }\n });\n return found;\n }\n // If the character is not a '.' and not found, return false\n return false;\n } else {\n // If the character is found, move down to the next level in the trie\n node = node.children.get(ch)!;\n }\n }\n // Return true if the current node marks the end of a word\n return node.word;\n }\n\n search(word: string): boolean {\n return this.searchInNode(word, this.trie);\n }\n}\n`;function u(r){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",h3:\"h3\",ol:\"ol\",li:\"li\",strong:\"strong\",ul:\"ul\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"1. \\u4F7F\\u7528Trie\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4F7F\\u7528Trie\\uFF08\\u524D\\u7F00\\u6811\\uFF09\\u6784\\u5EFA\",(0,n.jsx)(e.code,{children:\"WordFinder\"}),\"\\uFF0C\\u4EE5\\u9AD8\\u6548\\u5730\\u5B58\\u50A8\\u548C\\u641C\\u7D22\\u5355\\u8BCD\\u3002\",(0,n.jsx)(e.code,{children:\"TrieNode\"}),\"\\u7ED3\\u6784\\u7531\\u4E00\\u4E2A\",(0,n.jsx)(e.code,{children:\"Map\"}),\"\\u7EC4\\u6210\\uFF0C\\u7528\\u4E8E\\u5B58\\u50A8\\u5B50\\u8282\\u70B9\\uFF0C\\u4EE5\\u53CA\\u4E00\\u4E2A\\u5E03\\u5C14\\u6807\\u5FD7\\uFF0C\\u6307\\u793A\\u8BE5\\u8282\\u70B9\\u662F\\u5426\\u4EE3\\u8868\\u5355\\u8BCD\\u7684\\u7ED3\\u5C3E\\u3002\\u8FD9\\u79CD\\u8BBE\\u8BA1\\u5BF9\\u4E8E\\u89E3\\u51B3\\u6D89\\u53CA\\u4F7F\\u7528\",(0,n.jsx)(e.code,{children:\".\"}),\"\\u8FDB\\u884C\\u7CBE\\u786E\\u5339\\u914D\\u6216\\u901A\\u914D\\u7B26\\u6A21\\u5F0F\\u7684\\u5355\\u8BCD\\u641C\\u7D22\\u95EE\\u9898\\u7279\\u522B\\u6709\\u6548\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E3B\\u8981\\u601D\\u60F3\\u662F\\u9010\\u4E2A\\u8282\\u70B9\\u5730\\u5C06\\u5355\\u8BCD\\u6DFB\\u52A0\\u5230Trie\\u4E2D\\uFF0C\\u5176\\u4E2D\\u6BCF\\u4E2A\\u5B57\\u7B26\\u4EE3\\u8868Trie\\u4E2D\\u7684\\u4E00\\u4E2A\\u8DEF\\u5F84\\u3002\\u641C\\u7D22\\u662F\\u9012\\u5F52\\u5B8C\\u6210\\u7684\\uFF0C\\u5BF9\",(0,n.jsx)(e.code,{children:\".\"}),\"\\u5B57\\u7B26\\u8FDB\\u884C\\u7279\\u6B8A\\u5904\\u7406\\uFF0C\\u5B83\\u5145\\u5F53\\u901A\\u914D\\u7B26\\u3002\",(0,n.jsx)(e.code,{children:\".\"}),\"\\u53EF\\u4EE5\\u5339\\u914D\\u4EFB\\u4F55\\u5B57\\u7B26\\uFF0C\\u5E76\\u9012\\u5F52\\u5730\\u63A2\\u7D22\\u6240\\u6709\\u53EF\\u80FD\\u7684\\u5B50\\u8282\\u70B9\\u4EE5\\u627E\\u5230\\u5339\\u914D\\u9879\\u3002\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u7B97\\u6CD5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.strong,{children:\"\\u6DFB\\u52A0\\u5355\\u8BCD\"}),\":\"]}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"\\u4ECE\\u6839\\u8282\\u70B9\\u5F00\\u59CB\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u5355\\u8BCD\\u4E2D\\u7684\\u6BCF\\u4E2A\\u5B57\\u7B26\\uFF0C\\u68C0\\u67E5\\u5B83\\u662F\\u5426\\u5B58\\u5728\\u4E8E\\u5F53\\u524D\\u8282\\u70B9\\u7684\",(0,n.jsx)(e.code,{children:\"children\"}),\"\\u6620\\u5C04\\u4E2D\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u4E0D\\u5B58\\u5728\\uFF0C\\u521B\\u5EFA\\u4E00\\u4E2A\\u65B0\\u7684\",(0,n.jsx)(e.code,{children:\"TrieNode\"}),\"\\u5E76\\u5C06\\u5176\\u6DFB\\u52A0\\u5230\\u6620\\u5C04\\u4E2D\\u3002\"]}),`\n`,(0,n.jsx)(e.li,{children:\"\\u79FB\\u52A8\\u5230\\u4E0B\\u4E00\\u4E2A\\u8282\\u70B9\\u5E76\\u91CD\\u590D\\uFF0C\\u76F4\\u5230\\u5B8C\\u5168\\u6DFB\\u52A0\\u5355\\u8BCD\\u3002\"}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u901A\\u8FC7\\u5C06\",(0,n.jsx)(e.code,{children:\"word\"}),\"\\u6807\\u5FD7\\u8BBE\\u7F6E\\u4E3A\",(0,n.jsx)(e.code,{children:\"true\"}),\"\\uFF0C\\u5C06\\u6700\\u7EC8\\u8282\\u70B9\\u6807\\u8BB0\\u4E3A\\u5355\\u8BCD\\u7684\\u7ED3\\u5C3E\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.strong,{children:\"\\u641C\\u7D22\"}),\":\"]}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4F7F\\u7528\\u8F85\\u52A9\\u51FD\\u6570\",(0,n.jsx)(e.code,{children:\"searchInNode\"}),\"\\u9012\\u5F52\\u904D\\u5386Trie\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5BF9\\u4E8E\\u6BCF\\u4E2A\\u5B57\\u7B26:\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5B83\\u5B58\\u5728\\u4E8E\\u5F53\\u524D\\u8282\\u70B9\\u7684\",(0,n.jsx)(e.code,{children:\"children\"}),\"\\u4E2D\\uFF0C\\u5219\\u79FB\\u52A8\\u5230\\u5B50\\u8282\\u70B9\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5B57\\u7B26\\u662F\",(0,n.jsx)(e.code,{children:\".\"}),\"\\uFF0C\\u5219\\u8FED\\u4EE3\\u6240\\u6709\\u5B50\\u8282\\u70B9\\u5E76\\u9012\\u5F52\\u641C\\u7D22\\u5269\\u4F59\\u7684\\u5B50\\u5B57\\u7B26\\u4E32\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5982\\u679C\\u5B57\\u7B26\\u4E0D\\u5B58\\u5728\\u4E14\\u4E0D\\u662F\",(0,n.jsx)(e.code,{children:\".\"}),\"\\uFF0C\\u5219\\u8FD4\\u56DE\",(0,n.jsx)(e.code,{children:\"false\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u5728\\u5355\\u8BCD\\u7684\\u672B\\u5C3E\\uFF0C\\u5982\\u679C\\u5F53\\u524D\\u8282\\u70B9\\u6807\\u8BB0\\u5355\\u8BCD\\u7684\\u7ED3\\u5C3E\\uFF0C\\u5219\\u8FD4\\u56DE\",(0,n.jsx)(e.code,{children:\"true\"}),\"\\u3002\"]}),`\n`]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(s,{children:a}),`\n`,(0,n.jsx)(e.h3,{children:\"Big-O \\u5206\\u6790\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\"}),\": O(m)\\uFF0C\\u5BF9\\u4E8E\\u6CA1\\u6709\\u70B9\\u7684\\u660E\\u786E\\u5B9A\\u4E49\\u7684\\u5355\\u8BCD\\uFF0C\\u5176\\u4E2D\",(0,n.jsx)(e.code,{children:\"m\"}),\"\\u662F\\u5355\\u8BCD\\u7684\\u957F\\u5EA6\\u3002\\u5BF9\\u4E8E\\u201C\\u672A\\u5B9A\\u4E49\\u201D\\u7684\\u5355\\u8BCD\\uFF0C\\u65F6\\u95F4\\u590D\\u6742\\u5EA6\\u4E3AO(n.26\",(0,n.jsx)(\"sup\",{children:\"m\"}),\")\\uFF0C\\u5176\\u4E2Dn\\u662F\\u952E\\u7684\\u6570\\u91CF\\uFF0Cm\\u662F\\u672A\\u5B9A\\u4E49\\u5355\\u8BCD\\u7684\\u957F\\u5EA6\\u3002\\u8FD9\\u8868\\u793A\\u641C\\u7D22\\u672A\\u5B9A\\u4E49\\u5355\\u8BCD\\u7684\\u6700\\u574F\\u60C5\\u51B5\\uFF0C\\u5176\\u4E2D\\u5305\\u542Bm\\u4E2A\\u9012\\u5F52\\u8C03\\u7528\\uFF0C\\u56E0\\u4E3A\\u8BE5\\u5355\\u8BCD\\u6BD4\\u6240\\u6709\\u63D2\\u5165\\u7684\\u952E\\u957F\\u4E00\\u4E2A\\u5B57\\u7B26\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\"}),\": O(1) \\u7528\\u4E8E\\u641C\\u7D22\\u6CA1\\u6709\\u70B9\\u7684\\u201C\\u5B9A\\u4E49\\u660E\\u786E\\u201D\\u7684\\u5355\\u8BCD\\u3002\\u5BF9\\u4E8E\\u201C\\u672A\\u5B9A\\u4E49\\u201D\\u7684\\u5355\\u8BCD\\uFF0C\\u7A7A\\u95F4\\u590D\\u6742\\u5EA6\\u53EF\\u4EE5\\u589E\\u52A0\\u5230O(m)\\u4EE5\\u9002\\u5E94\\u9012\\u5F52\\u5806\\u6808\\u3002\"]}),`\n`]})]})}function v(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(u,r)})):u(r)}var b=v;return I(j);})();\n;return Component;" +} \ No newline at end of file diff --git a/apps/web/src/__generated__/questions/coding/list.zh-CN.json b/apps/web/src/__generated__/questions/coding/list.zh-CN.json index 7f6a176dc..7d6ac3f8e 100644 --- a/apps/web/src/__generated__/questions/coding/list.zh-CN.json +++ b/apps/web/src/__generated__/questions/coding/list.zh-CN.json @@ -192,39 +192,6 @@ ] } }, - { - "info": { - "excerpt": "Implement a function to find the product of elements in an array excluding the current element", - "title": "Array Product Excluding Current" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1718496000, - "difficulty": "medium", - "duration": 15, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/array-product-excluding-current", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "array-product-excluding-current", - "subtitle": null, - "topics": [ - "array" - ] - } - }, { "info": { "excerpt": "实现 Array.prototype.at() 方法", @@ -538,466 +505,6 @@ ] } }, - { - "info": { - "excerpt": "Implement a function to determine if a string contains balanced brackets", - "title": "Balanced Brackets" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1722729600, - "difficulty": "easy", - "duration": 25, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/array-balanced-brackets", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "array-balanced-brackets", - "subtitle": null, - "topics": [ - "array", - "stack" - ] - } - }, - { - "info": { - "excerpt": "Implement a function that performs binary search on an array of numbers", - "title": "Binary Search" - }, - "metadata": { - "access": "standard", - "author": null, - "companies": [], - "created": 1671667200, - "difficulty": "medium", - "duration": 15, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/binary-search", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [ - "selection-sort", - "quick-sort", - "merge-sort", - "depth-first-search", - "breadth-first-search" - ], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "binary-search", - "subtitle": null, - "topics": [ - "binary-search", - "sorting" - ] - } - }, - { - "info": { - "excerpt": "Implement a binary search tree data structure including essential BST operations", - "title": "Binary Search Tree" - }, - "metadata": { - "access": "standard", - "author": null, - "companies": [], - "created": 1745539200, - "difficulty": "medium", - "duration": 15, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/binary-search-tree", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [ - "heap", - "binary-search" - ], - "slug": "binary-search-tree", - "subtitle": null, - "topics": [ - "binary-tree", - "binary-search-tree", - "tree" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to find the kth smallest node in a BST", - "title": "Binary Search Tree Kth Smallest Element" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1724284800, - "difficulty": "medium", - "duration": 35, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/binary-search-tree-kth-smallest", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "binary-search-tree-kth-smallest", - "subtitle": null, - "topics": [ - "binary-tree", - "binary-search-tree", - "tree" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to find the LCA in a binary search tree", - "title": "Binary Search Tree Lowest Common Ancestor" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1724284800, - "difficulty": "medium", - "duration": 35, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/binary-search-tree-lowest-common-ancestor", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "binary-search-tree-lowest-common-ancestor", - "subtitle": null, - "topics": [ - "binary-tree", - "binary-search-tree", - "tree" - ] - } - }, - { - "info": { - "excerpt": "Implement a binary tree data structure including essential operations", - "title": "Binary Tree" - }, - "metadata": { - "access": "standard", - "author": null, - "companies": [], - "created": 1716422400, - "difficulty": "medium", - "duration": 15, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/binary-tree", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [ - "binary-search-tree", - "binary-search" - ], - "slug": "binary-tree", - "subtitle": null, - "topics": [ - "binary-tree", - "tree" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to determine whether two binary trees are equal", - "title": "Binary Tree Equal" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1723161600, - "difficulty": "easy", - "duration": 25, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/binary-tree-equal", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "binary-tree-equal", - "subtitle": null, - "topics": [ - "binary-tree", - "tree" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to find the level order traversal of a binary tree", - "title": "Binary Tree Level Order Traversal" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1723161600, - "difficulty": "medium", - "duration": 25, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/binary-tree-level-order-traversal", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "binary-tree-level-order-traversal", - "subtitle": null, - "topics": [ - "binary-tree", - "tree" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to find the maximum depth of a binary tree", - "title": "Binary Tree Maximum Depth" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1723161600, - "difficulty": "easy", - "duration": 20, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/binary-tree-maximum-depth", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "binary-tree-maximum-depth", - "subtitle": null, - "topics": [ - "binary-tree", - "tree", - "dfs" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to find the maximum total of nodes in a binary tree path", - "title": "Binary Tree Maximum Total Path" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1724112000, - "difficulty": "hard", - "duration": 40, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/binary-tree-maximum-total-path", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "binary-tree-maximum-total-path", - "subtitle": null, - "topics": [ - "binary-tree", - "tree", - "dfs" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to construct a binary tree from preorder and inorder traversals", - "title": "Binary Tree Rebuilding from Preorder and Inorder Traversals" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1724889600, - "difficulty": "medium", - "duration": 45, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/binary-tree-rebuilding-from-traversals", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "binary-tree-rebuilding-from-traversals", - "subtitle": null, - "topics": [ - "binary-tree", - "tree" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to serialize and deserialize a binary tree", - "title": "Binary Tree Serialization and Deserialization" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1724889600, - "difficulty": "hard", - "duration": 20, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/binary-tree-serialization-deserialization", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "binary-tree-serialization-deserialization", - "subtitle": null, - "topics": [ - "binary-tree", - "tree", - "dfs" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to check if a binary tree is a subtree of another binary tree", - "title": "Binary Tree Subtree" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1723852800, - "difficulty": "easy", - "duration": 35, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/binary-tree-subtree", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "binary-tree-subtree", - "subtitle": null, - "topics": [ - "binary-tree", - "tree" - ] - } - }, { "info": { "excerpt": "Build a widget that fetches birth year data from an API and plot it on a histogram", @@ -1047,145 +554,6 @@ "topics": [] } }, - { - "info": { - "excerpt": "Implement a function to find number of set bits from 0 to n", - "title": "Bit Counting" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1718928000, - "difficulty": "easy", - "duration": 25, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/bit-counting", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "bit-counting", - "subtitle": null, - "topics": [ - "binary" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to flip the order of the bits in a given number", - "title": "Bit Reversal" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1718928000, - "difficulty": "easy", - "duration": 25, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/bit-reversal", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "bit-reversal", - "subtitle": null, - "topics": [ - "binary" - ] - } - }, - { - "info": { - "excerpt": "Implement a breadth-first search algorithm that traverses a directed graph in a breadth-first manner", - "title": "Breadth-first Search" - }, - "metadata": { - "access": "free", - "author": null, - "companies": [], - "created": 1679788800, - "difficulty": "medium", - "duration": 15, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/breadth-first-search", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [ - "depth-first-search" - ], - "slug": "breadth-first-search", - "subtitle": null, - "topics": [ - "bfs" - ] - } - }, - { - "info": { - "excerpt": "Implement a function that performs a bubble sort", - "title": "Bubble Sort" - }, - "metadata": { - "access": "standard", - "author": null, - "companies": [], - "created": 1745539200, - "difficulty": "easy", - "duration": 15, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/bubble-sort", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [ - "quick-sort" - ], - "published": true, - "ranking": 100, - "similarQuestions": [ - "insertion-sort", - "selection-sort" - ], - "slug": "bubble-sort", - "subtitle": null, - "topics": [ - "sorting" - ] - } - }, { "info": { "excerpt": "实现一个函数,将一个数字限制在包含下限和上限的范围内", @@ -1285,39 +653,6 @@ "topics": [] } }, - { - "info": { - "excerpt": "Implement a function to count combinations that sum to the target", - "title": "Combinations for Target Sum" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1720310400, - "difficulty": "medium", - "duration": 40, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/combinations-target-sum", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "combinations-target-sum", - "subtitle": null, - "topics": [ - "dynamic-programming" - ] - } - }, { "info": { "excerpt": "实现一个函数,该函数创建一个数组,其中移除了所有假值", @@ -1530,73 +865,6 @@ ] } }, - { - "info": { - "excerpt": "Implement a function to count distinct islands in a 2D binary grid", - "title": "Count Islands in a Grid" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1721001600, - "difficulty": "medium", - "duration": 35, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/grid-count-islands", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "grid-count-islands", - "subtitle": null, - "topics": [ - "matrix", - "dfs" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to find set bits in binary representation of a given integer", - "title": "Count Set Bits in a Binary Number" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1718928000, - "difficulty": "easy", - "duration": 15, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/count-ones-in-binary", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "count-ones-in-binary", - "subtitle": null, - "topics": [ - "binary" - ] - } - }, { "info": { "excerpt": "Build a simple counter that increments whenever a button is clicked", @@ -1658,41 +926,6 @@ "topics": [] } }, - { - "info": { - "excerpt": "Implement a function to check if all courses can be completed given prerequisites", - "title": "Course Dependency" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1721260800, - "difficulty": "medium", - "duration": 40, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/course-dependency", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "course-dependency", - "subtitle": null, - "topics": [ - "graph", - "topological-sort", - "dfs" - ] - } - }, { "info": { "excerpt": "Build a users data table with pagination features", @@ -1901,108 +1134,6 @@ ] } }, - { - "info": { - "excerpt": "Implement a function to count ways to decode a numeric string", - "title": "Decode Message" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1720742400, - "difficulty": "medium", - "duration": 40, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/string-decode-message", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "string-decode-message", - "subtitle": null, - "topics": [ - "string", - "dynamic-programming" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to delete the nth node from the end of a linked list", - "title": "Delete Nth Node from End of Linked List" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1722297600, - "difficulty": "medium", - "duration": 35, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/linked-list-delete-nth-from-end", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "linked-list-delete-nth-from-end", - "subtitle": null, - "topics": [ - "linked-list" - ] - } - }, - { - "info": { - "excerpt": "Implement a depth-first search algorithm that traverses a directed graph in a depth-first manner", - "title": "Depth-first Search" - }, - "metadata": { - "access": "free", - "author": null, - "companies": [], - "created": 1671667200, - "difficulty": "medium", - "duration": 15, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/depth-first-search", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [ - "breadth-first-search" - ], - "slug": "depth-first-search", - "subtitle": null, - "topics": [ - "dfs" - ] - } - }, { "info": { "excerpt": "Build a dice roller app that simulates the results of rolling 6-sided dice", @@ -2114,8 +1245,8 @@ }, { "info": { - "excerpt": "Implement Dijkstra's algorithm to find the shortest paths from a source vertex in a graph represented as an adjacency list.", - "title": "Dijkstra's Algorithm" + "excerpt": "实现 Dijkstra 算法,以找到图中从源顶点开始的最短路径,该图表示为邻接表。", + "title": "Dijkstra 算法" }, "metadata": { "access": "free", @@ -2148,73 +1279,6 @@ ] } }, - { - "info": { - "excerpt": "Implement a function to determine the minimum amount of removals to get non-overlapping intervals", - "title": "Disjoint Intervals" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1722384000, - "difficulty": "medium", - "duration": 45, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/disjoint-intervals", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "disjoint-intervals", - "subtitle": null, - "topics": [ - "intervals", - "greedy" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to calculate distinct paths for a robot moving on an m x n grid", - "title": "Distinct Paths in Grid" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1720742400, - "difficulty": "medium", - "duration": 35, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/grid-distinct-paths", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "grid-distinct-paths", - "subtitle": null, - "topics": [ - "dynamic-programming" - ] - } - }, { "info": { "excerpt": "实现一个函数,该函数从数组末尾排除元素,直到谓词返回 false", @@ -2281,75 +1345,6 @@ "topics": [] } }, - { - "info": { - "excerpt": "Implement a function to determine if the end of the array is reachable", - "title": "End of Array Reachable" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1720828800, - "difficulty": "medium", - "duration": 45, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/array-reachable-end", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "array-reachable-end", - "subtitle": null, - "topics": [ - "array", - "dynamic-programming", - "greedy" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to verify and return an extraterrestrial language's alphabet order", - "title": "Extraterrestrial Language" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1722384000, - "difficulty": "hard", - "duration": 55, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/extraterrestrial-language", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "extraterrestrial-language", - "subtitle": null, - "topics": [ - "graph", - "topological-sort" - ] - } - }, { "info": { "excerpt": "Build a file explorer component to navigate files and directories in a tree-like hierarchical viewer", @@ -2484,208 +1479,6 @@ "topics": [] } }, - { - "info": { - "excerpt": "Implement a function to check if there are any duplicate numbers in the array", - "title": "Find Duplicates in Array" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1718409600, - "difficulty": "easy", - "duration": 15, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/array-find-duplicate", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "array-find-duplicate", - "subtitle": null, - "topics": [ - "array" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to find an integer in a rotated sorted array", - "title": "Find Element in Rotated Array" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1718928000, - "difficulty": "medium", - "duration": 30, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/array-rotated-find", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "array-rotated-find", - "subtitle": null, - "topics": [ - "array", - "binary-search" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to find the missing element in a sorted array", - "title": "Find Missing Number in Sequence" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1718928000, - "difficulty": "easy", - "duration": 15, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/array-find-missing-number-in-sequence", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "array-find-missing-number-in-sequence", - "subtitle": null, - "topics": [ - "array" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to find the longest palindromic substring", - "title": "Find the Longest Palindromic Substring" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1723161600, - "difficulty": "medium", - "duration": 45, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/longest-palindromic-substring", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "longest-palindromic-substring", - "subtitle": null, - "topics": [ - "string" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to check the existence of a word in a grid", - "title": "Find Word in Grid" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1722729600, - "difficulty": "medium", - "duration": 45, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/grid-find-word", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "grid-find-word", - "subtitle": null, - "topics": [ - "matrix", - "dfs" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to find all the words present in the grid", - "title": "Find Words in Grid" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1724976000, - "difficulty": "hard", - "duration": 40, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/grid-find-words", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "grid-find-words", - "subtitle": null, - "topics": [ - "matrix", - "tree", - "trie" - ] - } - }, { "info": { "excerpt": "Build a component that books a flight for specified dates", @@ -2739,40 +1532,6 @@ ] } }, - { - "info": { - "excerpt": "Implement a function to flip the nodes in a binary tree", - "title": "Flip Binary Tree" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1723766400, - "difficulty": "easy", - "duration": 20, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/binary-tree-flip", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "binary-tree-flip", - "subtitle": null, - "topics": [ - "binary-tree", - "tree" - ] - } - }, { "info": { "excerpt": "实现 Function.prototype.apply() 函数,该函数使用给定的 `this` 值和作为数组的参数调用该函数", @@ -3100,74 +1859,6 @@ ] } }, - { - "info": { - "excerpt": "Implement a function to deeply clone a connected and undirected graph", - "title": "Graph Clone" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1721260800, - "difficulty": "medium", - "duration": 50, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/graph-clone", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "graph-clone", - "subtitle": null, - "topics": [ - "graph", - "dfs" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to count connected components in a graph", - "title": "Graph Count Connected Components" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1721779200, - "difficulty": "medium", - "duration": 45, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/graph-count-connected-components", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "graph-count-connected-components", - "subtitle": null, - "topics": [ - "graph", - "dfs" - ] - } - }, { "info": { "excerpt": "Build a grid of lights where the lights deactivate in the reverse order they were activated", @@ -3222,81 +1913,6 @@ ] } }, - { - "info": { - "excerpt": "Implement a heap data structure containing essential heap operations", - "title": "Heap" - }, - "metadata": { - "access": "standard", - "author": null, - "companies": [], - "created": 1745539200, - "difficulty": "hard", - "duration": 15, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/heap", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [ - "heap-sort" - ], - "published": true, - "ranking": 100, - "similarQuestions": [ - "binary-search-tree" - ], - "slug": "heap", - "subtitle": null, - "topics": [ - "heap" - ] - } - }, - { - "info": { - "excerpt": "Implement a function that performs a heap sort", - "title": "Heap Sort" - }, - "metadata": { - "access": "free", - "author": null, - "companies": [], - "created": 1673395200, - "difficulty": "medium", - "duration": 15, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/heap-sort", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [ - "quick-sort" - ], - "published": true, - "ranking": 100, - "similarQuestions": [ - "selection-sort" - ], - "slug": "heap-sort", - "subtitle": null, - "topics": [ - "heap", - "sorting" - ] - } - }, { "info": { "excerpt": "Build the famous holy grail layout consisting of a header, 3 columns, and a footer", @@ -3545,43 +2161,6 @@ "topics": [] } }, - { - "info": { - "excerpt": "Implement a function that performs an insertion sort", - "title": "Insertion Sort" - }, - "metadata": { - "access": "free", - "author": null, - "companies": [], - "created": 1671667200, - "difficulty": "easy", - "duration": 15, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/insertion-sort", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [ - "quick-sort" - ], - "published": true, - "ranking": 100, - "similarQuestions": [ - "selection-sort" - ], - "slug": "insertion-sort", - "subtitle": null, - "topics": [ - "sorting" - ] - } - }, { "info": { "excerpt": "实现一个函数,该函数根据提供的迭代函数返回一个包含所有给定数组中包含的唯一值的数组。", @@ -3616,40 +2195,6 @@ "topics": [] } }, - { - "info": { - "excerpt": "Implement a function to determine if a graph is a valid tree", - "title": "Is the Graph a Tree" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1721779200, - "difficulty": "medium", - "duration": 15, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/graph-is-tree", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "graph-is-tree", - "subtitle": null, - "topics": [ - "graph", - "dfs" - ] - } - }, { "info": { "excerpt": "Build a job board that displays the latest job postings from Hacker News", @@ -3924,344 +2469,6 @@ ] } }, - { - "info": { - "excerpt": "Implement a linked list data structure containing the common linked list methods", - "title": "Linked List" - }, - "metadata": { - "access": "free", - "author": null, - "companies": [], - "created": 1745539200, - "difficulty": "medium", - "duration": 20, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/linked-list", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [ - "stack", - "queue" - ], - "slug": "linked-list", - "subtitle": null, - "topics": [ - "linked-list" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to detect if there are cycles in a linked list", - "title": "Linked List Detect Cycle" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1718928000, - "difficulty": "easy", - "duration": 30, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/linked-list-detect-cycle", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "linked-list-detect-cycle", - "subtitle": null, - "topics": [ - "linked-list" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to reverse a linked list", - "title": "Linked List Reversal" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1722038400, - "difficulty": "easy", - "duration": 25, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/linked-list-reversal", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "linked-list-reversal", - "subtitle": null, - "topics": [ - "linked-list" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to combine k sorted linked lists", - "title": "Linked Lists Combine K Sorted" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1722297600, - "difficulty": "hard", - "duration": 45, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/linked-list-combine-k-sorted", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "linked-list-combine-k-sorted", - "subtitle": null, - "topics": [ - "linked-list", - "heap" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to combine two sorted linked list", - "title": "Linked Lists Combine Two Sorted" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1722038400, - "difficulty": "easy", - "duration": 35, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/linked-list-combine-two-sorted", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "linked-list-combine-two-sorted", - "subtitle": null, - "topics": [ - "linked-list" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to find the longest common subsequence in two strings", - "title": "Longest Common Subsequence" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1719705600, - "difficulty": "medium", - "duration": 45, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/longest-common-subsequence", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "longest-common-subsequence", - "subtitle": null, - "topics": [ - "array", - "dynamic-programming" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to find the length of the longest consecutive number sequence", - "title": "Longest Consecutive Number Sequence" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1721606400, - "difficulty": "medium", - "duration": 40, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/longest-consecutive-number-sequence", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "longest-consecutive-number-sequence", - "subtitle": null, - "topics": [ - "array" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to find the length of the longest increasing subsequence", - "title": "Longest Increasing Subsequence" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1733616000, - "difficulty": "medium", - "duration": 40, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/longest-increasing-subsequence", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "longest-increasing-subsequence", - "subtitle": null, - "topics": [ - "array", - "binary-search", - "greedy" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to find the length of longest substring with unique characters", - "title": "Longest Non-repeating Substring" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1723161600, - "difficulty": "medium", - "duration": 45, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/longest-non-repeating-substring", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "longest-non-repeating-substring", - "subtitle": null, - "topics": [ - "string" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to find the longest uniform substring after up to k replacements", - "title": "Longest Repeating Substring After Replacements" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1723161600, - "difficulty": "medium", - "duration": 45, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/longest-repeating-substring-after-replacements", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "longest-repeating-substring-after-replacements", - "subtitle": null, - "topics": [ - "string", - "binary-search" - ] - } - }, { "info": { "excerpt": "实现一个函数,该函数使用异步映射函数映射一个项目数组", @@ -4350,238 +2557,6 @@ ] } }, - { - "info": { - "excerpt": "Implement a function to rotate the given matrix by 90 degrees", - "title": "Matrix Rotation" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1722038400, - "difficulty": "medium", - "duration": 45, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/matrix-rotation", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "matrix-rotation", - "subtitle": null, - "topics": [ - "matrix" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to traverse the matrix in spiral order", - "title": "Matrix Spiral Traversal" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": null, - "difficulty": "medium", - "duration": 45, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/matrix-spiral-traversal", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "matrix-spiral-traversal", - "subtitle": null, - "topics": [ - "matrix" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to set matrix rows and columns to zero", - "title": "Matrix Zeroing" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1722038400, - "difficulty": "medium", - "duration": 35, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/matrix-zeroing", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "matrix-zeroing", - "subtitle": null, - "topics": [ - "matrix" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to find the subarray which has the largest product", - "title": "Maximum Product in Contiguous Array" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1718236800, - "difficulty": "medium", - "duration": 30, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/array-maximum-product-contiguous", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "array-maximum-product-contiguous", - "subtitle": null, - "topics": [ - "array" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to find the subarray with the maximum sum", - "title": "Maximum Sum in Contiguous Array" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1718841600, - "difficulty": "medium", - "duration": 25, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/array-maximum-sum-contiguous", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "array-maximum-sum-contiguous", - "subtitle": null, - "topics": [ - "array" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to find the maximum water volume between two walls in an array of walls", - "title": "Maximum Water Trapped Between Walls" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1718236800, - "difficulty": "medium", - "duration": 15, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/maximum-water-between-walls", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "maximum-water-between-walls", - "subtitle": null, - "topics": [ - "array" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to check if all meetings can be attended", - "title": "Meeting Calendar" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1721779200, - "difficulty": "easy", - "duration": 35, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/intervals-meeting-calendar", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "intervals-meeting-calendar", - "subtitle": null, - "topics": [ - "intervals", - "sorting" - ] - } - }, { "info": { "excerpt": "实现一个函数,该函数返回一个函数的记忆化版本,该函数接受单个参数", @@ -4704,111 +2679,6 @@ "topics": [] } }, - { - "info": { - "excerpt": "Implement a function to insert a new interval in the given intervals", - "title": "Merge New Interval" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1722384000, - "difficulty": "medium", - "duration": 45, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/intervals-merge-new", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "intervals-merge-new", - "subtitle": null, - "topics": [ - "binary-search", - "intervals", - "sorting" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to merge overlapping intervals", - "title": "Merge Overlapping Intervals" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1722384000, - "difficulty": "medium", - "duration": 35, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/intervals-combine-overlapping", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "intervals-combine-overlapping", - "subtitle": null, - "topics": [ - "intervals", - "sorting", - "dfs" - ] - } - }, - { - "info": { - "excerpt": "Implement a function that performs a recursive merge sort", - "title": "Merge Sort" - }, - "metadata": { - "access": "free", - "author": null, - "companies": [], - "created": 1671667200, - "difficulty": "medium", - "duration": 20, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/merge-sort", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [ - "quick-sort" - ], - "slug": "merge-sort", - "subtitle": null, - "topics": [ - "sorting" - ] - } - }, { "info": { "excerpt": "实现一个基于指定条件的查找最小元素的函数", @@ -4843,73 +2713,6 @@ "topics": [] } }, - { - "info": { - "excerpt": "Implement a function to return minimum coins needed to make the given amount", - "title": "Minimum Coins for Change" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1733616000, - "difficulty": "medium", - "duration": 40, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/coin-change", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "coin-change", - "subtitle": null, - "topics": [ - "dynamic-programming" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to find the minimum number of required conference rooms", - "title": "Minimum Meeting Rooms Needed" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1722038400, - "difficulty": "medium", - "duration": 55, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/intervals-minimum-meeting-rooms", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "intervals-minimum-meeting-rooms", - "subtitle": null, - "topics": [ - "heap", - "intervals" - ] - } - }, { "info": { "excerpt": "Build a reusable modal dialog component that can be opened and closed", @@ -5137,108 +2940,6 @@ "topics": [] } }, - { - "info": { - "excerpt": "Implement a function to determine the most common elements in an integer array", - "title": "Most Common Elements" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1724889600, - "difficulty": "medium", - "duration": 35, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/array-most-common-elements", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "array-most-common-elements", - "subtitle": null, - "topics": [ - "array", - "heap" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to find maximum money to rob without alerting police", - "title": "Neighborhood Theft" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1720828800, - "difficulty": "medium", - "duration": 35, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/neighborhood-theft", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "neighborhood-theft", - "subtitle": null, - "topics": [ - "array", - "dynamic-programming" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to find maximum money to rob in circular houses without alerting police", - "title": "Neighborhood Theft (Circular)" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1720828800, - "difficulty": "medium", - "duration": 45, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/neighborhood-theft-circular", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "neighborhood-theft-circular", - "subtitle": null, - "topics": [ - "array", - "dynamic-programming" - ] - } - }, { "info": { "excerpt": "Build a nested checkboxes component with parent-child selection logic", @@ -5279,74 +2980,6 @@ "topics": [] } }, - { - "info": { - "excerpt": "Implement a function to find the median of a dynamic stream of integers", - "title": "Number Stream Median" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1724976000, - "difficulty": "hard", - "duration": 55, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/number-stream-median", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "number-stream-median", - "subtitle": null, - "topics": [ - "heap" - ] - } - }, - { - "info": { - "excerpt": "Implement a function returning cells with water flow to both oceans", - "title": "Ocean Flow" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1721088000, - "difficulty": "medium", - "duration": 45, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/ocean-flow", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "ocean-flow", - "subtitle": null, - "topics": [ - "graph", - "dfs", - "bfs" - ] - } - }, { "info": { "excerpt": "实现一个接受回调函数并将其调用限制为最多一次的函数", @@ -5386,41 +3019,7 @@ }, { "info": { - "excerpt": "Implement a function to find the maximum profit achievable by buying and selling a stock once", - "title": "Optimal Stock Trading" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1718582400, - "difficulty": "easy", - "duration": 15, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/optimal-stock-trading", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "optimal-stock-trading", - "subtitle": null, - "topics": [ - "array", - "greedy" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to find two numbers within an array of integers that add up to a target integer", + "excerpt": "实现一个函数,用于查找整数数组中两个相加等于目标整数的数字", "title": "Pair sum" }, "metadata": { @@ -5451,39 +3050,6 @@ ] } }, - { - "info": { - "excerpt": "Implement a function to count all palindromic substrings in a string", - "title": "Palindromic Substrings" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1723161600, - "difficulty": "medium", - "duration": 40, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/string-palindromic-substrings", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "string-palindromic-substrings", - "subtitle": null, - "topics": [ - "string" - ] - } - }, { "info": { "excerpt": "Build a pixel art drawing tool where users can paint pixels with selected colors", @@ -6181,76 +3747,6 @@ ] } }, - { - "info": { - "excerpt": "Implement a queue data structure containing the common queue methods", - "title": "Queue" - }, - "metadata": { - "access": "free", - "author": "yangshun", - "companies": [], - "created": 1670457600, - "difficulty": "medium", - "duration": 15, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/queue", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [ - "stack" - ], - "slug": "queue", - "subtitle": null, - "topics": [ - "queue" - ] - } - }, - { - "info": { - "excerpt": "Implement a function that performs a recursive quick sort", - "title": "Quick Sort" - }, - "metadata": { - "access": "free", - "author": null, - "companies": [], - "created": 1671667200, - "difficulty": "medium", - "duration": 20, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/quick-sort", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [ - "merge-sort" - ], - "slug": "quick-sort", - "subtitle": null, - "topics": [ - "sorting" - ] - } - }, { "info": { "excerpt": "实现一个按降序返回数字序列的函数", @@ -6287,74 +3783,6 @@ "topics": [] } }, - { - "info": { - "excerpt": "Implement a function to rearrange the nodes in a linked list", - "title": "Rearrange Linked List" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1722297600, - "difficulty": "medium", - "duration": 35, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/linked-list-rearrange", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "linked-list-rearrange", - "subtitle": null, - "topics": [ - "linked-list" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to check whether a string be formed from dictionary words", - "title": "Segment Words" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1720310400, - "difficulty": "medium", - "duration": 40, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/string-segment-words", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "string-segment-words", - "subtitle": null, - "topics": [ - "string", - "dynamic-programming", - "graph" - ] - } - }, { "info": { "excerpt": "Build an interface where users can drag to select multiple cells within a grid", @@ -6392,76 +3820,6 @@ "topics": [] } }, - { - "info": { - "excerpt": "Implement a function that performs a selection sort", - "title": "Selection Sort" - }, - "metadata": { - "access": "standard", - "author": null, - "companies": [], - "created": 1671667200, - "difficulty": "easy", - "duration": 10, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/selection-sort", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [ - "quick-sort" - ], - "published": true, - "ranking": 100, - "similarQuestions": [ - "insertion-sort" - ], - "slug": "selection-sort", - "subtitle": null, - "topics": [ - "sorting" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to return the smallest substring of a string containing all characters from another string", - "title": "Shortest Substring Containing Characters" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1723161600, - "difficulty": "hard", - "duration": 45, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/string-shortest-substring-containing-characters", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "string-shortest-substring-containing-characters", - "subtitle": null, - "topics": [ - "string" - ] - } - }, { "info": { "excerpt": "Build a signup form that does validation on user details and submits to a back end API", @@ -6539,40 +3897,6 @@ ] } }, - { - "info": { - "excerpt": "Implement a function to find the smallest element in rotated sorted array", - "title": "Smallest element in rotated sorted array" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1718928000, - "difficulty": "medium", - "duration": 25, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/array-smallest-in-rotated", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "array-smallest-in-rotated", - "subtitle": null, - "topics": [ - "array", - "binary-search" - ] - } - }, { "info": { "excerpt": "实现一个函数,在将输入对象压扁成单层深度后,返回一个新对象", @@ -6609,78 +3933,6 @@ ] } }, - { - "info": { - "excerpt": "Implement a stack data structure containing the common stack methods", - "title": "Stack" - }, - "metadata": { - "access": "free", - "author": "yangshun", - "companies": [ - "amazon" - ], - "created": 1670025600, - "difficulty": "easy", - "duration": 10, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/stack", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [ - "queue" - ], - "published": true, - "ranking": 100, - "similarQuestions": [ - "queue" - ], - "slug": "stack", - "subtitle": null, - "topics": [ - "stack" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to find the number of ways to reach at the top of staircase", - "title": "Staircase Climbing Combinations" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1719187200, - "difficulty": "easy", - "duration": 20, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/staircase-climbing-combinations", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "staircase-climbing-combinations", - "subtitle": null, - "topics": [ - "dynamic-programming" - ] - } - }, { "info": { "excerpt": "Build a star rating component that shows a row of star icons for users to select the number of filled stars corresponding to the rating", @@ -6796,140 +4048,6 @@ ] } }, - { - "info": { - "excerpt": "Implement a function to determine if two strings are anagram of each other", - "title": "String Anagram" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1722729600, - "difficulty": "easy", - "duration": 15, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/string-anagram", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "string-anagram", - "subtitle": null, - "topics": [ - "string" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to group an array of strings into anagrams", - "title": "String Anagram Groups" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [ - "amazon" - ], - "created": 1723161600, - "difficulty": "medium", - "duration": 40, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/string-anagram-groups", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "string-anagram-groups", - "subtitle": null, - "topics": [ - "string" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to determine if a string is a palindrome", - "title": "String Palindrome" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1722729600, - "difficulty": "easy", - "duration": 25, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/string-palindrome", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "string-palindrome", - "subtitle": null, - "topics": [ - "string" - ] - } - }, - { - "info": { - "excerpt": "Implement a function to find the sum of two integers without using + and - operator", - "title": "Sum Without Addition" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1718928000, - "difficulty": "medium", - "duration": 35, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/sum-without-addition", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "sum-without-addition", - "subtitle": null, - "topics": [ - "binary" - ] - } - }, { "info": { "excerpt": "Build a tabs component that displays a list of tab elements and one associated panel of content at a time", @@ -7092,40 +4210,6 @@ ] } }, - { - "info": { - "excerpt": "Implement a function to find minimum intervals for tasks with cooldown", - "title": "Task Coordination" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1725408000, - "difficulty": "medium", - "duration": 40, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/task-coordination", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "task-coordination", - "subtitle": null, - "topics": [ - "greedy", - "heap" - ] - } - }, { "info": { "excerpt": "Build a temperature converter widget that converts temperature values between Celsius and Fahrenheit", @@ -7362,46 +4446,6 @@ "topics": [] } }, - { - "info": { - "excerpt": "Implement a function that performs a topological sort", - "title": "Topological Sort" - }, - "metadata": { - "access": "free", - "author": null, - "companies": [ - "snap" - ], - "created": 1673395200, - "difficulty": "medium", - "duration": 20, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/topological-sort", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [ - "quick-sort" - ], - "published": true, - "ranking": 100, - "similarQuestions": [ - "selection-sort" - ], - "slug": "topological-sort", - "subtitle": null, - "topics": [ - "topological-sort", - "graph" - ] - } - }, { "info": { "excerpt": "Build a traffic light where the lights switch from green to yellow to red after predetermined intervals and loop indefinitely", @@ -7573,8 +4617,8 @@ }, { "info": { - "excerpt": "Implement a trie-prefix-tree with insert, search, and starts with functionality", - "title": "Trie (Prefix Tree)" + "excerpt": "实现一个具有插入、搜索和以...开头功能的 trie 前缀树", + "title": "Trie(前缀树)" }, "metadata": { "access": "standard", @@ -7605,39 +4649,6 @@ ] } }, - { - "info": { - "excerpt": "Implement a function to find all unique triplets with distinct indices that sum to 0", - "title": "Triplet Sum" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1718928000, - "difficulty": "medium", - "duration": 35, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/triplet-sum", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "triplet-sum", - "subtitle": null, - "topics": [ - "array" - ] - } - }, { "info": { "excerpt": "Build a component that resembles a Tweet from Twitter", @@ -9138,41 +6149,6 @@ ] } }, - { - "info": { - "excerpt": "Implement a function to validate whether a binary tree is a valid binary search tree", - "title": "Validate Binary Search Tree" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1724284800, - "difficulty": "medium", - "duration": 35, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/binary-search-tree-validate", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "binary-search-tree-validate", - "subtitle": null, - "topics": [ - "binary-tree", - "binary-search-tree", - "tree" - ] - } - }, { "info": { "excerpt": "Build a popular arcade game where players attempt to hit moles as they pop up from holes in a board", @@ -9226,41 +6202,6 @@ "topics": [] } }, - { - "info": { - "excerpt": "Implement a data structure where words can be added and support wildcard searching", - "title": "Word Finder" - }, - "metadata": { - "access": "standard", - "author": "hiten", - "companies": [], - "created": 1724976000, - "difficulty": "medium", - "duration": 45, - "featured": false, - "format": "algo", - "frameworkDefault": null, - "frameworks": [], - "href": "/questions/algo/word-finder", - "importance": "low", - "languages": [ - "js", - "ts" - ], - "nextQuestions": [], - "published": true, - "ranking": 100, - "similarQuestions": [], - "slug": "word-finder", - "subtitle": null, - "topics": [ - "matrix", - "graph", - "trie" - ] - } - }, { "info": { "excerpt": "Build Wordle, the word-guessing game that took the world by storm", @@ -9310,6 +6251,73 @@ "topics": [] } }, + { + "info": { + "excerpt": "实现一个函数,找到所有和为 0 且索引不同的唯一三元组。", + "title": "三元组之和" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718928000, + "difficulty": "medium", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/triplet-sum", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "triplet-sum", + "subtitle": null, + "topics": [ + "array" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,以确定需要移除的最小数量,以获得不重叠的区间", + "title": "不相交的区间" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722384000, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/disjoint-intervals", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "disjoint-intervals", + "subtitle": null, + "topics": [ + "intervals", + "greedy" + ] + } + }, { "info": { "excerpt": "实现一个类似于 Koa.js 中间件函数的异步中间件函数组合。", @@ -9437,6 +6445,398 @@ ] } }, + { + "info": { + "excerpt": "实现一个对数字数组执行二分查找的函数", + "title": "二分查找" + }, + "metadata": { + "access": "standard", + "author": null, + "companies": [], + "created": 1671667200, + "difficulty": "medium", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-search", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [ + "selection-sort", + "quick-sort", + "merge-sort", + "depth-first-search", + "breadth-first-search" + ], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "binary-search", + "subtitle": null, + "topics": [ + "binary-search", + "sorting" + ] + } + }, + { + "info": { + "excerpt": "实现一个二叉搜索树数据结构,包括基本的 BST 操作", + "title": "二叉搜索树" + }, + "metadata": { + "access": "standard", + "author": null, + "companies": [], + "created": 1745539200, + "difficulty": "medium", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-search-tree", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [ + "heap", + "binary-search" + ], + "slug": "binary-search-tree", + "subtitle": null, + "topics": [ + "binary-tree", + "binary-search-tree", + "tree" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,以找到二叉搜索树中的 LCA", + "title": "二叉搜索树的最低公共祖先" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1724284800, + "difficulty": "medium", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-search-tree-lowest-common-ancestor", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "binary-search-tree-lowest-common-ancestor", + "subtitle": null, + "topics": [ + "binary-tree", + "binary-search-tree", + "tree" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,用于查找 BST 中第 k 个最小的节点", + "title": "二叉搜索树第 K 小的元素" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1724284800, + "difficulty": "medium", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-search-tree-kth-smallest", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "binary-search-tree-kth-smallest", + "subtitle": null, + "topics": [ + "binary-tree", + "binary-search-tree", + "tree" + ] + } + }, + { + "info": { + "excerpt": "实现一个二叉树数据结构,包括基本操作", + "title": "二叉树" + }, + "metadata": { + "access": "standard", + "author": null, + "companies": [], + "created": 1716422400, + "difficulty": "medium", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-tree", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [ + "binary-search-tree", + "binary-search" + ], + "slug": "binary-tree", + "subtitle": null, + "topics": [ + "binary-tree", + "tree" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,以找到二叉树路径中节点的最大总和", + "title": "二叉树最大路径和" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1724112000, + "difficulty": "hard", + "duration": 40, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-tree-maximum-total-path", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "binary-tree-maximum-total-path", + "subtitle": null, + "topics": [ + "binary-tree", + "tree", + "dfs" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来检查一个二叉树是否是另一个二叉树的子树", + "title": "二叉树子树" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1723852800, + "difficulty": "easy", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-tree-subtree", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "binary-tree-subtree", + "subtitle": null, + "topics": [ + "binary-tree", + "tree" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来查找二叉树的层序遍历", + "title": "二叉树层序遍历" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1723161600, + "difficulty": "medium", + "duration": 25, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-tree-level-order-traversal", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "binary-tree-level-order-traversal", + "subtitle": null, + "topics": [ + "binary-tree", + "tree" + ] + } + }, + { + "info": { + "excerpt": "实现一个序列化和反序列化二叉树的函数", + "title": "二叉树序列化和反序列化" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1724889600, + "difficulty": "hard", + "duration": 20, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-tree-serialization-deserialization", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "binary-tree-serialization-deserialization", + "subtitle": null, + "topics": [ + "binary-tree", + "tree", + "dfs" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来查找二叉树的最大深度", + "title": "二叉树的最大深度" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1723161600, + "difficulty": "easy", + "duration": 20, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-tree-maximum-depth", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "binary-tree-maximum-depth", + "subtitle": null, + "topics": [ + "binary-tree", + "tree", + "dfs" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来确定两个二叉树是否相等", + "title": "二叉树相等" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1723161600, + "difficulty": "easy", + "duration": 25, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-tree-equal", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "binary-tree-equal", + "subtitle": null, + "topics": [ + "binary-tree", + "tree" + ] + } + }, { "info": { "excerpt": "实现一个计算数组交集的函数,返回一个新数组,其中包含所有给定数组中存在的唯一值。", @@ -9536,6 +6936,212 @@ "topics": [] } }, + { + "info": { + "excerpt": "实现一个函数,用于查找具有冷却时间的任务的最小间隔", + "title": "任务协调" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1725408000, + "difficulty": "medium", + "duration": 40, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/task-coordination", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "task-coordination", + "subtitle": null, + "topics": [ + "greedy", + "heap" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来检查是否可以参加所有会议", + "title": "会议日历" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1721779200, + "difficulty": "easy", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/intervals-meeting-calendar", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "intervals-meeting-calendar", + "subtitle": null, + "topics": [ + "intervals", + "sorting" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来翻转给定数字中的位顺序", + "title": "位翻转" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718928000, + "difficulty": "easy", + "duration": 25, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/bit-reversal", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "bit-reversal", + "subtitle": null, + "topics": [ + "binary" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,用于查找从 0 到 n 的设置位数量", + "title": "位计数" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718928000, + "difficulty": "easy", + "duration": 25, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/bit-counting", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "bit-counting", + "subtitle": null, + "topics": [ + "binary" + ] + } + }, + { + "info": { + "excerpt": "实现一个执行冒泡排序的函数", + "title": "冒泡排序" + }, + "metadata": { + "access": "standard", + "author": null, + "companies": [], + "created": 1745539200, + "difficulty": "easy", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/bubble-sort", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [ + "quick-sort" + ], + "published": true, + "ranking": 100, + "similarQuestions": [ + "insertion-sort", + "selection-sort" + ], + "slug": "bubble-sort", + "subtitle": null, + "topics": [ + "sorting" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,通过买入和卖出股票一次来找到可实现的最大利润", + "title": "最佳股票交易" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718582400, + "difficulty": "easy", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/optimal-stock-trading", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "optimal-stock-trading", + "subtitle": null, + "topics": [ + "array", + "greedy" + ] + } + }, { "info": { "excerpt": "实现一个基于指定条件查找最大元素的函数", @@ -9570,6 +7176,175 @@ "topics": [] } }, + { + "info": { + "excerpt": "实现一个函数来确定整数数组中最常见的元素", + "title": "最常见的元素" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1724889600, + "difficulty": "medium", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/array-most-common-elements", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "array-most-common-elements", + "subtitle": null, + "topics": [ + "array", + "heap" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来查找具有唯一字符的最长子串的长度", + "title": "最长不重复子串" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1723161600, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/longest-non-repeating-substring", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "longest-non-repeating-substring", + "subtitle": null, + "topics": [ + "string" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来查找两个字符串中最长的公共子序列", + "title": "最长公共子序列" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1719705600, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/longest-common-subsequence", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "longest-common-subsequence", + "subtitle": null, + "topics": [ + "array", + "dynamic-programming" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来查找最长连续数字序列的长度", + "title": "最长连续数字序列" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1721606400, + "difficulty": "medium", + "duration": 40, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/longest-consecutive-number-sequence", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "longest-consecutive-number-sequence", + "subtitle": null, + "topics": [ + "array" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来查找最长递增子序列的长度", + "title": "最长递增子序列" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1733616000, + "difficulty": "medium", + "duration": 40, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/longest-increasing-subsequence", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "longest-increasing-subsequence", + "subtitle": null, + "topics": [ + "array", + "binary-search", + "greedy" + ] + } + }, { "info": { "excerpt": "实现一个函数,该函数返回函数期望的参数数量", @@ -9746,6 +7521,39 @@ ] } }, + { + "info": { + "excerpt": "实现一个函数,用于删除链表倒数第 n 个节点", + "title": "删除链表倒数第 N 个节点" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722297600, + "difficulty": "medium", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/linked-list-delete-nth-from-end", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "linked-list-delete-nth-from-end", + "subtitle": null, + "topics": [ + "linked-list" + ] + } + }, { "info": { "excerpt": "实现一个接受整数值的函数,并返回一个可以重复调用的函数,以返回递增的值", @@ -9785,6 +7593,39 @@ ] } }, + { + "info": { + "excerpt": "实现一个函数,返回包含来自另一个字符串的所有字符(包括重复字符)的字符串的最小子字符串", + "title": "包含字符的最短子字符串" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1723161600, + "difficulty": "hard", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/string-shortest-substring-containing-characters", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "string-shortest-substring-containing-characters", + "subtitle": null, + "topics": [ + "string" + ] + } + }, { "info": { "excerpt": "实现一个单例类,确保一个类只有一个实例,同时提供对该实例的全局访问点", @@ -9816,6 +7657,76 @@ "topics": [] } }, + { + "info": { + "excerpt": "实现一个函数来检查一个字符串是否可以由字典中的单词组成", + "title": "单词分割" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1720310400, + "difficulty": "medium", + "duration": 40, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/string-segment-words", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "string-segment-words", + "subtitle": null, + "topics": [ + "string", + "dynamic-programming", + "graph" + ] + } + }, + { + "info": { + "excerpt": "实现一个可以添加单词并支持通配符搜索的数据结构", + "title": "单词查找器" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1724976000, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/word-finder", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "word-finder", + "subtitle": null, + "topics": [ + "matrix", + "graph", + "trie" + ] + } + }, { "info": { "excerpt": "实现一个函数,该函数返回它被调用时所带的参数个数", @@ -9958,6 +7869,76 @@ ] } }, + { + "info": { + "excerpt": "实现一个函数,将一个新区间插入给定的区间中", + "title": "合并新区间" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722384000, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/intervals-merge-new", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "intervals-merge-new", + "subtitle": null, + "topics": [ + "binary-search", + "intervals", + "sorting" + ] + } + }, + { + "info": { + "excerpt": "实现一个合并重叠区间的函数", + "title": "合并重叠区间" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722384000, + "difficulty": "medium", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/intervals-combine-overlapping", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "intervals-combine-overlapping", + "subtitle": null, + "topics": [ + "intervals", + "sorting", + "dfs" + ] + } + }, { "info": { "excerpt": "实现一个函数,从数组中删除所有重复的值", @@ -9991,6 +7972,244 @@ "topics": [] } }, + { + "info": { + "excerpt": "实现一个函数来计算字符串中所有回文子串的数量", + "title": "回文子串" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1723161600, + "difficulty": "medium", + "duration": 40, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/string-palindromic-substrings", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "string-palindromic-substrings", + "subtitle": null, + "topics": [ + "string" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来确定一个图是否为有效的树", + "title": "图是否为树" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1721779200, + "difficulty": "medium", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/graph-is-tree", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "graph-is-tree", + "subtitle": null, + "topics": [ + "graph", + "dfs" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,深度克隆一个连通的无向图", + "title": "图的克隆" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1721260800, + "difficulty": "medium", + "duration": 50, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/graph-clone", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "graph-clone", + "subtitle": null, + "topics": [ + "graph", + "dfs" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来计算图中连通分量的数量", + "title": "图计算连通分量" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1721779200, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/graph-count-connected-components", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "graph-count-connected-components", + "subtitle": null, + "topics": [ + "graph", + "dfs" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,在旋转排序数组中查找一个整数", + "title": "在旋转数组中查找元素" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718928000, + "difficulty": "medium", + "duration": 30, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/array-rotated-find", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "array-rotated-find", + "subtitle": null, + "topics": [ + "array", + "binary-search" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来检查单词在网格中是否存在", + "title": "在网格中查找单词" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722729600, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/grid-find-word", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "grid-find-word", + "subtitle": null, + "topics": [ + "matrix", + "dfs" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,用于查找网格中存在的所有单词", + "title": "在网格中查找单词" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1724976000, + "difficulty": "hard", + "duration": 40, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/grid-find-words", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "grid-find-words", + "subtitle": null, + "topics": [ + "matrix", + "tree", + "trie" + ] + } + }, { "info": { "excerpt": "实现一个函数来检查一个数字是否在两个数字之间", @@ -10057,6 +8276,81 @@ "topics": [] } }, + { + "info": { + "excerpt": "实现一个包含基本堆操作的堆数据结构", + "title": "堆" + }, + "metadata": { + "access": "standard", + "author": null, + "companies": [], + "created": 1745539200, + "difficulty": "hard", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/heap", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [ + "heap-sort" + ], + "published": true, + "ranking": 100, + "similarQuestions": [ + "binary-search-tree" + ], + "slug": "heap", + "subtitle": null, + "topics": [ + "heap" + ] + } + }, + { + "info": { + "excerpt": "实现一个执行堆排序的函数", + "title": "堆排序" + }, + "metadata": { + "access": "free", + "author": null, + "companies": [], + "created": 1673395200, + "difficulty": "medium", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/heap-sort", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [ + "quick-sort" + ], + "published": true, + "ranking": 100, + "similarQuestions": [ + "selection-sort" + ], + "slug": "heap-sort", + "subtitle": null, + "topics": [ + "heap", + "sorting" + ] + } + }, { "info": { "excerpt": "实现一个用指定值填充数组指定索引范围的函数", @@ -10088,6 +8382,73 @@ "topics": [] } }, + { + "info": { + "excerpt": "实现一个函数,用于查找墙壁数组中两个墙壁之间的最大蓄水体积", + "title": "墙壁之间的最大蓄水" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718236800, + "difficulty": "medium", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/maximum-water-between-walls", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "maximum-water-between-walls", + "subtitle": null, + "topics": [ + "array" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来验证并返回外星语言的字母表顺序", + "title": "外星语言" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722384000, + "difficulty": "hard", + "duration": 55, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/extraterrestrial-language", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "extraterrestrial-language", + "subtitle": null, + "topics": [ + "graph", + "topological-sort" + ] + } + }, { "info": { "excerpt": "实现一个返回集合大小的函数", @@ -10119,6 +8480,107 @@ "topics": [] } }, + { + "info": { + "excerpt": "实现一个函数来确定一个字符串是否是回文", + "title": "字符串回文" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722729600, + "difficulty": "easy", + "duration": 25, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/string-palindrome", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "string-palindrome", + "subtitle": null, + "topics": [ + "string" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来确定两个字符串是否互为异位词", + "title": "字符串异位词" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722729600, + "difficulty": "easy", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/string-anagram", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "string-anagram", + "subtitle": null, + "topics": [ + "string" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,将字符串数组分组为异位词", + "title": "字符串异位词分组" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [ + "amazon" + ], + "created": 1723161600, + "difficulty": "medium", + "duration": 40, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/string-anagram-groups", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "string-anagram-groups", + "subtitle": null, + "topics": [ + "string" + ] + } + }, { "info": { "excerpt": "实现一个函数来转换对象中的值", @@ -10189,6 +8651,110 @@ "topics": [] } }, + { + "info": { + "excerpt": "实现一个函数来确定一个字符串是否包含平衡的括号", + "title": "平衡括号" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722729600, + "difficulty": "easy", + "duration": 25, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/array-balanced-brackets", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "array-balanced-brackets", + "subtitle": null, + "topics": [ + "array", + "stack" + ] + } + }, + { + "info": { + "excerpt": "实现一个广度优先搜索算法,该算法以广度优先的方式遍历有向图", + "title": "广度优先搜索" + }, + "metadata": { + "access": "free", + "author": null, + "companies": [], + "created": 1679788800, + "difficulty": "medium", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/breadth-first-search", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [ + "depth-first-search" + ], + "slug": "breadth-first-search", + "subtitle": null, + "topics": [ + "bfs" + ] + } + }, + { + "info": { + "excerpt": "实现一个执行递归归并排序的函数", + "title": "归并排序" + }, + "metadata": { + "access": "free", + "author": null, + "companies": [], + "created": 1671667200, + "difficulty": "medium", + "duration": 20, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/merge-sort", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [ + "quick-sort" + ], + "slug": "merge-sort", + "subtitle": null, + "topics": [ + "sorting" + ] + } + }, { "info": { "excerpt": "实现一个函数,该函数接受一个或多个值,并返回一个函数,该函数在每次调用时循环遍历这些值", @@ -10222,6 +8788,75 @@ ] } }, + { + "info": { + "excerpt": "实现一个执行递归快速排序的函数", + "title": "快速排序" + }, + "metadata": { + "access": "free", + "author": null, + "companies": [], + "created": 1671667200, + "difficulty": "medium", + "duration": 20, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/quick-sort", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [ + "merge-sort" + ], + "slug": "quick-sort", + "subtitle": null, + "topics": [ + "sorting" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来查找所需的最少会议室数量", + "title": "所需最少会议室" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722038400, + "difficulty": "medium", + "duration": 55, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/intervals-minimum-meeting-rooms", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "intervals-minimum-meeting-rooms", + "subtitle": null, + "topics": [ + "heap", + "intervals" + ] + } + }, { "info": { "excerpt": "实现一个函数,该函数将数组递归地扁平化为单层深度。", @@ -10273,6 +8908,79 @@ ] } }, + { + "info": { + "excerpt": "实现一个函数,返回组成给定金额所需的最少硬币数", + "title": "找零所需的最少硬币数" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1733616000, + "difficulty": "medium", + "duration": 40, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/coin-change", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "coin-change", + "subtitle": null, + "topics": [ + "dynamic-programming" + ] + } + }, + { + "info": { + "excerpt": "实现一个执行拓扑排序的函数", + "title": "拓扑排序" + }, + "metadata": { + "access": "free", + "author": null, + "companies": [ + "snap" + ], + "created": 1673395200, + "difficulty": "medium", + "duration": 20, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/topological-sort", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [ + "quick-sort" + ], + "published": true, + "ranking": 100, + "similarQuestions": [ + "selection-sort" + ], + "slug": "topological-sort", + "subtitle": null, + "topics": [ + "topological-sort", + "graph" + ] + } + }, { "info": { "excerpt": "实现一个函数,该函数根据函数或属性名称计算值在数组中出现的次数。", @@ -10306,6 +9014,76 @@ "topics": [] } }, + { + "info": { + "excerpt": "实现一个执行插入排序的函数", + "title": "插入排序" + }, + "metadata": { + "access": "free", + "author": null, + "companies": [], + "created": 1671667200, + "difficulty": "easy", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/insertion-sort", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [ + "quick-sort" + ], + "published": true, + "ranking": 100, + "similarQuestions": [ + "selection-sort" + ], + "slug": "insertion-sort", + "subtitle": null, + "topics": [ + "sorting" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来查找动态整数流的中位数", + "title": "数字流的中位数" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1724976000, + "difficulty": "hard", + "duration": 55, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/number-stream-median", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "number-stream-median", + "subtitle": null, + "topics": [ + "heap" + ] + } + }, { "info": { "excerpt": "实现一个函数,用于合并来自同一用户的数据行", @@ -10381,6 +9159,74 @@ "topics": [] } }, + { + "info": { + "excerpt": "实现一个函数来确定数组的末端是否可达", + "title": "数组末端可达" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1720828800, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/array-reachable-end", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "array-reachable-end", + "subtitle": null, + "topics": [ + "array", + "dynamic-programming", + "greedy" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,找到数组中除当前元素之外的所有元素的乘积。", + "title": "数组的乘积,不包含当前元素" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718496000, + "difficulty": "medium", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/array-product-excluding-current", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "array-product-excluding-current", + "subtitle": null, + "topics": [ + "array" + ] + } + }, { "info": { "excerpt": "实现一个函数,如果搜索词出现在文本中,则突出显示该文本", @@ -10453,6 +9299,73 @@ "topics": [] } }, + { + "info": { + "excerpt": "实现一个函数,找到旋转排序数组中的最小元素", + "title": "旋转排序数组中的最小元素" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718928000, + "difficulty": "medium", + "duration": 25, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/array-smallest-in-rotated", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "array-smallest-in-rotated", + "subtitle": null, + "topics": [ + "array", + "binary-search" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,无需使用 + 和 - 运算符即可找到两个整数的和", + "title": "无加法求和" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718928000, + "difficulty": "medium", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/sum-without-addition", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "sum-without-addition", + "subtitle": null, + "topics": [ + "binary" + ] + } + }, { "info": { "excerpt": "实现一个函数来检查一个值是否为空对象、集合、映射或集合", @@ -10484,6 +9397,40 @@ "topics": [] } }, + { + "info": { + "excerpt": "实现一个函数,在最多进行 k 次替换后,找到最长的统一子串", + "title": "替换后最长重复子串" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1723161600, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/longest-repeating-substring-after-replacements", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "longest-repeating-substring-after-replacements", + "subtitle": null, + "topics": [ + "string", + "binary-search" + ] + } + }, { "info": { "excerpt": "实现一个函数,该函数返回数组中满足提供的测试函数的最后一个元素的索引", @@ -10517,6 +9464,105 @@ "topics": [] } }, + { + "info": { + "excerpt": "实现一个函数来查找最长回文子串", + "title": "查找最长回文子串" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1723161600, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/longest-palindromic-substring", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "longest-palindromic-substring", + "subtitle": null, + "topics": [ + "string" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来查找已排序数组中缺失的元素", + "title": "查找序列中缺失的数字" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718928000, + "difficulty": "easy", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/array-find-missing-number-in-sequence", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "array-find-missing-number-in-sequence", + "subtitle": null, + "topics": [ + "array" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来检查数组中是否有任何重复的数字", + "title": "查找数组中的重复项" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718409600, + "difficulty": "easy", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/array-find-duplicate", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "array-find-duplicate", + "subtitle": null, + "topics": [ + "array" + ] + } + }, { "info": { "excerpt": "实现一个函数,该函数返回数组中满足提供的测试函数的第一个元素的索引", @@ -10664,6 +9710,45 @@ "topics": [] } }, + { + "info": { + "excerpt": "实现一个包含常见栈方法的栈数据结构", + "title": "栈" + }, + "metadata": { + "access": "free", + "author": "yangshun", + "companies": [ + "amazon" + ], + "created": 1670025600, + "difficulty": "easy", + "duration": 10, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/stack", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [ + "queue" + ], + "published": true, + "ranking": 100, + "similarQuestions": [ + "queue" + ], + "slug": "stack", + "subtitle": null, + "topics": [ + "stack" + ] + } + }, { "info": { "excerpt": "实现一个函数,该函数通过接受一个数字进行求和,并允许重复调用,传入更多数字,直到不传入任何数字为止。", @@ -10702,6 +9787,41 @@ ] } }, + { + "info": { + "excerpt": "实现一个函数,返回可以流向两个大洋的单元格", + "title": "海洋流动" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1721088000, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/ocean-flow", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "ocean-flow", + "subtitle": null, + "topics": [ + "graph", + "dfs", + "bfs" + ] + } + }, { "info": { "excerpt": "实现一个在二维平面上移动海龟的 Turtle 类", @@ -10770,6 +9890,41 @@ ] } }, + { + "info": { + "excerpt": "实现一个深度优先搜索算法,以深度优先的方式遍历有向图", + "title": "深度优先搜索" + }, + "metadata": { + "access": "free", + "author": null, + "companies": [], + "created": 1671667200, + "difficulty": "medium", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/depth-first-search", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [ + "breadth-first-search" + ], + "slug": "depth-first-search", + "subtitle": null, + "topics": [ + "dfs" + ] + } + }, { "info": { "excerpt": "实现一个对值进行深拷贝的函数,但也要处理循环引用", @@ -10960,6 +10115,39 @@ ] } }, + { + "info": { + "excerpt": "实现一个函数,找到到达楼梯顶部的不同方式的数量", + "title": "爬楼梯组合" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1719187200, + "difficulty": "easy", + "duration": 20, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/staircase-climbing-combinations", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "staircase-climbing-combinations", + "subtitle": null, + "topics": [ + "dynamic-programming" + ] + } + }, { "info": { "excerpt": "实现一个从 HTML 文档构建目录的函数", @@ -10998,6 +10186,39 @@ ] } }, + { + "info": { + "excerpt": "实现一个函数来计算总和为目标值的组合", + "title": "目标和的组合" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1720310400, + "difficulty": "medium", + "duration": 40, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/combinations-target-sum", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "combinations-target-sum", + "subtitle": null, + "topics": [ + "dynamic-programming" + ] + } + }, { "info": { "excerpt": "实现一个函数来确定两棵 DOM 树是否相同", @@ -11036,6 +10257,105 @@ ] } }, + { + "info": { + "excerpt": "实现一个函数,将给定的矩阵旋转 90 度", + "title": "矩阵旋转" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722038400, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/matrix-rotation", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "matrix-rotation", + "subtitle": null, + "topics": [ + "matrix" + ] + } + }, + { + "info": { + "excerpt": "实现一个将矩阵的行和列设置为零的函数", + "title": "矩阵置零" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722038400, + "difficulty": "medium", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/matrix-zeroing", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "matrix-zeroing", + "subtitle": null, + "topics": [ + "matrix" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,以螺旋顺序遍历矩阵", + "title": "矩阵螺旋遍历" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": null, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/matrix-spiral-traversal", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "matrix-spiral-traversal", + "subtitle": null, + "topics": [ + "matrix" + ] + } + }, { "info": { "excerpt": "实现一个函数,用于检查对象是否符合源对象", @@ -11139,6 +10459,73 @@ "topics": [] } }, + { + "info": { + "excerpt": "实现一个函数来计算机器人移动在 m x n 网格中的不同路径", + "title": "网格中的不同路径" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1720742400, + "difficulty": "medium", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/grid-distinct-paths", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "grid-distinct-paths", + "subtitle": null, + "topics": [ + "dynamic-programming" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来翻转二叉树中的节点", + "title": "翻转二叉树" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1723766400, + "difficulty": "easy", + "duration": 20, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-tree-flip", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "binary-tree-flip", + "subtitle": null, + "topics": [ + "binary-tree", + "tree" + ] + } + }, { "info": { "excerpt": "实现一个函数,通过限制其在一段时间内可以执行的次数来控制函数的执行。", @@ -11257,6 +10644,584 @@ ] } }, + { + "info": { + "excerpt": "实现一个函数来计算解码数字字符串的方法", + "title": "解码消息" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1720742400, + "difficulty": "medium", + "duration": 40, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/string-decode-message", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "string-decode-message", + "subtitle": null, + "topics": [ + "string", + "dynamic-programming" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来查找给定整数的二进制表示中的设置位", + "title": "计算二进制数中的设置位" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718928000, + "difficulty": "easy", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/count-ones-in-binary", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "count-ones-in-binary", + "subtitle": null, + "topics": [ + "binary" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来计算二维二进制网格中不同的岛屿数量", + "title": "计算网格中的岛屿数量" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1721001600, + "difficulty": "medium", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/grid-count-islands", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "grid-count-islands", + "subtitle": null, + "topics": [ + "matrix", + "dfs" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,用于检查在给定先决条件的情况下是否可以完成所有课程", + "title": "课程依赖" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1721260800, + "difficulty": "medium", + "duration": 40, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/course-dependency", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "course-dependency", + "subtitle": null, + "topics": [ + "graph", + "topological-sort", + "dfs" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来查找具有最大乘积的子数组", + "title": "连续数组中的最大乘积" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718236800, + "difficulty": "medium", + "duration": 30, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/array-maximum-product-contiguous", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "array-maximum-product-contiguous", + "subtitle": null, + "topics": [ + "array" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来查找具有最大和的子数组", + "title": "连续数组中的最大和" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718841600, + "difficulty": "medium", + "duration": 25, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/array-maximum-sum-contiguous", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "array-maximum-sum-contiguous", + "subtitle": null, + "topics": [ + "array" + ] + } + }, + { + "info": { + "excerpt": "实现一个执行选择排序的函数", + "title": "选择排序" + }, + "metadata": { + "access": "standard", + "author": null, + "companies": [], + "created": 1671667200, + "difficulty": "easy", + "duration": 10, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/selection-sort", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [ + "quick-sort" + ], + "published": true, + "ranking": 100, + "similarQuestions": [ + "insertion-sort" + ], + "slug": "selection-sort", + "subtitle": null, + "topics": [ + "sorting" + ] + } + }, + { + "info": { + "excerpt": "实现一个从先序和中序遍历构造二叉树的函数", + "title": "通过先序和中序遍历重建二叉树" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1724889600, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-tree-rebuilding-from-traversals", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "binary-tree-rebuilding-from-traversals", + "subtitle": null, + "topics": [ + "binary-tree", + "tree" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,找到在不惊动警察的情况下抢劫的最大金额", + "title": "邻里盗窃" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1720828800, + "difficulty": "medium", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/neighborhood-theft", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "neighborhood-theft", + "subtitle": null, + "topics": [ + "array", + "dynamic-programming" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数,用于在环形房屋中找到在不惊动警察的情况下抢劫的最大金额", + "title": "邻里盗窃(环形)" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1720828800, + "difficulty": "medium", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/neighborhood-theft-circular", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "neighborhood-theft-circular", + "subtitle": null, + "topics": [ + "array", + "dynamic-programming" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来重新排列链表中的节点", + "title": "重排链表" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722297600, + "difficulty": "medium", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/linked-list-rearrange", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "linked-list-rearrange", + "subtitle": null, + "topics": [ + "linked-list" + ] + } + }, + { + "info": { + "excerpt": "实现一个包含常见链表方法的链表数据结构", + "title": "链表" + }, + "metadata": { + "access": "free", + "author": null, + "companies": [], + "created": 1745539200, + "difficulty": "medium", + "duration": 20, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/linked-list", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [ + "stack", + "queue" + ], + "slug": "linked-list", + "subtitle": null, + "topics": [ + "linked-list" + ] + } + }, + { + "info": { + "excerpt": "实现一个反转链表的函数", + "title": "链表反转" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722038400, + "difficulty": "easy", + "duration": 25, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/linked-list-reversal", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "linked-list-reversal", + "subtitle": null, + "topics": [ + "linked-list" + ] + } + }, + { + "info": { + "excerpt": "实现一个合并 k 个已排序链表的函数", + "title": "链表合并 K 个已排序列表" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722297600, + "difficulty": "hard", + "duration": 45, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/linked-list-combine-k-sorted", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "linked-list-combine-k-sorted", + "subtitle": null, + "topics": [ + "linked-list", + "heap" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来合并两个已排序的链表", + "title": "链表合并两个已排序的列表" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1722038400, + "difficulty": "easy", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/linked-list-combine-two-sorted", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "linked-list-combine-two-sorted", + "subtitle": null, + "topics": [ + "linked-list" + ] + } + }, + { + "info": { + "excerpt": "实现一个函数来检测链表中是否有环", + "title": "链表检测环" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1718928000, + "difficulty": "easy", + "duration": 30, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/linked-list-detect-cycle", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "linked-list-detect-cycle", + "subtitle": null, + "topics": [ + "linked-list" + ] + } + }, + { + "info": { + "excerpt": "实现一个包含常见队列方法的队列数据结构", + "title": "队列" + }, + "metadata": { + "access": "free", + "author": "yangshun", + "companies": [], + "created": 1670457600, + "difficulty": "medium", + "duration": 15, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/queue", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [ + "stack" + ], + "slug": "queue", + "subtitle": null, + "topics": [ + "queue" + ] + } + }, { "info": { "excerpt": "实现一个函数,通过延迟函数执行,直到其最后一次执行尝试后经过指定时间,来限制函数可以执行的次数。", @@ -11375,5 +11340,40 @@ "recursion" ] } + }, + { + "info": { + "excerpt": "实现一个函数来验证二叉树是否为有效的二叉搜索树", + "title": "验证二叉搜索树" + }, + "metadata": { + "access": "standard", + "author": "hiten", + "companies": [], + "created": 1724284800, + "difficulty": "medium", + "duration": 35, + "featured": false, + "format": "algo", + "frameworkDefault": null, + "frameworks": [], + "href": "/questions/algo/binary-search-tree-validate", + "importance": "low", + "languages": [ + "js", + "ts" + ], + "nextQuestions": [], + "published": true, + "ranking": 100, + "similarQuestions": [], + "slug": "binary-search-tree-validate", + "subtitle": null, + "topics": [ + "binary-tree", + "binary-search-tree", + "tree" + ] + } } ] \ No newline at end of file diff --git a/apps/web/src/scripts/questions-algo-setup.ts b/apps/web/src/scripts/questions-algo-setup.ts index 4a7b8a97b..e8a051fa7 100644 --- a/apps/web/src/scripts/questions-algo-setup.ts +++ b/apps/web/src/scripts/questions-algo-setup.ts @@ -15,12 +15,11 @@ import { async function generateSetupForQuestion(slug: string) { const questionPath = getQuestionSrcPathAlgo(slug); - // This assumes that if the locale file is present for the description - // it's also present for the solution. - const globPattern = path.posix.join( // Globby only supports forward slashes. questionPath.replaceAll(path.sep, path.posix.sep), + // Assume that if the locale file is present for the description + // it's also present for the solution 'description', '*.mdx', ); @@ -29,15 +28,14 @@ async function generateSetupForQuestion(slug: string) { // Files are named after their locales. .map((filePath) => parse(filePath).name); - const outDir = getQuestionOutPathAlgo(slug); - - fs.mkdirSync(outDir, { recursive: true }); - const { metadata, files, skeleton, workspace } = await readQuestionAlgoLocaleAgnostic(slug); + + const outDir = getQuestionOutPathAlgo(slug); const metadataPath = path.join(outDir, 'metadata.json'); const setupPath = path.join(outDir, 'setup.json'); + fs.mkdirSync(outDir, { recursive: true }); fs.writeFileSync(metadataPath, JSON.stringify(metadata, null, 2)); fs.writeFileSync( setupPath, @@ -54,7 +52,7 @@ async function generateSetupForQuestion(slug: string) { await Promise.all( locales.map(async (locale) => { - const content = await readQuestionAlgo(slug); + const content = await readQuestionAlgo(slug, locale); const contentOutPath = getQuestionOutPathAlgoLocaleContents(slug, locale); fs.mkdirSync(path.dirname(contentOutPath), { recursive: true }); diff --git a/apps/web/src/scripts/questions-javascript-setup.ts b/apps/web/src/scripts/questions-javascript-setup.ts index 450e0746a..6c3f7f101 100644 --- a/apps/web/src/scripts/questions-javascript-setup.ts +++ b/apps/web/src/scripts/questions-javascript-setup.ts @@ -15,7 +15,6 @@ import { async function generateSetupForQuestion(slug: string) { const questionPath = getQuestionSrcPathJavaScript(slug); - const globPattern = path.posix.join( // Globby only supports forward slashes questionPath.replaceAll(path.sep, path.posix.sep), @@ -29,15 +28,14 @@ async function generateSetupForQuestion(slug: string) { // Files are named after their locales. .map((filePath) => parse(filePath).name); - const outDir = getQuestionOutPathJavaScript(slug); - - fs.mkdirSync(outDir, { recursive: true }); - const { metadata, files, skeleton, workspace } = await readQuestionJavaScriptLocaleAgnostic(slug); + + const outDir = getQuestionOutPathJavaScript(slug); const metadataPath = path.join(outDir, 'metadata.json'); const setupPath = path.join(outDir, 'setup.json'); + fs.mkdirSync(outDir, { recursive: true }); fs.writeFileSync(metadataPath, JSON.stringify(metadata, null, 2)); fs.writeFileSync( setupPath, diff --git a/apps/web/src/scripts/questions-metadata.ts b/apps/web/src/scripts/questions-metadata.ts index df2dbc8bb..27a9c6c05 100644 --- a/apps/web/src/scripts/questions-metadata.ts +++ b/apps/web/src/scripts/questions-metadata.ts @@ -81,10 +81,12 @@ export async function generateAllMetadata() { locale, ), ), - generateQuestionsMetadata( - readQuestionListMetadataAlgo, - getQuestionsListOutFilenameAlgo(sourceLocale), - sourceLocale, + ...locales.map((locale) => + generateQuestionsMetadata( + readQuestionListMetadataAlgo, + getQuestionsListOutFilenameAlgo(locale), + locale, + ), ), ...locales.map((locale) => generateQuestionsMetadata( diff --git a/apps/web/src/scripts/questions-quiz-setup.ts b/apps/web/src/scripts/questions-quiz-setup.ts index 5bf05cfa4..4b9518ded 100644 --- a/apps/web/src/scripts/questions-quiz-setup.ts +++ b/apps/web/src/scripts/questions-quiz-setup.ts @@ -22,16 +22,15 @@ async function generateSetupForQuestion( // Files are named after their locales. .map((filePath) => parse(filePath).name); - const outDir = getQuestionOutPathQuiz(slug); - - fs.mkdirSync(outDir, { recursive: true }); - const { metadata } = await readQuestionQuizLocaleAgnostic( quizSourceConfig, slug, ); + + const outDir = getQuestionOutPathQuiz(slug); const metadataPath = path.join(outDir, 'metadata.json'); + fs.mkdirSync(outDir, { recursive: true }); fs.writeFileSync(metadataPath, JSON.stringify(metadata, null, 2)); await Promise.all( diff --git a/apps/web/src/scripts/questions-system-design-setup.ts b/apps/web/src/scripts/questions-system-design-setup.ts index bf653ea57..ff0b46464 100644 --- a/apps/web/src/scripts/questions-system-design-setup.ts +++ b/apps/web/src/scripts/questions-system-design-setup.ts @@ -23,13 +23,12 @@ async function generateSetupForQuestion(slug: string) { // Files are named after their locales. .map((filePath) => parse(filePath).name); - const outDir = getQuestionOutPathSystemDesign(slug); - - fs.mkdirSync(outDir, { recursive: true }); - const metadata = await readQuestionMetadataSystemDesign(slug); + + const outDir = getQuestionOutPathSystemDesign(slug); const metadataPath = path.join(outDir, 'metadata.json'); + fs.mkdirSync(outDir, { recursive: true }); fs.writeFileSync(metadataPath, JSON.stringify(metadata, null, 2)); await Promise.all( diff --git a/contents/questions/algo/array-balanced-brackets/description/en-US.langnostic.json b/contents/questions/algo/array-balanced-brackets/description/en-US.langnostic.json new file mode 100644 index 000000000..75fc9e3b8 --- /dev/null +++ b/contents/questions/algo/array-balanced-brackets/description/en-US.langnostic.json @@ -0,0 +1,35 @@ +{ + "frontmatter": { + "title": "63070f41", + "excerpt": "8d0df6d6" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "fb2ad577", + "a5f08951", + "9e1f23a3", + "2d96efbe", + "7f86a7c3", + "d068a43f", + "b2065fc", + "cd9461da" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "fb2ad577", + "a5f08951", + "9e1f23a3", + "2d96efbe", + "7f86a7c3", + "d068a43f", + "b2065fc", + "cd9461da" + ] + } + } +} diff --git a/contents/questions/algo/array-balanced-brackets/description/zh-CN.mdx b/contents/questions/algo/array-balanced-brackets/description/zh-CN.mdx new file mode 100644 index 000000000..6f0330361 --- /dev/null +++ b/contents/questions/algo/array-balanced-brackets/description/zh-CN.mdx @@ -0,0 +1,26 @@ +--- +title: 平衡括号 +excerpt: 实现一个函数来确定一个字符串是否包含平衡的括号 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个字符串 `str`,由诸如 `'(', ')', '{', '}', '[ 和 ']'` 等字符组成,确定输入字符串是否正确平衡。 + +如果满足以下条件,则认为字符串是平衡的: + +- 每个左括号都由相同类型的右括号闭合(例如,`(` 对应 `)`, `{` 对应 `}`, `[` 对应 `]`) +- 括号按正确的顺序闭合(例如,`([])` 有效,但 `([)]` 无效) +- 任何包含在一对匹配括号内的括号子集也必须形成一个有效的匹配对(例如,`{[(])}` 不平衡,因为 `{` 和 `}` 内部的内容不平衡)。 + +### 输入 + +- `str: string`: 字符串 + + + +### 约束 + +- 1 <= `strs.length` <= 1000 +- 字符串 `str` 仅包含字符 `(`, `)`, `{`, `}`, `[` 和 `]` diff --git a/contents/questions/algo/array-balanced-brackets/solution/en-US.langnostic.json b/contents/questions/algo/array-balanced-brackets/solution/en-US.langnostic.json new file mode 100644 index 000000000..85ae10951 --- /dev/null +++ b/contents/questions/algo/array-balanced-brackets/solution/en-US.langnostic.json @@ -0,0 +1,40 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "6a63bdf5", + "e8e3a0e", + "381888f5", + "dd4d3d2", + "839b6d5c", + "d7e3ae24", + "2c330578", + "b68df8f8", + "4b281fb0", + "469639fa", + "8e2de8c8", + "d7d28b67" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "6a63bdf5", + "e8e3a0e", + "381888f5", + "dd4d3d2", + "839b6d5c", + "d7e3ae24", + "2c330578", + "b68df8f8", + "4b281fb0", + "469639fa", + "8e2de8c8", + "d7d28b67" + ] + } + } +} diff --git a/contents/questions/algo/array-balanced-brackets/solution/zh-CN.mdx b/contents/questions/algo/array-balanced-brackets/solution/zh-CN.mdx new file mode 100644 index 000000000..beb3a6fbc --- /dev/null +++ b/contents/questions/algo/array-balanced-brackets/solution/zh-CN.mdx @@ -0,0 +1,38 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import balancedBrackets from '../setup/src/array-balanced-brackets.ts'; + +## 1. 使用堆栈 + +平衡括号问题涉及确定包含括号的字符串是否有效。如果满足以下条件,则字符串有效: + +1. 每个开括号都有一个对应的、正确排序的闭括号。 +2. 括号嵌套正确。 + +堆栈数据结构非常适合解决这个问题,因为它具有 LIFO(后进先出)的特性。当遍历字符串时: + +1. 开括号被压入堆栈。 +2. 闭括号与堆栈的顶部元素匹配,如果匹配,则弹出顶部元素。 + +朴素方法中的瓶颈可能涉及反复扫描整个字符串以查找匹配的括号,从而导致 O(n2) 的复杂度。基于堆栈的方法通过维护单个遍历并使用用于 push 和 pop 的恒定时间操作来消除不必要的工作。 + +### 算法 + +1. 定义一个映射对象 `mappings`,其中每个闭括号映射到其对应的开括号。 +2. 初始化一个空堆栈,用于在遍历期间存储开括号。 +3. 遍历输入字符串中的每个字符: + * 如果该字符是闭括号: + * 从堆栈中弹出顶部元素(如果堆栈为空,则使用占位符)。 + * 检查弹出的元素是否与当前闭括号对应的开括号匹配: + * 如果不匹配,则返回 `false`。 + * 如果该字符是开括号,则将其压入堆栈。 +4. 处理完所有字符后,检查堆栈是否为空。如果堆栈不为空,则返回 `false`;否则,返回 `true`。 + + + {balancedBrackets} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。该算法仅处理输入字符串中的每个字符一次,其中 `n` 是字符串的长度。 +* **空间复杂度:O(n)**。在最坏的情况下,所有开括号都存储在堆栈中,导致 O(n) 的空间使用。 diff --git a/contents/questions/algo/array-find-duplicate/description/en-US.langnostic.json b/contents/questions/algo/array-find-duplicate/description/en-US.langnostic.json new file mode 100644 index 000000000..d53aa3c26 --- /dev/null +++ b/contents/questions/algo/array-find-duplicate/description/en-US.langnostic.json @@ -0,0 +1,31 @@ +{ + "frontmatter": { + "title": "5bf04094", + "excerpt": "bb4eae1" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "6b1cbe52", + "2d96efbe", + "d9c0d67b", + "d068a43f", + "b2065fc", + "66c11387" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "6b1cbe52", + "2d96efbe", + "d9c0d67b", + "d068a43f", + "b2065fc", + "66c11387" + ] + } + } +} diff --git a/contents/questions/algo/array-find-duplicate/description/zh-CN.mdx b/contents/questions/algo/array-find-duplicate/description/zh-CN.mdx new file mode 100644 index 000000000..dd9f86caa --- /dev/null +++ b/contents/questions/algo/array-find-duplicate/description/zh-CN.mdx @@ -0,0 +1,20 @@ +--- +title: 查找数组中的重复项 +excerpt: 实现一个函数来检查数组中是否有任何重复的数字 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个整数数组 `numbers`,确定该数组是否包含任何重复值。重复定义为数组中出现多次的任何数字。 + +### 输入 + +- `numbers: number[]`: 整数数组 + + + +### 约束 + +- 1 <= `numbers.length` <= 10,000 +- -1,000,000 <= `numbers[i]` <= 1,000,000 diff --git a/contents/questions/algo/array-find-duplicate/solution/en-US.langnostic.json b/contents/questions/algo/array-find-duplicate/solution/en-US.langnostic.json new file mode 100644 index 000000000..923da6cb9 --- /dev/null +++ b/contents/questions/algo/array-find-duplicate/solution/en-US.langnostic.json @@ -0,0 +1,62 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "f9b798ec", + "dfacf1c9", + "b3b9ce85", + "b68df8f8", + "392547d5", + "5af166f6", + "8e2de8c8", + "4e24555c", + "500ba04b", + "11590317", + "b68df8f8", + "bf984c1a", + "26be0a45", + "8e2de8c8", + "7933bbe2", + "df173b8c", + "bf9685df", + "999f209d", + "b68df8f8", + "81b57b0", + "87fe2539", + "8e2de8c8", + "f77a01f6" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "f9b798ec", + "dfacf1c9", + "b3b9ce85", + "b68df8f8", + "392547d5", + "5af166f6", + "8e2de8c8", + "4e24555c", + "500ba04b", + "11590317", + "b68df8f8", + "bf984c1a", + "26be0a45", + "8e2de8c8", + "7933bbe2", + "df173b8c", + "bf9685df", + "999f209d", + "b68df8f8", + "81b57b0", + "87fe2539", + "8e2de8c8", + "f77a01f6" + ] + } + } +} diff --git a/contents/questions/algo/array-find-duplicate/solution/zh-CN.mdx b/contents/questions/algo/array-find-duplicate/solution/zh-CN.mdx new file mode 100644 index 000000000..f26a39807 --- /dev/null +++ b/contents/questions/algo/array-find-duplicate/solution/zh-CN.mdx @@ -0,0 +1,72 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import findDuplicates from '../setup/src/array-find-duplicate.ts'; +import findDuplicateSorting from '../setup/src/array-find-duplicate-sorting.ts'; +import findDuplicateBruteForce from '../setup/src/array-find-duplicate-brute-force.ts'; + +## 1. 暴力解法 + +该问题涉及查找数组中是否存在重复元素。暴力方法检查数组中每对可能的元素,以确定它们是否相等。这是通过两个嵌套循环实现的,其中比较每一对。虽然这种方法很简单,但由于其 O(n2) 的时间复杂度,对于大型数组来说效率低下。 + +### 算法 + +1. 确定输入数组 `numbers` 的长度,并将其存储在变量 `n` 中。 +2. 使用索引 `i` 的循环遍历数组中的每个元素。 +3. 对于每个 `i`,使用另一个从 `i + 1` 开始的索引 `j` 的循环来检查数组中的每个后续元素。 +4. 比较索引 `i` 和 `j` 处的元素: + * 如果它们相等,则返回 `true` 以指示找到重复项。 +5. 如果在检查所有对后未找到重复项,则返回 `false`。 + + + {findDuplicateBruteForce} + + +### Big-O 分析 + +* **时间复杂度:O(n2)**。外层循环迭代 `n` 次,内层循环最多迭代 `n - i - 1` 次,导致二次时间复杂度。 +* **空间复杂度:O(1)**。该算法使用恒定量的额外空间,因为它不依赖于任何辅助数据结构。 + +## 2. 使用排序 + +之前的暴力解法有不必要的检查所有对的工作。为了消除冗余的比较,这个优化的解决方案将数组按升序排序,这确保了重复的元素连续出现。一旦数组排序完成,只需一次遍历即可检查是否有任何两个连续的元素相等。 + +### 算法 + +1. 使用内置的 `sort` 函数按升序对输入数组 `numbers` 进行排序。 +2. 使用循环从索引 `0` 到 `numbers.length - 1` 遍历排序后的数组。 + * 对于每个元素,将其与数组中的下一个元素进行比较。 + * 如果这两个元素相等,则返回 `true` 以指示已找到重复项。 +3. 如果在循环完成之后未找到重复项,则返回 `false`。 + + + {findDuplicateSorting} + + +### Big-O 分析 + +* **时间复杂度:O(n log n)**。排序操作以 O(n log n) 占据了运行时的大部分。随后对排序数组的线性遍历的复杂度为 O(n),与排序步骤相比,可以忽略不计。 +* **空间复杂度:O(1)**。排序是就地执行的,并且该算法不使用任何其他数据结构,从而导致恒定的空间使用。 + +## 3. 使用 Set + +之前的解决方案使用排序,由于排序步骤(O(n log n)),其时间复杂度存在瓶颈。排序确保重复项连续出现,但对于较大的输入数组需要大量时间。 + +当前的解决方案通过使用 `Set` 来跟踪到目前为止看到的元素来改进这一点。`Set` 允许以恒定时间进行操作,以检查存在性和添加元素。这消除了对排序的需求,将时间复杂度降低到线性 O(n)。它还保留了原始数组,因为没有进行就地更改。 + +### 算法 + +1. 创建一个空的 `Set` 来存储唯一元素。 +2. 遍历输入数组中的每个元素: + * 检查当前元素是否存在于 `Set` 中。 + * 如果该元素存在,则返回 `true`,表示已找到重复项。 + * 否则,将当前元素添加到 `Set` 中。 +3. 如果在未找到重复项的情况下完成迭代,则返回 `false`。 + + + {findDuplicates} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。该算法遍历数组一次,对 `Set` 中的添加和检查元素执行恒定时间的操作。 +* **空间复杂度:O(n)**。在所有元素都唯一的最坏情况下,`Set` 需要额外的空间来存储多达 `n` 个元素。 diff --git a/contents/questions/algo/array-find-missing-number-in-sequence/description/en-US.langnostic.json b/contents/questions/algo/array-find-missing-number-in-sequence/description/en-US.langnostic.json new file mode 100644 index 000000000..55bb67918 --- /dev/null +++ b/contents/questions/algo/array-find-missing-number-in-sequence/description/en-US.langnostic.json @@ -0,0 +1,31 @@ +{ + "frontmatter": { + "title": "1d173396", + "excerpt": "128a83f6" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "2f56dc53", + "2d96efbe", + "d9c0d67b", + "d068a43f", + "b2065fc", + "8decd177" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "2f56dc53", + "2d96efbe", + "d9c0d67b", + "d068a43f", + "b2065fc", + "8decd177" + ] + } + } +} diff --git a/contents/questions/algo/array-find-missing-number-in-sequence/description/zh-CN.mdx b/contents/questions/algo/array-find-missing-number-in-sequence/description/zh-CN.mdx new file mode 100644 index 000000000..83f065bdf --- /dev/null +++ b/contents/questions/algo/array-find-missing-number-in-sequence/description/zh-CN.mdx @@ -0,0 +1,20 @@ +--- +title: 查找序列中缺失的数字 +excerpt: 实现一个函数来查找已排序数组中缺失的元素 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个大小为 `n` 的数组 `numbers`,用于存储 `n` 个不同的整数,这些整数的范围在 `[0, n]` 之间,实现一个函数来识别数组中缺失的元素。除了一个数字外,所有数字都存在于数组中。找到缺失的数字。 + +### 输入 + +- `numbers: number[]`: 整数数组 + + + +### 约束 + +- 1 <= `n` <= 10,000 +- 0 <= `numbers[i]` <= `n` diff --git a/contents/questions/algo/array-find-missing-number-in-sequence/solution/en-US.langnostic.json b/contents/questions/algo/array-find-missing-number-in-sequence/solution/en-US.langnostic.json new file mode 100644 index 000000000..e4b1596a0 --- /dev/null +++ b/contents/questions/algo/array-find-missing-number-in-sequence/solution/en-US.langnostic.json @@ -0,0 +1,60 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "b69b4102", + "dfacf1c9", + "d88ab1df", + "b68df8f8", + "c01d6db1", + "176f999a", + "8e2de8c8", + "7508f36c", + "500ba04b", + "12bb74d", + "b68df8f8", + "f4fb795d", + "9f107aff", + "8e2de8c8", + "a0612674", + "dc20c6ca", + "a033426d", + "b68df8f8", + "d67592c4", + "d81a2827", + "8e2de8c8", + "e9b19bc3" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "b69b4102", + "dfacf1c9", + "d88ab1df", + "b68df8f8", + "c01d6db1", + "176f999a", + "8e2de8c8", + "7508f36c", + "500ba04b", + "12bb74d", + "b68df8f8", + "f4fb795d", + "9f107aff", + "8e2de8c8", + "a0612674", + "dc20c6ca", + "a033426d", + "b68df8f8", + "d67592c4", + "d81a2827", + "8e2de8c8", + "e9b19bc3" + ] + } + } +} diff --git a/contents/questions/algo/array-find-missing-number-in-sequence/solution/zh-CN.mdx b/contents/questions/algo/array-find-missing-number-in-sequence/solution/zh-CN.mdx new file mode 100644 index 000000000..dedd8f27d --- /dev/null +++ b/contents/questions/algo/array-find-missing-number-in-sequence/solution/zh-CN.mdx @@ -0,0 +1,74 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import findMissingNumberInSequence from '../setup/src/array-find-missing-number-in-sequence.ts'; +import findMissingNumberInSequenceSorting from '../setup/src/array-find-missing-number-in-sequence-sorting.ts'; +import findMissingNumberInSequenceBruteForce from '../setup/src/array-find-missing-number-in-sequence-brute-force.ts'; + +## 1. 暴力解法 + +该问题需要从 0 到 `n` 的序列中识别缺失的数字。暴力解法遍历期望的数字范围,并检查数组中是否存在每个数字。对于每个数字,将对数组进行另一次迭代以检查其是否存在。这种方法涉及嵌套循环,导致时间复杂度为 O(n2)。这种方法虽然简单,但由于重复检查,对于较大的数组效率低下。 + +### 算法 + +1. 计算期望的范围数 `n`。 +2. 遍历从 0 到 `n` 的数字范围: + * 对于每个数字,遍历数组以检查当前数字是否存在。 + * 如果找到该数字,停止搜索并移至下一个数字。 + * 如果未找到该数字,则将其作为缺失数字返回。 +3. 如果未找到缺失数字,则返回 -1。 + + + {findMissingNumberInSequenceBruteForce} + + +### Big-O 分析 + +* **时间复杂度:O(n2)**。对于范围 0 到 `n` 中的每个数字,都会对数组进行完全遍历以检查其是否存在。 +* **空间复杂度:O(1)**。除了用于存储中间结果的几个变量外,没有使用额外的空间。 + +## 2. 使用排序 + +为了消除暴力解法中的冗余检查,这种优化方法对输入数组进行排序,通过确保数字按升序排列,从而更容易识别序列中缺失的数字。排序后,该解决方案检查边界情况(序列中第一个或最后一个数字是否缺失)。如果未检测到边界情况,则该解决方案遍历排序后的数组以检查每个索引处是否存在期望值。 + +### 算法 + +1. 按升序对输入数组进行排序。 +2. 检查最后一个数字是否等于数组长度: + * 如果不是,则返回数组长度作为缺失数字。 +3. 检查第一个数字是否为 0: + * 如果不是,则返回 0 作为缺失数字。 +4. 遍历排序后的数组: + * 对于每个数字,将期望的下一个数字计算为当前数字加一。 + * 如果下一个数字与期望值不匹配,则返回期望值作为缺失数字。 +5. 如果未找到缺失数字,则返回 -1,这在使用有效输入时不会发生。 + + + {findMissingNumberInSequenceSorting} + + +### Big-O 分析 + +* **时间复杂度:O(n log n)**。对数组进行排序占据了运行时的大部分时间,需要 O(n log n) 时间。随后对数组的迭代是 O(n)。 +* **空间复杂度:O(1)**。排序是就地执行的,除了几个变量外,没有使用额外的空间。 + +## 3. 使用数学性质计算从 0 到 n 的数字之和 + +排序可能是不必要的,因为可以通过使用从 0 到 `n` 的整数之和的数学性质来确定缺失的数字。数学性质消除了迭代和比较元素的需要。相反,它计算总的期望和,并减去实际和以找到缺失的数字。这种优化消除了排序的瓶颈,并将总的时间复杂度降低到 O(n)。 + +### 算法 + +1. 将 `expectedSum` 初始化为 0。这将保存从 0 到 `n` 的所有整数的和。 +2. 使用循环计算从 0 到 `n` 的整数的总期望和,并将结果存储在 `expectedSum` 中。 +3. 将 `actualSum` 初始化为 0。这将保存给定数组中元素的总和。 +4. 遍历数组并计算所有元素的总和,将其存储在 `actualSum` 中。 +5. 从 `expectedSum` 中减去 `actualSum` 以确定缺失的数字。 +6. 返回结果。 + + + {findMissingNumberInSequence} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。计算期望和并遍历数组都需要 O(n) 时间。 +* **空间复杂度:O(1)**。该解决方案使用常量数量的变量空间。 diff --git a/contents/questions/algo/array-maximum-product-contiguous/description/en-US.langnostic.json b/contents/questions/algo/array-maximum-product-contiguous/description/en-US.langnostic.json new file mode 100644 index 000000000..54b6e12f6 --- /dev/null +++ b/contents/questions/algo/array-maximum-product-contiguous/description/en-US.langnostic.json @@ -0,0 +1,37 @@ +{ + "frontmatter": { + "title": "ffc6989d", + "excerpt": "ba0cf750" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "4432bcfc", + "48e9c933", + "2d96efbe", + "d9c0d67b", + "40808d83", + "97e6568b", + "d068a43f", + "b2065fc", + "9662203" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "4432bcfc", + "48e9c933", + "2d96efbe", + "d9c0d67b", + "40808d83", + "97e6568b", + "d068a43f", + "b2065fc", + "9662203" + ] + } + } +} diff --git a/contents/questions/algo/array-maximum-product-contiguous/description/zh-CN.mdx b/contents/questions/algo/array-maximum-product-contiguous/description/zh-CN.mdx new file mode 100644 index 000000000..4d0698cb1 --- /dev/null +++ b/contents/questions/algo/array-maximum-product-contiguous/description/zh-CN.mdx @@ -0,0 +1,27 @@ +--- +title: 连续数组中的最大乘积 +excerpt: 实现一个函数来查找具有最大乘积的子数组 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个整数数组 `numbers`,确定具有最高乘积的子数组并返回该乘积。 + +一个**子数组**是数组的连续段,其中所有元素都取自连续的索引,并保留其顺序,例如 `[2, 3]` 在 `[1, 2, 3, 4]` 中,而非连续的选择(如 `[1, 3]`)不是有效的子数组。 + +### 输入 + +- `numbers: number[]`: 整数数组 + +### 注意事项 + +- 测试用例的设计使得结果将适合 32 位整数 +- 保证 `numbers` 的任何前缀或后缀的乘积都适合 32 位整数 + + + +### 约束 + +- 1 <= `numbers.length` <= 1000 +- -10 <= `numbers[i]` <= 10 diff --git a/contents/questions/algo/array-maximum-product-contiguous/solution/en-US.langnostic.json b/contents/questions/algo/array-maximum-product-contiguous/solution/en-US.langnostic.json new file mode 100644 index 000000000..955a97a3a --- /dev/null +++ b/contents/questions/algo/array-maximum-product-contiguous/solution/en-US.langnostic.json @@ -0,0 +1,62 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "6840ae74", + "4ce347d1", + "60c8bf53", + "b68df8f8", + "869967f8", + "e9c467e3", + "8e2de8c8", + "ce6b0dfb", + "e5dc1bc8", + "39797531", + "a605a915", + "b68df8f8", + "b6f651a1", + "11b37e28", + "8e2de8c8", + "50290b1f", + "fc3acd7b", + "bb0b1397", + "b68df8f8", + "b3fa1b86", + "93aa63bd", + "8e2de8c8", + "126ab63f" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "6840ae74", + "4ce347d1", + "60c8bf53", + "b68df8f8", + "869967f8", + "e9c467e3", + "8e2de8c8", + "ce6b0dfb", + "e5dc1bc8", + "39797531", + "a605a915", + "b68df8f8", + "b6f651a1", + "11b37e28", + "8e2de8c8", + "50290b1f", + "fc3acd7b", + "bb0b1397", + "b68df8f8", + "b3fa1b86", + "93aa63bd", + "8e2de8c8", + "126ab63f" + ] + } + } +} diff --git a/contents/questions/algo/array-maximum-product-contiguous/solution/zh-CN.mdx b/contents/questions/algo/array-maximum-product-contiguous/solution/zh-CN.mdx new file mode 100644 index 000000000..f5e9738b1 --- /dev/null +++ b/contents/questions/algo/array-maximum-product-contiguous/solution/zh-CN.mdx @@ -0,0 +1,77 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import maxProductSubArray from '../setup/src/array-maximum-product-contiguous.ts'; +import maxProductSubArrayDP from '../setup/src/array-maximum-product-contiguous-dp.ts'; +import maxProductSubArrayBruteForce from '../setup/src/array-maximum-product-contiguous-bruteforce.ts'; + +## 1. 暴力方法 + +朴素的方法是考虑所有可能的连续子数组以确定最大乘积。该过程涉及选择起始索引 `i`,然后遍历该子数组的所有可能的结束索引 `j`。对于每个子数组,计算累积乘积并将其与存储在 `result` 中的当前最大值进行比较。由于检查了每个子数组,因此该方法保证找到最大乘积。 + +### 算法 + +1. 检查输入数组 `numbers` 是否为空,如果为空则返回 `0`。 +2. 将 `result` 初始化为 `numbers` 的第一个元素。 +3. 使用索引 `i` 遍历 `numbers` 中的每个元素。 +4. 为当前子数组乘积将累加器 `accu` 初始化为 `1`。 +5. 对于每个 `i`,使用索引 `j` 遍历从 `i` 到 `numbers` 结尾的元素。 +6. 通过将 `accu` 乘以 `numbers[j]` 来更新 `accu`。 +7. 将 `accu` 与 `result` 进行比较,如果 `accu` 大于 `result`,则更新 `result`。 +8. 考虑所有子数组后,返回 `result`。 + + + {maxProductSubArrayBruteForce} + + +### Big-O 分析 + +* **时间复杂度:O(n2)**。考虑每个子数组,导致对数组进行嵌套迭代。 +* **空间复杂度:O(1)**。仅使用几个变量 `result` 和 `accu`,需要恒定的额外空间。 + +## 2. 使用动态规划 + +一种暴力方法考虑了所有可能的子数组并计算乘积,这会导致重复乘法和冗余检查。该方法的时间复杂度为 O(n2),其中每个元素都用作起始点,所有后续元素构成要考虑的子数组。瓶颈在于多次重新计算大量子数组。 + +此解决方案使用动态规划方法在 O(n) 时间内解决问题。该方法跟踪每个位置以该位置结尾的最大和最小子数组乘积。负数会影响乘积符号,并可以将最小乘积翻转为最大乘积。通过维护到目前为止最大和最小乘积的运行值,计算避免了重新计算所有子数组的乘积。 + +### 算法 + +1. 检查 `numbers` 是否为空,如果为真则返回 `0`。 +2. 将 `maxSoFar`、`minSoFar` 和 `result` 初始化为 `numbers` 的第一个元素。 +3. 从 `numbers` 的第二个元素迭代到结尾。 +4. 对于每个元素 `curr`,计算临时最大乘积,即 `curr`、`maxSoFar * curr` 和 `minSoFar * curr` 的最大值。 +5. 将 `minSoFar` 更新为 `curr`、`maxSoFar * curr` 和 `minSoFar * curr` 的最小值。 +6. 使用临时最大值更新 `maxSoFar`。 +7. 如果 `maxSoFar` 大于 `result`,则更新 `result`。 +8. 返回 `result`。 + + + {maxProductSubArrayDP} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。每个元素只处理一次。 +* **空间复杂度:O(1)**。没有使用额外的数据结构,因此使用了恒定空间。 + +## 3. 使用前缀和后缀乘积 + +另一种优化方法使用前缀和后缀乘积来跟踪两端的运行乘积。通过这样做,可以更容易地处理零和负值。当遇到零时,可以重置运行乘积,而不是再次重新计算所有子数组。这种方法避免了冗余工作并实现了线性运行时。 + +### 算法 + +1. 初始化三个变量:`pre` 用于前缀乘积,`suff` 用于后缀乘积,`maxProduct` 用于跟踪找到的最大乘积。 +2. 使用索引 `i` 从 0 到 `n-1` 遍历数组。 +3. 通过检查 `pre` 是否为零来更新 `pre`,然后将 `pre` 设置为当前元素,否则将 `pre` 乘以当前元素。 +4. 类似地,通过检查 `suff` 是否为零来更新 `suff`,然后将 `suff` 设置为索引 `n - i - 1` 处的结尾元素,否则将 `suff` 乘以该元素。 +5. 通过将 `maxProduct` 与 `pre` 和 `suff` 进行比较并存储找到的最大值来更新 `maxProduct`。 +6. 在完成迭代后返回 `maxProduct`。 + + + {maxProductSubArray} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。每个元素只处理一次。 +* **空间复杂度:O(1)**。只需要恒定的额外空间。 diff --git a/contents/questions/algo/array-maximum-sum-contiguous/description/en-US.langnostic.json b/contents/questions/algo/array-maximum-sum-contiguous/description/en-US.langnostic.json new file mode 100644 index 000000000..8bd3f64f7 --- /dev/null +++ b/contents/questions/algo/array-maximum-sum-contiguous/description/en-US.langnostic.json @@ -0,0 +1,33 @@ +{ + "frontmatter": { + "title": "f61dd672", + "excerpt": "a0328eac" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "d80d615c", + "48e9c933", + "2d96efbe", + "d9c0d67b", + "d068a43f", + "b2065fc", + "b42f1d7" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "d80d615c", + "48e9c933", + "2d96efbe", + "d9c0d67b", + "d068a43f", + "b2065fc", + "b42f1d7" + ] + } + } +} diff --git a/contents/questions/algo/array-maximum-sum-contiguous/description/zh-CN.mdx b/contents/questions/algo/array-maximum-sum-contiguous/description/zh-CN.mdx new file mode 100644 index 000000000..27a231dc8 --- /dev/null +++ b/contents/questions/algo/array-maximum-sum-contiguous/description/zh-CN.mdx @@ -0,0 +1,22 @@ +--- +title: 连续数组中的最大和 +excerpt: 实现一个函数来查找具有最大和的子数组 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个整数数组 `numbers`,确定总和最高的子数组并返回该总和。 + +一个**子数组**是数组的连续段,其中所有元素都取自连续的索引,保留其顺序,例如 `[2, 3]` 在 `[1, 2, 3, 4]` 中,而非连续的选择(如 `[1, 3]`)不是有效的子数组。 + +### 输入 + +- `numbers: number[]`: 整数数组 + + + +### 约束 + +- 1 <= `numbers.length` <= 10,000 +- -10,000 <= `numbers[i]` <= 10,000 diff --git a/contents/questions/algo/array-maximum-sum-contiguous/solution/en-US.langnostic.json b/contents/questions/algo/array-maximum-sum-contiguous/solution/en-US.langnostic.json new file mode 100644 index 000000000..d74734049 --- /dev/null +++ b/contents/questions/algo/array-maximum-sum-contiguous/solution/en-US.langnostic.json @@ -0,0 +1,46 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "c7b9a06e", + "ccea94fc", + "ecb7ce67", + "b68df8f8", + "4ad3830a", + "eb4fcc41", + "8e2de8c8", + "343ae405", + "53d03e02", + "8f52aeea", + "b68df8f8", + "7d6e23a8", + "a6302227", + "8e2de8c8", + "c485866" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "c7b9a06e", + "ccea94fc", + "ecb7ce67", + "b68df8f8", + "4ad3830a", + "eb4fcc41", + "8e2de8c8", + "343ae405", + "53d03e02", + "8f52aeea", + "b68df8f8", + "7d6e23a8", + "a6302227", + "8e2de8c8", + "c485866" + ] + } + } +} diff --git a/contents/questions/algo/array-maximum-sum-contiguous/solution/zh-CN.mdx b/contents/questions/algo/array-maximum-sum-contiguous/solution/zh-CN.mdx new file mode 100644 index 000000000..e660aada9 --- /dev/null +++ b/contents/questions/algo/array-maximum-sum-contiguous/solution/zh-CN.mdx @@ -0,0 +1,48 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import maxSumSubArray from '../setup/src/array-maximum-sum-contiguous.ts'; +import maxSumSubArrayBruteForce from '../setup/src/array-maximum-sum-contiguous-bruteforce.ts'; + +## 1. 暴力破解方法 + +暴力破解方法用于查找最大和连续子数组,它会检查每个可能的子数组。这包括将每个元素作为起始点进行迭代,然后通过逐个包含后续元素来扩展子数组。当形成每个子数组时,计算其总和,并更新到目前为止找到的最大总和。这确保了每个子数组的总和都被评估和比较。 + +### 算法 + +1. 将变量 `maxSubarray` 初始化为 `Number.NEGATIVE_INFINITY`。 +2. 使用循环索引 `i` 从数组的开头开始迭代。 +3. 对于每个 `i`,将 `currentSubarray` 初始化为 0。 +4. 使用另一个循环索引 `j` 从 `i` 迭代到数组的末尾。 +5. 将 `numbers[j]` 添加到 `currentSubarray`。 +6. 使用 `maxSubarray` 和 `currentSubarray` 之间的最大值更新 `maxSubarray`。 +7. 在两个循环完成后,返回 `maxSubarray`。 + + + {maxSumSubArrayBruteForce} + + +### Big-O 分析 + +* **时间复杂度:O(n²)**。使用两个嵌套循环来考虑所有可能的子数组。 +* **空间复杂度:O(1)**。仅使用常量数量的额外空间。 + +## 2. 使用 Kadane 算法 + +之前的暴力破解方法枚举了所有可能的子数组并计算了它们的总和。这个过程涉及重复对重叠子数组求和,这会产生不必要的工作,导致 O(n²) 的复杂度。Kadane 算法通过维护一个运行的 `currentSum` 并在每一步更新它来解决这个问题。该算法没有重新计算整个子数组的总和,而是决定是扩展现有的子数组还是从当前元素开始一个新的子数组。全局 `maxSum` 会不断更新,确保跟踪遇到的最大总和,而无需枚举每个可能的子数组。这消除了不必要的重复工作,并将复杂度降低到 O(n)。 + +### 算法 + +1. 将 `currentSum` 初始化为 `0`,将 `maxSum` 初始化为 `-Infinity`。 +2. 遍历数组中的每个元素 `num`。 +3. 将 `currentSum` 更新为 `Math.max(num, currentSum + num)`。 +4. 将 `maxSum` 更新为 `Math.max(maxSum, currentSum)`。 +5. 返回 `maxSum`。 + + + {maxSumSubArray} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。每个元素只访问一次。 +* **空间复杂度:O(1)**。除了几个变量外,不需要额外的空间。 diff --git a/contents/questions/algo/array-most-common-elements/description/en-US.langnostic.json b/contents/questions/algo/array-most-common-elements/description/en-US.langnostic.json new file mode 100644 index 000000000..967c42bd7 --- /dev/null +++ b/contents/questions/algo/array-most-common-elements/description/en-US.langnostic.json @@ -0,0 +1,31 @@ +{ + "frontmatter": { + "title": "36184a09", + "excerpt": "b4772552" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "d6bc7f31", + "2d96efbe", + "2130e4cd", + "d068a43f", + "b2065fc", + "5b498f38" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "d6bc7f31", + "2d96efbe", + "2130e4cd", + "d068a43f", + "b2065fc", + "5b498f38" + ] + } + } +} diff --git a/contents/questions/algo/array-most-common-elements/description/zh-CN.mdx b/contents/questions/algo/array-most-common-elements/description/zh-CN.mdx new file mode 100644 index 000000000..289f10c12 --- /dev/null +++ b/contents/questions/algo/array-most-common-elements/description/zh-CN.mdx @@ -0,0 +1,23 @@ +--- +title: 最常见的元素 +excerpt: 实现一个函数来确定整数数组中最常见的元素 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个整数数组 `numbers` 和一个数字 `k`,找到数组中出现频率最高的 `k` 个数字。这里,`k` 表示应该返回的元素数量,这些元素是出现频率最高的元素。结果的顺序无关紧要。 + +### 输入 + +- `numbers: number[]`: 整数数组 +- `k`: 一个整数 + + + +### 约束 + +- 1 <= `numbers.length` <= 1000 +- -10,000 <= `numbers[i]` <= 10,000 +- 1 <= `k` <= `numbers` 中唯一元素的数量 +- 保证该解决方案具有唯一结果 diff --git a/contents/questions/algo/array-most-common-elements/solution/en-US.langnostic.json b/contents/questions/algo/array-most-common-elements/solution/en-US.langnostic.json new file mode 100644 index 000000000..f5d593bab --- /dev/null +++ b/contents/questions/algo/array-most-common-elements/solution/en-US.langnostic.json @@ -0,0 +1,60 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "e5895c23", + "dfacf1c9", + "58b7ecc1", + "b68df8f8", + "3b0de1fa", + "a9aeeaad", + "8e2de8c8", + "7529eb8b", + "2c57ee80", + "c64a48c2", + "b68df8f8", + "a128408", + "bfbb097b", + "8e2de8c8", + "7e408655", + "f598a478", + "373c5524", + "b68df8f8", + "9e8872b7", + "3110e207", + "8e2de8c8", + "38ac4c1f" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "e5895c23", + "dfacf1c9", + "58b7ecc1", + "b68df8f8", + "3b0de1fa", + "a9aeeaad", + "8e2de8c8", + "7529eb8b", + "2c57ee80", + "c64a48c2", + "b68df8f8", + "a128408", + "bfbb097b", + "8e2de8c8", + "7e408655", + "f598a478", + "373c5524", + "b68df8f8", + "9e8872b7", + "3110e207", + "8e2de8c8", + "38ac4c1f" + ] + } + } +} diff --git a/contents/questions/algo/array-most-common-elements/solution/zh-CN.mdx b/contents/questions/algo/array-most-common-elements/solution/zh-CN.mdx new file mode 100644 index 000000000..84a1ad4e8 --- /dev/null +++ b/contents/questions/algo/array-most-common-elements/solution/zh-CN.mdx @@ -0,0 +1,72 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import mostCommonElements from '../setup/src/array-most-common-elements.ts'; +import mostCommonElementsUsingMap from '../setup/src/array-most-common-elements-using-map.ts'; +import mostCommonElementsBruteForce from '../setup/src/array-most-common-elements-brute-force.ts'; + +## 1. 暴力解法 + +一种朴素的方法是使用嵌套循环计算每个元素的频率。频率存储在一个单独的数组中,然后对该数组进行排序以找到最常见的元素。 + +### 算法 + +1. 初始化一个空数组 `frequency`,用于存储具有 `value` 和 `count` 属性的对象。 +2. 遍历输入数组: + * 对于每个数字,检查它是否已存在于 `frequency` 数组中。 + * 如果存在,则递增其 `count`。 + * 如果不存在,则将其添加到 `frequency` 数组中,初始 `count` 为 1。 +3. 按 `count` 降序对 `frequency` 数组进行排序。 +4. 从排序后的 `frequency` 数组中提取前 `k` 个元素。 +5. 返回一个包含前 `k` 个元素的 `value` 的数组。 + + + {mostCommonElementsBruteForce} + + +### Big-O 分析 + +* **时间复杂度:O(n2)**。这是由于用于频率计算的嵌套循环。 +* **空间复杂度:O(n)**。如果数字中的所有 `n` 个元素都是唯一的,则频率数组的大小将为 O(n)。 + +## 2. 使用堆 + +暴力解法的主要瓶颈在于其用于计算频率和对整个频率数组进行排序的嵌套循环。这导致了冗余的比较和高时间复杂度。优化的方法使用哈希映射进行频率计数,这避免了重复计算,并使用最小堆来有效地维护前 `k` 个频繁元素。这大大减少了不必要的排序和比较,仅关注所需的元素。 + +### 算法 + +1. 检查 `k` 是否等于输入数组的大小。如果为真,则返回数组,因为需要所有元素。 +2. 创建一个哈希映射来计算数组中每个元素的频率: + * 遍历数组,更新哈希映射中每个元素的频率计数。 +3. 使用自定义比较器初始化最小堆以按频率对元素进行排序。 +4. 遍历哈希映射中的元素: + * 将每个元素插入堆中,同时将堆的大小保持为 `k`。 + * 每次插入后,使用比较器对堆进行排序,如果堆大小超过 `k`,则删除频率最低的元素。 +5. 返回堆中的元素,这些元素是 `k` 个最频繁的元素。 + + + {mostCommonElements} + + +### Big-O 分析 + +* **时间复杂度:O(n log k)**。维护堆需要对每个 n 个唯一元素最多 k 个元素进行排序,总共需要 O(n log k)。 +* **空间复杂度:O(n + k)**。哈希映射需要 O(n) 空间来存储不超过 `n` 个唯一元素,堆需要 O(k) 空间来存储前 `k` 个元素。 + +## 3. 使用 Map + +另一种方法使用频率映射来计算每个数字的出现次数。然后构建一个 `buckets` 数组,用于按频率对元素进行分组,其中索引对应于频率。从最高频率到最低频率遍历 `buckets` 数组可以有效地收集前 `k` 个频繁元素,而无需执行 O(n log n) 排序步骤。这种方法将总复杂度降低到 O(n)。 + +### 算法 + +1. 构建一个频率映射 `frequencyMap`,将每个数字映射到其频率计数。 +2. 构建一个 `buckets` 数组,其中每个索引对应一个频率,并存储具有该频率的数字数组。 +3. 从最高频率桶到最低频率桶遍历 `buckets`,并选择数字,直到达到 `k`。 + + + {mostCommonElementsUsingMap} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。计算频率,然后填充桶,两者都以 O(n) 运行,然后进行最后一次传递,选择最多 `k` 个元素,仍然是 O(n)。 +* **空间复杂度:O(n)**。`frequencyMap` 和 `buckets` 数组都占用最多 O(n) 空间。 diff --git a/contents/questions/algo/array-product-excluding-current/description/en-US.langnostic.json b/contents/questions/algo/array-product-excluding-current/description/en-US.langnostic.json new file mode 100644 index 000000000..cb28a2fa2 --- /dev/null +++ b/contents/questions/algo/array-product-excluding-current/description/en-US.langnostic.json @@ -0,0 +1,35 @@ +{ + "frontmatter": { + "title": "8adbd6e3", + "excerpt": "418c2d54" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "919979b8", + "2d96efbe", + "d9c0d67b", + "40808d83", + "49cc3808", + "d068a43f", + "b2065fc", + "e07bc5b2" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "919979b8", + "2d96efbe", + "d9c0d67b", + "40808d83", + "49cc3808", + "d068a43f", + "b2065fc", + "e07bc5b2" + ] + } + } +} diff --git a/contents/questions/algo/array-product-excluding-current/description/zh-CN.mdx b/contents/questions/algo/array-product-excluding-current/description/zh-CN.mdx new file mode 100644 index 000000000..0c413eb5b --- /dev/null +++ b/contents/questions/algo/array-product-excluding-current/description/zh-CN.mdx @@ -0,0 +1,25 @@ +--- +title: 数组的乘积,不包含当前元素 +excerpt: 实现一个函数,找到数组中除当前元素之外的所有元素的乘积。 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个整数数组 `numbers`,返回一个新数组 `result`,其中每个元素 `result[i]` 代表 `numbers` 中除 `numbers[i]` 之外的所有元素的乘积。 + +### 输入 + +- `numbers: number[]`: 整数数组 + +### 注意事项 + +- 确保 `numbers` 数组的任何前缀或后缀的乘积都适合 32 位整数 +- 禁止使用除法运算符 + + + +### 约束 + +- 2 <= `numbers.length` <= 1000 +- -10 <= `numbers[i]` <= 10 diff --git a/contents/questions/algo/array-product-excluding-current/solution/en-US.langnostic.json b/contents/questions/algo/array-product-excluding-current/solution/en-US.langnostic.json new file mode 100644 index 000000000..4596a6f21 --- /dev/null +++ b/contents/questions/algo/array-product-excluding-current/solution/en-US.langnostic.json @@ -0,0 +1,50 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "ce672c7d", + "730c083f", + "4ddd839e", + "468c6c8b", + "c3994fb4", + "b68df8f8", + "2809e208", + "7c06dec6", + "8e2de8c8", + "69d0ba02", + "6d1ca9da", + "6ec67728", + "b68df8f8", + "e806115a", + "2c15d1a3", + "8e2de8c8", + "8aba4c1b" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "ce672c7d", + "730c083f", + "4ddd839e", + "468c6c8b", + "c3994fb4", + "b68df8f8", + "2809e208", + "7c06dec6", + "8e2de8c8", + "69d0ba02", + "6d1ca9da", + "6ec67728", + "b68df8f8", + "e806115a", + "2c15d1a3", + "8e2de8c8", + "8aba4c1b" + ] + } + } +} diff --git a/contents/questions/algo/array-product-excluding-current/solution/zh-CN.mdx b/contents/questions/algo/array-product-excluding-current/solution/zh-CN.mdx new file mode 100644 index 000000000..2367a917d --- /dev/null +++ b/contents/questions/algo/array-product-excluding-current/solution/zh-CN.mdx @@ -0,0 +1,65 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import arrayProductExcludingCurrent from '../setup/src/array-product-excluding-current.ts'; +import arrayProductExcludingCurrentEfficientSpace from '../setup/src/array-product-excluding-current-efficient-space.ts'; + +## 1. 使用前缀和后缀 + +该任务是计算一个数组,其中索引 `i` 处的每个元素是输入数组中除 `i` 处元素之外的所有元素的乘积。此解决方案使用单独的前缀和后缀数组来存储中间计算结果,从而可以高效地计算结果。 + +一种蛮力方法将涉及遍历数组并计算每个索引的所有元素的乘积,除了当前索引。由于每个索引的重复乘法,这导致时间复杂度为 O(n2)。优化的前缀-后缀方法通过预先计算每个元素左侧和右侧的乘积来消除这种冗余。 + +前缀数组存储从开始到索引 `i - 1` 的元素的累积乘积,后缀数组存储从末尾到索引 `i + 1` 的元素的累积乘积。这些数组被组合起来计算最终结果数组,每个元素是相应的前缀和后缀值的乘积。负零的处理确保了一致的输出格式。 + +### 算法 + +1. 创建三个数组:`prefix`、`suffix` 和 `result`,每个数组的大小为 `n`,并初始化为 `1`。 +2. 计算前缀数组: + * 设置 `prefix[0] = 1`,因为第一个元素的左边没有元素。 + * 从索引 `1` 迭代到 `n - 1`,将 `prefix[i]` 设置为 `prefix[i - 1] * numbers[i - 1]`。 +3. 计算后缀数组: + * 设置 `suffix[n - 1] = 1`,因为最后一个元素的右边没有元素。 + * 从索引 `n - 2` 迭代到 `0`,将 `suffix[i]` 设置为 `suffix[i + 1] * numbers[i + 1]`。 +4. 计算结果数组: + * 遍历数组并将 `result[i]` 设置为 `prefix[i] * suffix[i]`。 +5. 处理特殊情况: + * 遍历 `result` 数组,并将 `-0` 的任何出现替换为 `0`,以获得一致的输出。 +6. 返回 `result` 数组。 + + + {arrayProductExcludingCurrent} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。该算法涉及三个线性遍历:一个用于计算前缀数组,一个用于计算后缀数组,一个用于计算结果数组。 +* **空间复杂度:O(n)**。除了 `result` 数组外,还使用了两个大小为 `n` 的辅助数组 (`prefix` 和 `suffix`)。 + +## 2. 上述方法的空间优化版本 + +此解决方案通过在第一遍中计算每个索引左侧的所有元素的乘积并将这些值存储在 `result` 数组中,从而进一步提高了空间使用率。在第二遍中,它计算每个索引右侧的所有元素的乘积,并将这些值与已存储在 `result` 数组中的相应值相乘。 + +### 算法 + +1. 初始化一个与输入数组长度相同的 `result` 数组,并将所有元素设置为 `1`。 +2. 计算左侧乘积: + * 从左到右遍历数组,从索引 `1` 开始。 + * 对于每个索引 `i`,通过将 `numbers[i - 1]` 与 `result[i - 1]` 相乘来计算左侧所有元素的乘积。 + * 将结果存储在 `result[i]` 中。 +3. 计算右侧乘积并与左侧乘积合并: + * 将变量 `rightProduct` 初始化为 `1`。 + * 从右到左遍历数组。 + * 对于每个索引 `i`,将 `result[i]` 中的值与 `rightProduct` 相乘,以包含右侧所有元素的乘积。 + * 通过将 `rightProduct` 与 `numbers[i]` 相乘来更新它。 +4. 处理特殊情况: + * 将 `result` 中 `-0` 的任何出现替换为 `0`,以获得一致的输出。 +5. 返回 `result` 数组。 + + + {arrayProductExcludingCurrentEfficientSpace} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。该算法涉及对数组进行两次线性遍历,用于计算左右乘积,以及一次额外的遍历用于归一化。 +* **空间复杂度:O(1)**。该解决方案使用恒定的额外空间,因为计算直接在 `result` 数组中执行。 diff --git a/contents/questions/algo/array-reachable-end/description/en-US.langnostic.json b/contents/questions/algo/array-reachable-end/description/en-US.langnostic.json new file mode 100644 index 000000000..29dba7ad2 --- /dev/null +++ b/contents/questions/algo/array-reachable-end/description/en-US.langnostic.json @@ -0,0 +1,33 @@ +{ + "frontmatter": { + "title": "b87cdfa8", + "excerpt": "afcc4661" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "9faa8a1b", + "544cc243", + "2d96efbe", + "bd88d25b", + "d068a43f", + "b2065fc", + "d64cdb4f" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "9faa8a1b", + "544cc243", + "2d96efbe", + "bd88d25b", + "d068a43f", + "b2065fc", + "d64cdb4f" + ] + } + } +} diff --git a/contents/questions/algo/array-reachable-end/description/zh-CN.mdx b/contents/questions/algo/array-reachable-end/description/zh-CN.mdx new file mode 100644 index 000000000..55d2d1234 --- /dev/null +++ b/contents/questions/algo/array-reachable-end/description/zh-CN.mdx @@ -0,0 +1,22 @@ +--- +title: 数组末端可达 +excerpt: 实现一个函数来确定数组的末端是否可达 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个整数数组`numbers`,其中数组中的每个元素表示可以从该索引向前移动的**最大**位置数;可以移动较少的位置。 + +确定是否可以通过从第一个索引开始到达数组的最后一个索引。如果可以到达,则返回`true`,否则返回`false`。 + +### 输入 + +- `numbers: number[]`: 一个整数数组,每个索引的值是从该索引可到达的最大位置数 + + + +### 约束 + +- 1 <= `numbers.length` <= 10,000 +- 0 <= `numbers[i]` <= 100,000 diff --git a/contents/questions/algo/array-reachable-end/solution/en-US.langnostic.json b/contents/questions/algo/array-reachable-end/solution/en-US.langnostic.json new file mode 100644 index 000000000..742650021 --- /dev/null +++ b/contents/questions/algo/array-reachable-end/solution/en-US.langnostic.json @@ -0,0 +1,62 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "ebb99185", + "e52f69c4", + "a4f1e1f0", + "c5d4182b", + "b68df8f8", + "35239933", + "1a004b3c", + "8e2de8c8", + "41ce0bd4", + "55105613", + "77309bb8", + "b68df8f8", + "72788259", + "67ff7800", + "8e2de8c8", + "9206b7dd", + "ef16542a", + "8506de10", + "b68df8f8", + "df972350", + "2dc60425", + "8e2de8c8", + "8e68aa4f" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "ebb99185", + "e52f69c4", + "a4f1e1f0", + "c5d4182b", + "b68df8f8", + "35239933", + "1a004b3c", + "8e2de8c8", + "41ce0bd4", + "55105613", + "77309bb8", + "b68df8f8", + "72788259", + "67ff7800", + "8e2de8c8", + "9206b7dd", + "ef16542a", + "8506de10", + "b68df8f8", + "df972350", + "2dc60425", + "8e2de8c8", + "8e68aa4f" + ] + } + } +} diff --git a/contents/questions/algo/array-reachable-end/solution/zh-CN.mdx b/contents/questions/algo/array-reachable-end/solution/zh-CN.mdx new file mode 100644 index 000000000..3d1476757 --- /dev/null +++ b/contents/questions/algo/array-reachable-end/solution/zh-CN.mdx @@ -0,0 +1,81 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import arrayReachableEnd from '../setup/src/array-reachable-end.ts'; +import arrayReachableEndTopDown from '../setup/src/array-reachable-end-top-down.ts'; +import arrayReachableEndBottomUp from '../setup/src/array-reachable-end-bottom-up.ts'; + +## 1. 自底向上动态规划 + +一个朴素的解决方案将涉及递归地探索从第一个位置开始的所有可能路径,以检查是否可以到达最后一个位置。这种方法存在冗余计算和指数时间复杂度的缺点,因为它多次探索重叠的子问题。 + +自底向上动态规划方法通过从倒数第二个位置迭代到第一个位置来优化这一点,同时维护一个 `memo` 数组,该数组记录每个位置是 `GOOD`、`BAD` 还是 `UNKNOWN`。如果一个位置可以到达最后一个位置或已经标记为 `GOOD` 的位置,则该位置为 `GOOD`。优化通过使用 `memo` 数组中先前计算的结果来消除冗余检查。 + +### 算法 + +1. 定义一个枚举 `Index`,其状态为 `GOOD`、`BAD` 和 `UNKNOWN`,以表示每个索引的状态。 +2. 初始化一个与输入数组长度相同的 `memo` 数组,所有值都设置为 `Index.UNKNOWN`。 +3. 将 `memo` 数组中的最后一个位置设置为 `Index.GOOD`,因为最后一个位置可以很容易地到达它自己。 +4. 从倒数第二个位置到第一个位置向后遍历输入数组: + * 使用 `i + numbers[i]` 和最后一个索引的最小值来计算从当前索引可以到达的最远位置。 + * 检查当前索引和最远可到达位置之间的所有位置: + * 如果这些位置中的任何一个在 `memo` 中被标记为 `Index.GOOD`,则将当前位置标记为 `Index.GOOD` 并中断内循环。 +5. 如果第一个位置在 `memo` 中被标记为 `Index.GOOD`,则返回 `true`,表示可以到达最后一个位置。否则,返回 `false`。 + + + {arrayReachableEndBottomUp} + + +### Big-O 分析 + +* **时间复杂度:O(n2)**。对于每个位置,内循环检查最多 `numbers[i]` 个位置,导致最坏情况下的二次方复杂度。 +* **空间复杂度:O(n)**。大小为 `n` 的 `memo` 数组用于动态规划存储。 + +## 2. 自顶向下动态规划 + +还有另一种自顶向下的动态规划方法,该方法从第一个位置开始,并使用递归来确定后续可到达的位置是否可以到达最后一个位置。备忘录数组确保重用先前计算的结果,避免了冗余计算并提高了效率。 + +### 算法 + +1. 初始化一个与输入数组长度相同的 `memo` 数组,所有值都设置为 `'UNKNOWN'`。 +2. 将 `memo` 数组中的最后一个位置设置为 `'GOOD'`,因为它本身可以轻松到达。 +3. 定义一个辅助函数 `canReachLastPosition`,它将当前位置和输入数组作为参数: + * 如果当前位置已经在 `memo` 中标记,则返回相应的结果。 + * 如果当前位置的值为 `0`,则将其标记为 `'BAD'` 并返回 `false`,因为它无法继续前进。 + * 计算从当前位置可以到达的最远位置,即 `position + numbers[position]` 和最后一个索引的最小值。 + * 从当前位置向后遍历所有可到达的位置: + * 如果任何可到达的位置是 `'GOOD'`,则将当前位置标记为 `'GOOD'` 并返回 `true`。 + * 如果没有任何可到达的位置是 `'GOOD'`,则将当前位置标记为 `'BAD'` 并返回 `false`。 +4. 使用辅助函数从第一个位置开始递归。 +5. 如果第一个位置是 `'GOOD'`,则返回 `true`,表示可以到达最后一个位置。否则,返回 `false`。 + + + {arrayReachableEndTopDown} + + +### Big-O 分析 + +* **时间复杂度:O(n2)**。最坏的情况涉及检查每个索引的所有可到达位置,导致二次方复杂度。 +* **空间复杂度:O(n)**。大小为 `n` 的 `memo` 数组用于存储中间结果,并且递归堆栈可能达到 `n` 次调用。 + +## 3. 贪心算法 + +在贪心算法中,算法从最后一个位置开始并向后迭代。对于每个位置,它检查当前位置是否可以到达最远的可到达位置。如果可以,则将最远的可到达位置更新为当前位置。如果在处理完整个数组后,最远的可到达位置变为第一个索引,则表示可以到达最后一个位置。 + +### 算法 + +1. 将变量 `farthestReachable` 初始化为数组的最后一个索引 (`numbers.length - 1`)。 +2. 从最后一个索引开始向后遍历数组: + * 对于每个位置,检查 `currentPosition + numbers[currentPosition]` 是否大于或等于 `farthestReachable`。 + * 如果为真,则将 `farthestReachable` 更新为 `currentPosition`。 +3. 迭代后,检查 `farthestReachable` 是否等于 `0`: + * 如果 `farthestReachable` 为 `0`,则返回 `true`,表示可以从第一个位置到达最后一个位置。 + * 否则,返回 `false`。 + + + {arrayReachableEnd} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。该算法以相反的顺序遍历数组一次。 +* **空间复杂度:O(1)**。除了常量数量的变量外,没有使用额外的空间。 diff --git a/contents/questions/algo/array-rotated-find/description/en-US.langnostic.json b/contents/questions/algo/array-rotated-find/description/en-US.langnostic.json new file mode 100644 index 000000000..eeff547ff --- /dev/null +++ b/contents/questions/algo/array-rotated-find/description/en-US.langnostic.json @@ -0,0 +1,37 @@ +{ + "frontmatter": { + "title": "569dc0bb", + "excerpt": "54a8f8cd" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "7d50704c", + "fba5223a", + "9a840d3f", + "2d96efbe", + "4d1fce3c", + "40808d83", + "d068a43f", + "b2065fc", + "a647193b" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "7d50704c", + "fba5223a", + "9a840d3f", + "2d96efbe", + "4d1fce3c", + "40808d83", + "d068a43f", + "b2065fc", + "a647193b" + ] + } + } +} diff --git a/contents/questions/algo/array-rotated-find/description/zh-CN.mdx b/contents/questions/algo/array-rotated-find/description/zh-CN.mdx new file mode 100644 index 000000000..76114132e --- /dev/null +++ b/contents/questions/algo/array-rotated-find/description/zh-CN.mdx @@ -0,0 +1,28 @@ +--- +title: 在旋转数组中查找元素 +excerpt: 实现一个函数,在旋转排序数组中查找一个整数 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个包含唯一元素的已排序和旋转的数组 `numbers` 和一个整数 `target`,如果 `target` 在 `numbers` 中,则返回 `target` 的索引,如果不在,则返回 `-1`。 + +将数组 `[a[0], a[1], a[2], ..., a[n-1]]` 旋转一次会得到 `[a[n-1], a[0], a[1], a[2], ..., a[n-2]]`。将其旋转第二次会得到 `[a[n-2], a[n-1], a[0], a[1], ..., a[n-3]]`。 + +开发一个时间复杂度为 O(log n) 的算法。 + +### 输入 + +- `numbers: number[]`: 整数数组 +- `target: number`: 整数 + +### 注意事项 + + + +### 约束 + +- 1 <= `numbers.length` <= 1000 +- -10,000 <= `numbers[i]` <= 10,000 +- -10,000 <= `target` <= 10,000 diff --git a/contents/questions/algo/array-rotated-find/solution/en-US.langnostic.json b/contents/questions/algo/array-rotated-find/solution/en-US.langnostic.json new file mode 100644 index 000000000..0ecb4f901 --- /dev/null +++ b/contents/questions/algo/array-rotated-find/solution/en-US.langnostic.json @@ -0,0 +1,52 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "64157874", + "b426dac6", + "bcae148e", + "de39fa10", + "7a53e0ea", + "b68df8f8", + "d6bb467a", + "771ae3e4", + "8e2de8c8", + "81cf956a", + "1ff50de2", + "38115ae7", + "18a1f3a", + "b68df8f8", + "cfde61f", + "77fa6cb9", + "8e2de8c8", + "2d5e325" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "64157874", + "b426dac6", + "bcae148e", + "de39fa10", + "7a53e0ea", + "b68df8f8", + "d6bb467a", + "771ae3e4", + "8e2de8c8", + "81cf956a", + "1ff50de2", + "38115ae7", + "18a1f3a", + "b68df8f8", + "cfde61f", + "77fa6cb9", + "8e2de8c8", + "2d5e325" + ] + } + } +} diff --git a/contents/questions/algo/array-rotated-find/solution/zh-CN.mdx b/contents/questions/algo/array-rotated-find/solution/zh-CN.mdx new file mode 100644 index 000000000..66d8be04c --- /dev/null +++ b/contents/questions/algo/array-rotated-find/solution/zh-CN.mdx @@ -0,0 +1,77 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import findInRotatedArray from '../setup/src/array-rotated-find.ts'; +import findInRotatedArrayPivotBinarySearch from '../setup/src/array-rotated-find-pivot-binary-search.ts'; + +## 1. 使用枢轴索引和二分查找 + +该解决方案通过结合两种有效技术来解决在旋转排序数组中查找目标的问题:识别枢轴索引和执行二分查找。 在朴素方法中,线性扫描整个数组是主要的瓶颈,因为它导致时间复杂度为 O(n)。 该解决方案通过使用数组已排序但已旋转的事实来消除不必要的工作。 + +第一步是找到枢轴索引,它是数组中最小的元素。 该索引也表示排序数组被分成两个子数组的旋转点。 知道这个枢轴索引有助于确定要搜索目标的数组部分。 + +确定枢轴索引后,使用二分查找来有效地搜索目标。 搜索空间根据目标相对于枢轴的值进行划分。 这允许仅关注数组的相关一半。 使用二分查找将总运行时间从 O(n) 减少到 O(log n),使解决方案达到最佳。 + +### 算法 + +1. 定义一个辅助函数 `findPivotIndex` 来定位数组旋转的枢轴点。 + + * 分别在数组的开头和结尾初始化两个指针 `low` 和 `high`。 + * 使用循环调整指针: + * 计算中间索引 `mid`。 + * 如果 `numbers[mid]` 大于 `numbers[high]`,则枢轴在右侧。 将 `low` 更新为 `mid + 1`。 + * 否则,枢轴在左侧或在 `mid` 处。 将 `high` 更新为 `mid`。 + * 当循环结束时,`low` 指向枢轴索引。 + +2. 定义一个辅助函数 `binarySearch` 以在排序的子数组中搜索目标。 + + * 将 `low` 和 `high` 指针初始化为子数组的开头和结尾。 + * 使用循环执行二分查找: + * 计算中间索引 `mid`。 + * 如果 `numbers[mid]` 与目标匹配,则返回 `mid`。 + * 如果 `numbers[mid]` 小于目标,则将 `low` 调整为 `mid + 1`。 + * 否则,将 `high` 调整为 `mid - 1`。 + * 如果循环结束时未找到目标,则返回 `-1`。 + +3. 使用 `findPivotIndex` 找到枢轴索引。 + +4. 根据目标决定搜索数组的哪一部分。 + + * 如果目标位于旋转部分的范围内(从 `pivot` 到数组的末尾),则对该部分执行二分查找。 + * 否则,对非旋转部分(从数组的开头到 `pivot - 1`)执行二分查找。 + +5. 返回二分查找的结果。 + + + {findInRotatedArrayPivotBinarySearch} + + +### Big-O 分析 + +* **时间复杂度:O(log n)**。 枢轴查找操作和二分查找都花费 O(log n) 时间,导致总时间复杂度为 O(log n)。 +* **空间复杂度:O(1)**。 该算法在恒定空间中运行,仅使用几个变量进行指针操作。 + +## 2. 使用修改后的二分查找 + +给定的解决方案通过消除显式的枢轴索引计算来改进之前的方案。 该方法没有将数组分成两部分并执行两个单独的二分查找,而是使用一个二分查找,并添加了额外的逻辑来处理旋转排序数组。 + +关键的见解是,在旋转排序数组中,数组的至少一半(左侧或右侧)始终已排序。 通过在每一步检查哪一半已排序,该算法确定目标是否位于已排序的范围内。 如果是,则调整搜索范围以排除未排序的一半。 否则,搜索将继续在未排序的一半中进行。 这种方法避免了显式查找枢轴索引的开销,直接缩小了搜索空间。 + +### 算法 + +1. 分别将两个指针 `low` 和 `high` 初始化为数组的开头和结尾。 +2. 使用循环执行二分查找,当 `low` 小于或等于 `high` 时: + * 将中间索引 `mid` 计算为 `low` 和 `high` 的平均值的下限。 + * 如果 `numbers[mid]` 等于目标,则返回 `mid`。 + * 通过比较 `numbers[low]` 和 `numbers[mid]` 来确定数组的左半部分是否已排序。 + * 如果左半部分已排序,请检查目标是否位于此范围内。 如果是,则将 `high` 调整为 `mid - 1`。 否则,将 `low` 调整为 `mid + 1`。 + * 如果左半部分未排序,则右半部分必须已排序。 检查目标是否位于此范围内。 如果是,则将 `low` 调整为 `mid + 1`。 否则,将 `high` 调整为 `mid - 1`。 +3. 如果循环结束时未找到目标,则返回 `-1` 以指示目标不存在于数组中。 + + + {findInRotatedArray} + + +### Big-O 分析 + +* **时间复杂度:O(log n)**。 二分查找在每一步将搜索空间减半,从而产生对数时间复杂度。 +* **空间复杂度:O(1)**。 该算法使用恒定量的额外空间用于变量,因为它直接对输入数组进行操作。 diff --git a/contents/questions/algo/array-smallest-in-rotated/description/en-US.langnostic.json b/contents/questions/algo/array-smallest-in-rotated/description/en-US.langnostic.json new file mode 100644 index 000000000..b8598b5b6 --- /dev/null +++ b/contents/questions/algo/array-smallest-in-rotated/description/en-US.langnostic.json @@ -0,0 +1,35 @@ +{ + "frontmatter": { + "title": "faf192ab", + "excerpt": "c9dec76a" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "e7a49443", + "fba5223a", + "9a840d3f", + "2d96efbe", + "d9c0d67b", + "d068a43f", + "b2065fc", + "8e1b5cea" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "e7a49443", + "fba5223a", + "9a840d3f", + "2d96efbe", + "d9c0d67b", + "d068a43f", + "b2065fc", + "8e1b5cea" + ] + } + } +} diff --git a/contents/questions/algo/array-smallest-in-rotated/description/zh-CN.mdx b/contents/questions/algo/array-smallest-in-rotated/description/zh-CN.mdx new file mode 100644 index 000000000..34d9ec97b --- /dev/null +++ b/contents/questions/algo/array-smallest-in-rotated/description/zh-CN.mdx @@ -0,0 +1,24 @@ +--- +title: 旋转排序数组中的最小元素 +excerpt: 实现一个函数,找到旋转排序数组中的最小元素 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个包含唯一元素的已排序和旋转的数组 `numbers`,找到并返回该数组中的最小元素。 + +旋转数组 `[a[0], a[1], a[2], ..., a[n-1]]` 一次会得到 `[a[n-1], a[0], a[1], a[2], ..., a[n-2]]`。再次旋转会得到 `[a[n-2], a[n-1], a[0], a[1], ..., a[n-3]]`。 + +开发一个时间复杂度为 O(log n) 的算法。 + +### 输入 + +- `numbers: number[]`: 整数数组 + + + +### 约束 + +- 1 <= `numbers.length` <= 1000 +- -10,000 <= `numbers[i]` <= 10,000 diff --git a/contents/questions/algo/array-smallest-in-rotated/solution/en-US.langnostic.json b/contents/questions/algo/array-smallest-in-rotated/solution/en-US.langnostic.json new file mode 100644 index 000000000..b4a82acd2 --- /dev/null +++ b/contents/questions/algo/array-smallest-in-rotated/solution/en-US.langnostic.json @@ -0,0 +1,36 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "c23a3810", + "1f3229bf", + "83dbcc47", + "55248b40", + "d735521a", + "b68df8f8", + "9a20415e", + "ac725418", + "8e2de8c8", + "dde35e8b" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "c23a3810", + "1f3229bf", + "83dbcc47", + "55248b40", + "d735521a", + "b68df8f8", + "9a20415e", + "ac725418", + "8e2de8c8", + "dde35e8b" + ] + } + } +} diff --git a/contents/questions/algo/array-smallest-in-rotated/solution/zh-CN.mdx b/contents/questions/algo/array-smallest-in-rotated/solution/zh-CN.mdx new file mode 100644 index 000000000..7775b2216 --- /dev/null +++ b/contents/questions/algo/array-smallest-in-rotated/solution/zh-CN.mdx @@ -0,0 +1,35 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import smallestInRotatedArray from '../setup/src/array-smallest-in-rotated.ts'; + +## 1. 使用修改后的二分查找 + +问题是在旋转排序数组中使用修改后的二分查找方法找到最小的元素。暴力解法将遍历数组以在 O(n) 时间内找到最小元素。但是,可以利用数组的排序性质,使用二分查找将时间复杂度降低到 O(log n)。 + +关键的见解是,在旋转排序数组中,数组的一部分始终是有序的。通过检查哪一部分是有序的,可以有效地缩小搜索空间。该算法迭代地减少搜索空间,同时跟踪到目前为止遇到的最小元素。 + +这种方法通过仅关注可能包含最小元素的部分数组来消除不必要的迭代。 + +### 算法 + +1. 将 `low` 初始化为 0,将 `high` 初始化为 `numbers.length - 1`,以表示搜索空间。 +2. 将 `ans` 初始化为 `Number.MAX_SAFE_INTEGER`,以存储到目前为止找到的最小元素。 +3. 使用循环 `while low <= high`: + * 将 `mid` 计算为 `(low + high) / 2` 的向下取整。 + * 通过比较 `numbers[low]` 和 `numbers[mid]` 来检查数组的左半部分是否已排序。 + * 如果左半部分已排序: + * 使用 `ans` 和 `numbers[low]` 中较小的值更新 `ans`。 + * 通过将 `low` 设置为 `mid + 1` 来消除左半部分。 + * 否则,右半部分必须已排序: + * 使用 `ans` 和 `numbers[mid]` 中较小的值更新 `ans`。 + * 通过将 `high` 设置为 `mid - 1` 来消除右半部分。 +4. 循环结束后,将 `ans` 作为数组中的最小元素返回。 + + + {smallestInRotatedArray} + + +### Big-O 分析 + +* **时间复杂度:O(log n)**。二分查找在每一步都将搜索空间减半,从而产生对数时间复杂度。 +* **空间复杂度:O(1)**。该算法使用常量空间用于变量,因为它直接对输入数组进行操作。 diff --git a/contents/questions/algo/binary-search-tree-kth-smallest/description/en-US.langnostic.json b/contents/questions/algo/binary-search-tree-kth-smallest/description/en-US.langnostic.json new file mode 100644 index 000000000..ce13e480c --- /dev/null +++ b/contents/questions/algo/binary-search-tree-kth-smallest/description/en-US.langnostic.json @@ -0,0 +1,37 @@ +{ + "frontmatter": { + "title": "88213ce0", + "excerpt": "28e18688" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "782e9858", + "6b6bad6a", + "c9f2b457", + "ff4afcec", + "2d96efbe", + "5b035340", + "d068a43f", + "b2065fc", + "d7d75573" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "782e9858", + "6b6bad6a", + "c9f2b457", + "ff4afcec", + "2d96efbe", + "5b035340", + "d068a43f", + "b2065fc", + "d7d75573" + ] + } + } +} diff --git a/contents/questions/algo/binary-search-tree-kth-smallest/description/zh-CN.mdx b/contents/questions/algo/binary-search-tree-kth-smallest/description/zh-CN.mdx new file mode 100644 index 000000000..be040b970 --- /dev/null +++ b/contents/questions/algo/binary-search-tree-kth-smallest/description/zh-CN.mdx @@ -0,0 +1,32 @@ +--- +title: 二叉搜索树第 K 小的元素 +excerpt: 实现一个函数,用于查找 BST 中第 k 个最小的节点 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个二叉搜索树 (BST) 的 `root` 节点和一个整数 `k`,编写一个函数来查找并返回 BST 中的第 `k` 个最小值。树中的最小值是 1。 + +二叉树由 `TreeNode` 的集合表示,其中每个节点都有可选的 `left` 和 `right` 子节点,它们也是 `TreeNode`。 + +一个 `TreeNode` 具有以下接口: + +```ts +interface TreeNode { + val: number; + left: TreeNode | null; + right: TreeNode | null; +} +``` + +### 输入 + +- `root: TreeNode`: 树的根节点。示例显示树的 [广度优先遍历](https://en.wikipedia.org/wiki/Breadth-first_search) + + + +### 约束 + +- 1 <= `k` <= 节点数 <= 1000 +- 1 <= `TreeNode.val` <= 1,000,000 diff --git a/contents/questions/algo/binary-search-tree-kth-smallest/solution/en-US.langnostic.json b/contents/questions/algo/binary-search-tree-kth-smallest/solution/en-US.langnostic.json new file mode 100644 index 000000000..7d840278e --- /dev/null +++ b/contents/questions/algo/binary-search-tree-kth-smallest/solution/en-US.langnostic.json @@ -0,0 +1,58 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "e3a077b0", + "3404f91b", + "3a0a43c0", + "3ac603b8", + "6af1efb3", + "8784f769", + "b68df8f8", + "b5ce0015", + "1a352393", + "8e2de8c8", + "1c6e91f9", + "ce6bcb79", + "974f62e2", + "acab6710", + "2ad8582d", + "e69abc76", + "b68df8f8", + "a7cfb2ed", + "98b819fd", + "8e2de8c8", + "9a1718f8" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "e3a077b0", + "3404f91b", + "3a0a43c0", + "3ac603b8", + "6af1efb3", + "8784f769", + "b68df8f8", + "b5ce0015", + "1a352393", + "8e2de8c8", + "1c6e91f9", + "ce6bcb79", + "974f62e2", + "acab6710", + "2ad8582d", + "e69abc76", + "b68df8f8", + "a7cfb2ed", + "98b819fd", + "8e2de8c8", + "9a1718f8" + ] + } + } +} diff --git a/contents/questions/algo/binary-search-tree-kth-smallest/solution/zh-CN.mdx b/contents/questions/algo/binary-search-tree-kth-smallest/solution/zh-CN.mdx new file mode 100644 index 000000000..5592c1df3 --- /dev/null +++ b/contents/questions/algo/binary-search-tree-kth-smallest/solution/zh-CN.mdx @@ -0,0 +1,67 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import kthSmallestElementInABst from '../setup/src/binary-search-tree-kth-smallest.ts'; +import kthSmallestElementInABstIteration from '../setup/src/binary-search-tree-kth-smallest-iteration.ts'; + +## 1. 使用递归 + +在二叉搜索树 (BST) 中查找第 `k` 个最小元素的这个问题使用了中序遍历的属性。BST 的中序遍历按照节点值的升序访问节点。利用此属性,该算法按排序顺序收集节点值并直接检索第 `k` 个最小值。 + +中序遍历确保 BST 的值按升序访问。通过遍历左子树,然后是当前节点,最后是右子树,该算法系统地收集排序后的值。 + +该算法递归地遍历 BST,在此过程中将节点值附加到数组中。此数组包含所有按升序排列的节点值。 + +由于数组已排序,第 `k` 个最小元素对应于索引 `k-1` 处的元素,因为索引是从零开始的。这使得检索效率很高。 + +### 算法 + +1. 定义一个辅助函数 `inorderTraversal`,该函数: + 1. 接受一个节点 `root` 和一个数组 `arr` 作为输入。 + 2. 检查当前节点是否为 `null`。如果为真,则返回数组。 + 3. 通过在 `root.left` 上调用 `inorderTraversal` 来递归遍历左子树。 + 4. 将当前节点的值附加到数组中。 + 5. 通过在 `root.right` 上调用 `inorderTraversal` 来递归遍历右子树。 + 6. 返回按排序顺序收集的值的数组。 +2. 在 BST 的根节点上调用 `inorderTraversal`,并使用一个空数组来获取所有按排序顺序排列的节点值。 +3. 通过访问排序数组的 `(k-1)`-th 索引来检索第 `k` 个最小元素。 +4. 将此值作为结果返回。 + + + {kthSmallestElementInABst} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。中序遍历正好访问每个节点一次。 +* **空间复杂度:O(n)**。数组存储所有节点值,递归堆栈也可能使用高达 O(h) 的空间,其中 `h` 是 BST 的高度。 + +## 2. 使用迭代 + +用于在二叉搜索树 (BST) 中查找第 `k` 个最小元素的迭代方法使用中序遍历,该遍历按升序访问节点。与递归方法不同,此方法使用堆栈来管理遍历,避免递归并减少调用堆栈的使用。 + +中序遍历按升序处理 BST 的节点。通过遍历左子树,访问根节点,然后遍历右子树,节点按排序顺序依次访问。 + +该算法没有遍历整个树,而是跟踪已访问的节点数 (`k`),并在找到第 `k` 个最小节点后停止。这种优化确保了效率。 + +迭代方法避免了递归的开销,并使用堆栈来管理遍历,堆栈大小与树的高度成正比。 + +### 算法 + +1. 初始化一个空堆栈以在遍历期间存储节点。 +2. 当 `true`(无限循环)时: + 1. 遍历到最左边的节点: + * 将当前 `root` 节点推入堆栈。 + * 移动到左子节点 (`root = root.left`)。 + 2. 弹出堆栈顶部的节点: + * 将弹出的节点分配给 `root`。 + 3. 递减 `k`。如果 `k` 变为 `0`,则返回当前节点的值 (`root.val`)。 + 4. 移动到右子树 (`root = root.right`)。 + + + {kthSmallestElementInABstIteration} + + +### Big-O 分析 + +* **时间复杂度:O(h + k)**。该算法最多访问 `k` 个节点,并在最左边的遍历中探索最大深度 `h`(树的高度)。 +* **空间复杂度:O(h)**。堆栈存储沿通往最左边节点的路径的节点,这与树的高度成正比。 diff --git a/contents/questions/algo/binary-search-tree-lowest-common-ancestor/description/en-US.langnostic.json b/contents/questions/algo/binary-search-tree-lowest-common-ancestor/description/en-US.langnostic.json new file mode 100644 index 000000000..71fe3418e --- /dev/null +++ b/contents/questions/algo/binary-search-tree-lowest-common-ancestor/description/en-US.langnostic.json @@ -0,0 +1,43 @@ +{ + "frontmatter": { + "title": "d1b7539", + "excerpt": "b65b9835" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "231d9313", + "809445d1", + "6b6bad6a", + "c9f2b457", + "ff4afcec", + "2d96efbe", + "579ee4b6", + "662802c0", + "1b15b5a7", + "d068a43f", + "b2065fc", + "5436b830" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "231d9313", + "809445d1", + "6b6bad6a", + "c9f2b457", + "ff4afcec", + "2d96efbe", + "579ee4b6", + "662802c0", + "1b15b5a7", + "d068a43f", + "b2065fc", + "5436b830" + ] + } + } +} diff --git a/contents/questions/algo/binary-search-tree-lowest-common-ancestor/description/zh-CN.mdx b/contents/questions/algo/binary-search-tree-lowest-common-ancestor/description/zh-CN.mdx new file mode 100644 index 000000000..f5b3fad66 --- /dev/null +++ b/contents/questions/algo/binary-search-tree-lowest-common-ancestor/description/zh-CN.mdx @@ -0,0 +1,42 @@ +--- +title: 二叉搜索树的最低公共祖先 +excerpt: 实现一个函数,以找到二叉搜索树中的 LCA +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定二叉搜索树 (BST) 的 `root`,确定树中两个指定节点的最低公共祖先 (LCA)。 + +LCA 是树中同时拥有给定两个节点作为后代的最低节点。根据 LCA 的标准定义,一个节点可以被认为是其自身的后代。 + +二叉树由 `TreeNode` 的集合表示,其中每个节点都有可选的 `left` 和 `right` 子节点,它们也是 `TreeNode`。 + +一个 `TreeNode` 具有以下接口: + +```ts +interface TreeNode { + val: number; + left: TreeNode | null; + right: TreeNode | null; +} +``` + +### 输入 + +- `root: TreeNode`: 树的根节点。示例显示树的 [层序遍历](https://en.wikipedia.org/wiki/Breadth-first_search) +- `a: TreeNode`: 第一个树节点。示例显示节点的值 +- `b: TreeNode`: 第二个树节点。示例显示节点的值 + +### 输出 + +- 一个 `TreeNode` 对象,它是 `a` 和 `b` 的 LCA + + + +### 约束 + +- 1 <= 节点数 <= 1000 +- 1 <= `TreeNode.val` <= 1,000,000 +- 保证 `a` 和 `b` 存在于 BST 中 +- 所有 `TreeNode.val` 在树中都是唯一的 diff --git a/contents/questions/algo/binary-search-tree-lowest-common-ancestor/solution/en-US.langnostic.json b/contents/questions/algo/binary-search-tree-lowest-common-ancestor/solution/en-US.langnostic.json new file mode 100644 index 000000000..d6372de84 --- /dev/null +++ b/contents/questions/algo/binary-search-tree-lowest-common-ancestor/solution/en-US.langnostic.json @@ -0,0 +1,62 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "bda33695", + "3404f91b", + "e041b858", + "82a62b43", + "f4bb27d1", + "947d412f", + "9fd64821", + "b68df8f8", + "9590cc93", + "7bc1c0de", + "8e2de8c8", + "bf878bb8", + "ce6bcb79", + "46a644dc", + "276f5c5d", + "1359d730", + "43da798e", + "3d2d5537", + "b68df8f8", + "53085cbb", + "699bb6a1", + "8e2de8c8", + "abec34ff" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "bda33695", + "3404f91b", + "e041b858", + "82a62b43", + "f4bb27d1", + "947d412f", + "9fd64821", + "b68df8f8", + "9590cc93", + "7bc1c0de", + "8e2de8c8", + "bf878bb8", + "ce6bcb79", + "46a644dc", + "276f5c5d", + "1359d730", + "43da798e", + "3d2d5537", + "b68df8f8", + "53085cbb", + "699bb6a1", + "8e2de8c8", + "abec34ff" + ] + } + } +} diff --git a/contents/questions/algo/binary-search-tree-lowest-common-ancestor/solution/zh-CN.mdx b/contents/questions/algo/binary-search-tree-lowest-common-ancestor/solution/zh-CN.mdx new file mode 100644 index 000000000..ee4da167a --- /dev/null +++ b/contents/questions/algo/binary-search-tree-lowest-common-ancestor/solution/zh-CN.mdx @@ -0,0 +1,70 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import lowestCommonAncestorOfABinarySearchTree from '../setup/src/binary-search-tree-lowest-common-ancestor.ts'; +import lowestCommonAncestorOfABinarySearchTreeIteration from '../setup/src/binary-search-tree-lowest-common-ancestor-iteration.ts'; + +## 1. 使用递归 + +在二叉搜索树 (BST) 中寻找最近公共祖先 (LCA) 的问题利用了 BST 的有序属性。 LCA 是一个节点,其中一个节点 (`a`) 位于当前节点的一侧,而另一个节点 (`b`) 位于另一侧,或者当前节点本身是要搜索的节点之一。 + +对于 BST 中的任何节点,左子树中的所有值都较小,右子树中的所有值都较大。 此属性简化了查找 LCA 的过程。 + +该算法检查 `a` 和 `b` 的值相对于当前节点 (`root`) 的值。 + +* 如果两个值都大于当前节点的值,则 LCA 必须位于右子树中。 +* 如果两个值都较小,则 LCA 必须位于左子树中。 +* 如果一个值在左侧,另一个值在右侧(或者其中一个节点与当前节点匹配),则当前节点是 LCA。 + +该算法根据 `a` 和 `b` 的相对值递归遍历树,直到找到 LCA。 + +### 算法 + +1. 检查基本情况: + * 如果 `root` 为 `null`,则返回 `null`,因为没有祖先。 +2. 检索当前节点 (`parentVal`)、`a` (`aVal`) 和 `b` (`bVal`) 的值。 +3. 将 `aVal` 和 `bVal` 与 `parentVal` 进行比较: + 1. 如果 `aVal` 和 `bVal` 都大于 `parentVal`,则使用右子树 (`root.right`) 作为新根递归调用该函数。 + 2. 如果 `aVal` 和 `bVal` 都小于 `parentVal`,则使用左子树 (`root.left`) 作为新根递归调用该函数。 + 3. 如果一个值在左侧,另一个值在右侧,或者一个值与 `parentVal` 匹配,则返回当前节点 (`root`) 作为 LCA。 + + + {lowestCommonAncestorOfABinarySearchTree} + + +### Big-O 分析 + +* **时间复杂度:O(h)**。 该算法遍历树的高度,其中 `h` 是 BST 的高度。 在平衡的 BST 中,这是 O(log n),在最坏的情况下(不平衡树),这是 O(n)。 +* **空间复杂度:O(h)**。 递归堆栈需要与树的高度成比例的空间。 + +## 2. 使用迭代 + +在二叉搜索树 (BST) 中寻找最近公共祖先 (LCA) 的迭代方法使用 BST 的属性,无需递归即可从根节点导航到 LCA。 LCA 被标识为两个节点 (`a` 和 `b`) 的路径发散或其中一个节点与当前节点匹配的节点。 + +在 BST 中,左子树中的所有值都小于根,右子树中的所有值都大于根。 此属性有助于确定遍历方向: + +* 如果 `a` 和 `b` 都小于当前节点,则 LCA 位于左子树中。 +* 如果 `a` 和 `b` 都大于当前节点,则 LCA 位于右子树中。 +* 如果一个节点在左侧,另一个节点在右侧,或者一个节点与当前节点匹配,则当前节点是 LCA。 + +该算法通过基于比较迭代移动指针 (`node`) 来消除递归,从而保持效率和简单性。 + +找到 LCA 后,遍历立即停止,避免了不必要的操作。 + +### 算法 + +1. 检索 `a` 和 `b` 的值 (`aVal` 和 `bVal`)。 +2. 将指针 `node` 初始化为 BST 的根。 +3. 使用 `while` 循环遍历 BST,直到 `node` 为 `null`: + 1. 检索当前节点的值 (`parentVal`)。 + 2. 将 `aVal` 和 `bVal` 与 `parentVal` 进行比较: + * 如果两者都大于 `parentVal`,则将 `node` 移动到右子节点 (`node = node.right`)。 + * 如果两者都小于 `parentVal`,则将 `node` 移动到左子节点 (`node = node.left`)。 + * 否则,当前节点是 LCA;返回它。 +4. 如果未找到 LCA(边缘情况),则返回 `null`。 + + {lowestCommonAncestorOfABinarySearchTreeIteration} + +### Big-O 分析 + +* **时间复杂度:O(h)**。该算法遍历树的高度,其中 `h` 是 BST 的高度。在平衡 BST 中,这是 O(log n),在最坏情况下(不平衡树),这是 O(n)。 +* **空间复杂度:O(1)**。该算法使用恒定的空间量,因为没有递归或辅助数据结构。 diff --git a/contents/questions/algo/binary-search-tree-validate/description/en-US.langnostic.json b/contents/questions/algo/binary-search-tree-validate/description/en-US.langnostic.json new file mode 100644 index 000000000..9c116fbaa --- /dev/null +++ b/contents/questions/algo/binary-search-tree-validate/description/en-US.langnostic.json @@ -0,0 +1,41 @@ +{ + "frontmatter": { + "title": "2aa35d9", + "excerpt": "b03d468" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "6b120d3b", + "305a4270", + "54999ee2", + "6b6bad6a", + "c9f2b457", + "ff4afcec", + "2d96efbe", + "2dfde09", + "d068a43f", + "b2065fc", + "a86e3050" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "6b120d3b", + "305a4270", + "54999ee2", + "6b6bad6a", + "c9f2b457", + "ff4afcec", + "2d96efbe", + "2dfde09", + "d068a43f", + "b2065fc", + "a86e3050" + ] + } + } +} diff --git a/contents/questions/algo/binary-search-tree-validate/description/zh-CN.mdx b/contents/questions/algo/binary-search-tree-validate/description/zh-CN.mdx new file mode 100644 index 000000000..945c95fb1 --- /dev/null +++ b/contents/questions/algo/binary-search-tree-validate/description/zh-CN.mdx @@ -0,0 +1,38 @@ +--- +title: 验证二叉搜索树 +excerpt: 实现一个函数来验证二叉树是否为有效的二叉搜索树 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个二叉树的`root`,确定它是否是一个有效的二叉搜索树(BST)。 + +为了使树符合有效的BST的条件,它必须满足以下条件: + +- 节点的左子树只包含值小于该节点值的节点 +- 节点的右子树只包含值大于该节点值的节点 +- 左子树和右子树也都是有效的BST + +二叉树由`TreeNode`的集合表示,其中每个节点都有可选的`left`和`right`子节点,它们也是`TreeNode`。 + +一个`TreeNode`有以下接口: + +```ts +interface TreeNode { + val: number; + left: TreeNode | null; + right: TreeNode | null; +} +``` + +### 输入 + +- `root: TreeNode`: 树的根节点。示例显示树的[层序遍历](https://en.wikipedia.org/wiki/Breadth-first_search) + + + +### 约束 + +- 1 <= 节点数 <= 1000 +- -1,000,000 <= `TreeNode.val` <= 1,000,000 diff --git a/contents/questions/algo/binary-search-tree-validate/solution/en-US.langnostic.json b/contents/questions/algo/binary-search-tree-validate/solution/en-US.langnostic.json new file mode 100644 index 000000000..357064c2e --- /dev/null +++ b/contents/questions/algo/binary-search-tree-validate/solution/en-US.langnostic.json @@ -0,0 +1,64 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "18285bbd", + "3404f91b", + "17ffb33d", + "a02f26ea", + "74d2cb07", + "634754eb", + "dd674218", + "b68df8f8", + "dfcc3959", + "d6875574", + "8e2de8c8", + "a4e87909", + "ce6bcb79", + "d19f909e", + "e9e5de48", + "ba71fb00", + "65a76ee8", + "8efb2ec", + "75914ad4", + "b68df8f8", + "564c417d", + "5329a8f7", + "8e2de8c8", + "2d720abf" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "18285bbd", + "3404f91b", + "17ffb33d", + "a02f26ea", + "74d2cb07", + "634754eb", + "dd674218", + "b68df8f8", + "dfcc3959", + "d6875574", + "8e2de8c8", + "a4e87909", + "ce6bcb79", + "d19f909e", + "e9e5de48", + "ba71fb00", + "65a76ee8", + "8efb2ec", + "75914ad4", + "b68df8f8", + "564c417d", + "5329a8f7", + "8e2de8c8", + "2d720abf" + ] + } + } +} diff --git a/contents/questions/algo/binary-search-tree-validate/solution/zh-CN.mdx b/contents/questions/algo/binary-search-tree-validate/solution/zh-CN.mdx new file mode 100644 index 000000000..b59c0a515 --- /dev/null +++ b/contents/questions/algo/binary-search-tree-validate/solution/zh-CN.mdx @@ -0,0 +1,82 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import binarySearchTreeValidate from '../setup/src/binary-search-tree-validate.ts'; +import binarySearchTreeValidateIteration from '../setup/src/binary-search-tree-validate-iteration.ts'; + +## 1. 使用递归 + +验证二叉搜索树(BST)的问题确保了对于每个节点,左子树中所有节点的值都较小,而右子树中所有节点的值都较大。这种递归方法利用范围检查来验证 BST 属性。 + +对于每个节点,都会维护一个范围: + +* 节点的值必须位于其祖先定义的范围内。 +* 对于左子节点,范围更新为 `[minAllowed, node.val)`。 +* 对于右子节点,范围更新为 `(node.val, maxAllowed]`。 + +该算法递归地检查每个节点,确保它位于其允许的范围内。如果任何节点违反范围约束,则该树不是有效的 BST。 + +该算法正好遍历每个节点一次,并通过递归调用传播范围约束来确保正确性。 + +### 算法 + +1. 定义一个辅助函数 `checkNodeInRange`,它: + * 接受 `node`、`minAllowed` 和 `maxAllowed` 作为参数。 + * 如果节点及其子树满足 BST 属性,则返回 `true`。 +2. 对于每个节点: + 1. 如果 `node` 为 `null`,则返回 `true`(递归的基本情况)。 + 2. 检查 `node.val` 是否在 `minAllowed` 和 `maxAllowed` 定义的范围之外。如果为真,则返回 `false`。 + 3. 递归地使用范围 `[minAllowed, node.val)` 验证左子树。 + 4. 递归地使用范围 `(node.val, maxAllowed]` 验证右子树。 + 5. 仅当左右子树都有效时才返回 `true`。 +3. 从根节点开始验证,范围为 `[-Infinity, Infinity]`。 +4. 返回辅助函数的结果。 + + + {binarySearchTreeValidate} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。每个节点只访问一次。 +* **空间复杂度:O(h)**。递归堆栈需要的空间与树的高度成正比,其中 `h` 是 BST 的高度。 + +## 2. 使用迭代 + +用于验证二叉搜索树(BST)的迭代方法确保所有节点都符合 BST 属性:左子树中的所有值都小于根,右子树中的所有值都大于根。此解决方案使用堆栈来管理节点及其在遍历期间对应的有效值范围。 + +每个节点都与一个范围(`low` 和 `high`)相关联,该范围表示基于其祖先的允许值。 + +* 对于左子节点,范围更新为 `[low, node.val)`。 +* 对于右子节点,范围更新为 `(node.val, high]`。 + +堆栈用于维护尚未验证的节点及其有效范围。迭代过程避免了递归,并确保所有节点都按照 BST 规则进行验证。 + +对于每个节点,将其值与其分配的范围进行比较。如果该值违反了范围约束,则该树无效。 + +该算法正好处理每个节点一次,并使用堆栈来管理遍历,使其具有时间和空间效率。 + +### 算法 + +1. 初始化三个栈: + * `stack` 用于存储节点。 + * `lowerLimits` 用于存储每个节点的下限范围。 + * `upperLimits` 用于存储每个节点的上限范围。 +2. 定义一个辅助函数 `update`,该函数将: + * 将一个节点及其更新后的范围 (`low`, `high`) 推入各自的栈中。 +3. 将根节点推入栈中,初始限制为 `null`(无约束)。 +4. 当 `stack` 不为空时: + 1. 弹出顶部节点及其对应的范围 (`low`, `high`)。 + 2. 如果节点为 `null`,则跳过。 + 3. 验证节点的值: + * 检查该值是否小于或等于 `low` 或大于或等于 `high`。 + * 如果违反任何条件,则返回 `false`。 + 4. 将右子节点推入栈中,更新限制为 `[node.val, high]`。 + 5. 将左子节点推入栈中,更新限制为 `[low, node.val]`。 +5. 如果未发现违规行为,则返回 `true`。 + + {binarySearchTreeValidateIteration} + +### Big-O 分析 + +* **时间复杂度:O(n)**。每个节点只处理一次。 +* **空间复杂度:O(h)**。栈最多同时容纳 `h` 个节点,其中 `h` 是树的高度。 diff --git a/contents/questions/algo/binary-search-tree/description/en-US.langnostic.json b/contents/questions/algo/binary-search-tree/description/en-US.langnostic.json new file mode 100644 index 000000000..dc12dfecb --- /dev/null +++ b/contents/questions/algo/binary-search-tree/description/en-US.langnostic.json @@ -0,0 +1,25 @@ +{ + "frontmatter": { + "title": "edcbb7a6", + "excerpt": "35b145b1" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "8a87fe72", + "5db9c604", + "493e8bd0", + "92da4ea9" + ] + }, + "targets": { + "zh-CN": [ + "8a87fe72", + "5db9c604", + "493e8bd0", + "92da4ea9" + ] + } + } +} diff --git a/contents/questions/algo/binary-search-tree/description/zh-CN.mdx b/contents/questions/algo/binary-search-tree/description/zh-CN.mdx new file mode 100644 index 000000000..1982340ff --- /dev/null +++ b/contents/questions/algo/binary-search-tree/description/zh-CN.mdx @@ -0,0 +1,23 @@ +--- +title: 二叉搜索树 +excerpt: 实现一个二叉搜索树数据结构,包括基本的 BST 操作 +--- + +实现一个支持以下操作的二叉搜索树 (BST) 数据结构: + +* `new BST()`:创建一个 BST 类的实例。它将根节点初始化为 `null`,因为最初树中没有节点。 +* `insert(value)`:将一个新值添加到 BST 中。新值被插入到正确的位置以保持二叉搜索树的顺序。如果树为空,则新值成为根节点。所需的时间复杂度:平均为 O(log n),但在树变成线性链的最坏情况下可能会降低到 O(n)。 +* `search(value)`:在 BST 中搜索一个值。如果该值存在于树中,则返回 `true`;否则,返回 `false`。此操作也遵循平均时间复杂度 O(log n),但在最坏情况下可能变为 O(n)。 +* `delete(value)`:如果存在,则从 BST 中删除一个值。此方法需要处理三种情况:删除没有子节点的节点、一个子节点的节点或两个子节点的节点。该函数在删除后保持 BST 的属性。所需的时间复杂度:平均为 O(log n),但在最坏情况下可能为 O(n)。 + +## 例子 + +```js +const bst = new BST(); +bst.insert(15); +bst.insert(10); +bst.insert(20); +bst.search(10); // true +bst.delete(10); +bst.search(10); // false +``` diff --git a/contents/questions/algo/binary-search-tree/solution/en-US.langnostic.json b/contents/questions/algo/binary-search-tree/solution/en-US.langnostic.json new file mode 100644 index 000000000..2305879d8 --- /dev/null +++ b/contents/questions/algo/binary-search-tree/solution/en-US.langnostic.json @@ -0,0 +1,46 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "1c9acc90", + "26e3ffe5", + "b860ee63", + "e5929936", + "b9e8a2fa", + "9510cf40", + "4a13908c", + "6da6ae9b", + "f21938cc", + "d4004604", + "499e5031", + "a993b036", + "d87b3100", + "e860de94", + "23ca46e9" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "1c9acc90", + "26e3ffe5", + "b860ee63", + "e5929936", + "b9e8a2fa", + "9510cf40", + "4a13908c", + "6da6ae9b", + "f21938cc", + "d4004604", + "499e5031", + "a993b036", + "d87b3100", + "e860de94", + "23ca46e9" + ] + } + } +} diff --git a/contents/questions/algo/binary-search-tree/solution/zh-CN.mdx b/contents/questions/algo/binary-search-tree/solution/zh-CN.mdx new file mode 100644 index 000000000..90ebe5b27 --- /dev/null +++ b/contents/questions/algo/binary-search-tree/solution/zh-CN.mdx @@ -0,0 +1,41 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import binarySearchTreeJs from '../setup/src/binary-search-tree.js'; +import binarySearchTreeTs from '../setup/src/binary-search-tree.ts'; + +## 解决方案 + +二叉搜索树 (BST) 是计算机科学中的一种基本数据结构,主要用于以排序顺序维护动态变化的数据集。BST 中的每个节点都包含一个键和指向其左子节点和右子节点的指针。该树的结构使得对于任何给定的节点,其左子树中的所有节点都具有小于该节点键的键,并且其右子树中的所有节点都具有大于该节点键的键。此属性支持高效的搜索、插入和删除操作。 + + + +### 操作 + +* `new BST()`:初始化 BST 的新实例。构造函数将树的根设置为 null,表示树最初为空。 +* `insert(value)`:将具有给定值的节点添加到 BST。如果树为空,则新节点将成为根。如果不是,则从根开始遍历树,以找到新节点以维护 BST 属性的正确位置。此操作涉及将新值与当前节点的值进行比较,并决定向左或向右移动。平均时间复杂度为 O(log n),但如果按升序/降序插入值,则可能会降低到 O(n)。 + +![Insert](/img/questions/binary-search-tree/insert.png) + +* `search(value)`:搜索包含指定值的节点。从根开始,根据目标值与当前节点的值的比较结果,向左或向右遍历树。重复此过程,直到找到该值或到达叶子。与 `insert(value)` 类似,平均时间复杂度为 O(log n),最坏情况为 O(n)。 +* `delete(value)`:从 BST 中删除具有指定值的节点。此操作更为复杂,因为它需要处理三种情况: + * 叶节点:直接删除该节点。 + * 具有一个子节点的节点:删除该节点并将其替换为其子节点。 + * 具有两个子节点的节点:将节点的值替换为右子树中的最小值,然后删除后继节点。 + +![Delete](/img/questions/binary-search-tree/delete.png) + +删除过程确保在删除节点后维护 BST 属性。与插入类似,时间复杂度平均为 O(log n),但可能变为 O(n)。 + +## 边缘情况 + +* 插入树中已存在的值。 +* 从空树或不存在的值中删除节点。 +* 搜索树中不存在的值。 +* 删除二叉搜索树中的重复值。 + +## 技术 + +* **中序遍历**:在删除操作期间用于查找后继节点。 +* **面向对象设计**:使用 Node 类表示每个树节点,并使用 BST 类进行树操作,从而提供清晰的结构和封装。 + +此二叉搜索树实现使用迭代解决方案,而 `delete(value)` 的递归解决方案可能更容易实现。 diff --git a/contents/questions/algo/binary-search/description/en-US.langnostic.json b/contents/questions/algo/binary-search/description/en-US.langnostic.json new file mode 100644 index 000000000..122c65657 --- /dev/null +++ b/contents/questions/algo/binary-search/description/en-US.langnostic.json @@ -0,0 +1,31 @@ +{ + "frontmatter": { + "title": "3097c26d", + "excerpt": "4714eb14" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "904d3910", + "493e8bd0", + "a70bd1d9", + "a8f76cea", + "d59db749", + "6c43a243", + "653fdfc8" + ] + }, + "targets": { + "zh-CN": [ + "904d3910", + "493e8bd0", + "a70bd1d9", + "a8f76cea", + "d59db749", + "6c43a243", + "653fdfc8" + ] + } + } +} diff --git a/contents/questions/algo/binary-search/description/zh-CN.mdx b/contents/questions/algo/binary-search/description/zh-CN.mdx new file mode 100644 index 000000000..8b60eeef9 --- /dev/null +++ b/contents/questions/algo/binary-search/description/zh-CN.mdx @@ -0,0 +1,25 @@ +--- +title: 二分查找 +excerpt: 实现一个对数字数组执行二分查找的函数 +--- + +实现一个对数字数组执行二分查找的函数。该函数应接收一个已排序的整数数组和一个要查找的目标整数。如果目标元素不存在于数组中,则返回目标元素的索引或 -1。 + +## 例子 + +```js +binarySearch([1, 2, 3, 6, 9, 11], 6); // 3 +binarySearch([1, 2, 3, 12, 14, 16], 5); // -1 +``` + +## 回顾 + +二分查找是一种搜索算法,可以有效地确定已排序的整数数组是否包含特定数字。该算法将输入数组重复地分成两半,直到找到目标元素,从而使搜索空间每一步都减少一半。与线性搜索相比,这是一个显着的改进。 + +以下是关于二分查找在已排序数组上如何工作的快速说明: + +1. 计算数组的中间索引并检索中间元素。 +2. 如果目标元素大于中间元素,则搜索数组的右半部分(忽略左半部分)。 +3. 如果目标元素小于中间元素,则搜索数组的左半部分。 +4. 如果目标元素等于中间元素,则返回该元素的索引。 +5. 重复上述步骤,直到我们完成搜索。如果未找到目标,则返回 -1。 diff --git a/contents/questions/algo/binary-search/solution/en-US.langnostic.json b/contents/questions/algo/binary-search/solution/en-US.langnostic.json new file mode 100644 index 000000000..d39dc0bb9 --- /dev/null +++ b/contents/questions/algo/binary-search/solution/en-US.langnostic.json @@ -0,0 +1,58 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "78be3f2b", + "2a15dc20", + "4cd64b66", + "ef0e1931", + "4ad9b0dc", + "26e3ffe5", + "ec438fc2", + "6658f3d1", + "a9fb3bf9", + "1589c220", + "499e5031", + "bf768069", + "c998b811", + "a34a2355", + "bb1b042d", + "a7d4847f", + "2a1103ac", + "dbb47b5", + "5b6426bb", + "47800b92", + "73325036" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "78be3f2b", + "2a15dc20", + "4cd64b66", + "ef0e1931", + "4ad9b0dc", + "26e3ffe5", + "ec438fc2", + "6658f3d1", + "a9fb3bf9", + "1589c220", + "499e5031", + "bf768069", + "c998b811", + "a34a2355", + "bb1b042d", + "a7d4847f", + "2a1103ac", + "dbb47b5", + "5b6426bb", + "47800b92", + "73325036" + ] + } + } +} diff --git a/contents/questions/algo/binary-search/solution/zh-CN.mdx b/contents/questions/algo/binary-search/solution/zh-CN.mdx new file mode 100644 index 000000000..9082f2c0d --- /dev/null +++ b/contents/questions/algo/binary-search/solution/zh-CN.mdx @@ -0,0 +1,51 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import binarySearchJs from '../setup/src/binary-search.js'; +import binarySearchTs from '../setup/src/binary-search.ts'; +import binarySearchRecursive from '../setup/src/binarySearchRecursive'; + +二分查找是一种高效的搜索算法,它在每一步都将搜索空间减半,这意味着它可以在 O(log(n)) 时间内找到目标元素,其中 n 是输入数组的大小。这使得它比线性搜索快得多,线性搜索的时间复杂度为 O(n)。 + +## 澄清问题 + +如果未指定: + +* 排序顺序:是升序还是降序? +* 我们需要处理什么样的输入? + * 它只是一个整数数组,还是我们应该处理其他数据类型? + * 是否有重复的元素? + * 应该如何处理负数? + +## 解决方案 + +注意:这个问题处理的是一个标准的二分查找,它使用迭代方法,并假设数组已经排序。有关其他替代方案,请参阅“注释”部分。 + + + +如果面试官要求使用递归方法: + + + {binarySearchRecursive} + + +## 边缘情况 + +* 非整数元素输入:如果输入数组包含不同数据类型的元素,您可能需要返回一个错误,以尽力而为的方式进行排序,例如,仅对输入数据的子集进行排序,甚至为非整数定义自定义比较函数。 + +## Big-O 分析 + +让我们分析一下算法的时间和空间复杂度。 + +### 时间复杂度 + +二分查找在平均和最坏情况下的时间复杂度为 O(log(n)),因为它每一步都将搜索空间减半。即使在目标元素不在数组中的最坏情况下,它仍然将搜索空间减半,因此在对数时间内完成搜索。 + +在最佳情况下,二分查找的时间复杂度为 O(1)。当目标元素恰好位于输入数组的中间索引时,就会发生这种情况。 + +但是,二分查找假设输入数组已排序。如果需要排序,则需要额外的时间复杂度,具体取决于所选的排序算法。 + +### 空间复杂度 + +二分查找在所有情况下,迭代方法的时间复杂度为 O(1),因为它使用恒定的额外内存来存储变量。除了输入之外,我们不保留额外的内存。 + +但是,如果使用递归方法,空间复杂度取决于递归调用堆栈所需的空间。由于递归树的高度是 log(n) + 1,并且在每一层只有一个递归调用,我们预计空间复杂度为 O(log(n))。 diff --git a/contents/questions/algo/binary-tree-equal/description/en-US.langnostic.json b/contents/questions/algo/binary-tree-equal/description/en-US.langnostic.json new file mode 100644 index 000000000..d7467a9fa --- /dev/null +++ b/contents/questions/algo/binary-tree-equal/description/en-US.langnostic.json @@ -0,0 +1,39 @@ +{ + "frontmatter": { + "title": "a27f1bc1", + "excerpt": "bed53d39" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "da89faf6", + "376e22dc", + "6b6bad6a", + "c9f2b457", + "ff4afcec", + "2d96efbe", + "e0ad6ab5", + "d068a43f", + "b2065fc", + "56c1dafc" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "da89faf6", + "376e22dc", + "6b6bad6a", + "c9f2b457", + "ff4afcec", + "2d96efbe", + "e0ad6ab5", + "d068a43f", + "b2065fc", + "56c1dafc" + ] + } + } +} diff --git a/contents/questions/algo/binary-tree-equal/description/zh-CN.mdx b/contents/questions/algo/binary-tree-equal/description/zh-CN.mdx new file mode 100644 index 000000000..9bfb4f9e6 --- /dev/null +++ b/contents/questions/algo/binary-tree-equal/description/zh-CN.mdx @@ -0,0 +1,35 @@ +--- +title: 二叉树相等 +excerpt: 实现一个函数来确定两个二叉树是否相等 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定两棵二叉树的根节点`a`和`b`,确定这两棵树是否相等。 + +如果两棵二叉树具有相同的结构,并且两棵树中对应的节点具有相同的值,则认为它们相等。 + +二叉树由`TreeNode`的集合表示,其中每个节点都有可选的`left`和`right`子节点,它们也是`TreeNode`。 + +一个`TreeNode`具有以下接口: + +```ts +interface TreeNode { + val: number; + left: TreeNode | null; + right: TreeNode | null; +} +``` + +### 输入 + +- `a: TreeNode`: 第一棵树的根节点。示例显示树的[层序遍历](https://en.wikipedia.org/wiki/Breadth-first_search) +- `b: TreeNode`: 第二棵树的根节点。示例显示树的[层序遍历](https://en.wikipedia.org/wiki/Breadth-first_search) + + + +### 约束 + +- 0 <= 节点数 <= 100 +- -10,000 <= `TreeNode.val` <= 10,000 diff --git a/contents/questions/algo/binary-tree-equal/solution/en-US.langnostic.json b/contents/questions/algo/binary-tree-equal/solution/en-US.langnostic.json new file mode 100644 index 000000000..1a1fc0914 --- /dev/null +++ b/contents/questions/algo/binary-tree-equal/solution/en-US.langnostic.json @@ -0,0 +1,52 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "a60dc173", + "bef8478e", + "8070eb35", + "a32b22ff", + "895afb4b", + "b68df8f8", + "6264f85e", + "d72ee09d", + "8e2de8c8", + "40d62a4d", + "f793d1f1", + "8b2617b7", + "7dfe7ceb", + "b68df8f8", + "21c5db16", + "f70bb280", + "8e2de8c8", + "a8aed387" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "a60dc173", + "bef8478e", + "8070eb35", + "a32b22ff", + "895afb4b", + "b68df8f8", + "6264f85e", + "d72ee09d", + "8e2de8c8", + "40d62a4d", + "f793d1f1", + "8b2617b7", + "7dfe7ceb", + "b68df8f8", + "21c5db16", + "f70bb280", + "8e2de8c8", + "a8aed387" + ] + } + } +} diff --git a/contents/questions/algo/binary-tree-equal/solution/zh-CN.mdx b/contents/questions/algo/binary-tree-equal/solution/zh-CN.mdx new file mode 100644 index 000000000..8923c6c82 --- /dev/null +++ b/contents/questions/algo/binary-tree-equal/solution/zh-CN.mdx @@ -0,0 +1,59 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import binaryTreeEqual from '../setup/src/binary-tree-equal.ts'; +import binaryTreeEqualIterative from '../setup/src/binary-tree-equal-stack.ts'; + +## 1. 递归 + +检查两个二叉树是否相同的问题涉及逐个比较两个树的结构和值。递归方法通过将其分解为左右子树的较小子问题来简化此过程。 + +该方法首先检查基本情况:如果两个节点都为 null,则树在该点上相同,但如果一个节点为 null 而另一个节点不为 null,或者它们的值不同,则树不相同。然后它执行递归检查,比较两棵树的左子树和两棵树的右子树。仅当左右子树都相同时,才认为树相同。一旦所有对应的节点都已比较或发现不匹配,递归就会终止。 + +这种方法确保检查每个节点的结构和值。 + +### 算法 + +1. 检查基本情况: + 1. 如果 `a` 和 `b` 都为 `null`,则返回 `true`,因为树在该点上相同。 + 2. 如果 `a` 或 `b` 其中之一为 `null`,则返回 `false`,因为树的结构不同。 + 3. 如果 `a` 和 `b` 的值不相等,则返回 `false`,因为树的值不同。 +2. 递归检查左右子树: + * 对 `a` 和 `b` 的右子树调用 `binaryTreeEqual`。 + * 对 `a` 和 `b` 的左子树调用 `binaryTreeEqual`。 +3. 如果左右子树的比较都返回 `true`,则返回 `true`。 + + + {binaryTreeEqual} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。 两个树中的每个节点都会被访问一次。 +* **空间复杂度:O(h)**。 递归堆栈需要与树的高度成比例的空间,其中 `h` 是两棵树的最大高度。 + +## 2. 迭代 + +用于确定两个二叉树是否相同的迭代方法使用广度优先遍历策略。 这种方法不依赖于递归,而是使用队列来管理来自两棵树的节点对,从而确保结构和值的等价性。 + +该算法首先初始化一个队列,其中包含两棵树的根节点作为一对。 每一对节点都会出列,并检查它们的等价性。 如果两个节点都为 `null`,则该对在该点上被认为是相同的。 如果一个节点为 `null` 而另一个节点不为 `null`,或者它们的值不同,则树不相同。 对于非 `null` 节点,将两个节点的左右子节点作为新对入队。 该过程一直持续到队列为空,这表明两棵树中所有对应的节点在结构和值上都是相同的。 + +### 算法 + +1. 定义一个辅助函数 `check`,该函数: + * 如果两个节点都为 `null`,则返回 `true`。 + * 如果一个节点为 `null` 而另一个节点不为 `null`,则返回 `false`。 + * 比较两个非 `null` 节点的值,如果它们相等,则返回 `true`。 +2. 使用两棵树的根节点作为一对来初始化队列。 +3. 当队列不为空时: + * 出队第一对节点,并使用 `check` 函数验证它们。 + * 如果节点有效,则将它们的左右子节点作为新对入队以进行进一步比较。 +4. 如果在遍历过程中未发现违规行为,则返回 `true`。 + + + {binaryTreeEqualIterative} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。 两个树中的每个节点都会被处理一次。 +* **空间复杂度:O(n)**。 队列最多存储 `n` 对节点,具体取决于树的大小。 diff --git a/contents/questions/algo/binary-tree-flip/description/en-US.langnostic.json b/contents/questions/algo/binary-tree-flip/description/en-US.langnostic.json new file mode 100644 index 000000000..b88d0dc4e --- /dev/null +++ b/contents/questions/algo/binary-tree-flip/description/en-US.langnostic.json @@ -0,0 +1,37 @@ +{ + "frontmatter": { + "title": "f45ce1a6", + "excerpt": "f389d7da" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "cbc8c1f4", + "6b6bad6a", + "c9f2b457", + "ff4afcec", + "2d96efbe", + "2dfde09", + "d068a43f", + "b2065fc", + "bcddf617" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "cbc8c1f4", + "6b6bad6a", + "c9f2b457", + "ff4afcec", + "2d96efbe", + "2dfde09", + "d068a43f", + "b2065fc", + "bcddf617" + ] + } + } +} diff --git a/contents/questions/algo/binary-tree-flip/description/zh-CN.mdx b/contents/questions/algo/binary-tree-flip/description/zh-CN.mdx new file mode 100644 index 000000000..5a641b30c --- /dev/null +++ b/contents/questions/algo/binary-tree-flip/description/zh-CN.mdx @@ -0,0 +1,32 @@ +--- +title: 翻转二叉树 +excerpt: 实现一个函数来翻转二叉树中的节点 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个二叉树的`root`节点,通过交换每个节点的左孩子和右孩子来翻转树,然后返回翻转后的树的根节点。 + +二叉树由`TreeNode`的集合表示,其中每个节点都有可选的`left`和`right`子节点,它们也是`TreeNode`。 + +一个`TreeNode`具有以下接口: + +```ts +interface TreeNode { + val: number; + left: TreeNode | null; + right: TreeNode | null; +} +``` + +### 输入 + +- `root: TreeNode`: 树的根节点。示例显示树的[层序遍历](https://en.wikipedia.org/wiki/Breadth-first_search) + + + +### 约束 + +- 1 <= 节点数 <= 100 +- -100 <= `TreeNode.val` <= 100 diff --git a/contents/questions/algo/binary-tree-flip/solution/en-US.langnostic.json b/contents/questions/algo/binary-tree-flip/solution/en-US.langnostic.json new file mode 100644 index 000000000..5bd6fc8bb --- /dev/null +++ b/contents/questions/algo/binary-tree-flip/solution/en-US.langnostic.json @@ -0,0 +1,50 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "33899657", + "3404f91b", + "a2c8bc3c", + "23e37c9e", + "b68df8f8", + "4792e77f", + "3646fd19", + "8e2de8c8", + "d840a0dd", + "ce6bcb79", + "444f6e96", + "ac57e825", + "b68df8f8", + "eb8b28ef", + "b4e41247", + "8e2de8c8", + "a64c7199" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "33899657", + "3404f91b", + "a2c8bc3c", + "23e37c9e", + "b68df8f8", + "4792e77f", + "3646fd19", + "8e2de8c8", + "d840a0dd", + "ce6bcb79", + "444f6e96", + "ac57e825", + "b68df8f8", + "eb8b28ef", + "b4e41247", + "8e2de8c8", + "a64c7199" + ] + } + } +} diff --git a/contents/questions/algo/binary-tree-flip/solution/zh-CN.mdx b/contents/questions/algo/binary-tree-flip/solution/zh-CN.mdx new file mode 100644 index 000000000..443b51e73 --- /dev/null +++ b/contents/questions/algo/binary-tree-flip/solution/zh-CN.mdx @@ -0,0 +1,52 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import binaryTreeFlip from '../setup/src/binary-tree-flip.ts'; +import binaryTreeFlipIteration from '../setup/src/binary-tree-flip-iteration.ts'; + +## 1. 使用递归 + +翻转二叉树涉及交换树中每个节点的左右子树。递归方法通过将问题分解为每个子树的较小问题来简化此操作。 + +它从一个基本情况开始:如果当前节点为 `null`,则无需翻转,因此返回 `null`。对于每个非 `null` 节点,递归翻转左右子树,并将结果存储在临时变量中。递归后,交换当前节点的左右子节点。这确保了树的所有层都被正确翻转,并且结构完全颠倒。 + +### 算法 + +1. 检查基本情况:如果节点为 `null`,则返回 `null`。 +2. 递归调用右子树上的函数并存储结果。 +3. 递归调用左子树上的函数并存储结果。 +4. 交换当前节点的左右子节点。 +5. 将当前节点作为翻转树的根节点返回。 + + + {binaryTreeFlip} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。每个节点只访问一次。 +* **空间复杂度:O(h)**。递归堆栈使用的空间与树的高度成正比,其中 `h` 是树的高度。 + +## 2. 使用迭代 + +翻转二叉树涉及交换每个节点的左右子树。迭代方法使用队列逐层遍历树,确保处理所有节点。此方法避免了递归,使其成为处理深度树以防止堆栈溢出的一个很好的替代方案。 + +迭代方法从一个基本情况开始,其中空树(`null` 根)直接返回 `null`。使用根节点初始化一个队列,并执行广度优先遍历。在每个步骤中,交换当前节点的左右子节点。如果交换的子节点不为 `null`,则将它们添加到队列中以进行后续处理。该过程一直持续到队列为空,确保树中的所有节点都被翻转。 + +### 算法 + +1. 通过在根为 `null` 时返回 `null` 来处理基本情况。 +2. 初始化一个队列并添加根节点。 +3. 当队列不为空时: + * 出队一个节点并交换其左右子节点。 + * 如果左子节点存在,则将其入队。 + * 如果右子节点存在,则将其入队。 +4. 返回反转树的根。 + + + {binaryTreeFlipIteration} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。树中的每个节点只处理一次。 +* **空间复杂度:O(n)**。在最坏的情况下,队列最多可以存储 `n` 个节点,这与树在其最宽层上的广度成正比。 diff --git a/contents/questions/algo/binary-tree-level-order-traversal/description/en-US.langnostic.json b/contents/questions/algo/binary-tree-level-order-traversal/description/en-US.langnostic.json new file mode 100644 index 000000000..50bf05b83 --- /dev/null +++ b/contents/questions/algo/binary-tree-level-order-traversal/description/en-US.langnostic.json @@ -0,0 +1,37 @@ +{ + "frontmatter": { + "title": "52ee227b", + "excerpt": "827289f4" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "dbbd5098", + "6b6bad6a", + "c9f2b457", + "ff4afcec", + "2d96efbe", + "2dfde09", + "d068a43f", + "b2065fc", + "25054d9b" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "dbbd5098", + "6b6bad6a", + "c9f2b457", + "ff4afcec", + "2d96efbe", + "2dfde09", + "d068a43f", + "b2065fc", + "25054d9b" + ] + } + } +} diff --git a/contents/questions/algo/binary-tree-level-order-traversal/description/zh-CN.mdx b/contents/questions/algo/binary-tree-level-order-traversal/description/zh-CN.mdx new file mode 100644 index 000000000..3dafdf466 --- /dev/null +++ b/contents/questions/algo/binary-tree-level-order-traversal/description/zh-CN.mdx @@ -0,0 +1,32 @@ +--- +title: 二叉树层序遍历 +excerpt: 实现一个函数来查找二叉树的层序遍历 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定二叉树的`root`节点,返回一个数组的数组,其中每个内部数组表示树中每一层的节点的值,从左到右遍历。 + +二叉树由`TreeNode`的集合表示,其中每个节点都有可选的`left`和`right`子节点,它们也是`TreeNode`。 + +一个`TreeNode`具有以下接口: + +```ts +interface TreeNode { + val: number; + left: TreeNode | null; + right: TreeNode | null; +} +``` + +### 输入 + +- `root: TreeNode`: 树的根节点。示例显示树的[层序遍历](https://en.wikipedia.org/wiki/Breadth-first_search) + + + +### 约束 + +- 1 <= 节点数 <= 10,000 +- -100 <= `TreeNode.val` <= 100 diff --git a/contents/questions/algo/binary-tree-level-order-traversal/solution/en-US.langnostic.json b/contents/questions/algo/binary-tree-level-order-traversal/solution/en-US.langnostic.json new file mode 100644 index 000000000..90c22d390 --- /dev/null +++ b/contents/questions/algo/binary-tree-level-order-traversal/solution/en-US.langnostic.json @@ -0,0 +1,46 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "918d7c24", + "3404f91b", + "5c13f657", + "b68df8f8", + "d7515d31", + "1426272a", + "8e2de8c8", + "35117bbd", + "ce6bcb79", + "d3fc9fe7", + "b68df8f8", + "aa3c29bf", + "b25d2914", + "8e2de8c8", + "51491351" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "918d7c24", + "3404f91b", + "5c13f657", + "b68df8f8", + "d7515d31", + "1426272a", + "8e2de8c8", + "35117bbd", + "ce6bcb79", + "d3fc9fe7", + "b68df8f8", + "aa3c29bf", + "b25d2914", + "8e2de8c8", + "51491351" + ] + } + } +} diff --git a/contents/questions/algo/binary-tree-level-order-traversal/solution/zh-CN.mdx b/contents/questions/algo/binary-tree-level-order-traversal/solution/zh-CN.mdx new file mode 100644 index 000000000..55916c82f --- /dev/null +++ b/contents/questions/algo/binary-tree-level-order-traversal/solution/zh-CN.mdx @@ -0,0 +1,47 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import binaryTreeLevelOrderTraversal from '../setup/src/binary-tree-level-order-traversal.ts'; +import binaryTreeLevelOrderTraversalIteration from '../setup/src/binary-tree-level-order-traversal-iteration.ts'; + +## 1. 使用递归 + +递归方法通过其深度级别对二叉树中的节点进行分组。每个级别都表示为一个数组,并且将同一深度的所有节点存储在一起。遍历从根节点开始,逐级进行,确保保留树的层次结构。每当到达一个新级别时,都会初始化一个新组以容纳该深度处的节点。这确保了节点被有效地分组,从而保持了树的级别之间的清晰区分。 + +### 算法 + +1. 从根节点开始遍历树,跟踪当前的深度级别。 +2. 对于第一次遇到的每个级别,初始化一个新组来存储节点值。 +3. 将每个节点的值添加到其对应的组中,具体取决于其深度级别。 +4. 递归处理左子节点和右子节点,在遍历深入树时增加级别。 +5. 继续,直到所有节点都被处理并按级别分组。 + + + {binaryTreeLevelOrderTraversal} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。树中的每个节点只访问一次。 +* **空间复杂度:O(h)**。递归堆栈使用的空间与树的高度 `h` 成正比,并且使用额外的空间来存储级别组。 + +## 2. 使用迭代 + +迭代方法使用队列通过其深度级别对二叉树中的节点进行分组。遍历从根节点开始,并分别处理每个级别。在每个级别,所有节点都会出队,它们的值存储在对应于当前级别的组中,并且它们的子节点会排队等待下一次迭代。这确保了在移动到下一级别之前,同一深度的所有节点都被一起处理。该方法以广度优先的方式有效地处理所有节点,从而保持了树的层次结构。 + +### 算法 + +1. 使用根节点初始化一个队列以迭代处理级别。 +2. 使用循环逐级处理节点,直到队列为空。 +3. 在每个级别,跟踪要处理的节点数,并初始化一个新组以存储它们的值。 +4. 移除当前级别的每个节点,将其值添加到组中,并将其左子节点和右子节点排队(如果存在)。 +5. 将值组附加到结果中,然后继续到下一级别。 +6. 继续,直到所有节点都被处理并按深度分组。 + + + {binaryTreeLevelOrderTraversalIteration} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。每个节点只访问一次。 +* **空间复杂度:O(m)**。队列保存当前级别的节点,其中 `m` 是任何级别上的最大节点数(等于树的宽度)。 diff --git a/contents/questions/algo/binary-tree-maximum-depth/description/en-US.langnostic.json b/contents/questions/algo/binary-tree-maximum-depth/description/en-US.langnostic.json new file mode 100644 index 000000000..00d73ce52 --- /dev/null +++ b/contents/questions/algo/binary-tree-maximum-depth/description/en-US.langnostic.json @@ -0,0 +1,37 @@ +{ + "frontmatter": { + "title": "43115546", + "excerpt": "e1b18aca" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "a62ac155", + "6b6bad6a", + "c9f2b457", + "ff4afcec", + "2d96efbe", + "2dfde09", + "d068a43f", + "b2065fc", + "25054d9b" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "a62ac155", + "6b6bad6a", + "c9f2b457", + "ff4afcec", + "2d96efbe", + "2dfde09", + "d068a43f", + "b2065fc", + "25054d9b" + ] + } + } +} diff --git a/contents/questions/algo/binary-tree-maximum-depth/description/zh-CN.mdx b/contents/questions/algo/binary-tree-maximum-depth/description/zh-CN.mdx new file mode 100644 index 000000000..c0fa0b311 --- /dev/null +++ b/contents/questions/algo/binary-tree-maximum-depth/description/zh-CN.mdx @@ -0,0 +1,32 @@ +--- +title: 二叉树的最大深度 +excerpt: 实现一个函数来查找二叉树的最大深度 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个二叉树的`root`,确定树的深度,它被定义为从根到最远叶子节点的最长路径上的节点数。 + +二叉树由`TreeNode`的集合表示,其中每个节点都有可选的`left`和`right`子节点,它们也是`TreeNode`。 + +一个`TreeNode`具有以下接口: + +```ts +interface TreeNode { + val: number; + left: TreeNode | null; + right: TreeNode | null; +} +``` + +### 输入 + +- `root: TreeNode`: 树的根节点。示例显示树的[广度优先遍历](https://en.wikipedia.org/wiki/Breadth-first_search) + + + +### 约束 + +- 1 <= 节点数 <= 10,000 +- -100 <= `TreeNode.val` <= 100 diff --git a/contents/questions/algo/binary-tree-maximum-depth/solution/en-US.langnostic.json b/contents/questions/algo/binary-tree-maximum-depth/solution/en-US.langnostic.json new file mode 100644 index 000000000..08c581fae --- /dev/null +++ b/contents/questions/algo/binary-tree-maximum-depth/solution/en-US.langnostic.json @@ -0,0 +1,46 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "3e0a7ccc", + "3404f91b", + "959549dd", + "b68df8f8", + "ffa092c7", + "3156092e", + "8e2de8c8", + "dab6df34", + "ce6bcb79", + "ed08ce7a", + "b68df8f8", + "f7b364cb", + "c4f519df", + "8e2de8c8", + "19338334" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "3e0a7ccc", + "3404f91b", + "959549dd", + "b68df8f8", + "ffa092c7", + "3156092e", + "8e2de8c8", + "dab6df34", + "ce6bcb79", + "ed08ce7a", + "b68df8f8", + "f7b364cb", + "c4f519df", + "8e2de8c8", + "19338334" + ] + } + } +} diff --git a/contents/questions/algo/binary-tree-maximum-depth/solution/zh-CN.mdx b/contents/questions/algo/binary-tree-maximum-depth/solution/zh-CN.mdx new file mode 100644 index 000000000..309a8d9fc --- /dev/null +++ b/contents/questions/algo/binary-tree-maximum-depth/solution/zh-CN.mdx @@ -0,0 +1,49 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import binaryTreeMaximumDepth from '../setup/src/binary-tree-maximum-depth.ts'; +import binaryTreeMaximumDepthIteration from '../setup/src/binary-tree-maximum-depth-iteration.ts'; + +## 1. 使用递归 + +二叉树的最大深度是通过找到从根节点到叶节点的最长路径来确定的。递归方法非常适合这个问题,因为节点的深度是其左子树和右子树的最大深度加 1。从根节点开始,算法探索左子树和右子树,计算它们的深度,并选择较大的值,有效地以分治方式遍历所有节点。 + +### 算法 + +1. 从根节点开始。 +2. 如果当前节点为 `null`,则返回深度 0,因为其下没有节点。 +3. 递归计算左子树的深度。 +4. 递归计算右子树的深度。 +5. 通过将 1(对于当前节点本身)添加到其左子树和右子树的深度的最大值来计算当前节点的深度。 +6. 继续此过程,直到所有节点都被访问。 + + + {binaryTreeMaximumDepth} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。树中的每个节点只访问一次以计算其深度。 +* **空间复杂度:O(h)**。递归堆栈大小取决于树的高度,其中 `h` 是树的高度。 + +## 2. 使用迭代 + +迭代方法查找二叉树的最大深度,使用堆栈来模拟深度优先遍历。每个堆栈条目包含一个节点及其当前深度。这避免了递归,并使用堆栈显式管理遍历。从深度为 1 的根节点开始,算法遍历树中的所有节点,在处理每个节点时更新最大深度。节点以其深度增加 1 的方式添加到堆栈中,表示树的下一层。这种方法确保考虑从根到叶的每条路径,并记录最大深度。 + +### 算法 + +1. 使用根节点及其初始深度设置为 1 来初始化堆栈。 +2. 使用一个变量来跟踪遍历期间遇到的最大深度。 +3. 当堆栈不为空时: + * 弹出顶部节点及其关联的深度。 + * 如果当前深度更大,则更新最大深度。 + * 将节点的左子节点和右子节点推入堆栈,其深度增加 1。 +4. 继续,直到所有节点都被处理。 + + + {binaryTreeMaximumDepthIteration} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。树中的每个节点在遍历期间只访问一次。 +* **空间复杂度:O(h)**。堆栈大小取决于树的高度,其中 `h` 是树的高度。 diff --git a/contents/questions/algo/binary-tree-maximum-total-path/description/en-US.langnostic.json b/contents/questions/algo/binary-tree-maximum-total-path/description/en-US.langnostic.json new file mode 100644 index 000000000..2ebe25070 --- /dev/null +++ b/contents/questions/algo/binary-tree-maximum-total-path/description/en-US.langnostic.json @@ -0,0 +1,39 @@ +{ + "frontmatter": { + "title": "26063b8a", + "excerpt": "66e594a2" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "550f02ec", + "15f687c", + "6b6bad6a", + "c9f2b457", + "ff4afcec", + "2d96efbe", + "2dfde09", + "d068a43f", + "b2065fc", + "25054d9b" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "550f02ec", + "15f687c", + "6b6bad6a", + "c9f2b457", + "ff4afcec", + "2d96efbe", + "2dfde09", + "d068a43f", + "b2065fc", + "25054d9b" + ] + } + } +} diff --git a/contents/questions/algo/binary-tree-maximum-total-path/description/zh-CN.mdx b/contents/questions/algo/binary-tree-maximum-total-path/description/zh-CN.mdx new file mode 100644 index 000000000..a76f6f10e --- /dev/null +++ b/contents/questions/algo/binary-tree-maximum-total-path/description/zh-CN.mdx @@ -0,0 +1,34 @@ +--- +title: 二叉树最大路径和 +excerpt: 实现一个函数,以找到二叉树路径中节点的最大总和 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个二叉树的`root`,确定树中任何非空路径的最大可能总和。 + +在二叉树中,路径定义为节点的序列,其中序列中的每对连续节点都由边直接连接。一个节点只能在路径序列中出现一次,并且路径不一定需要包含根节点。路径的总和通过将该路径中存在的所有节点的值相加来计算。 + +二叉树由`TreeNode`的集合表示,其中每个节点都有可选的`left`和`right`子节点,它们也是`TreeNode`。 + +一个`TreeNode`具有以下接口: + +```ts +interface TreeNode { + val: number; + left: TreeNode | null; + right: TreeNode | null; +} +``` + +### 输入 + +- `root: TreeNode`: 树的根节点。示例显示树的[广度优先遍历](https://en.wikipedia.org/wiki/Breadth-first_search) + + + +### 约束 + +- 1 <= 节点数 <= 10,000 +- -100 <= `TreeNode.val` <= 100 diff --git a/contents/questions/algo/binary-tree-maximum-total-path/solution/en-US.langnostic.json b/contents/questions/algo/binary-tree-maximum-total-path/solution/en-US.langnostic.json new file mode 100644 index 000000000..115af544e --- /dev/null +++ b/contents/questions/algo/binary-tree-maximum-total-path/solution/en-US.langnostic.json @@ -0,0 +1,32 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "75aeaf26", + "4b266561", + "f220228c", + "b68df8f8", + "dd284489", + "b0d8c848", + "8e2de8c8", + "ccdf3382" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "75aeaf26", + "4b266561", + "f220228c", + "b68df8f8", + "dd284489", + "b0d8c848", + "8e2de8c8", + "ccdf3382" + ] + } + } +} diff --git a/contents/questions/algo/binary-tree-maximum-total-path/solution/zh-CN.mdx b/contents/questions/algo/binary-tree-maximum-total-path/solution/zh-CN.mdx new file mode 100644 index 000000000..00289089f --- /dev/null +++ b/contents/questions/algo/binary-tree-maximum-total-path/solution/zh-CN.mdx @@ -0,0 +1,24 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import binaryTreeMaximumPathSum from '../setup/src/binary-tree-maximum-total-path.ts'; + +## 1. 使用后序遍历DFS + +二叉树中的最大路径和是任何路径中节点值的最大总和。路径可以从树中的任何节点开始和结束,但它必须遵循父子连接。该策略使用后序深度优先搜索(DFS)来探索每个子树,并计算每个节点左右子树的最大增益。对于每个节点,潜在的最大路径和计算为其值与左右子树的最大增益之和。忽略来自子树的负增益,以确保仅包含具有正贡献的路径。通过遍历整个树,确定全局最大路径和。 + +### 算法 + +1. 对树执行后序遍历,仅在处理完其左右子树后才处理每个节点。 +2. 对于每个节点,计算其左右子树的最大增益。如果子树贡献负增益,则将其忽略,视为 0。 +3. 计算当前节点的路径和,即其值与其左右子树的最大增益之和。 +4. 如果当前节点的计算路径和更大,则更新全局最大路径和。 +5. 返回可以传递给父节点的最大增益,其中包括节点的值以及来自其左子树或右子树的较大增益。 + + + {binaryTreeMaximumPathSum} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。在遍历期间,每个节点都会被访问一次。 +* **空间复杂度:O(h)**。递归堆栈所需的空间与树的高度成正比,其中 `h` 是树的高度。 diff --git a/contents/questions/algo/binary-tree-rebuilding-from-traversals/description/en-US.langnostic.json b/contents/questions/algo/binary-tree-rebuilding-from-traversals/description/en-US.langnostic.json new file mode 100644 index 000000000..21e9508a8 --- /dev/null +++ b/contents/questions/algo/binary-tree-rebuilding-from-traversals/description/en-US.langnostic.json @@ -0,0 +1,31 @@ +{ + "frontmatter": { + "title": "d421e1d9", + "excerpt": "b7be6205" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "42b9897e", + "2d96efbe", + "b33b1e74", + "d068a43f", + "b2065fc", + "763a2c32" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "42b9897e", + "2d96efbe", + "b33b1e74", + "d068a43f", + "b2065fc", + "763a2c32" + ] + } + } +} diff --git a/contents/questions/algo/binary-tree-rebuilding-from-traversals/description/zh-CN.mdx b/contents/questions/algo/binary-tree-rebuilding-from-traversals/description/zh-CN.mdx new file mode 100644 index 000000000..1a1d096bc --- /dev/null +++ b/contents/questions/algo/binary-tree-rebuilding-from-traversals/description/zh-CN.mdx @@ -0,0 +1,22 @@ +--- +title: 通过先序和中序遍历重建二叉树 +excerpt: 实现一个从先序和中序遍历构造二叉树的函数 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定两个整数数组 `preorder` 和 `inorder`,其中 `preorder` 表示二叉树的先序遍历值,`inorder` 表示同一棵树的中序遍历值,从这些遍历构造并返回二叉树。 + +### 输入 + +- `preorder: number[]`: 正整数数组 +- `inorder: number[]`: 正整数数组 + + + +### 约束 + +- 1 <= 节点数 <= 1000 +- 1 <= `TreeNode.val` <= 1,000,000 +- `preorder` 和 `inorder` 包含唯一值 diff --git a/contents/questions/algo/binary-tree-rebuilding-from-traversals/solution/en-US.langnostic.json b/contents/questions/algo/binary-tree-rebuilding-from-traversals/solution/en-US.langnostic.json new file mode 100644 index 000000000..f2546ab56 --- /dev/null +++ b/contents/questions/algo/binary-tree-rebuilding-from-traversals/solution/en-US.langnostic.json @@ -0,0 +1,34 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "3ee9080", + "3404f91b", + "66b2a302", + "24ddcd7e", + "b68df8f8", + "ea64abf8", + "358809d7", + "8e2de8c8", + "2c3f88de" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "3ee9080", + "3404f91b", + "66b2a302", + "24ddcd7e", + "b68df8f8", + "ea64abf8", + "358809d7", + "8e2de8c8", + "2c3f88de" + ] + } + } +} diff --git a/contents/questions/algo/binary-tree-rebuilding-from-traversals/solution/zh-CN.mdx b/contents/questions/algo/binary-tree-rebuilding-from-traversals/solution/zh-CN.mdx new file mode 100644 index 000000000..4e209ef45 --- /dev/null +++ b/contents/questions/algo/binary-tree-rebuilding-from-traversals/solution/zh-CN.mdx @@ -0,0 +1,29 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import binaryTreeRebuildingFromTraversals from '../setup/src/binary-tree-rebuilding-from-traversals.ts'; + +## 1. 使用递归 + +目标是从其先序遍历和中序遍历重建二叉树。在先序遍历中,第一个元素始终是树的根。中序遍历根据根的位置将树分成其左子树和右子树。通过结合这两个遍历,可以识别根并递归地重建左子树和右子树。 + +为了优化此过程,创建一个映射来存储中序遍历中元素的索引,从而允许 O(1) 查找根在中序数组中的位置。使用此映射,该算法避免了在中序遍历中重复搜索元素,否则会导致更高的时间复杂度。 + +### 算法 + +1. 创建一个映射,用于存储中序数组中每个值的索引,以便快速查找。 +2. 定义一个递归函数,用于在给定的中序数组范围内构造树。 +3. 在递归函数中: + * 选择先序数组中的当前元素作为根,并递增先序索引。 + * 使用中序映射来定位根在中序数组中的位置。 + * 使用中序数组中根左侧的元素递归地构建左子树。 + * 使用中序数组中根右侧的元素递归地构建右子树。 +4. 在处理完先序数组中的所有元素后,返回构造的树。 + + + {binaryTreeRebuildingFromTraversals} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。每个节点只处理一次,并且该映射允许在中序数组中进行 O(1) 索引查找。 +* **空间复杂度:O(n)**。空间用于递归堆栈和存储中序数组中元素索引的映射。 diff --git a/contents/questions/algo/binary-tree-serialization-deserialization/description/en-US.langnostic.json b/contents/questions/algo/binary-tree-serialization-deserialization/description/en-US.langnostic.json new file mode 100644 index 000000000..3d79a55ee --- /dev/null +++ b/contents/questions/algo/binary-tree-serialization-deserialization/description/en-US.langnostic.json @@ -0,0 +1,43 @@ +{ + "frontmatter": { + "title": "d435e82e", + "excerpt": "9fc0950" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "4835c3d1", + "6b6bad6a", + "c9f2b457", + "ff4afcec", + "2d96efbe", + "2d891f83", + "2dfde09", + "34625930", + "af2070b0", + "d068a43f", + "b2065fc", + "162c1b47" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "4835c3d1", + "6b6bad6a", + "c9f2b457", + "ff4afcec", + "2d96efbe", + "2d891f83", + "2dfde09", + "34625930", + "af2070b0", + "d068a43f", + "b2065fc", + "162c1b47" + ] + } + } +} diff --git a/contents/questions/algo/binary-tree-serialization-deserialization/description/zh-CN.mdx b/contents/questions/algo/binary-tree-serialization-deserialization/description/zh-CN.mdx new file mode 100644 index 000000000..079c5a194 --- /dev/null +++ b/contents/questions/algo/binary-tree-serialization-deserialization/description/zh-CN.mdx @@ -0,0 +1,38 @@ +--- +title: 二叉树序列化和反序列化 +excerpt: 实现一个序列化和反序列化二叉树的函数 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +设计一种序列化和反序列化二叉树的方法。对序列化和反序列化的实现方式没有具体限制;关键要求是序列化的二叉树必须能够转换回原始树结构。 + +二叉树由`TreeNode`的集合表示,其中每个节点都有可选的`left`和`right`子节点,它们也是`TreeNode`。 + +一个`TreeNode`具有以下接口: + +```ts +interface TreeNode { + val: number; + left: TreeNode | null; + right: TreeNode | null; +} +``` + +### 输入 + +#### `serializeBinaryTree` + +- `root: TreeNode`: 树的根节点。示例显示树的[层序遍历](https://en.wikipedia.org/wiki/Breadth-first_search) + +#### `deserializeBinaryTree` + +- `data: string`: 树的字符串表示形式。格式由您设计 + + + +### 约束 + +- 1 <= 节点数 <= 10,000 +- 1 <= `TreeNode.val` <= 1,000,000 diff --git a/contents/questions/algo/binary-tree-serialization-deserialization/solution/en-US.langnostic.json b/contents/questions/algo/binary-tree-serialization-deserialization/solution/en-US.langnostic.json new file mode 100644 index 000000000..404ce75d7 --- /dev/null +++ b/contents/questions/algo/binary-tree-serialization-deserialization/solution/en-US.langnostic.json @@ -0,0 +1,46 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "9ec7068", + "addb9fcc", + "fbd7c18", + "25c96069", + "161bcc9", + "9c4b77d3", + "9bc7b921", + "b68df8f8", + "25c96069", + "413c15fd", + "9c4b77d3", + "ab60b3af", + "b158d5fb", + "8e2de8c8", + "1ff7fee1" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "9ec7068", + "addb9fcc", + "fbd7c18", + "25c96069", + "161bcc9", + "9c4b77d3", + "9bc7b921", + "b68df8f8", + "25c96069", + "413c15fd", + "9c4b77d3", + "ab60b3af", + "b158d5fb", + "8e2de8c8", + "1ff7fee1" + ] + } + } +} diff --git a/contents/questions/algo/binary-tree-serialization-deserialization/solution/zh-CN.mdx b/contents/questions/algo/binary-tree-serialization-deserialization/solution/zh-CN.mdx new file mode 100644 index 000000000..226d37772 --- /dev/null +++ b/contents/questions/algo/binary-tree-serialization-deserialization/solution/zh-CN.mdx @@ -0,0 +1,47 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import serializeAndDeserializeBinaryTree from '../setup/src/binary-tree-serialization-deserialization.ts'; + +## 1. 使用 DFS + +二叉树的序列化和反序列化分别涉及将树结构转换为字符串表示形式,以及从字符串重建树。该解决方案使用深度优先遍历 (DFS) 方法来实现此目的。 + +#### 序列化 + +* 每个节点的值附加到字符串中,然后递归地序列化其左子树和右子树。 +* 如果节点为 `null`,则表示为字符串 `"null"` 以保留树的结构。 + +#### 反序列化 + +* 序列化字符串被拆分成一个节点值的列表以进行遍历。 +* `null` 值表示分支的结尾,而其他值用于创建树节点。 +* 递归地,反序列化左子树和右子树以重建树。 + +### 算法 + +#### 序列化 + +1. 检查当前节点是否为 `null`。如果是,则将 `"null,"` 附加到字符串并返回。 +2. 将当前节点的值附加到字符串,后跟一个逗号。 +3. 递归地序列化左子树并将其附加到字符串。 +4. 递归地序列化右子树并将其附加到字符串。 +5. 返回序列化后的字符串。 + +#### 反序列化 + +1. 按逗号分割序列化字符串,形成节点值的列表。 +2. 检查列表中第一个元素是否为 `"null"`。如果是,则将其从列表中删除并返回 `null`。 +3. 使用列表的第一个元素创建一个 `TreeNode`,将其转换为数字。 +4. 从列表中删除第一个元素。 +5. 递归地反序列化左子树并将其分配给节点的左子节点。 +6. 递归地反序列化右子树并将其分配给节点的右子节点。 +7. 返回重建的树节点。 + + + {serializeAndDeserializeBinaryTree} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。序列化和反序列化都遍历二叉树的所有 `n` 个节点一次。 +* **空间复杂度:O(n)**。DFS 的递归堆栈以及存储序列化字符串或列表所需的空间随树的大小而扩展。 diff --git a/contents/questions/algo/binary-tree-subtree/description/en-US.langnostic.json b/contents/questions/algo/binary-tree-subtree/description/en-US.langnostic.json new file mode 100644 index 000000000..58427fd0d --- /dev/null +++ b/contents/questions/algo/binary-tree-subtree/description/en-US.langnostic.json @@ -0,0 +1,41 @@ +{ + "frontmatter": { + "title": "efad4785", + "excerpt": "7abd2c0d" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "7edad200", + "6b6bad6a", + "c9f2b457", + "ff4afcec", + "d89525", + "f90ef694", + "2d96efbe", + "c463d9df", + "d068a43f", + "b2065fc", + "fa7b6054" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "7edad200", + "6b6bad6a", + "c9f2b457", + "ff4afcec", + "d89525", + "f90ef694", + "2d96efbe", + "c463d9df", + "d068a43f", + "b2065fc", + "fa7b6054" + ] + } + } +} diff --git a/contents/questions/algo/binary-tree-subtree/description/zh-CN.mdx b/contents/questions/algo/binary-tree-subtree/description/zh-CN.mdx new file mode 100644 index 000000000..0fe3d8827 --- /dev/null +++ b/contents/questions/algo/binary-tree-subtree/description/zh-CN.mdx @@ -0,0 +1,38 @@ +--- +title: 二叉树子树 +excerpt: 实现一个函数来检查一个二叉树是否是另一个二叉树的子树 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定两棵二叉树的根节点 `root` 和 `subRoot`,确定 `subRoot` 是否是 `root` 的子树。如果 `root` 中存在一个子树,其结构和节点值与 `subRoot` 相同,则该函数应返回 `true`。如果不存在这样的子树,则返回 `false`。 + +二叉树由 `TreeNode` 的集合表示,其中每个节点都有可选的 `left` 和 `right` 子节点,它们也是 `TreeNode`。 + +一个 `TreeNode` 具有以下接口: + +```ts +interface TreeNode { + val: number; + left: TreeNode | null; + right: TreeNode | null; +} +``` + +二叉树的子树定义为树的一部分,它由一个节点及其所有后代组成。子树具有以下属性: + +1. **结构匹配**:为了使 `subRoot` 成为 `root` 的子树,`subRoot` 中的节点必须与 `root` 的相应部分中的节点在值和结构上匹配。 +2. **自包含**:一棵树始终被认为是其自身的子树。 + +### 输入 + +- `root: TreeNode`:树的根节点。示例显示树的[层序遍历](https://en.wikipedia.org/wiki/Breadth-first_search) +- `subRoot: TreeNode`:子树的根节点。示例显示树的[层序遍历](https://en.wikipedia.org/wiki/Breadth-first_search) + + + +### 约束 + +- 1 <= 节点数 <= 100 +- -10,000 <= `TreeNode.val` <= 10,000 diff --git a/contents/questions/algo/binary-tree-subtree/solution/en-US.langnostic.json b/contents/questions/algo/binary-tree-subtree/solution/en-US.langnostic.json new file mode 100644 index 000000000..5bb7ab920 --- /dev/null +++ b/contents/questions/algo/binary-tree-subtree/solution/en-US.langnostic.json @@ -0,0 +1,56 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "f12b120e", + "3404f91b", + "d0cb93a", + "90c7e8cf", + "b9a87129", + "b68df8f8", + "7311f921", + "92ee6cf3", + "7e3c3498", + "fb8529a3", + "8e2de8c8", + "5adc9169", + "ab816a5d", + "271af4fd", + "3a03b8fe", + "b68df8f8", + "e758670c", + "5a4d459c", + "8e2de8c8", + "ce48cfb2" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "f12b120e", + "3404f91b", + "d0cb93a", + "90c7e8cf", + "b9a87129", + "b68df8f8", + "7311f921", + "92ee6cf3", + "7e3c3498", + "fb8529a3", + "8e2de8c8", + "5adc9169", + "ab816a5d", + "271af4fd", + "3a03b8fe", + "b68df8f8", + "e758670c", + "5a4d459c", + "8e2de8c8", + "ce48cfb2" + ] + } + } +} diff --git a/contents/questions/algo/binary-tree-subtree/solution/zh-CN.mdx b/contents/questions/algo/binary-tree-subtree/solution/zh-CN.mdx new file mode 100644 index 000000000..1e9cadb3a --- /dev/null +++ b/contents/questions/algo/binary-tree-subtree/solution/zh-CN.mdx @@ -0,0 +1,65 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import binaryTreeSubtree from '../setup/src/binary-tree-subtree.ts'; +import binaryTreeSubtreeHashing from '../setup/src/binary-tree-subtree-hashing.ts'; + +## 1. 使用递归 + +该问题需要确定一个二叉树是否是另一个二叉树的子树。子树必须在结构和节点值上与较大树的一部分完全匹配。 挑战在于有效地比较子树,同时避免冗余检查。 + +一种蛮力解决方案涉及将较大树中的每个可能的子树与较小的树进行比较,但这种方法会导致大量不必要的工作。 为了优化,该解决方案使用递归方法直接验证当前子树是否与给定的较小树匹配。 + +其直觉基于将问题简化为更小的子问题:如果当前子树不匹配,则解决方案检查当前节点的左子树和右子树。 为了确定两棵树是否相同,一个辅助函数验证它们的根值并递归地比较它们的左子树和右子树。 这消除了不必要的重复比较,并确保了有效的子树匹配。 + +### 算法 + +1. 检查 `root` 是否为 `null`。 如果是,则返回 `false`,因为找不到子树。 +2. 使用辅助函数验证当前子树是否与 `subRoot` 相同。 + * 如果相同,则返回 `true`。 +3. 递归地检查当前节点的左子树和右子树。 +4. 如果任何递归调用找到匹配项,则返回 `true`;否则,返回 `false`。 + + + {binaryTreeSubtree} + + +#### `isIdentical` 辅助函数: + +1. 如果任一树为空,则仅当两者都为空时才返回 `true`。 +2. 如果两棵树都非空: + * 比较每棵树根节点的值。 + * 递归检查左子树是否相同。 + * 递归检查右子树是否相同。 +3. 仅当值和结构完全匹配时才返回 `true`。 + +### Big-O 分析 + +* **时间复杂度:O(m.n)**。 对于较大树中的每个节点 (O(m)),子树与较小的树 (O(n)) 进行比较。 +* **空间复杂度:O(h)**。 由于递归调用,使用的空间与较大树的高度成正比。 + +## 2. 使用哈希 + +该问题涉及确定一个二叉树是否是另一个二叉树的子树。 该方法没有重复地直接比较节点和结构,而是使用哈希来将子树表示为紧凑的哈希值。 这通过使用哈希函数的属性来有效地检测子树匹配,从而消除了冗余的结构比较。 + +直觉是为较大树中的每个子树计算唯一的哈希值,并将它们与较小树的哈希值进行比较。 子树哈希取决于节点值及其左右子节点的哈希值,确保不同子树结构的唯一性。 通过将所有子树哈希存储在集合中,可以在每次哈希比较中以恒定的时间检查较小树是否存在作为子树。 这避免了重复的结构检查并提高了效率。 + +### 算法 + +1. 定义一个辅助函数 `hashSubtreeAtNode`,用于计算以给定节点为根的子树的哈希值: + * 对于 `null` 节点,返回预定义的基哈希值。 + * 递归计算左子树和右子树的哈希值。 + * 使用当前节点的值及其子节点的哈希值计算当前节点的哈希值,应用模运算以防止溢出。 + * 如果需要,将哈希值存储在全局集合中。 +2. 初始化一个空集合 `memo` 以存储较大树中所有子树的哈希值。 +3. 计算整个较大树的哈希值,将每个子树的哈希值存储在 `memo` 中。 +4. 计算较小树的哈希值,而不将其添加到集合中。 +5. 检查较小树的计算哈希值是否存在于 `memo` 集合中。 如果找到,则返回 `true`;否则,返回 `false`。 + + + {binaryTreeSubtreeHashing} + + +### Big-O 分析 + +* **时间复杂度:O(n + m)**。 较大树有 `n` 个节点,较小树有 `m` 个节点,在哈希期间分别遍历一次,导致总的时间复杂度为 O(n + m)。 +* **空间复杂度:O(n)**。 较大树中所有 `n` 个节点的哈希值都存储在 `memo` 集合中。 diff --git a/contents/questions/algo/binary-tree/description/en-US.langnostic.json b/contents/questions/algo/binary-tree/description/en-US.langnostic.json new file mode 100644 index 000000000..eeaee7e7b --- /dev/null +++ b/contents/questions/algo/binary-tree/description/en-US.langnostic.json @@ -0,0 +1,31 @@ +{ + "frontmatter": { + "title": "6fca1755", + "excerpt": "25dbbccb" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "f2d122af", + "a99d4a5d", + "29cfea10", + "493e8bd0", + "f72596f8", + "379467c4", + "1173205f" + ] + }, + "targets": { + "zh-CN": [ + "f2d122af", + "a99d4a5d", + "29cfea10", + "493e8bd0", + "f72596f8", + "379467c4", + "1173205f" + ] + } + } +} diff --git a/contents/questions/algo/binary-tree/description/zh-CN.mdx b/contents/questions/algo/binary-tree/description/zh-CN.mdx new file mode 100644 index 000000000..aa0515dae --- /dev/null +++ b/contents/questions/algo/binary-tree/description/zh-CN.mdx @@ -0,0 +1,39 @@ +--- +title: 二叉树 +excerpt: 实现一个二叉树数据结构,包括基本操作 +--- + +使用以下操作实现二叉树数据结构: + +- `new BinaryTree()`:创建一个 `BinaryTree` 实例。根节点初始化为 `null`,表示树开始为空。 +- `size()`:返回树中节点的数量。所需的时间复杂度:O(n),其中 n 是树中节点的数量。 +- `height()`:返回树的高度,定义为从根到叶子的最长路径上的边数。空树的高度为 0。所需的时间复杂度:O(n)。 +- `inOrder()`:返回一个按中序遍历的值的数组。所需的时间复杂度:O(n)。 +- `preOrder()`:返回一个按前序遍历的值的数组。所需的时间复杂度:O(n)。 +- `postOrder()`:返回一个按后序遍历的值的数组。所需的时间复杂度:O(n)。 +- `isBalanced()`:如果树是平衡的,则返回 `true`。如果对于树中的每个节点,其左子树和右子树的高度差最多为 1,则二叉树是平衡的。所需的时间复杂度:O(n)。 +- `isComplete()`:如果树是完全的,则返回 `true`。如果所有层都已完全填充,除了最后一层,最后一层必须从左到右填充,则二叉树是完全的。所需的时间复杂度:O(n)。 + +> 使用辅助类 `BinaryTreeNode` 来表示节点,具有 `value`、`left` 和 `right` 属性。 + +## 例子 + +```js +const tree = new BinaryTree(); +tree.root = new BinaryTreeNode(10); +tree.root.left = new BinaryTreeNode(5); +tree.root.right = new BinaryTreeNode(15); + +tree.size(); // 3 +tree.height(); // 1 +tree.inOrder(); // [5, 10, 15] +tree.preOrder(); // [10, 5, 15] +tree.postOrder(); // [5, 15, 10] +tree.isBalanced(); // true +tree.isComplete(); // true +``` + +## 约束 + +- 0 <= 节点数 <= 100 +- 二叉树中的每个节点最多有一个左子节点和一个右子节点 diff --git a/contents/questions/algo/binary-tree/solution/en-US.langnostic.json b/contents/questions/algo/binary-tree/solution/en-US.langnostic.json new file mode 100644 index 000000000..0fc26f6bd --- /dev/null +++ b/contents/questions/algo/binary-tree/solution/en-US.langnostic.json @@ -0,0 +1,42 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "43936cf7", + "db779f6", + "fc3171fc", + "b2dbc64a", + "d0b4bcff", + "5889cd6f", + "b68df8f8", + "766295bd", + "8e2de8c8", + "cc4a83ad", + "2a1b36da", + "499e5031", + "f0185f15" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "43936cf7", + "db779f6", + "fc3171fc", + "b2dbc64a", + "d0b4bcff", + "5889cd6f", + "b68df8f8", + "766295bd", + "8e2de8c8", + "cc4a83ad", + "2a1b36da", + "499e5031", + "f0185f15" + ] + } + } +} diff --git a/contents/questions/algo/binary-tree/solution/zh-CN.mdx b/contents/questions/algo/binary-tree/solution/zh-CN.mdx new file mode 100644 index 000000000..eb96c6d41 --- /dev/null +++ b/contents/questions/algo/binary-tree/solution/zh-CN.mdx @@ -0,0 +1,64 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import binaryTreeJs from '../setup/src/binary-tree.js'; +import binaryTreeTs from '../setup/src/binary-tree.ts'; + +二叉树是一种分层数据结构,其中每个节点最多有两个子节点:`left`子节点和`right`子节点。该结构由存储`value`和对其子节点的引用的节点组成。最顶层的节点称为`root`。 + +此实现将二叉树结构(`BinaryTree`)与其各个节点(`BinaryTreeNode`)分开。每个节点包含一个`value`,以及指向其`left`和`right`子节点的指针。 + +核心操作可以使用递归方法实现,这对于二叉树来说是自然且高效的,因为每个子树本身就是一棵二叉树: + +* **遍历方法**(`inOrder`、`preOrder`、`postOrder`)使用简单的深度优先递归以正确的顺序访问节点,并将其值收集到一个数组中。 +* `size()`和`height()`通过访问每个节点一次来递归计算,结合左右子节点的结果。 +* `isBalanced()`使用递归方法从底部向上遍历树,检查每个子树是否平衡。在执行此操作时,它还会计算每个节点的高度。如果它发现一个子树的高度差 > 1,它会立即返回 -1,这会冒泡并停止进一步的检查,使时间复杂度保持在 O(n)。 +* `isComplete()`使用层序遍历(BFS)来确保所有层都已完全填充,并且最后一层从左到右填充,没有间隙。 + + + +### 算法 + +1. `new BinaryTree(value)`: + * 初始化一棵树。如果传递了`value`,则将根设置为具有该值的新的`BinaryTreeNode`。如果没有,则根为`null`。 +2. `size()`: + * 基本情况:如果`node`为`null`,则返回 0。 + * 递归情况:1 + 左子树的大小 + 右子树的大小。 +3. `height()`: + * 基本情况:如果`node`为`null`,则返回 -1。 + * 递归情况:1 + max(左子树的高度,右子树的高度)。 + * 对于空树,`height()`返回 0。 +4. 遍历方法(`inOrder()`、`preOrder()`、`postOrder()`): + * 这些方法根据不同的遍历顺序返回节点值的数组: + * 中序遍历(左 → 根 → 右) + * 前序遍历(根 → 左 → 右) + * 后序遍历(左 → 右 → 根) + * 每种方法都使用一个递归助手,该助手使用 DFS 从根遍历树,并按指定的顺序访问子节点。 + * 在递归调用期间构建一个临时数组,以按正确的顺序收集值。 +5. `isBalanced()`: + * 递归助手返回高度(如果子树平衡),或者如果未平衡则返回 -1。 + * 主方法检查结果是否不为 -1。 +6. `isComplete()`: + * 使用 BFS(层序遍历)与队列。 + * 当节点出队时,如果找到`null`,则所有后续节点也必须为`null`,才能认为树是完整的。如果在 null 之后出现任何非 null 节点,则树不完整。 + +### Big-O 分析 + +设`n`为节点的数量,`h`为树的高度。 + +* **时间复杂度**: + * `size()`、`height()`、`inOrder()`、`preOrder()`、`postOrder()`、`isBalanced()`、`isComplete()`:O(n)。每个节点访问一次。 +* **空间复杂度**: + * 递归方法(`size()`、`height()`、遍历、`isBalanced()`):O(h) 由于调用堆栈。在最坏的情况下(倾斜树),h = O(n)。在平衡树中,h = O(log n)。 + * `isComplete()`:在最坏的情况下为 O(n),因为 BFS 队列在完整树的最后一层最多可以容纳 n/2 个节点。 + +## 边缘情况 + +* **空树**: + * `size()`为 0 + * `height()`为 0 + * 遍历返回`[]` + * 树既平衡又完整 +* **单节点树**: + * `size()`为 1 + * `height()`为 0 + * 树既平衡又完整 diff --git a/contents/questions/algo/bit-counting/description/en-US.langnostic.json b/contents/questions/algo/bit-counting/description/en-US.langnostic.json new file mode 100644 index 000000000..963009de6 --- /dev/null +++ b/contents/questions/algo/bit-counting/description/en-US.langnostic.json @@ -0,0 +1,31 @@ +{ + "frontmatter": { + "title": "57b1cc8a", + "excerpt": "b1afdcab" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "96220869", + "2d96efbe", + "d24913dd", + "d068a43f", + "b2065fc", + "81354bf9" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "96220869", + "2d96efbe", + "d24913dd", + "d068a43f", + "b2065fc", + "81354bf9" + ] + } + } +} diff --git a/contents/questions/algo/bit-counting/description/zh-CN.mdx b/contents/questions/algo/bit-counting/description/zh-CN.mdx new file mode 100644 index 000000000..c5c939fee --- /dev/null +++ b/contents/questions/algo/bit-counting/description/zh-CN.mdx @@ -0,0 +1,19 @@ +--- +title: 位计数 +excerpt: 实现一个函数,用于查找从 0 到 n 的设置位数量 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个非负整数 `n`,编写一个函数,该函数接受非负整数 `n` 并返回一个大小为 `n + 1` 的数组 `result`,其中 `result[i]` 表示整数 `i` 的二进制表示中活动位(设置为 1 的位)的数量(其中 0 <= `i` <= `n`)。 + +### 输入 + +- `n: number`: 一个整数 + + + +### 约束 + +- 0 <= `n` <= 10,000 diff --git a/contents/questions/algo/bit-counting/solution/en-US.langnostic.json b/contents/questions/algo/bit-counting/solution/en-US.langnostic.json new file mode 100644 index 000000000..aa29a903e --- /dev/null +++ b/contents/questions/algo/bit-counting/solution/en-US.langnostic.json @@ -0,0 +1,64 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "1f69cb09", + "33bcc7cd", + "59ffd3c1", + "4a883ffa", + "b68df8f8", + "f2614b0e", + "d74e4d84", + "8e2de8c8", + "cf593146", + "c4bcf9a7", + "12b2b624", + "893958c0", + "b68df8f8", + "e8d4e93e", + "453eb67b", + "8e2de8c8", + "f234659c", + "e51f4c90", + "91b03ba3", + "b68df8f8", + "da01c6ab", + "16f1041", + "8e2de8c8", + "dacc9703" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "1f69cb09", + "33bcc7cd", + "59ffd3c1", + "4a883ffa", + "b68df8f8", + "f2614b0e", + "d74e4d84", + "8e2de8c8", + "cf593146", + "c4bcf9a7", + "12b2b624", + "893958c0", + "b68df8f8", + "e8d4e93e", + "453eb67b", + "8e2de8c8", + "f234659c", + "e51f4c90", + "91b03ba3", + "b68df8f8", + "da01c6ab", + "16f1041", + "8e2de8c8", + "dacc9703" + ] + } + } +} diff --git a/contents/questions/algo/bit-counting/solution/zh-CN.mdx b/contents/questions/algo/bit-counting/solution/zh-CN.mdx new file mode 100644 index 000000000..b54f05a72 --- /dev/null +++ b/contents/questions/algo/bit-counting/solution/zh-CN.mdx @@ -0,0 +1,80 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import bitCounting from '../setup/src/bit-counting.ts'; +import bitCountingDpMSB from '../setup/src/bit-counting-dp-msb.ts'; +import bitCountingPopulationCount from '../setup/src/bit-counting-pop-count.ts'; + +## 1. 使用人口计数 + +这种方法使用简单的位操作技术来计算每个数字中 `1` 的数量。 关键的直觉是,一个数字的二进制表示可以通过逐位处理来检查其最低有效位,然后右移该数字以检查下一位。 这个过程一直持续到数字变为 `0`。 + +这种方法遍历从 `0` 到 `n` 的所有数字,并在 O(k) 时间内处理每个数字,其中 `k` 是数字中的位数。 + +### 算法 + +1. 初始化一个空数组 `ans` 来存储结果。 +2. 遍历从 `0` 到 `n` 的所有数字: + * 将变量 `count` 设置为 `0` 以跟踪当前数字中 `1` 的数量。 + * 将当前数字分配给临时变量 `num`。 + * 使用 `while` 循环处理该数字: + * 将最低有效位 (`num & 1`) 添加到 `count`。 + * 使用 `num >>= 1` 将该数字右移一位。 + * 将 `count` 附加到 `ans` 数组。 +3. 返回数组 `ans`。 + + + {bitCountingPopulationCount} + + +### Big-O 分析 + +* **时间复杂度:O(n.k)**。 该算法处理从 `0` 到 `n` 的每个数字,其中 `k` 是该数字的二进制表示中的位数。 +* **空间复杂度:O(n)**。 数组 `ans` 存储从 `0` 到 `n` 的所有数字的结果。 + +## 2. 使用动态规划和 MSB + +具有最高有效位的动态规划方法通过使用先前计算的结果来提高效率。 关键的直觉是,一个数字的二进制表示中 `1` 的数量可以通过将 `1` 添加到较小范围内的数字中 `1` 的计数来确定。 具体来说,如果 `b` 是 2 的幂,则范围 `[b, 2b)` 中的任何数字都与 `[0, b)` 中的数字具有相同的位模式,并设置了额外的最高有效位 `1`。 + +这种方法消除了像朴素解法那样重复处理每个数字的每一位的需要。 相反,它通过加倍范围和重用先前计算的计数来动态构建结果,从而减少了冗余工作。 + +### 算法 + +1. 初始化一个大小为 `n + 1` 的数组 `ans`,并将所有值设置为 `0`。 +2. 将 `x` 设置为 `0`,将 `b` 设置为 `1`,其中 `b` 表示当前的 2 的幂范围。 +3. 使用 `while` 循环处理范围: + * 当 `b` 小于或等于 `n` 时: + * 遍历范围 `[b, 2b)` 中的数字: + * 对于范围内每个数字 `x + b`,计算 `1` 的计数为 `ans[x] + 1`。 + * 递增 `x`。 + * 将 `x` 重置为 `0` 并将 `b` 加倍以处理下一个范围。 +4. 返回数组 `ans`。 + + + {bitCountingDpMSB} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。 由于范围递增加倍,因此每个数字只处理一次。 +* **空间复杂度:O(n)**。 `ans` 数组需要的空间与输入大小 `n` 成正比。 + +## 3. 使用动态规划和 LSB + +另一种解决方案使用最低有效位与动态规划方法相结合来计算从 `0` 到 `n` 的整数的二进制表示中 `1` 的数量。 关键的直觉是,数字 `i` 中 `1` 的数量可以从 `i / 2`(`i` 的右移值)和 `i` 的最低有效位推导出来。 最低有效位可以使用 `i & 1` 确定。 + +### 算法 + +1. 初始化一个大小为 `n + 1` 的数组 `counts`,并将所有值设置为 `0`。 +2. 遍历从 `1` 到 `n` 的数字: + * 使用 `i & 1` 计算当前数字的最低有效位。 + * 使用动态规划公式 `counts[i] = counts[Math.floor(i / 2)] + least significant bit` 计算 `1` 的计数。 +3. 返回数组 `counts`。 + + + {bitCounting} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。从 `1` 到 `n` 的每个数字都只处理一次,并且每个数字的操作都是恒定时间。 +* **空间复杂度:O(n)**。数组 `counts` 需要与输入大小 `n` 成比例的空间。 diff --git a/contents/questions/algo/bit-reversal/description/en-US.langnostic.json b/contents/questions/algo/bit-reversal/description/en-US.langnostic.json new file mode 100644 index 000000000..ae54ffb68 --- /dev/null +++ b/contents/questions/algo/bit-reversal/description/en-US.langnostic.json @@ -0,0 +1,31 @@ +{ + "frontmatter": { + "title": "a120bf2a", + "excerpt": "5ce63d79" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "1b0d8d4d", + "2d96efbe", + "d24913dd", + "d068a43f", + "b2065fc", + "f88d6618" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "1b0d8d4d", + "2d96efbe", + "d24913dd", + "d068a43f", + "b2065fc", + "f88d6618" + ] + } + } +} diff --git a/contents/questions/algo/bit-reversal/description/zh-CN.mdx b/contents/questions/algo/bit-reversal/description/zh-CN.mdx new file mode 100644 index 000000000..e46619e04 --- /dev/null +++ b/contents/questions/algo/bit-reversal/description/zh-CN.mdx @@ -0,0 +1,19 @@ +--- +title: 位翻转 +excerpt: 实现一个函数来翻转给定数字中的位顺序 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +实现一个函数,该函数反转给定 32 位无符号整数的位顺序,并返回其对应的十进制表示形式。 + +### 输入 + +- `n: number`: 一个整数 + + + +### 约束 + +- 0 <= `n` <= 1,000,000 diff --git a/contents/questions/algo/bit-reversal/solution/en-US.langnostic.json b/contents/questions/algo/bit-reversal/solution/en-US.langnostic.json new file mode 100644 index 000000000..602d97045 --- /dev/null +++ b/contents/questions/algo/bit-reversal/solution/en-US.langnostic.json @@ -0,0 +1,50 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "2efe5f9e", + "1f3c0c88", + "2081f60a", + "738b148f", + "b68df8f8", + "9c4b8867", + "88a632c", + "8e2de8c8", + "b1d28732", + "6592afc7", + "43fce5c3", + "8450c490", + "b68df8f8", + "52d8eb86", + "8524b837", + "8e2de8c8", + "e94e4824" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "2efe5f9e", + "1f3c0c88", + "2081f60a", + "738b148f", + "b68df8f8", + "9c4b8867", + "88a632c", + "8e2de8c8", + "b1d28732", + "6592afc7", + "43fce5c3", + "8450c490", + "b68df8f8", + "52d8eb86", + "8524b837", + "8e2de8c8", + "e94e4824" + ] + } + } +} diff --git a/contents/questions/algo/bit-reversal/solution/zh-CN.mdx b/contents/questions/algo/bit-reversal/solution/zh-CN.mdx new file mode 100644 index 000000000..226fe504f --- /dev/null +++ b/contents/questions/algo/bit-reversal/solution/zh-CN.mdx @@ -0,0 +1,67 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import reverseBits from '../setup/src/bit-reversal.ts'; +import reverseBitsMaskAndShift from '../setup/src/bit-reversal-mask-shift.ts'; + +## 1. 使用掩码和移位方法 + +用于位反转的掩码和移位方法使用位运算来有效地反转 32 位无符号整数的位。 关键直觉是,反转可以通过分层执行,方法是交换越来越小的位组。 从大组开始,例如 16 位的一半,该算法继续交换较小的组(字节、4 位半字节、成对的位,最后是单个位),直到所有位都处于其反转位置。 + +使用位掩码可确保在每个步骤中仅操作相关位,并且移位(`>>>` 用于无符号右移,`<<` 用于左移)将交换的位重新定位到它们正确的位置。 这种方法消除了单独处理每个位的需要,从而使算法非常高效。 + +### 算法 + +1. 交换左右 16 位的一半: + * 使用 `n >>> 16` 将右半部分移到最左边的位置。 + * 使用 `n << 16` 将左半部分移到最右边的位置。 + * 使用按位 OR 运算 (`|`) 组合结果。 +2. 交换连续的字节(8 位): + * 使用掩码 `0xff00ff00` 隔离最左边和最右边的字节,并将它们右移 8 位。 + * 使用掩码 `0x00ff00ff` 隔离内部字节,并将它们左移 8 位。 + * 使用按位 OR 运算组合结果。 +3. 交换连续的 4 位组(半字节): + * 使用掩码 `0xf0f0f0f0` 隔离 4 位组,并将它们右移 4 位。 + * 使用掩码 `0x0f0f0f0f` 隔离其他组,并将它们左移 4 位。 + * 使用按位 OR 运算组合结果。 +4. 交换连续的位对: + * 使用掩码 `0xcccccccc` 隔离位对,并将它们右移 2 位。 + * 使用掩码 `0x33333333` 隔离其他对,并将它们左移 2 位。 + * 使用按位 OR 运算组合结果。 +5. 交换单个位: + * 使用掩码 `0xaaaaaaaa` 隔离交替位,并将它们右移 1 位。 + * 使用掩码 `0x55555555` 隔离其他交替位,并将它们左移 1 位。 + * 使用按位 OR 运算组合结果。 +6. 使用 `>>> 0` 将最终结果作为无符号 32 位整数返回。 + + + {reverseBitsMaskAndShift} + + +### Big-O 分析 + +* **时间复杂度:O(1)**。 无论输入值如何,该算法都会执行固定数量的位运算。 +* **空间复杂度:O(1)**。 除了存储中间结果的几个变量之外,不需要额外的空间。 + +## 2. 使用位运算 + +用于位反转的位运算方法依赖于遍历给定整数的所有 32 位,并在新变量中重建反转的位序列。 关键思想是提取输入数字的最低有效位 (LSB),将其移到反转数字中的新位置,然后通过右移输入数字移到下一位。 此过程将一直持续到所有位都被反转。 + +反转的位通过左移反转的数字并在每个步骤中附加提取的位来逐步构建。 该方法通过直接操作单个位来确保正确性和效率。 + +### 算法 + +1. 将变量 `reversed` 初始化为 `0` 以存储反转的位序列。 +2. 循环 32 次以处理输入数字的每一位: + * 使用 `n & 1` 提取数字的最低有效位 (LSB)。 + * 将 `reversed` 左移一位,并使用按位 OR 运算 (`|`) 附加 LSB。 + * 将输入数字 (`n`) 右移一位以处理下一位。 +3. 使用 `>>> 0` 将 `reversed` 值作为无符号 32 位整数返回。 + + + {reverseBits} + + +### Big-O 分析 + +* **时间复杂度:O(1)**。 该算法处理固定数量的 32 位,因此运行时不依赖于输入大小。 +* **空间复杂度:O(1)**。 除了存储中间结果的几个变量之外,没有使用额外的空间。 diff --git a/contents/questions/algo/breadth-first-search/description/en-US.langnostic.json b/contents/questions/algo/breadth-first-search/description/en-US.langnostic.json new file mode 100644 index 000000000..6398da54a --- /dev/null +++ b/contents/questions/algo/breadth-first-search/description/en-US.langnostic.json @@ -0,0 +1,51 @@ +{ + "frontmatter": { + "title": "1e0d1e7c", + "excerpt": "99320ac7" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "efd115c9", + "616bcdd2", + "493e8bd0", + "d76ab8ca", + "784fa453", + "1fa48e13", + "e1958b52", + "49c8731f", + "dd526cc7", + "249b3d85", + "821ba3db", + "40bedc2b", + "6f85802e", + "862263c8", + "7dcecfa0", + "13731cea", + "c5441853" + ] + }, + "targets": { + "zh-CN": [ + "efd115c9", + "616bcdd2", + "493e8bd0", + "d76ab8ca", + "784fa453", + "1fa48e13", + "e1958b52", + "49c8731f", + "dd526cc7", + "249b3d85", + "821ba3db", + "40bedc2b", + "6f85802e", + "862263c8", + "7dcecfa0", + "13731cea", + "c5441853" + ] + } + } +} diff --git a/contents/questions/algo/breadth-first-search/description/en-US.mdx b/contents/questions/algo/breadth-first-search/description/en-US.mdx index 68ce3a12e..cb84b35c4 100644 --- a/contents/questions/algo/breadth-first-search/description/en-US.mdx +++ b/contents/questions/algo/breadth-first-search/description/en-US.mdx @@ -3,7 +3,7 @@ title: Breadth-first Search excerpt: Implement a breadth-first search algorithm that traverses a directed graph in a breadth-first manner --- -Write a function that implements the breadth-first search (BFS) algorithm on a directed graph (in adjacency list format), given a starting node. +Write a function `breadthFirstSearch(graph, source)` that implements the breadth-first search (BFS) algorithm on a directed graph (in adjacency list format), given a starting node (`source`). BFS is an algorithm used for traversing a graph or a tree, starting from the root node and exploring all the neighbors at the current depth before moving on to nodes at the next depth level. The output from BFS is an array of the graph's nodes in the order they were traversed. Visiting neighboring nodes in any order is a valid BFS, but for this question, please visit each node's neighbors from left to right. @@ -70,8 +70,14 @@ breadthFirstSearch(graph2, 'A'); // ['A', 'B', 'C', 'D', 'E', 'F', 'G'] ```js breadthFirstSearch(graph2, 'E'); // ['E'] +breadthFirstSearch({}, ''); // [] ``` +**Note:** + +- Return an empty array if the graph is empty. +- The `source` node, if provided, is guaranteed to be present in `graph`. + A `Queue` data structure is also provided for you at the bottom of the skeleton code. ## Recap (Hint) diff --git a/contents/questions/algo/breadth-first-search/description/zh-CN.mdx b/contents/questions/algo/breadth-first-search/description/zh-CN.mdx new file mode 100644 index 000000000..fbf81e8d2 --- /dev/null +++ b/contents/questions/algo/breadth-first-search/description/zh-CN.mdx @@ -0,0 +1,83 @@ +--- +title: 广度优先搜索 +excerpt: 实现一个广度优先搜索算法,该算法以广度优先的方式遍历有向图 +--- + +编写一个函数`breadthFirstSearch(graph, source)`,该函数在有向图(邻接表格式)上实现广度优先搜索(BFS)算法,给定一个起始节点(`source`)。 + +BFS 是一种用于遍历图或树的算法,从根节点开始,在移动到下一深度级别上的节点之前,先探索当前深度的所有邻居。BFS 的输出是一个数组,其中包含图的节点,按照它们被遍历的顺序排列。以任何顺序访问相邻节点都是有效的 BFS,但对于这个问题,请从左到右访问每个节点的邻居。 + +## 示例 + +```js +const graph1 = { + A: ['B', 'C', 'D'], + B: ['E', 'F'], + C: ['G', 'H'], + D: ['I', 'J'], + E: ['D'], + F: [], + G: [], + H: [], + I: [], + J: [], +}; + +breadthFirstSearch(graph1, 'A'); // ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'] +``` + +
+ Illustration of graph1 from node 'A' +
+ +```js +breadthFirstSearch(graph1, 'B'); // ['B', 'E', 'F', 'D', 'I', 'J'] +``` + +
+ Illustration of graph1 from node 'B' +
+ +```js +const graph2 = { + A: ['B', 'C'], + B: ['D', 'E'], + C: ['F', 'G'], + D: [], + E: [], + F: [], + G: [], +}; + +breadthFirstSearch(graph2, 'A'); // ['A', 'B', 'C', 'D', 'E', 'F', 'G'] +``` + +
+ Illustration of graph2 from node 'A' +
+ +```js +breadthFirstSearch(graph2, 'E'); // ['E'] +breadthFirstSearch({}, ''); // [] +``` + +**注意:** + +* 如果图为空,则返回一个空数组。 +* 如果提供了`source`节点,则保证它存在于`graph`中。 + +在骨架代码的底部也为您提供了一个`Queue`数据结构。 + +## 回顾(提示) + +广度优先搜索(BFS)是一种用于遍历图或树的算法。以下是 BFS 如何遍历图的概述,使用接受邻接表(我们使用数组代替)和根节点的标准实现: + +1. 初始化一个队列来存储要访问的节点。将根节点入队。 +2. 初始化一个集合来跟踪已访问的节点。 +3. 进入一个循环,该循环将持续到队列为空。在循环的每次迭代中: + 1. 从队列中出队并将其标记为已访问。 + 2. 从输入图中检索节点的邻居。 + 3. 对于每个邻居,检查它是否已被访问。如果尚未访问,则将节点入队。 +4. 返回已访问节点的集合。 + +广度优先搜索与[深度优先搜索](/questions/javascript/depth-first-search)的用途相同,并且特别适用于查找两个节点之间的最短路径。 diff --git a/contents/questions/algo/breadth-first-search/solution/en-US.langnostic.json b/contents/questions/algo/breadth-first-search/solution/en-US.langnostic.json new file mode 100644 index 000000000..dda4e71dd --- /dev/null +++ b/contents/questions/algo/breadth-first-search/solution/en-US.langnostic.json @@ -0,0 +1,54 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "53f85809", + "4cd64b66", + "ef0e1931", + "f8fa4769", + "44ff996b", + "16337cd9", + "ec054560", + "2d75adff", + "8670a8f2", + "a7ce86ac", + "499e5031", + "11ffe059", + "c998b811", + "a34a2355", + "bb1b042d", + "4e228b51", + "77f21390", + "5b6426bb", + "52f61c04" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "53f85809", + "4cd64b66", + "ef0e1931", + "f8fa4769", + "44ff996b", + "16337cd9", + "ec054560", + "2d75adff", + "8670a8f2", + "a7ce86ac", + "499e5031", + "11ffe059", + "c998b811", + "a34a2355", + "bb1b042d", + "4e228b51", + "77f21390", + "5b6426bb", + "52f61c04" + ] + } + } +} diff --git a/contents/questions/algo/breadth-first-search/solution/zh-CN.mdx b/contents/questions/algo/breadth-first-search/solution/zh-CN.mdx new file mode 100644 index 000000000..426f777a7 --- /dev/null +++ b/contents/questions/algo/breadth-first-search/solution/zh-CN.mdx @@ -0,0 +1,49 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import breadthFirstSearchJs from '../setup/src/breadth-first-search.js'; +import breadthFirstSearchTs from '../setup/src/breadth-first-search.ts'; +import breadthFirstSearchRecursive from '../setup/src/breadthFirstSearchRecursive'; + +## 澄清问题 + +如果未指定: + +* 遍历顺序:我们应该使用标准的先序遍历还是其他遍历顺序? +* 输入格式:输入数据的格式是什么?我们可以假设输入将是一个 JavaScript 对象的邻接表,其中键是节点,值是子节点吗? +* 输出格式:输出应该如何格式化?是否有具体要求,或者我们可以返回一个包含遍历顺序元素的数组? +* 不连通图:我们是否必须考虑或处理不连通图的情况,即存在多个彼此不连接的子图? + +## 迭代解法 + +该解决方案实现了描述中概述的算法。 + + + +## 递归解法 + +我们也可以递归地执行 BFS,这在某些情况下可能更直观。递归调用堆栈是一个隐式堆栈,用于跟踪接下来要访问的节点。 + + + {breadthFirstSearchRecursive} + + +## 边缘情况 + +* **空图**:返回一个空数组,不会崩溃。 +* **只有一两个节点的图**:遍历,不会崩溃。 +* **循环图**:确保不再遍历已访问的节点。 +* **不相交图**:不需要特殊处理,但最好知道。 + +## Big-O 分析 + +让我们分析一下算法的时间和空间复杂度。 + +### 时间复杂度 + +在最坏的情况下,BFS 访问图的每个顶点和每条边一次。因此,BFS 的时间复杂度为 O(V + E),其中 V 是图中顶点的数量,E 是边的数量。这是因为 BFS 必须探索所有顶点和边,以确保它覆盖整个图。 + +请注意,您不应该使用 `Array.shift()`,因为它需要 O(n) 时间来出列,其中 n 是数组中的元素数。 + +### 空间复杂度 + +BFS 使用队列来跟踪要访问的节点。在任何给定时间,队列都包含正在探索的图的当前级别的节点。因此,BFS 的空间复杂度为 O(图中任何级别的最大节点数)。 diff --git a/contents/questions/algo/bubble-sort/description/en-US.langnostic.json b/contents/questions/algo/bubble-sort/description/en-US.langnostic.json new file mode 100644 index 000000000..0209a2341 --- /dev/null +++ b/contents/questions/algo/bubble-sort/description/en-US.langnostic.json @@ -0,0 +1,37 @@ +{ + "frontmatter": { + "title": "11edf18a", + "excerpt": "86bad0ab" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "9769426a", + "493e8bd0", + "4d21496b", + "a8f76cea", + "44b403e9", + "e3a44875", + "9ae337dc", + "1934d3e0", + "52921986", + "2b9f8b06" + ] + }, + "targets": { + "zh-CN": [ + "9769426a", + "493e8bd0", + "4d21496b", + "a8f76cea", + "44b403e9", + "e3a44875", + "9ae337dc", + "1934d3e0", + "52921986", + "2b9f8b06" + ] + } + } +} diff --git a/contents/questions/algo/bubble-sort/description/zh-CN.mdx b/contents/questions/algo/bubble-sort/description/zh-CN.mdx new file mode 100644 index 000000000..46ad8d05a --- /dev/null +++ b/contents/questions/algo/bubble-sort/description/zh-CN.mdx @@ -0,0 +1,27 @@ +--- +title: 冒泡排序 +excerpt: 实现一个执行冒泡排序的函数 +--- + +实现一个执行冒泡排序的函数。该函数应接收一个整数数组,并返回一个按升序排序整数的数组。输入数组已修改。 + +## 例子 + +```js +bubbleSort([9, 3, 6, 2, 1, 11]); // [1, 2, 3, 6, 9, 11] +bubbleSort([12, 16, 14, 1, 2, 3]); // [1, 2, 3, 12, 14, 16] +``` + +## 回顾 + +冒泡排序是一种简单的排序算法,它比较并交换相邻的元素,使得在对数组进行每次迭代后,又一个元素将被排序/正确放置,从最大的元素开始。 + +该算法首先遍历数组,比较每对相邻的元素,如果较大的元素在左边,则交换它们。这将确保在一次完整的迭代之后,数组中最大的元素将在最后一个索引处。 + +![冒泡排序算法的第一次迭代插图](/img/questions/bubble-sort/bubble-sort-first-iteration.jpg) + +然后,该算法继续遍历数组并比较相邻的对,使得第二个最大的元素将在倒数第二个索引处。相邻对的比较可以忽略最后一个元素,因为它已经通过第一次迭代确认是数组中最大的元素。 + +例如,从上面的算法继续,该算法将进入第 3 次迭代,比较相邻的对,同时忽略最后一个和倒数第二个元素,因为它们已经按正确的顺序排列。 + +![冒泡排序算法的后续迭代插图](/img/questions/bubble-sort/bubble-sort-subsequent-iteration.png) diff --git a/contents/questions/algo/bubble-sort/solution/en-US.langnostic.json b/contents/questions/algo/bubble-sort/solution/en-US.langnostic.json new file mode 100644 index 000000000..6b0ca5b21 --- /dev/null +++ b/contents/questions/algo/bubble-sort/solution/en-US.langnostic.json @@ -0,0 +1,54 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "daf90dc5", + "36faae28", + "4cd64b66", + "ef0e1931", + "25738220", + "26e3ffe5", + "d9b370e", + "b919d1ff", + "499e5031", + "9b40838a", + "add698fb", + "7d476982", + "8aae30f9", + "c998b811", + "a34a2355", + "bb1b042d", + "9aeaaf24", + "5b6426bb", + "bcd620ac" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "daf90dc5", + "36faae28", + "4cd64b66", + "ef0e1931", + "25738220", + "26e3ffe5", + "d9b370e", + "b919d1ff", + "499e5031", + "9b40838a", + "add698fb", + "7d476982", + "8aae30f9", + "c998b811", + "a34a2355", + "bb1b042d", + "9aeaaf24", + "5b6426bb", + "bcd620ac" + ] + } + } +} diff --git a/contents/questions/algo/bubble-sort/solution/zh-CN.mdx b/contents/questions/algo/bubble-sort/solution/zh-CN.mdx new file mode 100644 index 000000000..a7482ef51 --- /dev/null +++ b/contents/questions/algo/bubble-sort/solution/zh-CN.mdx @@ -0,0 +1,48 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import bubbleSortJs from '../setup/src/bubble-sort.js'; +import bubbleSortTs from '../setup/src/bubble-sort.ts'; + +冒泡排序是一种稳定的、原地的、基于比较的算法,适用于小型到中型数组以及部分排序的数组。 + +## 澄清问题 + +如果未指定: + +* 应该按升序还是降序对数据进行排序? +* 我们需要处理什么样的输入? + * 它只是一个整数数组,还是我们应该处理其他数据类型? + * 是否存在大量重复元素? + * 应该如何处理负数? + +## 解决方案 + +注意:这个问题处理的是原地排序,以升序输出。请参阅下面的“注释”部分,了解如何处理其他情况。 + + + +## 边缘情况 + +* 非整数元素输入:如果输入数组包含不同数据类型的元素,您可能需要返回一个错误或满足于尽力排序,例如,仅对输入数据的子集进行排序,甚至为非整数定义自定义比较函数。 +* 单个元素/空输入:返回原始数据结构、引发错误或澄清所需处理。 +* 无效输入:如果输入不是数组,请考虑抛出错误。 + +## 注释 + +* 如果要求以降序排序:只需将比较更改为 `<` 而不是 `>`,如下所示: + +```js +if (arr[j] < arr[j + 1]) +``` + +## Big-O 分析 + +让我们分析一下算法的时间和空间复杂度。 + +### 时间复杂度 + +对于冒泡排序,时间复杂度为 O(n2),因为它需要一个嵌套循环结构。外循环对数组进行多次迭代,内循环遍历数组以比较每个相邻对,并根据它们的正确顺序交换元素。 + +### 空间复杂度 + +冒泡排序的空间复杂度为 O(1),因为它进行原地排序,不需要与输入大小成比例的额外存储。 diff --git a/contents/questions/algo/coin-change/description/en-US.langnostic.json b/contents/questions/algo/coin-change/description/en-US.langnostic.json new file mode 100644 index 000000000..5b51a94bf --- /dev/null +++ b/contents/questions/algo/coin-change/description/en-US.langnostic.json @@ -0,0 +1,33 @@ +{ + "frontmatter": { + "title": "e7e439fb", + "excerpt": "149cfec6" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "fa88ba5a", + "91c5bb5a", + "2d96efbe", + "4aba4a79", + "d068a43f", + "b2065fc", + "c27f5805" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "fa88ba5a", + "91c5bb5a", + "2d96efbe", + "4aba4a79", + "d068a43f", + "b2065fc", + "c27f5805" + ] + } + } +} diff --git a/contents/questions/algo/coin-change/description/zh-CN.mdx b/contents/questions/algo/coin-change/description/zh-CN.mdx new file mode 100644 index 000000000..278c194ea --- /dev/null +++ b/contents/questions/algo/coin-change/description/zh-CN.mdx @@ -0,0 +1,24 @@ +--- +title: 找零所需的最少硬币数 +excerpt: 实现一个函数,返回组成给定金额所需的最少硬币数 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个整数数组 `coins`,表示不同面额的硬币,以及一个整数 `target`,表示总金额,返回组成 `target` 所需的最少硬币数。如果无法通过任何硬币组合组成 `target`,则返回 `-1`。 + +假设每种硬币都有无限供应。 + +### 输入 + +- `coins: number[]`: 整数数组 +- `target: number`: 整数 + + + +### 约束 + +- 1 <= `coins.length` <= 12 +- 1 <= `coins[i]` <= 1,000,000 +- 0 <= `target` <= 10,000 diff --git a/contents/questions/algo/coin-change/solution/en-US.langnostic.json b/contents/questions/algo/coin-change/solution/en-US.langnostic.json new file mode 100644 index 000000000..d0f7a725e --- /dev/null +++ b/contents/questions/algo/coin-change/solution/en-US.langnostic.json @@ -0,0 +1,46 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "402e86a", + "f53543d7", + "f9e0abbb", + "b68df8f8", + "2e5dff0", + "d82fd847", + "8e2de8c8", + "367b8c4e", + "e5dc1bc8", + "8624f53", + "b68df8f8", + "bf0f0bee", + "caad9cd3", + "8e2de8c8", + "76815681" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "402e86a", + "f53543d7", + "f9e0abbb", + "b68df8f8", + "2e5dff0", + "d82fd847", + "8e2de8c8", + "367b8c4e", + "e5dc1bc8", + "8624f53", + "b68df8f8", + "bf0f0bee", + "caad9cd3", + "8e2de8c8", + "76815681" + ] + } + } +} diff --git a/contents/questions/algo/coin-change/solution/zh-CN.mdx b/contents/questions/algo/coin-change/solution/zh-CN.mdx new file mode 100644 index 000000000..7ad1a3866 --- /dev/null +++ b/contents/questions/algo/coin-change/solution/zh-CN.mdx @@ -0,0 +1,53 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import minimumCoinsForChange from '../setup/src/coin-change.ts'; +import minimumCoinsForChangeBruteForce from '../setup/src/coin-change-bruteforce-recursive.ts'; + +## 1. 使用递归的蛮力方法 + +目标是确定使用可用的硬币面额组成给定目标金额所需的最少硬币数量。蛮力方法递归地尝试每一种可能的硬币组合,以找到硬币最少的解决方案。递归探索减少目标金额到零的所有有效方法,并跟踪所需的最少硬币数量。 + +### 算法 + +1. 定义一个辅助函数`minimumCoinsForChangeHelper`,该函数接受硬币数组和剩余的目标金额作为参数。 +2. 如果目标金额为`0`,则返回`0`,因为不需要硬币。 +3. 将变量`minCoins`初始化为`Infinity`,以跟踪所需的最少硬币数量。 +4. 遍历硬币数组: + 1. 检查当前硬币面额是否小于或等于剩余的目标金额。 + 2. 递归调用辅助函数,传入剩余金额(`target - coin`)。 + 3. 如果找到有效的解决方案并且使用的硬币数量小于`minCoins`,则更新`minCoins`。 +5. 遍历所有硬币后,如果没有找到有效的解决方案,则返回`-1`;否则,返回`minCoins`的值。 +6. 主函数`minimumCoinsForChange`通过使用完整的目标金额调用辅助函数来初始化递归。 + + + {minimumCoinsForChangeBruteForce} + + +### Big-O 分析 + +* **时间复杂度:O(ct)**。 递归探索目标金额`t`的所有`c`硬币组合,导致指数时间复杂度。 +* **空间复杂度:O(t)**。 递归调用栈与目标金额`t`成正比增长。 + +## 2. 使用动态规划 + +动态规划方法通过避免对相同子问题的重复计算来改进蛮力解决方案。该方法没有递归地解决每一种可能的硬币组合,而是使用`dp`数组来存储组成从`0`到目标金额所需的最少硬币数量。通过建立在先前计算的值之上,迭代地计算每个值,确保每个子问题只解决一次。这消除了冗余工作,并显着降低了时间复杂度。 + +### 算法 + +1. 初始化一个大小为`target + 1`的`dp`数组,所有值都设置为`Number.MAX_VALUE`,以表示不可达状态。 +2. 将`dp[0]`设置为`0`,因为不需要硬币来组成金额`0`。 +3. 迭代金额从`1`到`target`: + 1. 对于每个金额,遍历硬币列表。 + 2. 如果当前硬币可以贡献到该金额(`i - coin >= 0`),则使用其当前值或`dp[i - coin] + 1`的最小值来更新`dp[i]`。 +4. 填充`dp`数组后,检查`dp[target]`处的值: + * 如果它仍然是`Number.MAX_VALUE`,则返回`-1`,因为目标金额无法实现。 + * 否则,返回`dp[target]`作为所需的最少硬币数量。 + + + {minimumCoinsForChange} + + +### Big-O 分析 + +* **时间复杂度:O(n.t)**。 遍历`target`金额并检查每个`n`硬币,结果为O(n.t)。 +* **空间复杂度:O(t)**。 `dp`数组所需的空间与目标金额`t`成正比。 diff --git a/contents/questions/algo/combinations-target-sum/description/en-US.langnostic.json b/contents/questions/algo/combinations-target-sum/description/en-US.langnostic.json new file mode 100644 index 000000000..2d4c3f37f --- /dev/null +++ b/contents/questions/algo/combinations-target-sum/description/en-US.langnostic.json @@ -0,0 +1,35 @@ +{ + "frontmatter": { + "title": "5c588a5", + "excerpt": "928fc115" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "ad42834b", + "2d96efbe", + "4d1fce3c", + "40808d83", + "82063913", + "d068a43f", + "b2065fc", + "5dc88300" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "ad42834b", + "2d96efbe", + "4d1fce3c", + "40808d83", + "82063913", + "d068a43f", + "b2065fc", + "5dc88300" + ] + } + } +} diff --git a/contents/questions/algo/combinations-target-sum/description/zh-CN.mdx b/contents/questions/algo/combinations-target-sum/description/zh-CN.mdx new file mode 100644 index 000000000..6f7966ec8 --- /dev/null +++ b/contents/questions/algo/combinations-target-sum/description/zh-CN.mdx @@ -0,0 +1,28 @@ +--- +title: 目标和的组合 +excerpt: 实现一个函数来计算总和为目标值的组合 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个唯一的整数列表 `numbers` 和一个整数 `target`,找到 `numbers` 中元素的不同组合的数量,这些组合加起来等于目标值。 + +### 输入 + +- `numbers: number[]`: 整数数组 +- `target: number`: 一个整数 + +### 注意事项 + +- 测试用例经过精心挑选,以确保输出落在 32 位整数的限制范围内 +- 由相同元素组成但顺序不同的组合被认为是不同的 + + + +### 约束 + +- 1 <= `numbers.length` <= 200 +- 1 <= `numbers[i]` <= 1000 +- 1 <= `target` <= 1000 +- numbers 的所有元素都是唯一的 diff --git a/contents/questions/algo/combinations-target-sum/solution/en-US.langnostic.json b/contents/questions/algo/combinations-target-sum/solution/en-US.langnostic.json new file mode 100644 index 000000000..d1eefa8b1 --- /dev/null +++ b/contents/questions/algo/combinations-target-sum/solution/en-US.langnostic.json @@ -0,0 +1,52 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "ec4cefc", + "e52f69c4", + "c29d3a08", + "86586572", + "154d4f7a", + "eb3bbf1b", + "b68df8f8", + "ab047c09", + "8e2de8c8", + "c7cf4abc", + "55105613", + "d09eb78e", + "538b75a6", + "b68df8f8", + "dfa33639", + "9c8641d", + "8e2de8c8", + "f2bd36bc" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "ec4cefc", + "e52f69c4", + "c29d3a08", + "86586572", + "154d4f7a", + "eb3bbf1b", + "b68df8f8", + "ab047c09", + "8e2de8c8", + "c7cf4abc", + "55105613", + "d09eb78e", + "538b75a6", + "b68df8f8", + "dfa33639", + "9c8641d", + "8e2de8c8", + "f2bd36bc" + ] + } + } +} diff --git a/contents/questions/algo/combinations-target-sum/solution/zh-CN.mdx b/contents/questions/algo/combinations-target-sum/solution/zh-CN.mdx new file mode 100644 index 000000000..d397f0950 --- /dev/null +++ b/contents/questions/algo/combinations-target-sum/solution/zh-CN.mdx @@ -0,0 +1,58 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import combinationTargetSum from '../setup/src/combinations-target-sum.ts'; +import combinationTargetSumTopDownApproach from '../setup/src/combinations-target-sum-top-down.ts'; + +## 1. 自底向上动态规划 + +解决组合目标和问题的动态规划方法通过将问题分解为更小的子问题来工作。关键的直觉是,实现特定和的方法的数量可以从实现更小和的方法的数量推导出来。通过从最小的子问题(和为 0)到目标和迭代地构建解决方案,该算法确保了所有中间结果都被重用。 + +对于从 1 到目标值的每个可能的和,都会考虑输入数组中的每个数字。如果该数字可以从当前和中减去而不会导致负值,则将剩余和的组合添加到当前和的组合中。这确保了所有对当前和的有效贡献都被考虑在内。基本情况是,形成和为 0 的方法恰好有一种(不使用任何元素),这确保了该过程正确开始。 + +这种方法避免了蛮力解决方案的低效率,蛮力解决方案会生成并检查数组的所有可能子集。相反,它通过使用先前计算的结果来迭代地构建解决方案,从而消除了冗余计算并显着降低了运行时复杂度。 + + + {combinationTargetSum} + + +### 算法 + +1. 初始化一个大小为 `target + 1` 的 `dp` 数组,并用 `0` 填充。此数组将存储从 `0` 到 `target` 的每个和的组合数。 +2. 设置 `dp[0] = 1` 以表示基本情况,其中实现和为 `0` 的方法恰好有一种(不使用任何元素)。 +3. 迭代所有可能的和 (`combSum`),从 `1` 到 `target`: + 1. 对于每个和,迭代输入数组 `numbers` 的元素。 + 2. 检查当前数字是否可以从 `combSum` 中减去而不会导致负值。这确保只考虑有效的组合。 + 3. 如果有效,通过添加 `dp[combSum - num]` 的值来更新 `dp[combSum]`。这会将实现剩余和 (`combSum - num`) 的方法数添加到当前和的计数中。 +4. 返回 `dp[target]`,它保存实现目标和的不同组合的数量。 + +### Big-O 分析 + +* **时间复杂度:O(n.t)**。该算法迭代从 `1` 到 `target` 的所有和(外循环),并处理 `numbers` 数组中的每个元素(内循环)。 +* **空间复杂度:O(t)**。`dp` 数组需要的空间与目标值成正比。 + +## 2. 自顶向下动态规划 + +自顶向下动态规划方法使用带有记忆的递归。关键思想是通过考虑从数组中减去每个数字后剩余的目标,将问题分解为更小的子问题。对于给定的目标,组合的数量是可以通过减去每个数字形成的较小目标的组合的总和。 + +这种方法避免了重新计算重叠子问题的低效率,这是蛮力递归解决方案中常见的瓶颈。记忆化将先前解决的子问题的结果存储在映射中,允许在后续计算中进行恒定时间检索。与朴素的递归方法相比,这减少了冗余计算并提高了效率。 + +### 算法 + +1. 初始化一个 `memo` 映射,以存储每个剩余目标的组合数。 +2. 定义一个递归辅助函数 `combs(remain)`: + 1. 检查 `remain` 是否等于 0。如果是,则返回 1,因为存在一个有效的组合(不使用其他数字)。 + 2. 如果 `memo` 映射包含 `remain` 的结果,则返回存储的值以避免冗余计算。 + 3. 初始化一个变量 `result` 为 0,以存储当前 `remain` 的组合数。 + 4. 迭代 `numbers` 数组中的每个数字: + 1. 如果 `remain - num` 为非负数,则递归调用 `combs(remain - num)` 并将结果添加到 `result`。 + 5. 将计算出的 `result` 存储在 `memo` 映射中以供将来参考。 +3. 返回调用 `combs(target)` 的结果,作为给定目标的总组合数。 + + + {combinationTargetSumTopDownApproach} + + +### Big-O 分析 + +* **时间复杂度:O(n.t)**。每个目标值的子问题只解决一次,解决每个问题都涉及迭代 `numbers`。 +* **空间复杂度:O(t)**。`memo` 映射存储了多达 `target` 个不同值的结果,并且递归堆栈在最坏的情况下可以深入到 `target`。 diff --git a/contents/questions/algo/count-ones-in-binary/description/en-US.langnostic.json b/contents/questions/algo/count-ones-in-binary/description/en-US.langnostic.json new file mode 100644 index 000000000..3624dbcef --- /dev/null +++ b/contents/questions/algo/count-ones-in-binary/description/en-US.langnostic.json @@ -0,0 +1,31 @@ +{ + "frontmatter": { + "title": "3f858584", + "excerpt": "156be330" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "62d7cee3", + "2d96efbe", + "ba0f89c6", + "d068a43f", + "b2065fc", + "e9069926" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "62d7cee3", + "2d96efbe", + "ba0f89c6", + "d068a43f", + "b2065fc", + "e9069926" + ] + } + } +} diff --git a/contents/questions/algo/count-ones-in-binary/description/zh-CN.mdx b/contents/questions/algo/count-ones-in-binary/description/zh-CN.mdx new file mode 100644 index 000000000..0749ee00d --- /dev/null +++ b/contents/questions/algo/count-ones-in-binary/description/zh-CN.mdx @@ -0,0 +1,19 @@ +--- +title: 计算二进制数中的设置位 +excerpt: 实现一个函数来查找给定整数的二进制表示中的设置位 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个正整数`num`,确定给定数字的二进制表示中存在的设置位(1s)的数量,通常称为汉明权重。 + +### 输入 + +- `num: number`: 一个正整数 + + + +### 约束 + +- 1 <= `num` <= 2^31 - 1 diff --git a/contents/questions/algo/count-ones-in-binary/solution/en-US.langnostic.json b/contents/questions/algo/count-ones-in-binary/solution/en-US.langnostic.json new file mode 100644 index 000000000..a2939317c --- /dev/null +++ b/contents/questions/algo/count-ones-in-binary/solution/en-US.langnostic.json @@ -0,0 +1,32 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "de2480c6", + "b3faebc0", + "2823b7c4", + "b68df8f8", + "b6648bed", + "1adaa653", + "8e2de8c8", + "15fd7e40" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "de2480c6", + "b3faebc0", + "2823b7c4", + "b68df8f8", + "b6648bed", + "1adaa653", + "8e2de8c8", + "15fd7e40" + ] + } + } +} diff --git a/contents/questions/algo/count-ones-in-binary/solution/zh-CN.mdx b/contents/questions/algo/count-ones-in-binary/solution/zh-CN.mdx new file mode 100644 index 000000000..190fef1f5 --- /dev/null +++ b/contents/questions/algo/count-ones-in-binary/solution/zh-CN.mdx @@ -0,0 +1,26 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import countOnesInBinary from '../setup/src/count-ones-in-binary.ts'; + +## 1. 使用 Brian Kernighan 算法 + +Brian Kernighan 算法用于遍历数字的二进制表示。该方法不是直接遍历所有位,而是在每次迭代中检查最低有效位,如果该位为 `1`,则更新计数,然后进行右移以丢弃最低有效位。此过程将持续到所有位都被处理。 + +### 算法 + +1. 初始化一个变量 `count`,用于存储在二进制表示中遇到的 `1` 的数量。 +2. 使用循环处理输入数字: + * 使用数字和 `1` 之间的按位 `AND` 运算来检查最低有效位。 + * 如果最低有效位是 `1`,则递增 `count`。 + * 对数字进行无符号右移 `1` 位,以丢弃最低有效位。 +3. 继续循环,直到数字变为 `0`,这意味着所有位都已处理。 +4. 返回 `count` 的值。 + + + {countOnesInBinary} + + +### Big-O 分析 + +* **时间复杂度:O(1)**。输入数字是一个 32 位整数。 +* **空间复杂度:O(1)**。该算法使用恒定的空间量,与输入大小无关。 diff --git a/contents/questions/algo/course-dependency/description/en-US.langnostic.json b/contents/questions/algo/course-dependency/description/en-US.langnostic.json new file mode 100644 index 000000000..6eac85b03 --- /dev/null +++ b/contents/questions/algo/course-dependency/description/en-US.langnostic.json @@ -0,0 +1,33 @@ +{ + "frontmatter": { + "title": "86d53fae", + "excerpt": "7c9c9d5b" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "647f07f5", + "7616a4be", + "2d96efbe", + "ae3bb861", + "d068a43f", + "b2065fc", + "61dbd09e" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "647f07f5", + "7616a4be", + "2d96efbe", + "ae3bb861", + "d068a43f", + "b2065fc", + "61dbd09e" + ] + } + } +} diff --git a/contents/questions/algo/course-dependency/description/zh-CN.mdx b/contents/questions/algo/course-dependency/description/zh-CN.mdx new file mode 100644 index 000000000..02edbcf3a --- /dev/null +++ b/contents/questions/algo/course-dependency/description/zh-CN.mdx @@ -0,0 +1,26 @@ +--- +title: 课程依赖 +excerpt: 实现一个函数,用于检查在给定先决条件的情况下是否可以完成所有课程 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +有一组课程,编号从`0`到`courses - 1`。每门课程可能有先决条件,这些先决条件决定了必须修读课程的顺序。这些先决条件以对列表的形式给出,其中每对`[a, b]`表示必须在课程`a`之前完成课程`b`。 + +确定是否可以在不违反任何先决条件约束的情况下完成所有课程。如果可以完成所有课程,则返回`true`;否则,返回`false`。 + +### 输入 + +- `courses: number`: 一个整数,表示课程的总数 +- `prerequisites: Array<[number, number]>`: 一个二维数组,其中每个元素`[a, b]`表示课程`b`是课程`a`的先决条件 + + + +### 约束 + +- 1 <= `courses` <= 1000 +- 0 <= `prerequisites.length` <= 1000 +- `prerequisites[i].length` == 2 +- 0 <= `a`, `b` \< courses +- `prerequisites`中的所有对`[a, b]`都是唯一的 diff --git a/contents/questions/algo/course-dependency/solution/en-US.langnostic.json b/contents/questions/algo/course-dependency/solution/en-US.langnostic.json new file mode 100644 index 000000000..e01ae4d24 --- /dev/null +++ b/contents/questions/algo/course-dependency/solution/en-US.langnostic.json @@ -0,0 +1,54 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "a97de3a4", + "bc1f8ace", + "129ae616", + "990660a7", + "742ff9e0", + "b68df8f8", + "d04efa66", + "e03630f7", + "8e2de8c8", + "66d4e142", + "5620eaf7", + "84531120", + "2447e612", + "367e3a98", + "b68df8f8", + "95e88f66", + "d419a8e1", + "8e2de8c8", + "826bf6b8" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "a97de3a4", + "bc1f8ace", + "129ae616", + "990660a7", + "742ff9e0", + "b68df8f8", + "d04efa66", + "e03630f7", + "8e2de8c8", + "66d4e142", + "5620eaf7", + "84531120", + "2447e612", + "367e3a98", + "b68df8f8", + "95e88f66", + "d419a8e1", + "8e2de8c8", + "826bf6b8" + ] + } + } +} diff --git a/contents/questions/algo/course-dependency/solution/zh-CN.mdx b/contents/questions/algo/course-dependency/solution/zh-CN.mdx new file mode 100644 index 000000000..6f8bbf099 --- /dev/null +++ b/contents/questions/algo/course-dependency/solution/zh-CN.mdx @@ -0,0 +1,80 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import courseDependency from '../setup/src/course-dependency.ts'; +import courseDependencyUsingDFS from '../setup/src/course-dependency-dfs.ts'; + +## 1. Kahn's Topological Sort + +该问题涉及确定是否可以在给定一组先决条件的情况下完成所有课程。这是一个经典的有向图循环检测问题。如果存在循环,则无法完成所有课程。Kahn 算法是一种拓扑排序方法,用于通过系统地删除没有传入边的节点来解决该问题。 + +关键思想是: + +* 使用邻接表构建图。 +* 跟踪每门课程的先决条件(入度)的数量。 +* 从没有先决条件的课程开始。 +* 处理每门课程,减少其邻居的入度。如果邻居的入度变为 0,则将其添加到处理队列中。 +* 如果所有课程都已处理完毕,而没有任何未访问的节点,则表示没有循环。 + +### 算法 + +1. 初始化一个 `indegree` 数组,以计算每门课程的先决条件数量。 +2. 初始化一个邻接表 (`adj`) 来表示有向图。 +3. 通过迭代先决条件来填充邻接表和 `indegree` 数组: + * 对于每对 `[a, b]`,在 `adj` 中将 `a` 添加为 `b` 的邻居。 + * 增加 `a` 的入度。 +4. 初始化一个队列,并将所有 `indegree` 为 0 的课程添加到队列中。 +5. 初始化一个计数器 `nodesVisited` 来跟踪已处理的课程数量。 +6. 执行 BFS: + * 从队列中删除一门课程并增加 `nodesVisited`。 + * 对于当前课程的每个邻居,减少其入度。 + * 如果邻居的入度变为 0,则将其添加到队列中。 +7. 处理完所有节点后,检查 `nodesVisited` 是否等于课程总数: + * 如果为真,则返回 `true`(所有课程都可以完成)。 + * 否则,返回 `false`(存在循环)。 + + + {courseDependency} + + +### Big-O 分析 + +* **时间复杂度:O(v + e)**。图在 O(e) 中构建,其中 `e` 是先决条件的数量。BFS 遍历每个课程和边一次,需要 O(v + e),其中 `v` 是课程的数量。 +* **空间复杂度:O(v + e)**。邻接表和队列需要 O(v + e) 空间。 + +## 2. 使用 DFS + +该问题涉及确定是否可以在给定一组先决条件的情况下完成所有课程。这是一个有向图中的图循环检测问题。如果存在循环,则并非所有课程都可以完成,因为至少有一门课程直接或间接依赖于自身。 + +该算法使用深度优先搜索 (DFS) 来检测循环: + +* 每门课程都表示为图中的一个节点。 +* 先决条件表示为节点之间的有向边。 +* 在 DFS 期间,节点被标记为已访问并添加到递归堆栈 (`inStack`) 中以检测循环。如果在递归堆栈中重新访问一个节点,则检测到循环。 +* 如果在访问所有节点后未找到循环,则可以完成所有课程。 + +### 算法 + +1. 初始化一个邻接表 `adj` 来表示图。 +2. 通过迭代 `prerequisites` 数组来构建图: + * 对于每对 `[a, b]`,在 `adj` 中将 `a` 添加为 `b` 的邻居。 +3. 初始化两个数组: + * `visit` 用于跟踪节点是否已被访问。 + * `inStack` 用于跟踪节点是否在当前的递归堆栈中。 +4. 定义一个 `dfs` 函数来执行以下操作: + * 如果当前节点在递归堆栈 (`inStack`) 中,则返回 `true`(检测到循环)。 + * 如果当前节点已被访问,则返回 `false`。 + * 将当前节点标记为已访问并将其添加到递归堆栈中。 + * 对于当前节点的每个邻居,递归调用 `dfs`。如果任何调用检测到循环,则返回 `true`。 + * 从递归堆栈中删除当前节点并返回 `false`(未检测到循环)。 +5. 对每个节点执行 DFS: + * 如果检测到循环,则返回 `false`。 +6. 如果在未检测到循环的情况下处理了所有节点,则返回 `true`。 + + + {courseDependencyUsingDFS} + + +### Big-O 分析 + +* **时间复杂度:O(v + e)**。构建图需要 O(e),其中 `e` 是先决条件的数量。DFS 访问每个节点和边一次,需要 O(v + e),其中 `v` 是课程的数量。 +* **空间复杂度:O(v + e)**。邻接表需要 O(e) 空间,而 `visit` 和 `inStack` 数组需要 O(v) 空间。 diff --git a/contents/questions/algo/depth-first-search/description/en-US.langnostic.json b/contents/questions/algo/depth-first-search/description/en-US.langnostic.json new file mode 100644 index 000000000..01c691a51 --- /dev/null +++ b/contents/questions/algo/depth-first-search/description/en-US.langnostic.json @@ -0,0 +1,33 @@ +{ + "frontmatter": { + "title": "d0a3593d", + "excerpt": "d518ec11" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "b38223d7", + "493e8bd0", + "78f19f59", + "862263c8", + "8725c5cf", + "27164468", + "1bd2d9e3", + "59cd8a45" + ] + }, + "targets": { + "zh-CN": [ + "b38223d7", + "493e8bd0", + "78f19f59", + "862263c8", + "8725c5cf", + "27164468", + "1bd2d9e3", + "59cd8a45" + ] + } + } +} diff --git a/contents/questions/algo/depth-first-search/description/zh-CN.mdx b/contents/questions/algo/depth-first-search/description/zh-CN.mdx new file mode 100644 index 000000000..044589470 --- /dev/null +++ b/contents/questions/algo/depth-first-search/description/zh-CN.mdx @@ -0,0 +1,58 @@ +--- +title: 深度优先搜索 +excerpt: 实现一个深度优先搜索算法,以深度优先的方式遍历有向图 +--- + +编写一个函数,该函数在给定起始节点的情况下,对有向图(邻接表格式)实现深度优先搜索算法。 + +## 例子 + +```js +const graph1 = { + A: ['B', 'C', 'D'], + B: ['E', 'F'], + C: ['G', 'H'], + D: ['I', 'J'], + E: ['D'], + F: [], + G: [], + H: [], + I: [], + J: [], +}; +depthFirstSearch(graph1, 'A'); // ['A', 'B', 'E', 'D', 'I', 'J', 'F', 'C', 'G', 'H'] +depthFirstSearch(graph1, 'B'); // ['B', 'E', 'D', 'I', 'J', 'F'] + +const graph2 = { + A: ['B', 'C'], + B: ['D', 'E'], + C: ['F', 'G'], + D: [], + E: [], + F: [], + G: [], +}; +depthFirstSearch(graph2, 'A'); // ['A', 'B', 'D', 'E', 'C', 'F', 'G'] +depthFirstSearch(graph2, 'E'); // ['E'] +``` + +## 回顾(提示) + +深度优先搜索 (DFS) 是一种用于遍历图或树的算法。DFS 的输出是图中节点按照遍历顺序排列的数组。此输出对于各种不同的用例和目的都很有用,这使得 DFS 成为一个有用的算法。一些用例: + +1. 查找特定节点或节点组。这在前端很常见,用于在 DOM 树中查找特定的 DOM 节点。 +2. 检查图是否已连接。 +3. 查找图中两个节点之间的路径。 +4. 生成有向无环图 (DAG) 的拓扑排序。 +5. 识别图中的循环。 +6. 作为其他算法的构建块。 + +以下是 DFS 如何遍历图的概述,使用接受邻接表(我们使用数组代替)和根节点的标准实现: + +1. 初始化一个数组或堆栈来存储要访问的节点。推送根节点。 +2. 初始化一个集合来跟踪已访问的节点。 +3. 进入一个循环,该循环将持续到堆栈为空。在循环的每次迭代中: + 1. 从数组/堆栈中弹出顶部节点。 + 2. 从输入图中检索节点的邻居。 + 3. 对于每个邻居,检查它是否已被访问。如果尚未访问,则将其添加到要访问的节点集中。 +4. 返回已访问节点的集合。 diff --git a/contents/questions/algo/depth-first-search/solution/en-US.langnostic.json b/contents/questions/algo/depth-first-search/solution/en-US.langnostic.json new file mode 100644 index 000000000..52e5a785d --- /dev/null +++ b/contents/questions/algo/depth-first-search/solution/en-US.langnostic.json @@ -0,0 +1,38 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "f34c4473", + "4cd64b66", + "ef0e1931", + "f8fa4769", + "26e3ffe5", + "16337cd9", + "b100770", + "9ae903ae", + "2bc74e06", + "499e5031", + "51ba3a7c" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "f34c4473", + "4cd64b66", + "ef0e1931", + "f8fa4769", + "26e3ffe5", + "16337cd9", + "b100770", + "9ae903ae", + "2bc74e06", + "499e5031", + "51ba3a7c" + ] + } + } +} diff --git a/contents/questions/algo/depth-first-search/solution/zh-CN.mdx b/contents/questions/algo/depth-first-search/solution/zh-CN.mdx new file mode 100644 index 000000000..3c770e2b7 --- /dev/null +++ b/contents/questions/algo/depth-first-search/solution/zh-CN.mdx @@ -0,0 +1,33 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import depthFirstSearchJs from '../setup/src/depth-first-search.js'; +import depthFirstSearchTs from '../setup/src/depth-first-search.ts'; +import depthFirstSearchRecursive from '../setup/src/depthFirstSearchRecursive'; + +## 澄清问题 + +如果未指定: + +* 遍历顺序:我们应该使用标准的先序遍历还是其他遍历顺序? +* 输入格式:输入数据的格式是什么?我们可以假设输入将是一个 JavaScript 对象的邻接表,其中键是节点,值是子节点吗? +* 输出格式:输出应该如何格式化?是否有特定的要求,或者我们可以返回一个数组,其中包含按遍历顺序排列的元素? +* 非连通图:我们是否必须考虑或处理非连通图的情况,其中有多个子图彼此不连接? + +## 解决方案 + +该解决方案实现了描述中概述的算法。 + + + +我们也可以递归地执行 DFS,这在某些情况下可能更直观。递归调用堆栈是一个隐式堆栈,用于跟踪接下来要访问的节点。 + + + {depthFirstSearchRecursive} + + +## 边缘情况 + +* 空图:返回一个空数组,不会崩溃。 +* 只有一两个节点的图:遍历而不会崩溃。 +* 循环图:确保不再遍历已访问的节点。 +* 不相交的图:不需要特殊处理,但最好知道。 diff --git a/contents/questions/algo/dijkstra/description/en-US.langnostic.json b/contents/questions/algo/dijkstra/description/en-US.langnostic.json new file mode 100644 index 000000000..c2495e2b6 --- /dev/null +++ b/contents/questions/algo/dijkstra/description/en-US.langnostic.json @@ -0,0 +1,45 @@ +{ + "frontmatter": { + "title": "9b888c4b", + "excerpt": "dbc604a2" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c479fc5b", + "2d96efbe", + "992080e0", + "662802c0", + "769690db", + "70e92007", + "a4d99643", + "b2065fc", + "c340d29d", + "862263c8", + "862336eb", + "1bfb1ae", + "fb10435b", + "ba7d2f89" + ] + }, + "targets": { + "zh-CN": [ + "c479fc5b", + "2d96efbe", + "992080e0", + "662802c0", + "769690db", + "70e92007", + "a4d99643", + "b2065fc", + "c340d29d", + "862263c8", + "862336eb", + "1bfb1ae", + "fb10435b", + "ba7d2f89" + ] + } + } +} diff --git a/contents/questions/algo/dijkstra/description/zh-CN.mdx b/contents/questions/algo/dijkstra/description/zh-CN.mdx new file mode 100644 index 000000000..0dff31037 --- /dev/null +++ b/contents/questions/algo/dijkstra/description/zh-CN.mdx @@ -0,0 +1,71 @@ +--- +title: Dijkstra 算法 +excerpt: 实现 Dijkstra 算法,以找到图中从源顶点开始的最短路径,该图表示为邻接表。 +--- + +给定一个加权有向图,表示为邻接表 (`graph`) 和一个起始节点 (`source`),实现 Dijkstra 算法以找到从 `source` 到图中所有其他节点的最短路径距离。该图包含节点和加权边。 + +### 输入 + +- `graph`:一个表示图的邻接表的对象。每个键都是一个节点标识符(例如 `'A'`、`'B'`),其值是另一个对象,将每个相邻节点映射到连接它们的边的非负权重。 +- `source`:用于计算最短路径的起始节点的标识符。 + +### 输出 + +- 一个对象,其中键是节点标识符,值表示从 `source` 到该节点的最短距离。从 `source` 无法到达的节点应将其距离设置为 `Infinity`(使用内置的 `Infinity` 常量)。 + +### 例子 + +```js +const graph1 = { + A: { B: 1, C: 4 }, + B: { E: 3, F: 2 }, + C: { G: 2 }, + D: { C: 3, J: 5 }, + E: { D: 2 }, + F: {}, + G: { H: 1 }, + H: { F: 4, J: 3 }, + I: {}, + J: {}, +}; + +dijkstra(graph1, 'A'); // Returns distances: { A: 0, B: 1, C: 4, D: 6, E: 4, F: 3, G: 6, H: 7, I: Infinity, J: 10 } + +const graph2 = { + A: { B: 2, C: 5 }, + B: { D: 1, E: 4 }, + C: { F: 3, G: 2 }, + D: {}, + E: {}, + F: {}, + G: {}, +}; + +dijkstra(graph2, 'A'); // Returns distances: { A: 0, B: 2, C: 5, D: 3, E: 6, F: 8, G: 7 } +``` + +### 约束 + +- 1 <= 节点数 <= 1000 +- 0 <= 边权重 <= 10000 +- 图可能包含循环 +- 图可能断开连接 + +## 回顾(提示) + +Dijkstra 算法是一种用于查找加权图中节点之间最短路径的基本算法。该算法可以处理具有非负权重的图,通常用于路由以及其他图算法的子程序。以下是一些典型的用例: + +1. 在 GPS 系统中,用于查找位置之间的最短驾驶路线。 +2. 在网络路由算法中,用于查找数据包的最短路径。 +3. 在调度理论中,用于查找通过一系列任务的最短(耗时最少)路径。 +4. 生成加权图的最小生成树 (MST)。 + +以下是 Dijkstra 算法的工作原理: + +1. 从图中所有节点的集合开始,为它们分配一个暂定的距离值:对于初始节点为零,对于所有其他节点为无穷大。将初始节点设置为当前节点。 +2. 对于当前节点,考虑其所有未访问的邻居并计算它们的暂定距离。将新计算的暂定距离与当前分配的值进行比较,并分配较小的一个。 +3. 一旦我们考虑了当前节点的所有未访问邻居,就将当前节点标记为已访问。已访问的节点将不再被检查。 +4. 如果目标节点已被标记为已访问,或者未访问集合中节点之间的最小暂定距离为无穷大(当初始节点和剩余未访问节点之间没有连接时发生),则停止。算法已完成。 +5. 否则,选择标有最小暂定距离的未访问节点,将其设置为新的“当前节点”,然后返回到步骤 2。 +6. 结果是从初始节点到所有其他节点的最短距离的映射。 diff --git a/contents/questions/algo/dijkstra/solution/en-US.langnostic.json b/contents/questions/algo/dijkstra/solution/en-US.langnostic.json new file mode 100644 index 000000000..4faeab965 --- /dev/null +++ b/contents/questions/algo/dijkstra/solution/en-US.langnostic.json @@ -0,0 +1,42 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "8647bead", + "d24a16db", + "46d12723", + "616cc5de", + "b68df8f8", + "3147f3b6", + "44bfbaf1", + "327b8ab1", + "2fb47a67", + "499e5031", + "eb13ccf4", + "8e2de8c8", + "6c4867dd" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "8647bead", + "d24a16db", + "46d12723", + "616cc5de", + "b68df8f8", + "3147f3b6", + "44bfbaf1", + "327b8ab1", + "2fb47a67", + "499e5031", + "eb13ccf4", + "8e2de8c8", + "6c4867dd" + ] + } + } +} diff --git a/contents/questions/algo/dijkstra/solution/zh-CN.mdx b/contents/questions/algo/dijkstra/solution/zh-CN.mdx new file mode 100644 index 000000000..32432ec09 --- /dev/null +++ b/contents/questions/algo/dijkstra/solution/zh-CN.mdx @@ -0,0 +1,35 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import dijkstraJs from '../setup/src/dijkstra.js'; +import dijkstraTs from '../setup/src/dijkstra.ts'; + +### 理由 + +Dijkstra 算法计算图中从具有非负边权重的源节点的**最短路径**。它使用贪心方法:在每一步中,它选择具有最小已知距离的未访问节点。 最小堆可以有效地执行此选择。 当找到到邻居的更短路径时,算法会更新其距离(松弛)并将其推入堆中。 这种策略保证了正确性,因为所有边权重都是非负的。 + +Dijkstra 算法假设非负权重。 对于具有负权重的图,需要使用其他算法,如 Bellman-Ford。 + +### 算法 + +提供的解决方案使用优先级队列(最小堆)来实现 Dijkstra 算法,以提高效率。 + +1. **初始化**:从所有节点设置为无穷大的距离开始,除了源节点设置为零。 +2. **优先级队列**:使用优先级队列贪婪地选择具有最小已知距离的下一个节点。 +3. **松弛**:对于每个选定的节点,如果通过当前节点找到更短的路径,则更新到其相邻节点的最短距离。 随后在优先级队列中添加或更新该邻居的距离。 +4. **终止**:当优先级队列为空时,算法终止,表明所有可到达的节点都已处理完毕。 + +![Dijkstra Illustration](/img/questions/dijkstra/dijkstra.png) + + + +## 边缘情况 + +* **空图**:返回一个空字典或映射,而不会崩溃 +* **一个或两个节点的图**:确保算法可以处理小图 +* **具有非连接组件的图**:从源无法到达的节点应保持其距离为无穷大 +* **具有零权重边的图**:确认零权重边不会导致算法逻辑出现问题 + +### Big-O 分析 + +* **时间复杂度:O((V + E) log V)**。 使用最小堆,提取最小值需要 O(log V)(最多执行 V 次),并且松弛每个 E 边也可能触发 O(log V) 堆更新。 +* **空间复杂度:O(v)**。 存储距离(`O(v)`)、已访问集合(`O(v)`)和优先级队列(最坏情况下为 `O(v)`)。 diff --git a/contents/questions/algo/disjoint-intervals/description/en-US.langnostic.json b/contents/questions/algo/disjoint-intervals/description/en-US.langnostic.json new file mode 100644 index 000000000..dd847fcca --- /dev/null +++ b/contents/questions/algo/disjoint-intervals/description/en-US.langnostic.json @@ -0,0 +1,37 @@ +{ + "frontmatter": { + "title": "3141f518", + "excerpt": "da8a699" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "6023fbc4", + "f5745adb", + "afbc3995", + "24fb4ca9", + "2d96efbe", + "3a913bd2", + "d068a43f", + "b2065fc", + "204c9b22" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "6023fbc4", + "f5745adb", + "afbc3995", + "24fb4ca9", + "2d96efbe", + "3a913bd2", + "d068a43f", + "b2065fc", + "204c9b22" + ] + } + } +} diff --git a/contents/questions/algo/disjoint-intervals/description/zh-CN.mdx b/contents/questions/algo/disjoint-intervals/description/zh-CN.mdx new file mode 100644 index 000000000..3ed68a5d9 --- /dev/null +++ b/contents/questions/algo/disjoint-intervals/description/zh-CN.mdx @@ -0,0 +1,28 @@ +--- +title: 不相交的区间 +excerpt: 实现一个函数,以确定需要移除的最小数量,以获得不重叠的区间 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个`intervals`数组,其中每个区间表示为`[start, end]`。每对表示数轴上区间的开始和结束。例如,`[1, 3]`表示一个从1开始到3结束的区间。 + +找到需要移除的最小区间数,使剩余的区间不相交。 + +如果数轴上没有两个区间重叠,则认为区间不相交。例如: + +- `[1, 3]` 和 `[4, 6]` 不相交,因为它们没有任何共同点 +- `[1, 5]` 和 `[4, 6]` 不相交,因为它们在4和5之间重叠 + +### 输入 + +- `intervals: Array<[number, number]>`: 整数对数组 + + + +### 约束 + +- 0 <= `intervals.length` <= 100 +- `intervals[i].length == 2` +- 0 <= `start` <= `end` <= 10,000 diff --git a/contents/questions/algo/disjoint-intervals/solution/en-US.langnostic.json b/contents/questions/algo/disjoint-intervals/solution/en-US.langnostic.json new file mode 100644 index 000000000..ccb30a2df --- /dev/null +++ b/contents/questions/algo/disjoint-intervals/solution/en-US.langnostic.json @@ -0,0 +1,32 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "9718d192", + "1d11ee9b", + "ab0d4101", + "b68df8f8", + "4a7b21bd", + "9697ddd4", + "8e2de8c8", + "ba3f87fa" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "9718d192", + "1d11ee9b", + "ab0d4101", + "b68df8f8", + "4a7b21bd", + "9697ddd4", + "8e2de8c8", + "ba3f87fa" + ] + } + } +} diff --git a/contents/questions/algo/disjoint-intervals/solution/zh-CN.mdx b/contents/questions/algo/disjoint-intervals/solution/zh-CN.mdx new file mode 100644 index 000000000..25de9c529 --- /dev/null +++ b/contents/questions/algo/disjoint-intervals/solution/zh-CN.mdx @@ -0,0 +1,26 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import nonOverLappingIntervals from '../setup/src/disjoint-intervals.ts'; + +## 1. 使用贪心方法 + +问题是找到要删除的最小区间数,使剩余的区间不重叠。贪心方法通过始终选择结束时间最早的区间来优化这一点,因为这为后续区间留出了最大的空间。按第二个元素排序可确保优先考虑结束时间最小的区间。 + +### 算法 + +1. 定义一个辅助函数 `compareSecondElement` 来比较两个区间的第二个元素并返回它们的差值。 +2. 使用 `compareSecondElement` 函数对输入 `intervals` 数组进行排序。 +3. 初始化 `ans` 以跟踪已删除的区间数,并初始化 `k` 以跟踪最后一个不重叠区间的结束时间。 +4. 遍历排序列表中的每个区间: + 1. 提取当前区间的开始 (`x`) 和结束 (`y`)。 + 2. 如果当前区间的开始时间大于或等于 `k`: + * 将 `k` 更新为当前区间的结束时间,因为没有重叠。 + 3. 否则,递增 `ans`,因为区间重叠并且需要删除。 +5. 返回 `ans`,它保存了为使区间不相交而删除的区间计数。 + + {nonOverLappingIntervals} + +### Big-O 分析 + +* **时间复杂度:O(n log n)**。对区间进行排序需要 O(n log n),后续遍历区间需要 O(n)。 +* **空间复杂度:O(1)**。该算法在恒定空间内运行,因为它就地处理输入数组。 diff --git a/contents/questions/algo/extraterrestrial-language/description/en-US.langnostic.json b/contents/questions/algo/extraterrestrial-language/description/en-US.langnostic.json new file mode 100644 index 000000000..ad8285d45 --- /dev/null +++ b/contents/questions/algo/extraterrestrial-language/description/en-US.langnostic.json @@ -0,0 +1,33 @@ +{ + "frontmatter": { + "title": "36c4c9fb", + "excerpt": "20554190" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "ac3caf30", + "34717be9", + "2d96efbe", + "d689bb99", + "d068a43f", + "b2065fc", + "e137d586" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "ac3caf30", + "34717be9", + "2d96efbe", + "d689bb99", + "d068a43f", + "b2065fc", + "e137d586" + ] + } + } +} diff --git a/contents/questions/algo/extraterrestrial-language/description/zh-CN.mdx b/contents/questions/algo/extraterrestrial-language/description/zh-CN.mdx new file mode 100644 index 000000000..c3f28844d --- /dev/null +++ b/contents/questions/algo/extraterrestrial-language/description/zh-CN.mdx @@ -0,0 +1,23 @@ +--- +title: 外星语言 +excerpt: 实现一个函数来验证并返回外星语言的字母表顺序 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +一种外星语言使用英文字母,但字母顺序未知。提供了一个字符串列表 `words`,它表示外星语言词典中的单词,并且声称这些单词是根据新语言的[字典顺序](https://en.wikipedia.org/wiki/Lexicographic_order)排序的。 + +如果此声明为假,并且 `words` 中的字符串排列方式无法匹配任何可能的字母顺序,则返回一个空字符串。否则,返回一个字符串,其中包含根据该语言规则排序的外星语言的唯一字母。如果存在多个有效解决方案,则接受其中任何一个。 + +### 输入 + +- `words: string[]`: 一个字符串数组,其中每个字符串都是外星语言中的一个单词 + + + +### 约束 + +- 1 <= `words.length` <= 100 +- 1 <= `words[i].length` <= 10 +- `words[i]` 仅由小写英文字母组成 diff --git a/contents/questions/algo/extraterrestrial-language/solution/en-US.langnostic.json b/contents/questions/algo/extraterrestrial-language/solution/en-US.langnostic.json new file mode 100644 index 000000000..089bccde4 --- /dev/null +++ b/contents/questions/algo/extraterrestrial-language/solution/en-US.langnostic.json @@ -0,0 +1,36 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "a894004", + "5abc6a64", + "8d028ee2", + "f900f190", + "96d8c8ca", + "b68df8f8", + "ba0590b3", + "a1dde2a0", + "8e2de8c8", + "36ba6ab3" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "a894004", + "5abc6a64", + "8d028ee2", + "f900f190", + "96d8c8ca", + "b68df8f8", + "ba0590b3", + "a1dde2a0", + "8e2de8c8", + "36ba6ab3" + ] + } + } +} diff --git a/contents/questions/algo/extraterrestrial-language/solution/zh-CN.mdx b/contents/questions/algo/extraterrestrial-language/solution/zh-CN.mdx new file mode 100644 index 000000000..c87c6020a --- /dev/null +++ b/contents/questions/algo/extraterrestrial-language/solution/zh-CN.mdx @@ -0,0 +1,38 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import extraterrestrialLanguage from '../setup/src/extraterrestrial-language.ts'; + +## 1. 使用BFS + +该问题是根据按字典顺序排序的单词列表来确定外星语言中字符的顺序。这涉及从给定的单词推断有向无环图 (DAG),并对其执行拓扑排序。 + +算法: + +* 构建一个图,其中节点代表唯一的字符,有向边表示字符的优先级。 +* 使用广度优先搜索 (BFS) 对图执行拓扑排序。 +* 处理无效情况,例如前缀冲突或图中的循环。 + +### 算法 + +1. 初始化一个邻接表 `adjList` 来表示图,并使用 `counts` 映射来跟踪每个字符的入度。 + * 将所有唯一字符添加到 `adjList` 和 `counts` 中。 +2. 遍历单词列表以建立优先级关系: + * 比较相邻的单词 `word1` 和 `word2`。 + * 检查 `word2` 是 `word1` 的前缀但更短的无效情况。 + * 对于 `word1` 和 `word2` 之间第一个不同的字符,在 `adjList` 中添加一条有向边,并增加 `counts` 中的入度。 +3. 使用 BFS 执行拓扑排序: + * 将所有入度为零的字符添加到队列中。 + * 处理队列中的每个字符: + * 将其附加到结果字符串中。 + * 减少其邻居的入度,并将入度变为零的任何邻居加入队列。 +4. 检查结果字符串是否包含所有唯一字符。如果不是,则存在循环,结果无效。 +5. 如果有效,则返回结果字符串,否则返回一个空字符串。 + + + {extraterrestrialLanguage} + + +### Big-O 分析 + +* **时间复杂度:O(n + m)**。处理所有字符需要 O(m),其中 `m` 是输入中字符的总数。构建边和执行 BFS 需要 O(n + m),其中 `n` 是唯一字符的数量。 +* **空间复杂度:O(n + m)**。邻接表和入度映射需要 O(n + m) 空间。 diff --git a/contents/questions/algo/graph-clone/description/en-US.langnostic.json b/contents/questions/algo/graph-clone/description/en-US.langnostic.json new file mode 100644 index 000000000..f8b5a6a3a --- /dev/null +++ b/contents/questions/algo/graph-clone/description/en-US.langnostic.json @@ -0,0 +1,43 @@ +{ + "frontmatter": { + "title": "13415d0d", + "excerpt": "46209640" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "1aca6225", + "f1730e77", + "cadc44f6", + "9b34acb9", + "e0db672f", + "2d96efbe", + "18ccc03c", + "d068a43f", + "40808d83", + "4cf0b88c", + "b2065fc", + "f6b688e4" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "1aca6225", + "f1730e77", + "cadc44f6", + "9b34acb9", + "e0db672f", + "2d96efbe", + "18ccc03c", + "d068a43f", + "40808d83", + "4cf0b88c", + "b2065fc", + "f6b688e4" + ] + } + } +} diff --git a/contents/questions/algo/graph-clone/description/zh-CN.mdx b/contents/questions/algo/graph-clone/description/zh-CN.mdx new file mode 100644 index 000000000..b4ddbffbc --- /dev/null +++ b/contents/questions/algo/graph-clone/description/zh-CN.mdx @@ -0,0 +1,40 @@ +--- +title: 图的克隆 +excerpt: 实现一个函数,深度克隆一个连通的无向图 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定对[连通无向图]()中节点的引用,创建并返回该克隆图节点的深拷贝。 + +深拷贝必须复制原始图的整个结构,确保所有节点及其连接都被准确复制,而无需引用原始图。 + +该图由`GraphNode`的集合表示,其中每个节点都有一个`neighbors`列表,它们也是`GraphNode`。 + +一个`GraphNode`具有以下接口: + +```ts +interface GraphNode { + val: number; + neighbors: GraphNode[]; +} +``` + +### 输入 + +- `node: GraphNode`: 连通无向图中的节点。示例显示了该图的[邻接表](https://en.wikipedia.org/wiki/Adjacency_list)表示 + + + +### 注意事项 + +- 不要返回原始图的任何节点 + +### 约束 + +- 0 <= 节点数 <= 100 +- 0 <= `GraphNode.val` <= 100 +- `GraphNode.val` 对于每个节点都是唯一的 +- 该图没有重复的边或自循环 +- 该图是连通的,这意味着从给定节点开始可以访问所有节点 diff --git a/contents/questions/algo/graph-clone/solution/en-US.langnostic.json b/contents/questions/algo/graph-clone/solution/en-US.langnostic.json new file mode 100644 index 000000000..d6e92c9b0 --- /dev/null +++ b/contents/questions/algo/graph-clone/solution/en-US.langnostic.json @@ -0,0 +1,52 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "447c2422", + "addb9fcc", + "21832d98", + "61383488", + "1da14fdc", + "b68df8f8", + "cb5e15b0", + "d43b311d", + "8e2de8c8", + "7cd3d063", + "bc315569", + "a9fb59d1", + "6d19f1f1", + "b68df8f8", + "a7c71e7f", + "82664ae3", + "8e2de8c8", + "ee7449ab" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "447c2422", + "addb9fcc", + "21832d98", + "61383488", + "1da14fdc", + "b68df8f8", + "cb5e15b0", + "d43b311d", + "8e2de8c8", + "7cd3d063", + "bc315569", + "a9fb59d1", + "6d19f1f1", + "b68df8f8", + "a7c71e7f", + "82664ae3", + "8e2de8c8", + "ee7449ab" + ] + } + } +} diff --git a/contents/questions/algo/graph-clone/solution/zh-CN.mdx b/contents/questions/algo/graph-clone/solution/zh-CN.mdx new file mode 100644 index 000000000..bf8a44da2 --- /dev/null +++ b/contents/questions/algo/graph-clone/solution/zh-CN.mdx @@ -0,0 +1,63 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import graphClone from '../setup/src/graph-clone.ts'; +import graphCloneBFS from '../setup/src/graph-clone-bfs.ts'; + +## 1. 使用 DFS + +任务是创建一个图的深拷贝。一个图由节点组成,每个节点都有一个值和邻居列表。挑战在于确保新图中的每个节点都是一个完全独立的副本,并且节点之间的所有连接都得到准确复制。 + +其基本原理是基于对图的深度优先搜索(DFS)遍历。从一个节点开始,算法递归地访问其所有邻居,并在遇到未访问的节点时创建新的克隆节点。为了避免重复工作并确保节点不会被多次克隆,使用 `Map` 来存储原始节点与其克隆对应物之间的关系。这确保了当一个节点被重新访问(由于循环或共享邻居)时,算法会重用 `Map` 中的现有克隆,而不是创建一个新的克隆。 + +这种方法反映了图的自然连接方式,在处理每个节点及其连接时逐步构建克隆图。通过递归处理邻居并利用 `Map` 来提高效率,该解决方案避免了不必要的工作重复,并保证了克隆图结构的正确性。 + +### 算法 + +1. 检查输入节点是否为 `null`。如果是,则返回 `null`,因为没有要克隆的图。 +2. 初始化一个 `Map` 来存储原始节点与其克隆对应物之间的映射。 +3. 定义一个递归的 `dfs` 函数: + * 如果当前节点已被访问,则从 `Map` 返回相应的克隆节点。 + * 创建一个具有当前节点的值和空邻居列表的新 `GraphNode`。 + * 将当前节点及其克隆添加到 `Map`。 + * 对于当前节点的每个邻居,使用 `dfs` 函数递归地克隆邻居,并将其添加到克隆节点的邻居列表中。 +4. 通过在输入节点上调用 `dfs` 来启动克隆过程。 +5. 返回克隆图的根节点。 + + + {graphClone} + + +### Big-O 分析 + +* **时间复杂度:O(v + e)**。在 DFS 遍历期间,图中的每个节点 (`v`) 和边 (`e`) 都只被访问一次。 +* **空间复杂度:O(v)**。`Map` 存储每个节点的映射,并且递归堆栈最多可以增长到图中节点的数量。 + +## 2. 使用 BFS + +这种方法使用广度优先搜索(BFS)遍历来系统地访问所有节点并克隆它们。BFS 确保节点逐层访问,并且每个节点只处理一次。`Map` 用于存储原始节点与其克隆之间的关系。这可以防止冗余克隆并有效地处理图中的循环。随着遍历的进行,每个节点的邻居都会被克隆并添加到相应克隆的邻居列表中。这确保了克隆图保持与原始图相同的结构。 + +此方法通过逐层处理节点,在遇到节点及其连接时克隆它们,并通过使用 `Map` 来避免重复,从而直观地工作。 + +### 算法 + +1. 检查输入节点是否为 `null`。如果是,则返回 `null`,因为没有要克隆的图。 +2. 初始化一个 `Map` 来存储原始节点与其克隆对应物之间的映射。 +3. 创建一个队列并将输入节点添加到其中以进行 BFS 遍历。 +4. 克隆输入节点并将其存储在 `Map` 中。 +5. 当队列不为空时: + * 从队列的前面删除一个节点。 + * 遍历当前节点的邻居。 + * 如果邻居尚未被克隆: + * 克隆邻居并将其添加到 `Map`。 + * 将邻居添加到队列中以进行进一步处理。 + * 将邻居的克隆添加到当前节点的克隆的邻居列表中。 +6. 从 `Map` 返回输入节点的克隆。 + + + {graphCloneBFS} + + +### Big-O 分析 + +* **时间复杂度:O(v + e)**。在 BFS 遍历期间,图中的每个节点 (`v`) 和边 (`e`) 都只被访问一次。 +* **空间复杂度:O(v)**。`Map` 存储每个节点的映射,并且队列在最坏的情况下最多包含 `v` 个节点。 diff --git a/contents/questions/algo/graph-count-connected-components/description/en-US.langnostic.json b/contents/questions/algo/graph-count-connected-components/description/en-US.langnostic.json new file mode 100644 index 000000000..0b8d2628a --- /dev/null +++ b/contents/questions/algo/graph-count-connected-components/description/en-US.langnostic.json @@ -0,0 +1,33 @@ +{ + "frontmatter": { + "title": "ca88fb2e", + "excerpt": "264105fe" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "23658d71", + "5ed2ede", + "2d96efbe", + "6db0230a", + "d068a43f", + "b2065fc", + "503906a" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "23658d71", + "5ed2ede", + "2d96efbe", + "6db0230a", + "d068a43f", + "b2065fc", + "503906a" + ] + } + } +} diff --git a/contents/questions/algo/graph-count-connected-components/description/zh-CN.mdx b/contents/questions/algo/graph-count-connected-components/description/zh-CN.mdx new file mode 100644 index 000000000..c51354bcb --- /dev/null +++ b/contents/questions/algo/graph-count-connected-components/description/zh-CN.mdx @@ -0,0 +1,27 @@ +--- +title: 图计算连通分量 +excerpt: 实现一个函数来计算图中连通分量的数量 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +考虑一个具有`num`个节点的图,从`0`到`num - 1`进行标记。给定`num`和边列表,其中每个`edges[i] = [a, b]`表示节点`a`和`b`之间的无向连接,确定图中连通分量的数量。 + +在图的上下文中,无向图的[component]()是一个连通的子图,它不是任何更大的连通子图的一部分。 + +### 输入 + +- `num: number`: 一个整数,图中节点的数量 +- `edges: Array<[number, number]>`: 一个二维数组,其中`edges[i] = [a, b]`表示节点`a`和`b`之间的无向边 + + + +### 约束 + +- 1 <= `num` <= 1000 +- 1 <= `edges.length` <= 2000 +- `edges[i].length` == 2 +- 0 <= `a` \< `b` \< `num` +- `a != b` +- 没有自循环或重复边 diff --git a/contents/questions/algo/graph-count-connected-components/solution/en-US.langnostic.json b/contents/questions/algo/graph-count-connected-components/solution/en-US.langnostic.json new file mode 100644 index 000000000..ea5c1ab1a --- /dev/null +++ b/contents/questions/algo/graph-count-connected-components/solution/en-US.langnostic.json @@ -0,0 +1,52 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "6b79fd69", + "addb9fcc", + "236b2e4f", + "576de2d5", + "c5eac327", + "b68df8f8", + "db07f1ba", + "5e6532df", + "8e2de8c8", + "bb6502fa", + "56cd8665", + "f259de8c", + "34884961", + "b68df8f8", + "41d24e34", + "16e42ebd", + "8e2de8c8", + "c5f2beef" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "6b79fd69", + "addb9fcc", + "236b2e4f", + "576de2d5", + "c5eac327", + "b68df8f8", + "db07f1ba", + "5e6532df", + "8e2de8c8", + "bb6502fa", + "56cd8665", + "f259de8c", + "34884961", + "b68df8f8", + "41d24e34", + "16e42ebd", + "8e2de8c8", + "c5f2beef" + ] + } + } +} diff --git a/contents/questions/algo/graph-count-connected-components/solution/zh-CN.mdx b/contents/questions/algo/graph-count-connected-components/solution/zh-CN.mdx new file mode 100644 index 000000000..4fa4dadfd --- /dev/null +++ b/contents/questions/algo/graph-count-connected-components/solution/zh-CN.mdx @@ -0,0 +1,67 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import graphCountConnectedComponents from '../setup/src/graph-count-connected-components.ts'; +import graphCountConnectedComponentsUsingDSU from '../setup/src/graph-count-connected-components-using-DSU.ts'; + +## 1. 使用 DFS + +该问题需要计算无向图中的连通分量数量。连通分量是一个子图,其中任意两个节点都可以相互到达,并且子图中的任何节点都不会连接到它之外的任何节点。 + +该方法使用深度优先搜索 (DFS) 来探索图。其思路是将图视为节点和边的集合,由邻接表表示。通过从一个未访问的节点开始,DFS 遍历将探索同一连通分量中的所有节点。每次遇到一个新的未访问节点时,它表示一个新的连通分量的开始。这确保了所有节点都被处理,并且不会遗漏任何组件。`visited` 数组用于跟踪已探索的节点,避免冗余遍历。 + +此方法消除了对已知连通分量中已存在的节点的非必要遍历,使其高效且系统化。 + +### 算法 + +1. 处理节点数 (`num`) 为 `0` 的边缘情况,立即返回 `0`。 +2. 初始化: + * 计数器 `components` 用于跟踪连通分量的数量。 + * 一个大小为 `num` 的数组 `visited`,所有元素都设置为 `0`,以标记未访问的节点。 + * 一个邻接表 `adjList` 来表示图,初始化为一个空数组的数组。 +3. 通过将每条边添加到两个连接节点的列表中,从给定的 `edges` 构建邻接表。 +4. 遍历所有节点: + * 如果一个节点未被访问,则增加 `components` 计数器。 + * 从该节点开始执行 DFS,将当前连通分量中所有可到达的节点标记为已访问。 +5. 返回 `components` 的值。 + + + {graphCountConnectedComponents} + + +### Big-O 分析 + +* **时间复杂度:O(v + e)**。在 DFS 遍历期间,每个节点 (`v`) 和边 (`e`) 都只被处理一次。 +* **空间复杂度:O(v + e)**。邻接表需要 O(v + e) 空间来存储图,`visited` 数组需要 O(v) 空间。 + +## 2. 不相交集合并 + +其思路是最初将每个节点视为其自己的组件。当处理边时,如果节点已连接,则将它们合并到同一组件中。并查集数据结构通过为每个集合维护一个代表并使用“按大小合并”策略来最小化树高,从而有效地跟踪组件。路径压缩通过在查找期间展平树结构来进一步优化 `find` 操作。 + +这种方法通过直接管理组件之间的关系来避免对图的冗余遍历,使用高效的操作,非常适合用于计算连通分量。 + +### 算法 + +1. 初始化两个数组: + * `representative` 用于跟踪每个节点的代表。最初,每个节点都是它自己的代表。 + * `size` 用于存储每个组件的大小。所有节点都初始化为大小 `1`。 +2. 将连通分量的初始计数设置为节点数 (`num`)。 +3. 定义一个 `find` 函数来确定节点的代表: + * 如果一个节点是它自己的代表,则返回该节点。 + * 否则,递归查找其父节点的代表,应用路径压缩以展平树结构。 +4. 定义一个 `combine` 函数来合并两个集合: + * 找到两个集合的根代表。 + * 如果代表相同,则节点已在同一集合中。返回 `0`。 + * 否则,执行按大小合并: + * 将较小的集合附加到较大的集合并更新大小。 + * 返回 `1` 以指示发生了合并。 +5. 遍历边列表。对于每条边,调用 `combine` 函数以合并连接的节点并减少连通分量的计数。 +6. 返回连通分量的最终计数。 + + + {graphCountConnectedComponentsUsingDSU} + + +### Big-O 分析 + +* **时间复杂度:O(e.α(v))**。由于路径压缩和按大小合并,并查集操作 `find` 和 `union` 几乎是恒定时间,其中 α(v) 是反阿克曼函数。 +* **空间复杂度:O(v)**。`representative` 和 `size` 数组所需的空间与节点数 (`v`) 成正比。 diff --git a/contents/questions/algo/graph-is-tree/description/en-US.langnostic.json b/contents/questions/algo/graph-is-tree/description/en-US.langnostic.json new file mode 100644 index 000000000..05717f81e --- /dev/null +++ b/contents/questions/algo/graph-is-tree/description/en-US.langnostic.json @@ -0,0 +1,37 @@ +{ + "frontmatter": { + "title": "718d8da", + "excerpt": "5f8c9b55" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "c8932604", + "b3ffbd3c", + "22445cbd", + "418a33ee", + "2d96efbe", + "55254b52", + "d068a43f", + "b2065fc", + "e9f10d5a" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "c8932604", + "b3ffbd3c", + "22445cbd", + "418a33ee", + "2d96efbe", + "55254b52", + "d068a43f", + "b2065fc", + "e9f10d5a" + ] + } + } +} diff --git a/contents/questions/algo/graph-is-tree/description/zh-CN.mdx b/contents/questions/algo/graph-is-tree/description/zh-CN.mdx new file mode 100644 index 000000000..b8f6b7141 --- /dev/null +++ b/contents/questions/algo/graph-is-tree/description/zh-CN.mdx @@ -0,0 +1,33 @@ +--- +title: 图是否为树 +excerpt: 实现一个函数来确定一个图是否为有效的树 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +考虑一个有`num`个节点的图,从`0`到`num - 1`进行标记。给定`num`和一个边列表,其中每个`edges[i] = [a, b]`表示节点`a`和`b`之间的无向连接,确定提供的边是否构成一个有效的树。 + +一个**[有效的树]()**是一个连通的、无环的图,它跨越所有`num`个节点。这意味着: + +1. 所有节点都必须可以从任何其他节点访问 +2. 图中不得包含任何循环 +3. 图中必须恰好有`num - 1`条边,其中`num`是节点的数量 + +如果边构成有效的树,则返回`true`;否则,返回`false`。 + +### 输入 + +- `num: number`: 图中节点的数量 +- `edges: Array<[number, number]>`: 一个二维数组,其中`edges[i] = [a, b]`表示节点`a`和`b`之间的无向边 + + + +### 约束 + +- 1 <= `num` <= 1000 +- 1 <= `edges.length` <= 1000 +- `edges[i].length` == 2 +- 0 <= `a`, `b` \< `num` +- `a != b` +- 没有自循环或重复的边 diff --git a/contents/questions/algo/graph-is-tree/solution/en-US.langnostic.json b/contents/questions/algo/graph-is-tree/solution/en-US.langnostic.json new file mode 100644 index 000000000..b3a553a95 --- /dev/null +++ b/contents/questions/algo/graph-is-tree/solution/en-US.langnostic.json @@ -0,0 +1,58 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "28b81023", + "689bf15b", + "904628b5", + "198d415d", + "12ebd4a8", + "2629f93a", + "de69e872", + "b68df8f8", + "2cc9ce6e", + "cb31de03", + "8e2de8c8", + "ebe98c61", + "310e04d8", + "6e5be79f", + "809e815", + "1b63198d", + "b68df8f8", + "84faa2a9", + "aa0cb872", + "8e2de8c8", + "17ca81ee" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "28b81023", + "689bf15b", + "904628b5", + "198d415d", + "12ebd4a8", + "2629f93a", + "de69e872", + "b68df8f8", + "2cc9ce6e", + "cb31de03", + "8e2de8c8", + "ebe98c61", + "310e04d8", + "6e5be79f", + "809e815", + "1b63198d", + "b68df8f8", + "84faa2a9", + "aa0cb872", + "8e2de8c8", + "17ca81ee" + ] + } + } +} diff --git a/contents/questions/algo/graph-is-tree/solution/zh-CN.mdx b/contents/questions/algo/graph-is-tree/solution/zh-CN.mdx new file mode 100644 index 000000000..9a6bdc3cc --- /dev/null +++ b/contents/questions/algo/graph-is-tree/solution/zh-CN.mdx @@ -0,0 +1,79 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import graphIsTree from '../setup/src/graph-is-tree.ts'; +import graphIsTreeUsingUnion from '../setup/src/graph-is-tree-using-union.ts'; + +## 1. 图论和 DFS + +问题是确定给定的无向图是否为有效树。 树定义为无环的连通图,对于 `n` 个节点,恰好有 `n - 1` 条边。 + +该解决方案背后的直觉是验证两个关键属性: + +1. 图应该是连通的,这意味着从任何节点开始都必须可以到达所有节点。 +2. 图中不应该有环。 + +深度优先搜索 (DFS) 用于遍历图,同时检测环。 遍历从单个节点开始,将节点标记为已访问在 `Set` 中。 在遍历期间,如果重新访问一个节点(不包括遍历中的父节点),则检测到一个环。 此外,检查边的数量以确保它恰好是 `n - 1`,因为这是有效树的必要条件。 + +这种方法通过在单个 DFS 遍历中结合环检测和连通性验证来避免冗余检查。 + +### 算法 + +1. 检查边的数量是否不等于 `num - 1`。 如果是,则返回 `false`,因为该图不能是树。 +2. 创建一个邻接表来表示该图: + * 初始化一个 `Map`,其中每个节点指向一个空数组。 + * 通过将每条边的两个端点添加到彼此的邻居列表中来填充邻接表。 +3. 初始化一个名为 `seen` 的空 `Set`,用于在遍历期间跟踪已访问的节点。 +4. 定义一个递归的 `dfs` 函数: + * 如果当前节点已经在 `seen` 中,则返回 `false`,因为这表示一个环。 + * 将当前节点添加到 `seen`。 + * 对于当前节点的每个邻居: + * 跳过父节点以避免误报环检测。 + * 递归地对邻居调用 `dfs`。 如果任何递归调用检测到环,则返回 `false`。 + * 在处理完所有邻居后返回 `true`。 +5. 从节点 `0` 开始调用 `dfs`,并将 `-1` 作为父节点。 +6. 通过检查 `seen` 的大小是否等于 `num` 来验证该图是否已连接。 +7. 如果未检测到环并且该图已连接,则返回 `true`。 + + + {graphIsTree} + + +### Big-O 分析 + +* **时间复杂度:O(v + e)**。 在 DFS 遍历期间,每个节点 (`v`) 和边 (`e`) 都会被访问一次。 +* **空间复杂度:O(v)**。 `seen` 集合和邻接表所需的空间与节点数成正比。 + +## 2. 图论和并查集 + +问题是确定给定的无向图是否为有效树。 树是一个连通图,没有环,对于 `n` 个节点,恰好有 `n - 1` 条边。 + +并查集数据结构用于有效地跟踪连通分量并检测环。 最初,每个节点都被视为其自己的分量。 当一条边连接两个节点时,`union` 操作会合并分量,而 `find` 操作使用路径压缩确保对节点分量的有效查找。 如果一条边连接了已经在同一分量中的两个节点,则检测到一个环。 此外,该图必须恰好有 `n - 1` 条边才能成为单个连通分量。 + +这种方法通过使用高效的并查集操作直接管理分量之间的关系,消除了对节点和边的冗余遍历。 + +### 算法 + +1. 检查边的数量是否不等于 `num - 1`。 如果是,则返回 `false`,因为该图不能是树。 +2. 初始化并查集数据结构: + * 创建一个 `parent` 数组,其中每个节点最初都是它自己的父节点。 + * 创建一个 `size` 数组来跟踪每个分量的大小,将所有大小初始化为 `1`。 +3. 定义 `find` 函数: + * 向上遍历父指针,直到到达分量的根。 + * 通过使路径上的所有节点直接指向根来应用路径压缩。 +4. 定义 `union` 函数: + * 使用 `find` 函数确定两个节点的根分量。 + * 如果根相同,则检测到一个环。 返回 `false`。 + * 否则,将较小的分量合并到较大的分量中并更新大小。 +5. 遍历边列表: + * 使用 `union` 函数合并由每条边连接的节点。 + * 如果在此过程中检测到环,则返回 `false`。 +6. 如果未检测到环,并且该图有 `n - 1` 条边,则返回 `true`。 + + + {graphIsTreeUsingUnion} + + +### Big-O 分析 + +* **时间复杂度:O(e.α(v))**。 由于路径压缩和按大小合并,`union` 和 `find` 操作几乎是恒定时间,其中 α(v) 是反阿克曼函数。 +* **空间复杂度:O(v)**。 `parent` 和 `size` 数组所需的空间与节点数 (`v`) 成正比。 diff --git a/contents/questions/algo/grid-count-islands/description/en-US.langnostic.json b/contents/questions/algo/grid-count-islands/description/en-US.langnostic.json new file mode 100644 index 000000000..dff4aac1c --- /dev/null +++ b/contents/questions/algo/grid-count-islands/description/en-US.langnostic.json @@ -0,0 +1,33 @@ +{ + "frontmatter": { + "title": "5ab85ac7", + "excerpt": "fd41fd5d" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "1e2776e3", + "6ecd341f", + "2d96efbe", + "e7b8f1a0", + "d068a43f", + "b2065fc", + "8e67716b" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "1e2776e3", + "6ecd341f", + "2d96efbe", + "e7b8f1a0", + "d068a43f", + "b2065fc", + "8e67716b" + ] + } + } +} diff --git a/contents/questions/algo/grid-count-islands/description/zh-CN.mdx b/contents/questions/algo/grid-count-islands/description/zh-CN.mdx new file mode 100644 index 000000000..430a31cb6 --- /dev/null +++ b/contents/questions/algo/grid-count-islands/description/zh-CN.mdx @@ -0,0 +1,22 @@ +--- +title: 计算网格中的岛屿数量 +excerpt: 实现一个函数来计算二维二进制网格中不同的岛屿数量 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个二维二进制网格`grid`,显示地图,其中`1`表示陆地,`0`表示水,确定不同岛屿的数量。 + +岛屿定义为水平或垂直连接的一组`1`,并被`0`或网格的边缘包围。假设网格完全被水包围。 + +### 输入 + +- `grid: number[][]`: 一个二维数组,其中每个元素是`1`或`0` + + + +### 约束 + +- 1 <= `grid.length`, `grid[i].length` <= 100 +- `grid[i][j]` is `0` or `1` diff --git a/contents/questions/algo/grid-count-islands/solution/en-US.langnostic.json b/contents/questions/algo/grid-count-islands/solution/en-US.langnostic.json new file mode 100644 index 000000000..994e58c07 --- /dev/null +++ b/contents/questions/algo/grid-count-islands/solution/en-US.langnostic.json @@ -0,0 +1,52 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "7272353d", + "addb9fcc", + "8db47ff7", + "7f3fe22d", + "8e91ab9", + "b68df8f8", + "6075c675", + "6c9956c5", + "8e2de8c8", + "f2c787d5", + "bc315569", + "6f93649e", + "f68bbd66", + "b68df8f8", + "436dd0d1", + "981c5c53", + "8e2de8c8", + "bf46a1d3" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "7272353d", + "addb9fcc", + "8db47ff7", + "7f3fe22d", + "8e91ab9", + "b68df8f8", + "6075c675", + "6c9956c5", + "8e2de8c8", + "f2c787d5", + "bc315569", + "6f93649e", + "f68bbd66", + "b68df8f8", + "436dd0d1", + "981c5c53", + "8e2de8c8", + "bf46a1d3" + ] + } + } +} diff --git a/contents/questions/algo/grid-count-islands/solution/zh-CN.mdx b/contents/questions/algo/grid-count-islands/solution/zh-CN.mdx new file mode 100644 index 000000000..8ea1967d1 --- /dev/null +++ b/contents/questions/algo/grid-count-islands/solution/zh-CN.mdx @@ -0,0 +1,62 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import countGridIslands from '../setup/src/grid-count-islands.ts'; +import countGridIsLandsBFS from '../setup/src/grid-count-islands-bfs.ts'; + +## 1. 使用 DFS + +该问题需要计算二维网格中岛屿的数量,其中每个单元格是陆地(`1`)或水域(`0`)。岛屿定义为水平或垂直连接的一组相邻陆地单元格。任务是计算网格中所有不同的岛屿。 + +该方法使用深度优先搜索(DFS)来遍历和标记岛屿的所有单元格,从陆地单元格开始。网格被就地修改,将已访问的单元格标记为水域(`0`),以避免重复访问它们。每次遇到未访问的陆地单元格时,它表示一个新的岛屿,并启动 DFS 以探索所有连接的陆地单元格。这确保了每个岛屿只被计算一次。 + +此方法消除了对已访问单元格的不必要检查,并通过直接修改网格来避免冗余处理。 + +### 算法 + +1. 从网格维度中检索行数和列数。 +2. 初始化计数器 `numIslands` 为 `0`,以存储岛屿的总数。 +3. 遍历网格中的每个单元格: + * 如果单元格值为 `1`(陆地),则增加 `numIslands` 计数器。 + * 从当前单元格执行 DFS,以探索整个岛屿并将所有连接的陆地单元格标记为已访问,方法是将其值设置为 `0`。 +4. 定义一个递归的 `dfs` 函数: + * 将当前单元格标记为已访问,方法是将其值设置为 `0`。 + * 递归地检查并访问所有相邻单元格(上、下、左、右),如果它们在范围内且其值为 `1`。 +5. 处理完网格中的所有单元格后,返回 `numIslands` 计数器。 + + + {countGridIslands} + + +### Big-O 分析 + +* **时间复杂度:O(m.n)**。网格中的每个单元格都会被访问一次,无论是在主迭代期间还是在 DFS 遍历期间。 +* **空间复杂度:O(m.n)**。当网格包含一个大的连接岛屿时,递归堆栈可能会增长到网格的大小。 + +## 2. 使用 BFS + +此方法使用广度优先搜索(BFS)来遍历网格。该方法从任何未访问的陆地单元格开始,这标志着一个新岛屿的开始。执行 BFS 遍历以访问所有连接的陆地单元格,将它们标记为已访问,方法是将其值设置为 `0`。这确保了每个岛屿只被计算一次。网格被就地修改,以节省用于跟踪已访问单元格的额外空间。 + +这种方法系统地探索每个岛屿,同时避免冗余检查,使其对大型网格高效。 + +### 算法 + +1. 从网格维度中检索行数和列数。 +2. 初始化计数器 `numIslands` 为 `0`,以跟踪岛屿的数量。 +3. 遍历网格中的每个单元格: + * 如果单元格值为 `1`(陆地),则增加 `numIslands` 计数器。 + * 将单元格值设置为 `0` 以将其标记为已访问。 + * 初始化一个用于 BFS 遍历的队列,并将当前单元格添加到队列中。 +4. 使用队列执行 BFS: + * 从队列中出队一个单元格。 + * 对于它的每个邻居(上、下、左、右): + * 如果邻居在范围内且其值为 `1`,则将其入队并将其标记为已访问,方法是将其值设置为 `0`。 +5. 处理完网格中的所有单元格后,返回 `numIslands` 计数器。 + + + {countGridIsLandsBFS} + + +### Big-O 分析 + +* **时间复杂度:O(m.n)**。网格中的每个单元格都会被访问一次,无论是在 BFS 遍历期间还是在主循环期间。 +* **空间复杂度:O(min(m, n))**。在最坏的情况下,BFS 队列可以增长到较小维度的尺寸,例如当网格只有一行或一列陆地时。 diff --git a/contents/questions/algo/grid-distinct-paths/description/en-US.langnostic.json b/contents/questions/algo/grid-distinct-paths/description/en-US.langnostic.json new file mode 100644 index 000000000..712e65d54 --- /dev/null +++ b/contents/questions/algo/grid-distinct-paths/description/en-US.langnostic.json @@ -0,0 +1,33 @@ +{ + "frontmatter": { + "title": "327214b9", + "excerpt": "c01a7e13" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "bd653fb0", + "dad757cb", + "2d96efbe", + "6141381f", + "d068a43f", + "b2065fc", + "83b2485" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "bd653fb0", + "dad757cb", + "2d96efbe", + "6141381f", + "d068a43f", + "b2065fc", + "83b2485" + ] + } + } +} diff --git a/contents/questions/algo/grid-distinct-paths/description/zh-CN.mdx b/contents/questions/algo/grid-distinct-paths/description/zh-CN.mdx new file mode 100644 index 000000000..bf6cd6073 --- /dev/null +++ b/contents/questions/algo/grid-distinct-paths/description/zh-CN.mdx @@ -0,0 +1,23 @@ +--- +title: 网格中的不同路径 +excerpt: 实现一个函数来计算机器人移动在 m x n 网格中的不同路径 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +一个机器人位于一个 `m` x `n` 网格中,从左上角 (`grid[0][0]`) 开始,目标是到达右下角 (`grid[m - 1][n - 1]`)。 在一步中,机器人只能向下或向右移动一个单元格。 + +给定整数 `m` 和 `n`,确定机器人可以到达右下角的不同的路径数量。 + +### 输入 + +- `m: number`: 一个整数 +- `n: number`: 一个整数 + + + +### 约束 + +- 结果不会超过 2^31 +- 1 <= `m`, `n` <= 100 diff --git a/contents/questions/algo/grid-distinct-paths/solution/en-US.langnostic.json b/contents/questions/algo/grid-distinct-paths/solution/en-US.langnostic.json new file mode 100644 index 000000000..fc410e993 --- /dev/null +++ b/contents/questions/algo/grid-distinct-paths/solution/en-US.langnostic.json @@ -0,0 +1,52 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "ca0f77f7", + "e52f69c4", + "49a20aad", + "60c65f98", + "29db1a5c", + "b68df8f8", + "57b0cde", + "22ceb49d", + "8e2de8c8", + "a2d1f3d7", + "55105613", + "de491688", + "8808f0a5", + "b68df8f8", + "fdee8968", + "3e9d040c", + "8e2de8c8", + "23c5a145" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "ca0f77f7", + "e52f69c4", + "49a20aad", + "60c65f98", + "29db1a5c", + "b68df8f8", + "57b0cde", + "22ceb49d", + "8e2de8c8", + "a2d1f3d7", + "55105613", + "de491688", + "8808f0a5", + "b68df8f8", + "fdee8968", + "3e9d040c", + "8e2de8c8", + "23c5a145" + ] + } + } +} diff --git a/contents/questions/algo/grid-distinct-paths/solution/zh-CN.mdx b/contents/questions/algo/grid-distinct-paths/solution/zh-CN.mdx new file mode 100644 index 000000000..301932c21 --- /dev/null +++ b/contents/questions/algo/grid-distinct-paths/solution/zh-CN.mdx @@ -0,0 +1,56 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import gridDistinctPaths from '../setup/src/grid-distinct-paths.ts'; +import gridDistinctPathsTopDown from '../setup/src/grid-distinct-paths-top-down.ts'; + +## 1. 自底向上动态规划 + +该问题要求找到一个 `m x n` 维网格从左上角到右下角的不同的路径数量。在任何时候,移动都仅限于向下或向右。 + +该方法使用自底向上的动态规划来高效地解决问题。其直觉是,到达网格中特定单元格的路径数量是到达其正上方单元格的路径数量与其左侧单元格的路径数量之和。这是因为到达当前单元格的唯一有效移动是从上方或从左侧。使用一个二维表来存储到达每个单元格的路径数量,避免了冗余计算。 + +这种方法通过迭代地在表中构建解决方案,消除了不必要的递归和重叠的子问题。 + +### 算法 + +1. 初始化一个大小为 `m x n` 的二维数组 `d`,所有单元格都设置为 `1`。这表示到达第一行或第一列的任何单元格只有一种方法。 +2. 从第二行和第二列开始遍历网格: + * 对于每个单元格 `(col, row)`,将到达该单元格的路径数量计算为到达其上方单元格 (`d[col-1][row]`) 的路径数量与到达其左侧单元格 (`d[col][row-1]`) 的路径数量之和。 +3. 继续此过程,直到所有单元格都被填充。 +4. 返回右下角单元格 `d[m-1][n-1]` 的值,该值表示从左上角到右下角的唯一路径总数。 + + + {gridDistinctPaths} + + +### Big-O 分析 + +* **时间复杂度:O(m.n)**。网格中的每个单元格都会被处理一次。 +* **空间复杂度:O(m.n)**。使用一个大小为 `m x n` 的二维数组来存储每个单元格的唯一路径数量。 + +## 2. 自顶向下动态规划 + +这种方法使用带备忘录的自顶向下动态规划来避免冗余计算。递归函数通过将直接下方单元格和直接右侧单元格的路径相加来计算从给定单元格到目的地的路径数量。备忘录表存储先前计算的单元格的结果,确保每个子问题只解决一次。这消除了不必要的重复工作,优化了解决方案。 + +这种方法有效地将问题分解为重叠的子问题,同时存储中间结果以减少总计算时间。 + +### 算法 + +1. 创建一个大小为 `m x n` 的备忘录表 `memo`,并将其初始化为 `null`,以存储子问题的结果。 +2. 定义一个递归辅助函数 `helper(row, col)`: + * 如果当前单元格是右下角 (`row === m-1` 且 `col === n-1`),则返回 `1`,因为到达目的地只有一条路径。 + * 如果当前单元格在网格之外 (`row >= m` 或 `col >= n`),则返回 `0`,因为不可能有路径。 + * 如果当前单元格的结果已存储在 `memo[row][col]` 中,则返回存储的值以避免冗余计算。 + * 将路径数量计算为来自下方单元格 (`helper(row+1, col)`) 和右侧单元格 (`helper(row, col+1)`) 的路径之和。 + * 将计算结果存储在 `memo[row][col]` 中。 +3. 通过为左上角调用 `helper(0, 0)` 来开始计算。 +4. 从递归调用中返回结果,该结果表示从左上角到右下角的路径总数。 + + + {gridDistinctPathsTopDown} + + +### Big-O 分析 + +* **时间复杂度:O(m.n)**。由于备忘录,每个单元格最多计算一次,总共有 `m.n` 个子问题。 +* **空间复杂度:O(m.n)**。备忘录表需要 `m.n` 的空间,并且递归堆栈在最坏的情况下可以增长到 `m + n` 层。 diff --git a/contents/questions/algo/grid-find-word/description/en-US.langnostic.json b/contents/questions/algo/grid-find-word/description/en-US.langnostic.json new file mode 100644 index 000000000..4cedfec57 --- /dev/null +++ b/contents/questions/algo/grid-find-word/description/en-US.langnostic.json @@ -0,0 +1,33 @@ +{ + "frontmatter": { + "title": "d8762a7f", + "excerpt": "7eae0374" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "19f6db8a", + "a3874bd3", + "2d96efbe", + "f9718f64", + "d068a43f", + "b2065fc", + "2706064b" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "19f6db8a", + "a3874bd3", + "2d96efbe", + "f9718f64", + "d068a43f", + "b2065fc", + "2706064b" + ] + } + } +} diff --git a/contents/questions/algo/grid-find-word/description/zh-CN.mdx b/contents/questions/algo/grid-find-word/description/zh-CN.mdx new file mode 100644 index 000000000..16d77cb4f --- /dev/null +++ b/contents/questions/algo/grid-find-word/description/zh-CN.mdx @@ -0,0 +1,24 @@ +--- +title: 在网格中查找单词 +excerpt: 实现一个函数来检查单词在网格中是否存在 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个尺寸为 `m x n` 的字符网格,确定是否可以通过连接网格中相邻的字符来形成指定的单词。 + +单词可以通过遍历相邻的单元格来形成,其中相邻的单元格是彼此直接相邻的,无论是水平还是垂直。网格中的每个单元格只能使用一次来形成单词。 + +### 输入 + +- `grid: string[][]`: 一个大小为 `m x n` 的二维数组,其中每个元素都是一个小写英文字母 +- `target: string`: 要在网格中搜索的字符串 + + + +### 约束 + +- 1 <= `grid.length`, `grid[i].length` <= 6 +- 1 <= `target.length` <= 15 +- 两个 `grid` 和 `target` 都只包含小写英文字母 diff --git a/contents/questions/algo/grid-find-word/solution/en-US.langnostic.json b/contents/questions/algo/grid-find-word/solution/en-US.langnostic.json new file mode 100644 index 000000000..c81c36f5e --- /dev/null +++ b/contents/questions/algo/grid-find-word/solution/en-US.langnostic.json @@ -0,0 +1,36 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "8523a609", + "554a4006", + "6179c45b", + "dd393583", + "8f06433b", + "b68df8f8", + "50de855f", + "57aaa633", + "8e2de8c8", + "3ba455db" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "8523a609", + "554a4006", + "6179c45b", + "dd393583", + "8f06433b", + "b68df8f8", + "50de855f", + "57aaa633", + "8e2de8c8", + "3ba455db" + ] + } + } +} diff --git a/contents/questions/algo/grid-find-word/solution/zh-CN.mdx b/contents/questions/algo/grid-find-word/solution/zh-CN.mdx new file mode 100644 index 000000000..eac5c750a --- /dev/null +++ b/contents/questions/algo/grid-find-word/solution/zh-CN.mdx @@ -0,0 +1,36 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import findWordInGrid from '../setup/src/grid-find-word.ts'; + +## 1. 使用回溯法 + +该问题要求判断给定的 `target` 单词是否存在于字符的二维网格中。该单词可以由网格中连续相邻的单元格构成,可以上下左右移动。一个单元格不能在同一个单词构造中重复使用。 + +该方法使用回溯法和深度优先搜索(DFS)来探索从网格中每个单元格开始的所有可能路径。在每一步,算法检查当前单元格是否与 `target` 的下一个字符匹配。如果发生不匹配或单元格超出边界,则放弃该路径。为了确保不重复访问单元格,在 DFS 探索期间,它被临时标记为已访问。在探索完所有方向后,单元格的值被恢复以使其他路径可以使用它。 + +这种方法系统地探索所有可能的路径,同时尽早修剪无效路径,优化搜索过程。 + +### 算法 + +1. 检索网格中的行数和列数。 +2. 定义一个递归的 `backtrack` 函数: + * 如果 `suffix` 为空,则返回 `true`,因为整个单词已匹配。 + * 检查当前单元格是否超出边界,或者它是否与 `suffix` 的第一个字符不匹配。如果是,则返回 `false`。 + * 通过暂时将其值更改为 `'#'` 来标记当前单元格为已访问。 + * 定义四个可能要探索的方向:右、下、左和上。 + * 遍历这些方向,并使用剩余的 `suffix` 递归调用相邻单元格的 `backtrack` 函数。 + * 在探索完所有方向后,恢复单元格的原始值。 + * 如果任何方向导致成功匹配,则返回 `true`;否则,返回 `false`。 +3. 遍历网格中的每个单元格: + * 从当前单元格开始,使用完整的 `target` 字符串调用 `backtrack` 函数。 + * 如果该函数返回 `true`,则该单词存在于网格中。 +4. 如果没有起始单元格导致匹配,则返回 `false`。 + + + {findWordInGrid} + + +### Big-O 分析 + +* **时间复杂度:O(m.n.3l)**。网格中的每个单元格 (`m.n`) 都可以启动搜索,并且对于单词中的每个字符 (`l`),最多探索 3 个方向(因为我们不会回到我们来的地方)。 +* **空间复杂度:O(l)**。递归堆栈深度与单词的长度 (`l`) 成正比。 diff --git a/contents/questions/algo/grid-find-words/description/en-US.langnostic.json b/contents/questions/algo/grid-find-words/description/en-US.langnostic.json new file mode 100644 index 000000000..5c7863874 --- /dev/null +++ b/contents/questions/algo/grid-find-words/description/en-US.langnostic.json @@ -0,0 +1,35 @@ +{ + "frontmatter": { + "title": "e7f9a4a4", + "excerpt": "76d13b66" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "919377d0", + "a3874bd3", + "ad09ffda", + "2d96efbe", + "7af3a443", + "d068a43f", + "b2065fc", + "14d25c9f" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "919377d0", + "a3874bd3", + "ad09ffda", + "2d96efbe", + "7af3a443", + "d068a43f", + "b2065fc", + "14d25c9f" + ] + } + } +} diff --git a/contents/questions/algo/grid-find-words/description/zh-CN.mdx b/contents/questions/algo/grid-find-words/description/zh-CN.mdx new file mode 100644 index 000000000..38890c948 --- /dev/null +++ b/contents/questions/algo/grid-find-words/description/zh-CN.mdx @@ -0,0 +1,30 @@ +--- +title: 在网格中查找单词 +excerpt: 实现一个函数,用于查找网格中存在的所有单词 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个字符网格`grid`,其尺寸为`m x n`,以及一个字符串列表`words`,找到网格中存在的所有单词。 + +可以通过遍历相邻的单元格来形成单词,其中相邻的单元格是彼此直接相邻的,无论是水平还是垂直。网格中的每个单元格只能使用一次来形成单词。 + +结果可以按任何顺序返回。 + +### 输入 + +- `grid: string[][]`: 大小为`m x n`的二维数组,其中每个元素都是小写英文字母 +- `words: string[]`: 要在网格中搜索的字符串列表 + + + +### 约束 + +- `m == grid.length` +- `n = grid[i].length` +- 1 <= `m`, `n` <= 12 +- 1 <= `words.length` <= 1000 +- 1 <= `words[i].length` <= 10 +- 仅由小写英文字母组成`grid`和`words[i]` +- `words`列表中的每个单词都是唯一的 diff --git a/contents/questions/algo/grid-find-words/solution/en-US.langnostic.json b/contents/questions/algo/grid-find-words/solution/en-US.langnostic.json new file mode 100644 index 000000000..96435dfa2 --- /dev/null +++ b/contents/questions/algo/grid-find-words/solution/en-US.langnostic.json @@ -0,0 +1,36 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "2dc7dc30", + "a92cbe7e", + "a4a425e9", + "67ee94cf", + "6cde9248", + "b68df8f8", + "c09fe3df", + "519efed5", + "8e2de8c8", + "cc34de77" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "2dc7dc30", + "a92cbe7e", + "a4a425e9", + "67ee94cf", + "6cde9248", + "b68df8f8", + "c09fe3df", + "519efed5", + "8e2de8c8", + "cc34de77" + ] + } + } +} diff --git a/contents/questions/algo/grid-find-words/solution/zh-CN.mdx b/contents/questions/algo/grid-find-words/solution/zh-CN.mdx new file mode 100644 index 000000000..1ce2cc441 --- /dev/null +++ b/contents/questions/algo/grid-find-words/solution/zh-CN.mdx @@ -0,0 +1,36 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import findWordsInGrid from '../setup/src/grid-find-words.ts'; + +## 1. 使用回溯和字典树 + +该任务是从给定的列表 (`words`) 中找到存在于 2D 网格中的所有单词。单词可以通过上下左右移动的相邻单元格顺序形成。每个单元格每个单词只能使用一次。 + +此解决方案使用字典树(前缀树)结合回溯来实现高效的单词查找和验证。字典树允许快速前缀匹配,使算法能够尽早放弃无效路径。列表中的每个单词都存储在字典树中,每条路径代表一个可能的单词。在回溯期间,算法从每个网格单元格开始探索所有可能的路径,并对照字典树进行检查以验证有效前缀。当字典树中匹配到完整的单词时,就会记录单词。 + +这种方法最大限度地减少了冗余检查,并有效地修剪了无效路径,与蛮力方法相比,显著提高了性能。 + +### 算法 + +1. 构建一个字典树来存储给定的 `words`: + * 使用根节点初始化字典树。 + * 对于 `words` 中的每个单词,遍历字典树,如果不存在,则为每个字符添加一个新节点。 + * 通过将单词存储在相应的节点中来标记字典树中每个单词的结尾。 +2. 定义一个 `backtracking` 函数来探索网格中的路径: + * 检查字典树中的当前节点是否代表一个完整的单词。如果是,将该单词添加到结果列表中,并将其标记为已使用以避免重复。 + * 暂时将当前网格单元格标记为已访问,方法是更改其值。 + * 探索所有相邻单元格(上、下、左、右),如果字典树中存在相应的字符,则递归调用 `backtracking` 函数。 + * 在探索完所有邻居后,恢复网格单元格的值。 + * 如果没有进一步的路径,则从字典树中删除叶节点以进行优化。 +3. 遍历网格中的每个单元格: + * 如果单元格的字符作为字典树中根节点的子节点存在,则从该单元格启动回溯搜索。 +4. 返回匹配的单词列表。 + + + {findWordsInGrid} + + +### Big-O 分析 + +* **时间复杂度:O(m.n.4.3l-1)**。该算法遍历所有 `m.n` 个单元格,在最坏的情况下,每个单元格最多探索 4.3l-1 条路径。当所有路径都有效时,就会发生这种情况,例如一个由相同字母填充的棋盘和一个包含单个长单词的字典。像从字典树中删除匹配节点这样的优化可以在找到所有单词后减少回溯成本。 +* **空间复杂度:O(l)**,其中 `l` 是字典中字母的总数。字典树使用 `l` 空间,如果单词也被存储,则使用 `2.l` 空间。在最坏的情况下,由于没有共享前缀,每个字母都有自己的节点。 diff --git a/contents/questions/algo/heap-sort/description/en-US.langnostic.json b/contents/questions/algo/heap-sort/description/en-US.langnostic.json new file mode 100644 index 000000000..e8f33f6c1 --- /dev/null +++ b/contents/questions/algo/heap-sort/description/en-US.langnostic.json @@ -0,0 +1,41 @@ +{ + "frontmatter": { + "title": "581d3a29", + "excerpt": "bb0f9b16" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "27328dbd", + "493e8bd0", + "1d122e45", + "a8f76cea", + "9eba7688", + "871c6263", + "f0c9f8ec", + "9d100621", + "ceff003e", + "93a33696", + "b8aead5c", + "8447dd6e" + ] + }, + "targets": { + "zh-CN": [ + "27328dbd", + "493e8bd0", + "1d122e45", + "a8f76cea", + "9eba7688", + "871c6263", + "f0c9f8ec", + "9d100621", + "ceff003e", + "93a33696", + "b8aead5c", + "8447dd6e" + ] + } + } +} diff --git a/contents/questions/algo/heap-sort/description/zh-CN.mdx b/contents/questions/algo/heap-sort/description/zh-CN.mdx new file mode 100644 index 000000000..820b2d4d3 --- /dev/null +++ b/contents/questions/algo/heap-sort/description/zh-CN.mdx @@ -0,0 +1,36 @@ +--- +title: 堆排序 +excerpt: 实现一个执行堆排序的函数 +--- + +实现一个执行堆排序的函数。该函数应接收一个整数数组,并返回一个按升序排序的整数数组。输入数组将就地修改。 + +## 例子 + +```js +heapSort([9, 3, 6, 2, 1, 11]); // [1, 2, 3, 6, 9, 11] +heapSort([12, 16, 14, 1, 2, 3]); // [1, 2, 3, 12, 14, 16] +``` + +## 回顾 + +堆排序是一种基于比较的排序算法,它迭代地将未排序的数组构建成一个最大堆数据结构,以识别最大元素,并逐步将其交换到未排序数组的末尾,从而构建一个已排序的数组。 + +### 最大堆 + +要理解堆排序,我们需要首先理解堆数据结构: + +* 二叉堆是一个部分排序的完整二叉树,它满足堆属性,类似于二叉搜索树,但具有不同的排序方式。 +* 堆属性 = 父节点和子节点之间的特定关系,它指定了它们的顺序。一个例子是最大堆属性,它指定所有父节点必须 >= 其子节点。同一级别的子节点之间的顺序无关紧要。因此,最大的节点总是在顶部,最小的节点在底部。同一级别的节点是无序的:![最大堆图示](/img/questions/heap-sort/max-heap-property.png) +* 完整二叉树 = 树的所有级别都已完全填充。如果最后一层部分填充,则首先从左到右填充。 +* 堆经常实现为数组。我们可以使用以下公式来计算堆的数组表示形式中父节点、左子节点和右子节点的索引: + * 左子节点索引 = 2 \* parentIdx + 1 + * 右子节点索引 = 2 \* parentIdx + 2 + +最大堆数组表示 + +### 堆排序的工作原理 + +堆排序本质上通过以下步骤工作: + +堆排序步骤 diff --git a/contents/questions/algo/heap-sort/solution/en-US.langnostic.json b/contents/questions/algo/heap-sort/solution/en-US.langnostic.json new file mode 100644 index 000000000..19743f836 --- /dev/null +++ b/contents/questions/algo/heap-sort/solution/en-US.langnostic.json @@ -0,0 +1,72 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "3300523a", + "5f5bf890", + "a5b75873", + "4cd64b66", + "ef0e1931", + "83c89232", + "26e3ffe5", + "d9b370e", + "fd056e58", + "499e5031", + "c5556e1", + "add698fb", + "be235ad2", + "51c231bc", + "362060ab", + "226bb4c2", + "86455a46", + "c998b811", + "a34a2355", + "bb1b042d", + "d85514a0", + "1139f95e", + "e706f679", + "ae9fb4dd", + "19bf71c", + "5b6426bb", + "f4db8963", + "3f64b30b" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "3300523a", + "5f5bf890", + "a5b75873", + "4cd64b66", + "ef0e1931", + "83c89232", + "26e3ffe5", + "d9b370e", + "fd056e58", + "499e5031", + "c5556e1", + "add698fb", + "be235ad2", + "51c231bc", + "362060ab", + "226bb4c2", + "86455a46", + "c998b811", + "a34a2355", + "bb1b042d", + "d85514a0", + "1139f95e", + "e706f679", + "ae9fb4dd", + "19bf71c", + "5b6426bb", + "f4db8963", + "3f64b30b" + ] + } + } +} diff --git a/contents/questions/algo/heap-sort/solution/zh-CN.mdx b/contents/questions/algo/heap-sort/solution/zh-CN.mdx new file mode 100644 index 000000000..ebffd3d90 --- /dev/null +++ b/contents/questions/algo/heap-sort/solution/zh-CN.mdx @@ -0,0 +1,83 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import heapSortJs from '../setup/src/heap-sort.js'; +import heapSortTs from '../setup/src/heap-sort.ts'; +import heapifyMin from '../setup/src/heapifyMin'; + +堆排序是一种原地、基于比较的算法,对于大型数组效果很好,因为它具有 O(nlog(n)) 的时间复杂度。 + +它也不需要任何额外的内存空间来对数据进行排序,因为它是一种原地排序算法。但是,它不是一种稳定的排序,这意味着具有相同值的元素的顺序可能不会被保留。 + +## 澄清问题 + +如果未指定: + +* 数据应该按升序还是降序排序? +* 应该对数据进行原地排序,还是可以使用额外的数据结构? +* 我们需要处理什么样的输入? + * 它只是一个整数数组,还是我们应该处理其他数据类型? + * 是否存在大量重复元素? + * 应该如何处理负数? + +## 解决方案 + +注意:此问题处理的是原地排序,用于升序输出。请参阅下面的“注释”部分,了解如何处理其他情况。 + + + +## 边缘情况 + +* 非整数元素输入:如果输入数组包含不同数据类型的元素,您可能需要返回一个错误,尽力进行排序,例如,仅对输入数据的子集进行排序,甚至为非整数定义自定义比较函数。 +* 单个元素/空输入:返回原始数据结构、引发错误或阐明所需处理方式。 +* 已排序的输入:您可能需要检测排序并原样返回输入。 +* 无效输入:如果输入不是数组,请考虑抛出错误。 + +## 注释 + +* 如果要求按降序排序:更改 `heapify()` 函数中的比较运算符,以便构建最小堆而不是最大堆,然后在 `heapSort` 中照常使用它: + + + {heapifyMin} + + +* 如果要求使用额外的数据结构或编写纯函数而不是对数据进行原地排序,请创建数组的副本并返回已排序数组的浅层副本: + +```js +function heapSort(arr) { + const result = arr.slice(0); + const size = arr.length; + for (let i = Math.floor(size / 2 - 1); i >= 0; i--) { + heapify(result, size, i); + } + for (let i = size - 1; i >= 0; i--) { + [result[0], result[i]] = [result[i], result[0]]; + heapify(result, i, 0); + } + return result; +} +``` + +* 如果您想知道为什么 `Math.floor(size / 2 - 1)` 能够计算最后一个父节点的索引,那是因为在完全二叉树中,父节点的数量等于 Math.floor(size / 2)。末尾的 -1 是必需的,因为数组中的索引从 0 开始,而不是 1。 + +## Big-O 分析 + +让我们分析一下算法的时间和空间复杂度。 + +### 时间复杂度 + +堆排序的最佳、平均和最坏情况下的时间复杂度为 O(nlog n)。 无论元素是否已排序,该算法都将始终需要 O(nlog(n)) 时间才能完成。 除非您检测到已排序的数组并立即返回它们以获得最佳情况下的 O(n) 时间复杂度(对于完全排序的数组),否则这是准确的。 + +要理解堆排序的时间复杂度,理解 `heapify()` 的时间复杂度至关重要。 在 `heapify()` 中,我们从上到下遍历树,这意味着时间复杂度与二叉树的高度成正比,对于大小为 n 的树,高度最多为 O(log(n))。 因此,`heapify()` 函数的时间复杂度为 O(log(n))。 + +堆排序的时间复杂度为 O(nlog(n)),因为该算法有 2 个步骤:构建堆,然后对数据进行排序。 + +1. 构建堆的时间复杂度为 O(n),因为 `heapify()` 方法是从最后一个节点开始,以树根结束,向后为每个父节点调用。 平均而言,这可以在 O(n) 时最佳地完成。 +2. 对数据进行排序时,我们调用 `heapify()` 方法 n-1 次以维护数组未排序部分的堆属性。 因此,总的时间复杂度为 O(nlog(n))。 + +堆排序的总时间复杂度是每个步骤的时间复杂度的总和,即 O(n) + O(nlog(n)) = O(nlog(n))。 + +### 空间复杂度 + +堆排序的空间复杂度为 O(1),因为它进行原地排序,不需要与输入大小成比例的额外存储空间。 + +但是,如果使用递归函数调用来实现该算法,则空间复杂度将为 O(n),这需要额外的内存空间来存储函数调用堆栈。 diff --git a/contents/questions/algo/heap/description/en-US.langnostic.json b/contents/questions/algo/heap/description/en-US.langnostic.json new file mode 100644 index 000000000..c93204cbd --- /dev/null +++ b/contents/questions/algo/heap/description/en-US.langnostic.json @@ -0,0 +1,25 @@ +{ + "frontmatter": { + "title": "1958ab29", + "excerpt": "a5fd3c18" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c678b447", + "c6721167", + "493e8bd0", + "5b2c22a0" + ] + }, + "targets": { + "zh-CN": [ + "c678b447", + "c6721167", + "493e8bd0", + "5b2c22a0" + ] + } + } +} diff --git a/contents/questions/algo/heap/description/zh-CN.mdx b/contents/questions/algo/heap/description/zh-CN.mdx new file mode 100644 index 000000000..7847b0160 --- /dev/null +++ b/contents/questions/algo/heap/description/zh-CN.mdx @@ -0,0 +1,29 @@ +--- +title: 堆 +excerpt: 实现一个包含基本堆操作的堆数据结构 +--- + +用 JavaScript 实现一个堆数据结构,它支持以下操作: + +* `new Heap(array)`: 创建一个 Heap 类的实例,用 `array` 初始化并堆化它以形成初始的堆结构。它还初始化维护堆属性所需的任何内部结构。 +* `heapify(array)`: 从无序数组构造堆,在所有元素中建立最大堆属性。这是作为构造函数的一部分执行的,或者可以是一个单独的方法,用于重置和重建堆。所需的时间复杂度:O(n),其中 n 是数组中的元素数。 +* `insert(value)`: 将一个新值添加到堆中,保持最大堆属性。所需的时间复杂度:O(log n),其中 n 是插入后堆中的元素数。 +* `delete()`: 从堆中删除并返回最大值,在删除后保持最大堆属性。所需的时间复杂度:O(log n)。 +* `findMax()`: 返回堆中的最大值,而不删除它。所需的时间复杂度:O(1)。 + +## 例子 + +```js +const heap = new Heap(); +heap.insert(20); +heap.insert(15); +heap.insert(30); +heap.findMax(); // 30 +heap.insert(10); +heap.delete(); // 30 +heap.findMax(); // 20 + +const array = [5, 3, 17, 10, 84, 19, 6, 22, 9]; +const newHeap = new Heap(array); +newHeap.findMax(); // 84 +``` diff --git a/contents/questions/algo/heap/solution/en-US.langnostic.json b/contents/questions/algo/heap/solution/en-US.langnostic.json new file mode 100644 index 000000000..d2c637fab --- /dev/null +++ b/contents/questions/algo/heap/solution/en-US.langnostic.json @@ -0,0 +1,48 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "d5511819", + "26e3ffe5", + "438f285f", + "b9e8a2fa", + "1c9e8560", + "c169b074", + "e36a4537", + "427f977c", + "9cd1a8de", + "17b745b0", + "499e5031", + "9a8edc15", + "d87b3100", + "490de692", + "36aac625", + "6ffa41bc" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "d5511819", + "26e3ffe5", + "438f285f", + "b9e8a2fa", + "1c9e8560", + "c169b074", + "e36a4537", + "427f977c", + "9cd1a8de", + "17b745b0", + "499e5031", + "9a8edc15", + "d87b3100", + "490de692", + "36aac625", + "6ffa41bc" + ] + } + } +} diff --git a/contents/questions/algo/heap/solution/zh-CN.mdx b/contents/questions/algo/heap/solution/zh-CN.mdx new file mode 100644 index 000000000..1fbae13e6 --- /dev/null +++ b/contents/questions/algo/heap/solution/zh-CN.mdx @@ -0,0 +1,39 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import heapJs from '../setup/src/heap.js'; +import heapTs from '../setup/src/heap.ts'; + +## 解决方案 + +堆是一种特殊的基于树的数据结构,它满足堆属性,其中在最大堆中,每个父节点都大于或等于其子节点的值。此属性使堆成为实现优先级队列的理想选择,在优先级队列中,需要快速访问最高(或最低)优先级元素。 + +### 操作 + +* `heapify(array)`:从无序数组构造堆。这是通过对数组的后半部分执行一系列插入操作来完成的,以就地构建堆。 +* `insert(value)`:向堆中添加一个新元素。这涉及将元素附加到数组的末尾(表示堆),然后向上移动新添加的元素,直到恢复堆属性(如果它被违反)。 + +![Insert](/img/questions/heap/insert.png) + +* `delete()`:删除堆的根元素,即最大堆中的最大值。堆的最后一个元素替换根,然后慢慢向下移动,直到恢复堆属性。 + +![Delete](/img/questions/heap/delete.png) + +* `findMax()`:返回堆的根元素,而不删除它,从而提供对最大值的恒定时间访问。 + +由于操作 `insert` 和 `delete` 可能涉及在堆的高度上移动元素,因此它们的时间复杂度为 O(log n),其中 n 是堆中元素的数量。`findMax` 是一个恒定时间操作,O(1),因为它返回第一个元素。`Heapify` 的时间复杂度为 O(n log(n)),因为它遍历每个元素并逐个缓慢地插入它们。 + +## 边缘情况 + +* 插入到空堆中。 +* 从空堆中删除。 +* 在空堆上调用 `findMax`。 + +## 技术 + +* 面向对象编程。 +* 数组操作以模拟二叉树。 +* 了解对数时间复杂度以及操作如何影响它。 + +此堆实现侧重于高效的数据操作,利用二叉树的属性来确保快速访问高优先级项目,同时保持以对数时间进行调整的能力。 + + diff --git a/contents/questions/algo/insertion-sort/description/en-US.langnostic.json b/contents/questions/algo/insertion-sort/description/en-US.langnostic.json new file mode 100644 index 000000000..33b3d2fe0 --- /dev/null +++ b/contents/questions/algo/insertion-sort/description/en-US.langnostic.json @@ -0,0 +1,39 @@ +{ + "frontmatter": { + "title": "b3d7fb22", + "excerpt": "c8653d16" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c6bcf9cb", + "c90aff8f", + "493e8bd0", + "eec274a9", + "a8f76cea", + "f101e2f8", + "2cb29a79", + "9f6638", + "532ae282", + "666cc7bb", + "b7035ba" + ] + }, + "targets": { + "zh-CN": [ + "c6bcf9cb", + "c90aff8f", + "493e8bd0", + "eec274a9", + "a8f76cea", + "f101e2f8", + "2cb29a79", + "9f6638", + "532ae282", + "666cc7bb", + "b7035ba" + ] + } + } +} diff --git a/contents/questions/algo/insertion-sort/description/zh-CN.mdx b/contents/questions/algo/insertion-sort/description/zh-CN.mdx new file mode 100644 index 000000000..48940b5ee --- /dev/null +++ b/contents/questions/algo/insertion-sort/description/zh-CN.mdx @@ -0,0 +1,29 @@ +--- +title: 插入排序 +excerpt: 实现一个执行插入排序的函数 +--- + +实现一个执行插入排序的函数。该函数应接收一个整数数组,并返回一个按升序排序的整数数组。输入数组将被修改。 + +![插入排序的预期输入和输出](/img/questions/insertion-sort/insertion-sort-input-output.png) + +## 例子 + +```js +insertionSort([9, 3, 6, 2, 1, 11]); // [1, 2, 3, 6, 9, 11] +insertionSort([12, 16, 14, 1, 2, 3]); // [1, 2, 3, 12, 14, 16] +``` + +## 回顾 + +插入排序是一种简单的排序算法,它一次将元素与前一个元素进行比较,将它们“插入”到正确的位置,并逐步构建一个已排序的数组。 + +该算法从检查输入数组的第二个元素(“当前”元素)开始,并将其与前一个元素(即第一个元素)进行比较。如果当前元素较小,我们交换它们的位置(通过复制)。结果是前 2 个元素按升序正确排序。 + +![插入排序算法的第一次迭代插图](/img/questions/insertion-sort/insertion-sort-first-iteration.png) + +然后,该算法移动到输入列表中的下一个元素,并将其与前面的元素(已按升序排序)进行比较,以将其插入到正确的位置。由于前面的元素已经排序,该算法只需要将当前元素与每个前面的元素进行比较,直到当前元素不小于该元素。然后将其插入到列表中的正确位置,并且该算法移动到输入列表中的下一个元素。 + +例如,从上面的例子继续,该算法将移动到第 3 个元素作为“当前”元素,并将其与前面的排序列表进行比较。通过向后遍历前面的列表,当前元素将与第 2 个元素逐步比较,然后是第 1 个元素,直到它不再小于该元素。然后它将把自己插入到那个位置。如果它小于第 2 个和第 1 个元素,它只是作为最小元素插入到列表的开头。 + +![插入排序算法的后续迭代插图](/img/questions/insertion-sort/insertion-sort-subsequent-iteration.png) diff --git a/contents/questions/algo/insertion-sort/solution/en-US.langnostic.json b/contents/questions/algo/insertion-sort/solution/en-US.langnostic.json new file mode 100644 index 000000000..ffd5f8553 --- /dev/null +++ b/contents/questions/algo/insertion-sort/solution/en-US.langnostic.json @@ -0,0 +1,62 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "e582c253", + "bc3e02e8", + "d4406ecb", + "4cd64b66", + "ef0e1931", + "83c89232", + "26e3ffe5", + "d9b370e", + "734a23ca", + "499e5031", + "6325a74c", + "add698fb", + "7d476982", + "8f23e5c5", + "edd50b17", + "c998b811", + "a34a2355", + "bb1b042d", + "8a0e726d", + "6c57eb87", + "58c344e2", + "5b6426bb", + "8d8ce822" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "e582c253", + "bc3e02e8", + "d4406ecb", + "4cd64b66", + "ef0e1931", + "83c89232", + "26e3ffe5", + "d9b370e", + "734a23ca", + "499e5031", + "6325a74c", + "add698fb", + "7d476982", + "8f23e5c5", + "edd50b17", + "c998b811", + "a34a2355", + "bb1b042d", + "8a0e726d", + "6c57eb87", + "58c344e2", + "5b6426bb", + "8d8ce822" + ] + } + } +} diff --git a/contents/questions/algo/insertion-sort/solution/zh-CN.mdx b/contents/questions/algo/insertion-sort/solution/zh-CN.mdx new file mode 100644 index 000000000..f25dd68bd --- /dev/null +++ b/contents/questions/algo/insertion-sort/solution/zh-CN.mdx @@ -0,0 +1,61 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import insertionSortJs from '../setup/src/insertion-sort.js'; +import insertionSortTs from '../setup/src/insertion-sort.ts'; + +插入排序是一种稳定的、原地的、基于比较的算法,适用于中小型数组以及部分排序的数组。 + +它只需要少量的工作就可以对已经部分排序的数组进行排序。 + +## 澄清问题 + +如果未指定: + +* 数据应该按升序还是降序排序? +* 数据应该就地排序还是可以使用其他数据结构? +* 我们需要处理什么样的输入? + * 它只是一个整数数组,还是我们应该处理其他数据类型? + * 是否存在大量重复元素? + * 应该如何处理负数? + +## 解决方案 + +注意:此问题针对升序输出的就地排序。请参阅下面的“注释”部分,了解如何处理其他情况。 + + + +## 边缘情况 + +* 非整数元素输入:如果输入数组包含不同数据类型的元素,您可能需要返回一个错误,尽力进行排序,例如,仅对输入数据的子集进行排序,甚至为非整数定义自定义比较函数。 +* 单个元素/空输入:返回原始数据结构、引发错误或阐明所需处理方式。 +* 大输入:您可能需要考虑使用其他优化,如二分查找,以加快插入速度。 +* 已排序的输入:您可能需要检测排序并保持输入不变。 +* 无效输入:如果输入不是数组,请考虑抛出错误。 + +## 笔记 + +* 如果要求按降序排序:只需将比较更改为 `<` 而不是 `>`,如下所示: + +```js +while (j >= 0 && arr[j] < currentValue) +``` + +* 如果要求使用其他数据结构或编写纯函数而不是就地排序数据,请使用扩展运算符或 `Array.prototype.slice()` 克隆输入数组,并在克隆的数组上进行排序。 + +## Big-O 分析 + +让我们分析一下算法的时间和空间复杂度。 + +### 时间复杂度 + +对于插入排序,最佳时间复杂度为 O(n),最坏时间复杂度为 O(n2),平均时间复杂度也为 O(n2)。 + +由于插入排序需要嵌套循环结构,其中外循环遍历数组,内循环遍历已排序的数组以找到插入当前元素的正确位置,因此时间复杂度通常为O(n2),如果两个循环都完全迭代。不同情况之间的差异受到原始输入排序程度的影响,这会影响我们是否需要对特定元素运行内循环。 + +* **最坏情况时间复杂度**:当输入以完全相反的顺序排列时,输出必须是(例如,当我们需要降序时升序)。我们需要对每个元素完全遍历外循环和内循环,时间复杂度为O(n2)。 +* **最佳情况时间复杂度**:当输入已经排序或接近排序时。这意味着内循环不需要迭代太多。在最好的情况下,输入数组已经完全排序,我们只运行外循环,复杂度为O(n)。 +* **平均情况时间复杂度**:考虑到输入数组随机排列的情况,算法的内循环仍然必须遍历数组的已排序部分,以便找到插入当前元素的正确位置。 + +### 空间复杂度 + +插入排序的空间复杂度为O(1),因为它进行原地排序,不需要与输入大小成比例的额外存储。 diff --git a/contents/questions/algo/intervals-combine-overlapping/description/en-US.langnostic.json b/contents/questions/algo/intervals-combine-overlapping/description/en-US.langnostic.json new file mode 100644 index 000000000..b50031ad5 --- /dev/null +++ b/contents/questions/algo/intervals-combine-overlapping/description/en-US.langnostic.json @@ -0,0 +1,33 @@ +{ + "frontmatter": { + "title": "10d0533b", + "excerpt": "2d62323f" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "6023fbc4", + "516a8837", + "2d96efbe", + "3a913bd2", + "d068a43f", + "b2065fc", + "c10b3509" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "6023fbc4", + "516a8837", + "2d96efbe", + "3a913bd2", + "d068a43f", + "b2065fc", + "c10b3509" + ] + } + } +} diff --git a/contents/questions/algo/intervals-combine-overlapping/description/zh-CN.mdx b/contents/questions/algo/intervals-combine-overlapping/description/zh-CN.mdx new file mode 100644 index 000000000..e8f99f2a8 --- /dev/null +++ b/contents/questions/algo/intervals-combine-overlapping/description/zh-CN.mdx @@ -0,0 +1,23 @@ +--- +title: 合并重叠区间 +excerpt: 实现一个合并重叠区间的函数 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个`intervals`数组,其中每个区间表示为`[start, end]`。每对表示数轴上区间的开始和结束。例如,`[1, 3]`表示从1开始到3结束的区间。 + +**合并数组中所有重叠的区间**,并返回一个**非重叠区间**数组,该数组完全覆盖输入区间指定的范围。 + +### 输入 + +- `intervals: Array<[number, number]>`: 整数对数组 + + + +### 约束 + +- 1 <= `intervals.length` <= 100 +- `intervals[i].length` == 2 +- 0 <= `start` <= `end` <= 10,000 diff --git a/contents/questions/algo/intervals-combine-overlapping/solution/en-US.langnostic.json b/contents/questions/algo/intervals-combine-overlapping/solution/en-US.langnostic.json new file mode 100644 index 000000000..fd44e7f67 --- /dev/null +++ b/contents/questions/algo/intervals-combine-overlapping/solution/en-US.langnostic.json @@ -0,0 +1,50 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "6bf38276", + "1d923e00", + "31239025", + "c1396240", + "b68df8f8", + "33b5a458", + "f316a5cd", + "8e2de8c8", + "170d29bd", + "2601c679", + "1948382f", + "a8995091", + "b68df8f8", + "abcc49a6", + "362a695c", + "8e2de8c8", + "e94601e6" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "6bf38276", + "1d923e00", + "31239025", + "c1396240", + "b68df8f8", + "33b5a458", + "f316a5cd", + "8e2de8c8", + "170d29bd", + "2601c679", + "1948382f", + "a8995091", + "b68df8f8", + "abcc49a6", + "362a695c", + "8e2de8c8", + "e94601e6" + ] + } + } +} diff --git a/contents/questions/algo/intervals-combine-overlapping/solution/zh-CN.mdx b/contents/questions/algo/intervals-combine-overlapping/solution/zh-CN.mdx new file mode 100644 index 000000000..f5d8524e2 --- /dev/null +++ b/contents/questions/algo/intervals-combine-overlapping/solution/zh-CN.mdx @@ -0,0 +1,60 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import mergeIntervals from '../setup/src/intervals-combine-overlapping.ts'; +import mergeIntervalsUsingConnectedComponents from '../setup/src/intervals-combine-overlapping-connected-components.js'; + +## 1. 使用排序 + +该问题涉及将重叠的区间合并成一个单一的区间,针对每个重叠组。该方法使用排序来确保区间按其开始时间的升序处理。通过迭代排序后的区间,可以有效地检测和合并重叠部分。 + +按开始时间对区间进行排序,确保所有潜在的重叠部分连续出现,从而减少不必要的比较。如果不进行排序,暴力方法将涉及将每个区间与所有其他区间进行比较,导致重复工作和效率低下。暴力方法的瓶颈在于这些冗余的比较,而排序消除了这些比较。排序后,只需遍历一次区间即可通过将当前区间与最后一个合并的区间进行比较来合并重叠部分。 + +### 算法 + +1. 按每个区间的起始点对 `intervals` 数组进行升序排序。 +2. 初始化一个空数组 `merged` 以存储合并后的区间。 +3. 遍历排序后的数组中的每个区间: + 1. 如果 `merged` 数组为空,或者当前区间与 `merged` 中的最后一个区间不重叠,则将当前区间追加到 `merged`。 + 2. 如果存在重叠,则将 `merged` 中最后一个区间的结束时间更新为其当前结束时间和当前区间的结束时间的最大值。 +4. 返回包含所有合并区间的 `merged` 数组。 + + + {mergeIntervals} + + +### Big-O 分析 + +* **时间复杂度:O(n log n)**。对区间进行排序需要 O(n log n),后续遍历区间需要 O(n)。 +* **空间复杂度:O(n)**。如果没有任何区间重叠,`merged` 数组最多可以容纳所有区间。 + +## 2. 使用连通分量 + +可以使用图论中的连通分量的概念来解决合并重叠区间的问题。每个区间被视为图中的一个节点,如果两个节点对应的区间重叠,则在它们之间创建一条边。目标是识别该图中的所有连通分量,其中每个分量代表一组重叠的区间。然后可以将每个分量合并成一个单一的区间。 + +通过构建连接区间的图并使用深度优先搜索 (DFS) 来识别连通分量,该过程变得结构化并避免了不必要的比较。一旦识别出这些分量,合并它们就变得很简单,因为它涉及找到分量中所有区间的最小开始时间和最大结束时间。 + +### 算法 + +1. 定义一个辅助函数 `overlap`,通过比较两个区间的起始点和结束点来检查它们是否重叠。 +2. 使用 `buildGraph` 函数构建一个图: + 1. 遍历所有区间对。 + 2. 如果两个区间重叠,则在图中的相应节点之间添加一条边。 +3. 定义一个 `mergeNodes` 函数,通过找到连通分量中所有区间的最小开始点和最大结束点来合并它们。 +4. 实现 `markComponentDFS` 函数以执行 DFS: + 1. 从一个节点开始,将所有连接的节点标记为同一分量的一部分。 + 2. 使用堆栈递归地探索所有邻居。 +5. 在主函数中: + 1. 使用 `buildGraph` 构建区间图。 + 2. 使用 DFS 识别所有连通分量,并将区间分组成分量。 + 3. 使用 `mergeNodes` 将每个分量合并成一个单一的区间。 +6. 返回合并后的区间。 + + + {mergeIntervalsUsingConnectedComponents} + + +### Big-O 分析 + +* **时间复杂度:O(n2)**。构建图需要比较每对区间,导致 O(n2) 次操作。 + +* **空间复杂度:O(n2)**。在最坏的情况下,该图最多可以有 O(n2) 条边,并且 `visited` 集合和 `nodesInComp` 存储会随着区间数量的增加而扩展。 diff --git a/contents/questions/algo/intervals-meeting-calendar/description/en-US.langnostic.json b/contents/questions/algo/intervals-meeting-calendar/description/en-US.langnostic.json new file mode 100644 index 000000000..378b374a4 --- /dev/null +++ b/contents/questions/algo/intervals-meeting-calendar/description/en-US.langnostic.json @@ -0,0 +1,31 @@ +{ + "frontmatter": { + "title": "8f2f3e6b", + "excerpt": "ecac4119" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "628cedd5", + "2d96efbe", + "e771d21c", + "d068a43f", + "b2065fc", + "40ef8566" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "628cedd5", + "2d96efbe", + "e771d21c", + "d068a43f", + "b2065fc", + "40ef8566" + ] + } + } +} diff --git a/contents/questions/algo/intervals-meeting-calendar/description/zh-CN.mdx b/contents/questions/algo/intervals-meeting-calendar/description/zh-CN.mdx new file mode 100644 index 000000000..4a9310221 --- /dev/null +++ b/contents/questions/algo/intervals-meeting-calendar/description/zh-CN.mdx @@ -0,0 +1,21 @@ +--- +title: 会议日历 +excerpt: 实现一个函数来检查是否可以参加所有会议 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个会议时间 `intervals` 数组,其中每个元素代表一个会议时间,格式为 `[start, end]`,确定一个人是否可以参加所有会议,而会议时间之间没有任何重叠。 + +### 输入 + +- 一个整数的二维数组 `intervals`,大小为 `n x 2`,其中 `n` 是会议的数量,每个区间 `[start, end]` 代表一个会议,开始时间为 start,结束时间为 end + + + +### 约束 + +- 0 <= `intervals.length` <= 1000 +- `intervals[i].length` == 2 +- 0 <= `start` \< `end` <= 1,000,000 diff --git a/contents/questions/algo/intervals-meeting-calendar/solution/en-US.langnostic.json b/contents/questions/algo/intervals-meeting-calendar/solution/en-US.langnostic.json new file mode 100644 index 000000000..bd5c0c737 --- /dev/null +++ b/contents/questions/algo/intervals-meeting-calendar/solution/en-US.langnostic.json @@ -0,0 +1,48 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "1df81c60", + "4ce347d1", + "28af9fb8", + "b68df8f8", + "5c9a2919", + "2dd96432", + "8e2de8c8", + "b7eaacf7", + "500ba04b", + "d4b9ecb4", + "38a24715", + "b68df8f8", + "288ad6f0", + "e4adb34b", + "8e2de8c8", + "e050dc13" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "1df81c60", + "4ce347d1", + "28af9fb8", + "b68df8f8", + "5c9a2919", + "2dd96432", + "8e2de8c8", + "b7eaacf7", + "500ba04b", + "d4b9ecb4", + "38a24715", + "b68df8f8", + "288ad6f0", + "e4adb34b", + "8e2de8c8", + "e050dc13" + ] + } + } +} diff --git a/contents/questions/algo/intervals-meeting-calendar/solution/zh-CN.mdx b/contents/questions/algo/intervals-meeting-calendar/solution/zh-CN.mdx new file mode 100644 index 000000000..aeeb8fd55 --- /dev/null +++ b/contents/questions/algo/intervals-meeting-calendar/solution/zh-CN.mdx @@ -0,0 +1,48 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import meetingCalendar from '../setup/src/intervals-meeting-calendar.ts'; +import meetingCalendarBruteForce from '../setup/src/intervals-meeting-calendar-bruteforce.ts'; + +## 1. 暴力方法 + +朴素的方法是通过验证一组间隔是否可以通过检查没有两个间隔重叠来形成有效的会议日历。 关键思想是遍历所有间隔对并比较它们的开始和结束时间。 对于每一对,重叠是通过检查一个间隔是否在另一个间隔结束之前开始以及反之亦然来确定的。 如果检测到任何重叠,则日历被认为无效。 + +### 算法 + +1. 定义一个辅助函数 `overlap`,它将两个间隔作为输入,并通过比较它们的开始和结束时间来检查它们是否重叠。 +2. 使用嵌套循环遍历所有间隔对: + 1. 对于每一对间隔,调用 `overlap` 函数。 + 2. 如果函数返回 `true`,则立即返回 `false`,因为这些间隔无效。 +3. 如果在所有比较之后未找到重叠的间隔,则返回 `true`。 + + + {meetingCalendarBruteForce} + + +### Big-O 分析 + +* **时间复杂度:O(n2)**。 该算法遍历所有间隔对,导致 n(n - 1)/2 次比较,即 O(n2)。 +* **空间复杂度:O(1)**。 该算法使用恒定空间,因为它不需要任何额外的数据结构。 + +## 2. 使用排序 + +这种方法依赖于按其开始时间对间隔进行排序,以保证重叠的间隔彼此相邻出现。 排序确保间隔按其开始时间按时间顺序排列。 如果两个间隔重叠,则较早间隔的结束时间将延伸到下一个间隔的开始时间范围内。 通过按其开始时间的升序排列间隔,只需将每个间隔与排序列表中的下一个间隔进行比较即可检测重叠。 + +此方法消除了蛮力方法中存在的不必要的比较。 无需比较每对间隔,只需检查排序顺序中相邻的间隔,因为在排序后,任何重叠的间隔都保证是连续的。 + +### 算法 + +1. 使用 `sort` 方法按其开始时间按升序对间隔进行排序。 +2. 遍历排序后的间隔: + 1. 对于每个间隔,检查其结束时间是否大于下一个间隔的开始时间。 + 2. 如果检测到重叠,则返回 `false`,因为日历无效。 +3. 如果循环在未检测到任何重叠的情况下完成,则返回 `true`。 + + + {meetingCalendar} + + +### Big-O 分析 + +* **时间复杂度:O(n log n)**。 排序间隔占据了运行时,需要 O(n log n),而线性扫描间隔需要 O(n),总共得到 O(n log n)。 +* **空间复杂度:O(1)**。 该算法使用恒定空间,因为它就地修改间隔数组,并且不需要额外的数据结构。 diff --git a/contents/questions/algo/intervals-merge-new/description/en-US.langnostic.json b/contents/questions/algo/intervals-merge-new/description/en-US.langnostic.json new file mode 100644 index 000000000..aa335a15f --- /dev/null +++ b/contents/questions/algo/intervals-merge-new/description/en-US.langnostic.json @@ -0,0 +1,31 @@ +{ + "frontmatter": { + "title": "bded08e", + "excerpt": "4e0cf900" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "6320e553", + "2d96efbe", + "36c3279f", + "d068a43f", + "b2065fc", + "f622e65a" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "6320e553", + "2d96efbe", + "36c3279f", + "d068a43f", + "b2065fc", + "f622e65a" + ] + } + } +} diff --git a/contents/questions/algo/intervals-merge-new/description/zh-CN.mdx b/contents/questions/algo/intervals-merge-new/description/zh-CN.mdx new file mode 100644 index 000000000..724c31d82 --- /dev/null +++ b/contents/questions/algo/intervals-merge-new/description/zh-CN.mdx @@ -0,0 +1,22 @@ +--- +title: 合并新区间 +excerpt: 实现一个函数,将一个新区间插入给定的区间中 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个已排序的非重叠区间数组 `intervals`,其中每个区间表示为 `[start, end]`,并按 `start` 时间升序排序,将一个新区间 `[start, end]` 插入到数组中。确保结果数组保持排序,并且没有重叠的区间,必要时通过合并任何重叠的区间。 + +### 输入 + +- `intervals: Array<[number, number]>`: 整数对数组 +- `newInterval: [number, number]`: 表示 `[start, end]` 的整数对 + + + +### 约束 + +- 1 <= `intervals.length` <= 100 +- `intervals[i].length == 2` +- 0 <= `start` <= `end` <= 10,000 diff --git a/contents/questions/algo/intervals-merge-new/solution/en-US.langnostic.json b/contents/questions/algo/intervals-merge-new/solution/en-US.langnostic.json new file mode 100644 index 000000000..be257d9b9 --- /dev/null +++ b/contents/questions/algo/intervals-merge-new/solution/en-US.langnostic.json @@ -0,0 +1,48 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "216583bd", + "8b875f8c", + "8ff22541", + "3a3e9bba", + "b68df8f8", + "3e61bcb9", + "8931139c", + "8e2de8c8", + "56d9a068", + "494d4118", + "28d9ba64", + "b68df8f8", + "6815677f", + "8996ea11", + "8e2de8c8", + "acef8d87" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "216583bd", + "8b875f8c", + "8ff22541", + "3a3e9bba", + "b68df8f8", + "3e61bcb9", + "8931139c", + "8e2de8c8", + "56d9a068", + "494d4118", + "28d9ba64", + "b68df8f8", + "6815677f", + "8996ea11", + "8e2de8c8", + "acef8d87" + ] + } + } +} diff --git a/contents/questions/algo/intervals-merge-new/solution/zh-CN.mdx b/contents/questions/algo/intervals-merge-new/solution/zh-CN.mdx new file mode 100644 index 000000000..094ff346e --- /dev/null +++ b/contents/questions/algo/intervals-merge-new/solution/zh-CN.mdx @@ -0,0 +1,61 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import mergeNewInterval from '../setup/src/intervals-merge-new.ts'; +import mergeNewIntervalUsingBinarySearch from '../setup/src/intervals-merge-new-using-binarysearch.ts'; + +## 1. 使用线性搜索 + +该方法通过执行一次线性扫描,将一个新区间合并到一组非重叠区间中。区间根据其与新区间之间的关系分为三个不同的阶段进行处理:完全在新区间之前的区间、重叠的区间和完全在新区间之后的区间。由于输入区间已经排序,因此不需要排序。 + +不与新区间重叠的区间将原样添加到结果中。与新区间重叠的区间通过更新新区间的开始和结束以覆盖组合范围来进行合并。合并所有重叠区间后,将新区间添加到结果中,然后添加剩余的区间。这种方法确保每个区间只处理一次。 + +### 算法 + +1. 初始化一个空的结果数组 `res`,并将指针 `i` 设置为 `0`。 +2. 处理新区间之前的区间: + 1. 当当前区间的结束小于新区间的开始时,将该区间添加到 `res`。 + 2. 为每个添加的区间递增指针 `i`。 +3. 处理重叠区间: + 1. 当当前区间的开始小于或等于新区间的结束时,通过更新新区间的开始和结束来合并区间。 + 2. 合并后递增指针 `i`。 +4. 将合并后的区间(新区间)添加到结果数组 `res`。 +5. 处理新区间之后的区间: + 1. 从当前指针位置 `i` 开始,将所有剩余区间添加到 `res`。 + 2. 为每个添加的区间递增指针 `i`。 +6. 返回结果数组 `res`。 + + + {mergeNewInterval} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。每个区间只处理一次,导致线性运行时长。 +* **空间复杂度:O(n)**。结果数组 `res` 存储所有区间,需要与输入大小成比例的空间。 + +## 2. 使用二分查找 + +这种方法结合了二分查找和合并,以有效地将一个新区间插入到已排序的区间列表中,并合并任何重叠部分。二分查找用于确定插入新区间基于其开始时间的正确位置。插入后,只需遍历一次区间即可合并重叠区间。合并过程通过检查结果列表中相邻的区间,确保将重叠区间合并成一个区间。 + +### 算法 + +1. 处理 `intervals` 数组为空的边缘情况,返回仅包含 `newInterval` 的列表。 +2. 使用二分查找找到插入 `newInterval` 的合适位置: + 1. 初始化两个指针 `left` 和 `right`,以表示搜索范围。 + 2. 将 `newInterval` 的开始值与当前范围的中间元素进行比较。 + 3. 调整指针,直到找到插入 `newInterval` 的位置。 +3. 使用 `splice` 方法将 `newInterval` 插入到确定的位置。 +4. 初始化一个空数组 `res` 以存储合并后的区间。 +5. 遍历 `intervals` 数组: + 1. 如果 `res` 为空,或者当前区间与 `res` 中的最后一个区间不重叠,则将当前区间添加到 `res`。 + 2. 如果存在重叠,则通过将 `res` 中最后一个区间的结束更新为两个重叠区间的最大值来合并区间。 +6. 返回包含合并区间的 `res` 数组。 + + + {mergeNewIntervalUsingBinarySearch} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。二分查找需要 O(log n) 时间,但与合并区间所需的 O(n) 时间相比,这可以忽略不计。 +* **空间复杂度:O(n)**。结果数组 `res` 需要与输入大小成比例的空间。 diff --git a/contents/questions/algo/intervals-minimum-meeting-rooms/description/en-US.langnostic.json b/contents/questions/algo/intervals-minimum-meeting-rooms/description/en-US.langnostic.json new file mode 100644 index 000000000..2c39b8013 --- /dev/null +++ b/contents/questions/algo/intervals-minimum-meeting-rooms/description/en-US.langnostic.json @@ -0,0 +1,31 @@ +{ + "frontmatter": { + "title": "a81e6482", + "excerpt": "f044855a" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "e573a9dd", + "2d96efbe", + "f0e7f065", + "d068a43f", + "b2065fc", + "40ef8566" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "e573a9dd", + "2d96efbe", + "f0e7f065", + "d068a43f", + "b2065fc", + "40ef8566" + ] + } + } +} diff --git a/contents/questions/algo/intervals-minimum-meeting-rooms/description/zh-CN.mdx b/contents/questions/algo/intervals-minimum-meeting-rooms/description/zh-CN.mdx new file mode 100644 index 000000000..b0c8db044 --- /dev/null +++ b/contents/questions/algo/intervals-minimum-meeting-rooms/description/zh-CN.mdx @@ -0,0 +1,21 @@ +--- +title: 所需最少会议室 +excerpt: 实现一个函数来查找所需的最少会议室数量 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个会议时间 `intervals` 数组,其中每个间隔表示为 `[start, end]`,表示会议在 `start` 时间开始,在 `end` 时间结束,确定容纳所有会议所需的最少会议室数量。 + +### 输入 + +- `intervals: Array<[number, number]>`: 整数对数组 + + + +### 约束 + +- 0 <= `intervals.length` <= 1000 +- `intervals[i].length` == 2 +- 0 <= `start` \< `end` <= 1,000,000 diff --git a/contents/questions/algo/intervals-minimum-meeting-rooms/solution/en-US.langnostic.json b/contents/questions/algo/intervals-minimum-meeting-rooms/solution/en-US.langnostic.json new file mode 100644 index 000000000..753b02865 --- /dev/null +++ b/contents/questions/algo/intervals-minimum-meeting-rooms/solution/en-US.langnostic.json @@ -0,0 +1,52 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "8e2ed91", + "da382dd8", + "85c56d8a", + "324017e", + "fab1dcd9", + "b68df8f8", + "18b3d4f", + "70e891b7", + "8e2de8c8", + "1c2982fa", + "5e0ab711", + "428e1e35", + "4d7b5875", + "b68df8f8", + "e6226291", + "4dfcb3da", + "8e2de8c8", + "4d1d0a7" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "8e2ed91", + "da382dd8", + "85c56d8a", + "324017e", + "fab1dcd9", + "b68df8f8", + "18b3d4f", + "70e891b7", + "8e2de8c8", + "1c2982fa", + "5e0ab711", + "428e1e35", + "4d7b5875", + "b68df8f8", + "e6226291", + "4dfcb3da", + "8e2de8c8", + "4d1d0a7" + ] + } + } +} diff --git a/contents/questions/algo/intervals-minimum-meeting-rooms/solution/zh-CN.mdx b/contents/questions/algo/intervals-minimum-meeting-rooms/solution/zh-CN.mdx new file mode 100644 index 000000000..a6d86da2c --- /dev/null +++ b/contents/questions/algo/intervals-minimum-meeting-rooms/solution/zh-CN.mdx @@ -0,0 +1,61 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import minMeetingRoomsNeeded from '../setup/src/intervals-minimum-meeting-rooms.ts'; +import minMeetingRoomsPQ from '../setup/src/intervals-minimum-meeting-rooms-pq.ts'; + +## 1. 使用双指针方法 + +这种方法通过分离并排序区间的开始和结束时间来确定所需的最少会议室数量。通过使用两个指针,一个用于`start`时间,一个用于`end`时间,该算法有效地跟踪并发会议的数量。 + +直觉是,当会议结束时,会议室就会空闲,这由`endPointer`表示。对于每个会议开始时间(`startPointer`),算法会检查会议是否可以重复使用一个可用的房间(通过将开始时间与最早的结束时间进行比较)。如果房间空闲,则将`endPointer`向前移动以标记该房间可用。否则,将分配一个新房间。 + +此方法避免了直接比较所有区间对,使用排序数组和两个指针来实现最佳效率。 + +### 算法 + +1. 处理基本情况,如果`intervals`数组为空,则返回`0`。 +2. 创建两个数组`start`和`end`,以存储每个区间的开始和结束时间。 +3. 通过遍历`intervals`数组来填充`start`和`end`数组。 +4. 按升序对`start`和`end`数组进行排序。 +5. 初始化两个指针`startPointer`和`endPointer`,分别遍历`start`和`end`数组。此外,初始化一个变量`usedRooms`以跟踪当前正在使用的房间数。 +6. 遍历`start`数组: + 1. 如果当前会议的开始时间大于或等于最早的结束时间(由`end[endPointer]`指示),则通过递减`usedRooms`并将`endPointer`向前移动来释放一个房间。 + 2. 为当前会议分配一个房间,方法是递增`usedRooms`。 + 3. 移动`startPointer`以处理下一个会议。 +7. 返回`usedRooms`的值,该值表示在任何时候所需的最大房间数。 + + + {minMeetingRoomsNeeded} + + +### Big-O 分析 + +* **时间复杂度:O(n log n)**。对`start`和`end`数组进行排序占据了运行时的大部分,而处理区间的线性扫描需要 O(n)。 +* **空间复杂度:O(n)**。使用两个额外的数组`start`和`end`来存储区间的开始和结束时间。 + +## 2. 使用优先级队列(最小堆) + +该方法使用最小堆来有效地跟踪正在进行的会议的结束时间,确保最早结束的会议始终首先被处理。这允许确定当新会议开始时房间是否空闲。按开始时间对区间进行排序可确保会议按时间顺序处理。 + +使用最小堆是因为它支持高效地插入和提取最小元素。在任何时候,堆都包含所有活动会议的结束时间。当会议开始时,将其开始时间与堆中最小的结束时间(最早结束的会议)进行比较。如果新会议可以重复使用房间(其开始时间大于或等于最小结束时间),则从堆中删除结束时间。否则,将分配一个新房间,并将会议的结束时间添加到堆中。 + +### 算法 + +1. 处理基本情况,如果`intervals`数组为空,则返回`0`。 +2. 按会议的开始时间对`intervals`数组进行升序排序。 +3. 初始化一个最小堆(`allocator`)以存储当前占用房间的会议的结束时间。 +4. 将第一个会议的结束时间添加到堆中。 +5. 遍历剩余的区间: + 1. 如果当前会议的开始时间大于或等于堆中最小的结束时间,则从堆中删除最小的结束时间(表示一个房间已释放)。 + 2. 将当前会议的结束时间添加到堆中,为其分配一个房间。 +6. 处理完所有区间后,堆的大小表示所需的最小房间数,因为堆中的每个元素对应于当前活动的会议。 +7. 返回堆的大小。 + + + {minMeetingRoomsPQ} + + +### Big-O 分析 + +* **时间复杂度:O(n log n)**。对区间进行排序需要 O(n log n),并且堆中的每个插入和删除操作都需要 O(log n),导致所有区间的堆操作为 O(n log n)。 +* **空间复杂度:O(n)**。最小堆在最坏情况下最多可以包含`n`个元素。 diff --git a/contents/questions/algo/linked-list-combine-k-sorted/description/en-US.langnostic.json b/contents/questions/algo/linked-list-combine-k-sorted/description/en-US.langnostic.json new file mode 100644 index 000000000..bf33afab2 --- /dev/null +++ b/contents/questions/algo/linked-list-combine-k-sorted/description/en-US.langnostic.json @@ -0,0 +1,37 @@ +{ + "frontmatter": { + "title": "efbee00f", + "excerpt": "bdcdc010" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "57b4199", + "14e22f81", + "6bd8b2c7", + "359939b4", + "2d96efbe", + "bd1a88d", + "d068a43f", + "b2065fc", + "1af44dba" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "57b4199", + "14e22f81", + "6bd8b2c7", + "359939b4", + "2d96efbe", + "bd1a88d", + "d068a43f", + "b2065fc", + "1af44dba" + ] + } + } +} diff --git a/contents/questions/algo/linked-list-combine-k-sorted/description/zh-CN.mdx b/contents/questions/algo/linked-list-combine-k-sorted/description/zh-CN.mdx new file mode 100644 index 000000000..a1f0df926 --- /dev/null +++ b/contents/questions/algo/linked-list-combine-k-sorted/description/zh-CN.mdx @@ -0,0 +1,32 @@ +--- +title: 链表合并 K 个已排序列表 +excerpt: 实现一个合并 k 个已排序链表的函数 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个 [链表](https://en.wikipedia.org/wiki/Linked_list) 数组 `lists`,其中每个链表的节点值都按**升序**排列,将所有这些链表合并成一个已排序的链表,并返回合并后链表的头节点。 + +链表由一系列 `ListNode` 表示,其中每个节点指向序列中的下一个节点,如果它是最后一个节点,则指向 `null`。 + +一个 `ListNode` 具有以下接口: + +```ts +interface ListNode { + val: number; + next: ListNode | null; +} +``` + +### 输入 + +- `lists: ListNode[]`: 链表头节点数组。示例将每个链表显示为列表中的值数组 + + + +### 约束 + +- 1 <= `lists.length` <= 100 +- 0 <= 每列表的节点数 <= 100 +- -10,000 <= `ListNode.val` <= 10,000 diff --git a/contents/questions/algo/linked-list-combine-k-sorted/solution/en-US.langnostic.json b/contents/questions/algo/linked-list-combine-k-sorted/solution/en-US.langnostic.json new file mode 100644 index 000000000..b3dcf51dc --- /dev/null +++ b/contents/questions/algo/linked-list-combine-k-sorted/solution/en-US.langnostic.json @@ -0,0 +1,56 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "e5d0a995", + "8ccbd74b", + "209ecb37", + "b68df8f8", + "e93d7784", + "828629b1", + "8e2de8c8", + "26ab74fd", + "6524b754", + "48909d0b", + "bd7202ad", + "9722c8ca", + "55affffe", + "b68df8f8", + "7acb82e4", + "94fd35a8", + "58e21140", + "9e7e7b5b", + "8e2de8c8", + "35a3eb18" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "e5d0a995", + "8ccbd74b", + "209ecb37", + "b68df8f8", + "e93d7784", + "828629b1", + "8e2de8c8", + "26ab74fd", + "6524b754", + "48909d0b", + "bd7202ad", + "9722c8ca", + "55affffe", + "b68df8f8", + "7acb82e4", + "94fd35a8", + "58e21140", + "9e7e7b5b", + "8e2de8c8", + "35a3eb18" + ] + } + } +} diff --git a/contents/questions/algo/linked-list-combine-k-sorted/solution/zh-CN.mdx b/contents/questions/algo/linked-list-combine-k-sorted/solution/zh-CN.mdx new file mode 100644 index 000000000..9ad772b9c --- /dev/null +++ b/contents/questions/algo/linked-list-combine-k-sorted/solution/zh-CN.mdx @@ -0,0 +1,68 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import linkedListCombineKSorted from '../setup/src/linked-list-combine-k-sorted.ts'; +import linkedListCombineKSortedBruteForce from '../setup/src/linked-list-combine-k-sorted-bruteforce.ts'; + +## 1. 暴力解法 + +一种朴素的方法是将所有`k`个链表中的所有值提取到一个数组中,对它们进行排序,然后从排序后的数组中重建一个新的排序链表。 + +### 算法 + +1. 创建一个空数组`nodes`,用于存储链表中所有节点的值。 +2. 创建一个虚拟节点,作为构建新链表的起点。 +3. 遍历`lists`数组中的每个链表。 + 1. 遍历当前链表。 + 2. 将每个节点的值追加到`nodes`数组中。 +4. 按升序对`nodes`数组进行排序。 +5. 遍历排序后的`nodes`数组。 + 1. 为每个值创建一个新节点,并将其链接到组合链表中。 + 2. 将指针移动到新添加的节点。 +6. 返回组合链表,跳过虚拟节点。 + + + {linkedListCombineKSortedBruteForce} + + +### Big-O 分析 + +* **时间复杂度:O(n log n)**。提取值需要 O(n),其中`n`是所有`k`个链表中节点的总数。对数组进行排序需要 O(n log n)。 +* **空间复杂度:O(n)**。使用额外的空间来存储大小为`n`的`nodes`数组和新的链表。 + +## 2. 分治法 + +分治法不是尝试一步合并所有`k`个列表,而是将问题分解成更小的部分。相邻的列表成对合并,在每一轮中将列表的数量减少一半。 + +这个过程可以被可视化为构建一个二叉树。在底层,`k`个列表中的每一个都被视为一个单独的节点。在下一层,相邻的列表对被合并以形成`k/2`个合并列表。这种配对和合并一直持续到只剩下一个列表,形成树的根。 + +每次成对合并操作都会处理被合并的两个列表中的所有节点。这确保了不会进行额外的比较,从而利用了列表的排序顺序。 + +合并过程中的层数对应于二叉树的高度,该高度与`log k`成正比。与暴力解法相比,这种分层减少显著减少了比较次数。 + +### 算法 + +1. 将`amount`初始化为要合并的链表数量。 +2. 将`interval`设置为 1,表示成对合并的距离。 +3. 当`interval`小于`amount`时: + 1. 遍历`lists`数组,合并相隔`interval`的链表对。 + 2. 将每对中的第一个列表替换为合并结果。 + 3. 将`interval`加倍。 +4. 如果`amount`大于 0,则返回`lists`数组中的第一个列表;否则,返回`null`。 + +辅助函数`merge2Lists`执行两个已排序链表的合并: + +1. 初始化一个虚拟节点和一个指针来构建新的组合列表。 +2. 遍历两个输入列表: + 1. 比较两个列表的当前节点,并将较小的节点附加到组合列表中。 + 2. 移动到较小节点所在的列表中的下一个节点。 +3. 将非空列表中剩余的任何节点附加到组合列表中。 +4. 返回组合列表,跳过虚拟节点。 + + + {linkedListCombineKSorted} + + +### Big-O 分析 + +* **时间复杂度:O(n log k)**。两个列表的每次合并操作为 O(n),其中`n`是两个列表中节点的总数。合并层数为 O(log k),其中`k`是列表的数量。 +* **空间复杂度:O(1)**。合并过程是就地执行的,不需要额外的空间。 diff --git a/contents/questions/algo/linked-list-combine-two-sorted/description/en-US.langnostic.json b/contents/questions/algo/linked-list-combine-two-sorted/description/en-US.langnostic.json new file mode 100644 index 000000000..40b1c613e --- /dev/null +++ b/contents/questions/algo/linked-list-combine-two-sorted/description/en-US.langnostic.json @@ -0,0 +1,37 @@ +{ + "frontmatter": { + "title": "ce829844", + "excerpt": "ebaa733d" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "bebf4744", + "14e22f81", + "6bd8b2c7", + "359939b4", + "2d96efbe", + "76435cd7", + "d068a43f", + "b2065fc", + "5bfc614d" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "bebf4744", + "14e22f81", + "6bd8b2c7", + "359939b4", + "2d96efbe", + "76435cd7", + "d068a43f", + "b2065fc", + "5bfc614d" + ] + } + } +} diff --git a/contents/questions/algo/linked-list-combine-two-sorted/description/zh-CN.mdx b/contents/questions/algo/linked-list-combine-two-sorted/description/zh-CN.mdx new file mode 100644 index 000000000..d28bd49fa --- /dev/null +++ b/contents/questions/algo/linked-list-combine-two-sorted/description/zh-CN.mdx @@ -0,0 +1,32 @@ +--- +title: 链表合并两个已排序的列表 +excerpt: 实现一个函数来合并两个已排序的链表 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个[链表](https://en.wikipedia.org/wiki/Linked_list)数组`lists`,其中每个链表的节点值按**升序**排列,将所有这些链表合并成一个已排序的链表,并返回合并后链表的头节点。 + +链表由一系列`ListNode`表示,其中每个节点指向序列中的下一个节点,如果它是最后一个节点,则指向`null`。 + +一个`ListNode`具有以下接口: + +```ts +interface ListNode { + val: number; + next: ListNode | null; +} +``` + +### 输入 + +- `listA: ListNode`: 第一个链表的头节点。示例将每个链表显示为列表中的值数组 +- `listB: ListNode`: 第二个链表的头节点。示例将每个链表显示为列表中的值数组 + + + +### 约束 + +- 1 <= 节点数 <= 50 +- -100 <= `ListNode.val` <= 100 diff --git a/contents/questions/algo/linked-list-combine-two-sorted/solution/en-US.langnostic.json b/contents/questions/algo/linked-list-combine-two-sorted/solution/en-US.langnostic.json new file mode 100644 index 000000000..da68561aa --- /dev/null +++ b/contents/questions/algo/linked-list-combine-two-sorted/solution/en-US.langnostic.json @@ -0,0 +1,52 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "172bf003", + "c902b578", + "51b0ca5d", + "b68df8f8", + "177014fe", + "a71b639a", + "8e2de8c8", + "c0d940", + "93bc344c", + "70598e9d", + "e58df872", + "fb6ca496", + "1bc2eb2f", + "b68df8f8", + "819b7b19", + "5dc087c2", + "8e2de8c8", + "553f5a9c" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "172bf003", + "c902b578", + "51b0ca5d", + "b68df8f8", + "177014fe", + "a71b639a", + "8e2de8c8", + "c0d940", + "93bc344c", + "70598e9d", + "e58df872", + "fb6ca496", + "1bc2eb2f", + "b68df8f8", + "819b7b19", + "5dc087c2", + "8e2de8c8", + "553f5a9c" + ] + } + } +} diff --git a/contents/questions/algo/linked-list-combine-two-sorted/solution/zh-CN.mdx b/contents/questions/algo/linked-list-combine-two-sorted/solution/zh-CN.mdx new file mode 100644 index 000000000..c2b46cc37 --- /dev/null +++ b/contents/questions/algo/linked-list-combine-two-sorted/solution/zh-CN.mdx @@ -0,0 +1,59 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import linkedListCombineTwoSorted from '../setup/src/linked-list-combine-two-sorted.ts'; +import linkedListCombineTwoSortedUsingRecursion from '../setup/src/linked-list-combine-two-sorted-using-recursion.ts'; + +## 1. 使用迭代方法 + +合并两个已排序链表的迭代方法侧重于通过使用输入列表的已排序特性来保持效率。该策略包括同时遍历两个列表,比较它们的当前节点,并逐个构建组合列表。这确保了合并后的列表保持排序,而无需额外的排序步骤。 + +### 算法 + +1. 创建一个带有占位符值的 `dummy` 节点,并将 `prev` 设置为指向 `dummy`。 +2. 当 `listA` 和 `listB` 都不为 `null` 时: + 1. 比较 `listA` 和 `listB` 的当前节点。 + 2. 通过更新 `prev.next` 将较小的节点附加到合并列表中。 + 3. 移动较小节点所在列表的指针到其下一个节点。 + 4. 更新 `prev` 以指向合并列表中的最后一个节点。 +3. 退出循环后,将 `listA` 或 `listB`(无论哪个不为 `null`)的剩余节点附加到合并列表中。 +4. 返回 `dummy.next`,它指向合并列表的头部。 + + + {linkedListCombineTwoSorted} + + +### Big-O 分析 + +* **时间复杂度:O(m + n)**。两个列表中的每个节点都只处理一次。 +* **空间复杂度:O(1)**。该算法仅使用恒定的额外空间。 + +## 2. 使用递归方法 + +合并两个已排序链表的递归方法依赖于使用递归来简化组合列表的过程。该策略包括比较两个列表的当前节点,并进行递归调用以合并列表的其余部分。这确保了合并列表在调用递归时以排序顺序构建。 + +在每一步中,算法都会比较 `listA` 和 `listB` 的当前节点。选择两个节点中较小的节点作为合并列表的头部。此过程将对列表中剩余的节点递归重复。 + +当 `listA` 或 `listB` 变为 `null` 时,递归终止。此时,非 `null` 列表将附加到合并列表中,因为它已经排序。 + +递归方法通过一次处理一个节点,有效地减小了每一步的问题规模。每个节点只处理一次,确保算法相对于节点总数是线性的。 + +### 算法 + +1. 检查 `listA` 是否为 `null`。如果是,则返回 `listB` 作为合并列表。 +2. 检查 `listB` 是否为 `null`。如果是,则返回 `listA` 作为合并列表。 +3. 比较 `listA` 和 `listB` 中当前节点的值。 + 1. 如果 `listA.val` 小于 `listB.val`: + * 将 `listA.next` 设置为递归合并 `listA.next` 和 `listB` 的结果。 + * 返回 `listA` 作为合并列表的头部。 + 2. 如果 `listB.val` 小于或等于 `listA.val`: + * 将 `listB.next` 设置为递归合并 `listA` 和 `listB.next` 的结果。 + * 返回 `listB` 作为合并列表的头部。 + + + {linkedListCombineTwoSortedUsingRecursion} + + +### Big-O 分析 + +* **时间复杂度:O(m + n)**。两个列表中的每个节点都只访问一次。 +* **空间复杂度:O(m + n)**。递归深度取决于节点的总数,这会导致额外的堆栈空间,与 `m + n` 成正比。 diff --git a/contents/questions/algo/linked-list-delete-nth-from-end/description/en-US.langnostic.json b/contents/questions/algo/linked-list-delete-nth-from-end/description/en-US.langnostic.json new file mode 100644 index 000000000..33b381450 --- /dev/null +++ b/contents/questions/algo/linked-list-delete-nth-from-end/description/en-US.langnostic.json @@ -0,0 +1,37 @@ +{ + "frontmatter": { + "title": "ac7f9278", + "excerpt": "d11e4a12" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "7626ccd8", + "14e22f81", + "6bd8b2c7", + "359939b4", + "2d96efbe", + "f4373306", + "d068a43f", + "b2065fc", + "c96a7a18" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "7626ccd8", + "14e22f81", + "6bd8b2c7", + "359939b4", + "2d96efbe", + "f4373306", + "d068a43f", + "b2065fc", + "c96a7a18" + ] + } + } +} diff --git a/contents/questions/algo/linked-list-delete-nth-from-end/description/zh-CN.mdx b/contents/questions/algo/linked-list-delete-nth-from-end/description/zh-CN.mdx new file mode 100644 index 000000000..dbc997488 --- /dev/null +++ b/contents/questions/algo/linked-list-delete-nth-from-end/description/zh-CN.mdx @@ -0,0 +1,32 @@ +--- +title: 删除链表倒数第 N 个节点 +excerpt: 实现一个函数,用于删除链表倒数第 n 个节点 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个 [链表](https://en.wikipedia.org/wiki/Linked_list) 的头节点,删除链表中倒数第 `n` 个节点,并返回更新后的头节点。 + +链表由一系列 `ListNode` 表示,其中每个节点指向序列中的下一个节点,如果它是最后一个节点,则指向 `null`。 + +一个 `ListNode` 具有以下接口: + +```ts +interface ListNode { + val: number; + next: ListNode | null; +} +``` + +### 输入 + +- `head: ListNode`: 链表的头节点。示例将每个链表显示为列表中的值数组 +- `n: number`: 一个整数,表示要删除的节点的位置(从末尾开始) + + + +### 约束 + +- 1 <= 节点数 <= 1000 +- 1 <= `ListNode.val` <= 1000 diff --git a/contents/questions/algo/linked-list-delete-nth-from-end/solution/en-US.langnostic.json b/contents/questions/algo/linked-list-delete-nth-from-end/solution/en-US.langnostic.json new file mode 100644 index 000000000..113291372 --- /dev/null +++ b/contents/questions/algo/linked-list-delete-nth-from-end/solution/en-US.langnostic.json @@ -0,0 +1,66 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "ac12c1cb", + "f7b44ff6", + "8b3a0b30", + "9acc13e3", + "f699b7e7", + "5aa9f3ea", + "a97c7278", + "f0fe06c0", + "b68df8f8", + "789585c2", + "ab03d923", + "8e2de8c8", + "175b131f", + "b1b88347", + "ff25d4a7", + "7e53207d", + "76323f9", + "5a1113da", + "69d96ad5", + "1bda2f47", + "b68df8f8", + "378b4c4c", + "6e1ea1c7", + "8e2de8c8", + "a4c43424" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "ac12c1cb", + "f7b44ff6", + "8b3a0b30", + "9acc13e3", + "f699b7e7", + "5aa9f3ea", + "a97c7278", + "f0fe06c0", + "b68df8f8", + "789585c2", + "ab03d923", + "8e2de8c8", + "175b131f", + "b1b88347", + "ff25d4a7", + "7e53207d", + "76323f9", + "5a1113da", + "69d96ad5", + "1bda2f47", + "b68df8f8", + "378b4c4c", + "6e1ea1c7", + "8e2de8c8", + "a4c43424" + ] + } + } +} diff --git a/contents/questions/algo/linked-list-delete-nth-from-end/solution/zh-CN.mdx b/contents/questions/algo/linked-list-delete-nth-from-end/solution/zh-CN.mdx new file mode 100644 index 000000000..cc509f780 --- /dev/null +++ b/contents/questions/algo/linked-list-delete-nth-from-end/solution/zh-CN.mdx @@ -0,0 +1,77 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import deleteNthNodeFromEndOfList from '../setup/src/linked-list-delete-nth-from-end.ts'; +import deleteNthNodeFromEndOfListOnePass from '../setup/src/linked-list-delete-nth-from-end-one-pass.ts'; + +## 1. 使用两遍扫描 + +删除链表中倒数第 `n` 个节点的两遍扫描方法将问题分解为两个清晰的步骤。第一遍确定链表的总长度,第二遍确定并删除目标节点。使用虚拟节点简化了边缘情况,例如当需要删除列表的头节点时。 + +通过在第一遍扫描中遍历列表,可以计算出链表的总长度。此步骤确保可以从列表的开头计算出倒数第 `n` 个节点的位置为 `(length - n)`。 + +使用计算出的位置,第二遍扫描在目标节点的前一个节点处停止。这至关重要,因为删除链表中的节点需要访问前一个节点。 + +在列表的开头添加一个虚拟节点,以处理需要删除头节点的情况。这确保了逻辑在列表中的节点位置无关紧要。 + +一旦找到目标节点的前一个节点,通过更新其前驱节点的 `next` 指针来绕过目标节点。此操作确保在删除后列表保持完整并正确链接。 + +这种方法简单明了,确保在最大限度地减少复杂性的同时有效地解决问题。 + +### 算法 + +1. 创建一个 `dummy` 节点,其 `next` 指针设置为列表的头节点。 +2. 将变量 `length` 初始化为 0,并将 `first` 设置为列表的头节点。 +3. 遍历列表以计算总长度: + 1. 遇到每个节点时,递增 `length`。 + 2. 将 `first` 移动到下一个节点,直到到达列表的末尾。 +4. 从 `length` 中减去 `n` 以计算目标节点前一个节点的位置。 +5. 将 `first` 重置为 `dummy` 节点。 +6. 再次遍历列表,直到到达目标节点的前一个节点的位置: + 1. 在每一步中递减 `length`。 + 2. 将 `first` 移动到下一个节点。 +7. 更新 `first` 的 `next` 指针,使其指向 `first.next.next`,从而绕过目标节点。 +8. 返回 `dummy.next` 作为修改后列表的头节点。 + + + {deleteNthNodeFromEndOfList} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。列表被遍历两次,一次用于计算其长度,一次用于定位目标节点的前驱节点。 +* **空间复杂度:O(1)**。该算法使用恒定量的额外空间。 + +## 2. 使用一遍扫描 + +从链表中删除倒数第 `n` 个节点的一遍扫描方法通过使用两个指针来优化遍历。此方法不是计算列表的总长度,而是确保两个指针在单个迭代中遍历列表,从而保持它们之间的固定间隙。 + +该算法使用两个指针 `first` 和 `second`,都从 `dummy` 节点开始。通过将 `first` 指针推进 `n + 1` 步,在 `first` 和 `second` 之间创建了 `n` 个节点的间隙。 + +一旦建立了间隙,两个指针同时移动,直到 `first` 到达列表的末尾。此时,`second` 指针位于要删除的节点的前面。 + +使用 `second` 指针,通过将 `second.next` 更新为 `second.next.next` 来跳过目标节点。这确保了在删除后列表保持完整并正确链接。 + +在列表的开头添加一个 `dummy` 节点,以处理需要删除头节点的情况。这消除了对特殊处理边缘情况的需求,并简化了逻辑。 + +这种单程方法是有效的,因为它最大限度地减少了迭代次数并保持线性时间复杂度。 + +### 算法 + +1. 创建一个 `dummy` 节点,其 `next` 指针设置为列表的头部。 +2. 初始化两个指针 `first` 和 `second`,都指向 `dummy` 节点。 +3. 将 `first` 指针推进 `n + 1` 步,在 `first` 和 `second` 之间创建 `n` 个节点的间隙: + 1. 如果 `first` 不为 `null`,则在每一步将其移动到下一个节点。 +4. 每次移动 `first` 和 `second` 指针一步,直到 `first` 到达列表的末尾: + 1. 将 `first` 移动到 `first.next`。 + 2. 将 `second` 移动到 `second.next`。 +5. 通过将 `second.next` 更新为 `second.next.next`,从末尾删除第 `n` 个节点。 +6. 返回 `dummy.next`,它指向修改后的列表的头部。 + + + {deleteNthNodeFromEndOfListOnePass} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。列表遍历一次。 +* **空间复杂度:O(1)**。该算法使用恒定的额外空间。 diff --git a/contents/questions/algo/linked-list-detect-cycle/description/en-US.langnostic.json b/contents/questions/algo/linked-list-detect-cycle/description/en-US.langnostic.json new file mode 100644 index 000000000..07e9254af --- /dev/null +++ b/contents/questions/algo/linked-list-detect-cycle/description/en-US.langnostic.json @@ -0,0 +1,39 @@ +{ + "frontmatter": { + "title": "265edced", + "excerpt": "bf9bdd8c" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "840340d7", + "d593fa5d", + "14e22f81", + "6bd8b2c7", + "359939b4", + "2d96efbe", + "9680cdf6", + "d068a43f", + "b2065fc", + "306da3be" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "840340d7", + "d593fa5d", + "14e22f81", + "6bd8b2c7", + "359939b4", + "2d96efbe", + "9680cdf6", + "d068a43f", + "b2065fc", + "306da3be" + ] + } + } +} diff --git a/contents/questions/algo/linked-list-detect-cycle/description/zh-CN.mdx b/contents/questions/algo/linked-list-detect-cycle/description/zh-CN.mdx new file mode 100644 index 000000000..965cdb348 --- /dev/null +++ b/contents/questions/algo/linked-list-detect-cycle/description/zh-CN.mdx @@ -0,0 +1,33 @@ +--- +title: 链表检测环 +excerpt: 实现一个函数来检测链表中是否有环 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个[链表](https://en.wikipedia.org/wiki/Linked_list)的头节点,确定该链表是否包含环。如果链表包含环,则返回`true`;否则,返回`false`。 + +如果存在一个节点可以通过连续跟随下一个指针被重新访问,则链表具有环。 + +链表由一系列`ListNode`表示,其中每个节点指向序列中的下一个节点,如果它是最后一个节点,则指向`null`。 + +一个`ListNode`具有以下接口: + +```ts +interface ListNode { + val: number; + next: ListNode | null; +} +``` + +### 输入 + +- `head: ListNode`: 链表的头节点。示例将每个链表显示为列表中的值数组 + + + +### 约束 + +- 0 <= 节点数 <= 1000 +- -1000 <= `ListNode.val` <= 1000 diff --git a/contents/questions/algo/linked-list-detect-cycle/solution/en-US.langnostic.json b/contents/questions/algo/linked-list-detect-cycle/solution/en-US.langnostic.json new file mode 100644 index 000000000..0e3b0ccb1 --- /dev/null +++ b/contents/questions/algo/linked-list-detect-cycle/solution/en-US.langnostic.json @@ -0,0 +1,64 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "6260853d", + "d5bacc51", + "cac8b254", + "cdfd69d", + "6045e653", + "14c580a5", + "e0320c38", + "bba3e1f9", + "b68df8f8", + "42769d9a", + "349f405", + "8e2de8c8", + "d1875ccf", + "dd7701bd", + "1a23b714", + "ae1551d9", + "476714db", + "ff0c7241", + "3fcfc7e7", + "b68df8f8", + "9207cec9", + "931d7624", + "8e2de8c8", + "6bec40d3" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "6260853d", + "d5bacc51", + "cac8b254", + "cdfd69d", + "6045e653", + "14c580a5", + "e0320c38", + "bba3e1f9", + "b68df8f8", + "42769d9a", + "349f405", + "8e2de8c8", + "d1875ccf", + "dd7701bd", + "1a23b714", + "ae1551d9", + "476714db", + "ff0c7241", + "3fcfc7e7", + "b68df8f8", + "9207cec9", + "931d7624", + "8e2de8c8", + "6bec40d3" + ] + } + } +} diff --git a/contents/questions/algo/linked-list-detect-cycle/solution/zh-CN.mdx b/contents/questions/algo/linked-list-detect-cycle/solution/zh-CN.mdx new file mode 100644 index 000000000..6171e802e --- /dev/null +++ b/contents/questions/algo/linked-list-detect-cycle/solution/zh-CN.mdx @@ -0,0 +1,70 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import linkedListDetectCycle from '../setup/src/linked-list-detect-cycle.ts'; +import linkedListDetectCycleFloydCycle from '../setup/src/linked-list-detect-cycle-floyd-cycle.ts'; + +## 1. 使用 Set + +使用 `Set` 检测链表中循环的方法利用了循环会导致对某些节点的重复遍历的特性。通过将访问过的节点存储在 `Set` 中,该算法可以有效地检查一个节点是否已经被访问过。如果一个节点被再次访问,则存在循环。否则,如果遍历到达列表的末尾,则不存在循环。 + +`Set` 提供了一种有效的方式来存储和检查节点是否存在。在 `Set` 中插入和查找的时间复杂度为 O(1),这使得它非常适合这项任务。 + +在遍历过程中,每个节点都会被添加到 `Set` 中。如果遇到一个已经存在于 `Set` 中的节点,这意味着列表已经循环回到了之前访问过的节点。 + +一旦检测到循环(找到重复的节点),遍历就会停止,确保算法的效率。 + +如果到达列表的末尾 (`null`) 且没有遇到重复的节点,则确认列表中没有循环。 + +这种方法很简单,并且使用额外的空间来跟踪访问过的节点。 + +### 算法 + +1. 创建一个名为 `nodesSeen` 的 `Set`,用于存储已访问的节点。 +2. 初始化一个变量 `current`,使其指向链表的头部。 +3. 使用 `while` 循环遍历列表,直到 `current` 变为 `null`: + 1. 检查 `current` 是否已经在 `nodesSeen` 中。 + * 如果为 `true`,则返回 `true`,因为检测到循环。 + 2. 将 `current` 添加到 `nodesSeen`。 + 3. 将 `current` 移动到列表中的下一个节点。 +4. 如果循环结束而未检测到循环,则返回 `false`。 + + + {linkedListDetectCycle} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。列表中的每个节点都会被访问一次。 +* **空间复杂度:O(n)**。`Set` 最多存储 `n` 个节点(在没有循环的最坏情况下)。 + +## 2. 使用 Floyd 循环算法 + +Floyd 循环检测算法,也称为“龟兔赛跑”算法,是一种用于检测链表中循环的有效方法。该算法使用两个指针,一个 `slow` 指针和一个 `fast` 指针,它们以不同的速度遍历列表。如果存在循环,这两个指针最终会相遇。否则,`fast` 指针将到达列表的末尾。 + +`slow` 指针一次移动一步,而 `fast` 指针一次移动两步。这种速度差异确保如果存在循环,`fast` 指针最终会追上 `slow` 指针。 + +如果两个指针在遍历过程中相遇,则确认存在循环。这是因为 `fast` 指针绕着循环转了一圈并追上了 `slow` 指针。 + +如果 `fast` 指针到达列表的末尾 (`null`),则表示列表中没有循环。这确保了该算法对非循环列表的有效终止。 + +该算法在线性时间内运行并使用恒定空间,使其成为检测链表中循环的最佳选择。 + +### 算法 + +1. 检查链表的头是否为 `null`。如果为真,则返回 `false`,因为空链表不能有环。 +2. 初始化两个指针: + * `slow` 指针设置为链表的头。 + * `fast` 指针设置为 `head.next`。 +3. 使用 `while` 循环遍历链表: + 1. 检查 `fast` 或 `fast.next` 是否为 `null`。如果为真,则返回 `false`,因为没有环。 + 2. 将 `slow` 指针向前移动一步 (`slow = slow.next`)。 + 3. 将 `fast` 指针向前移动两步 (`fast = fast.next.next`)。 + 4. 检查 `slow` 指针是否等于 `fast` 指针。如果为真,则返回 `true`,因为检测到环。 +4. 如果循环在指针未相遇的情况下结束,则返回 `false`,因为不存在环。 + + {linkedListDetectCycleFloydCycle} + +### Big-O 分析 + +* **时间复杂度:O(n)**。每个指针最多遍历列表一次。 +* **空间复杂度:O(1)**。该算法仅使用两个指针,与列表的大小无关。 diff --git a/contents/questions/algo/linked-list-rearrange/description/en-US.langnostic.json b/contents/questions/algo/linked-list-rearrange/description/en-US.langnostic.json new file mode 100644 index 000000000..cd2a96636 --- /dev/null +++ b/contents/questions/algo/linked-list-rearrange/description/en-US.langnostic.json @@ -0,0 +1,45 @@ +{ + "frontmatter": { + "title": "bb9ccad3", + "excerpt": "b61c722e" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "e3c45763", + "8aebfe42", + "1616e2de", + "6cf24523", + "77b1fc8c", + "14e22f81", + "6bd8b2c7", + "359939b4", + "2d96efbe", + "9680cdf6", + "d068a43f", + "b2065fc", + "c96a7a18" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "e3c45763", + "8aebfe42", + "1616e2de", + "6cf24523", + "77b1fc8c", + "14e22f81", + "6bd8b2c7", + "359939b4", + "2d96efbe", + "9680cdf6", + "d068a43f", + "b2065fc", + "c96a7a18" + ] + } + } +} diff --git a/contents/questions/algo/linked-list-rearrange/description/zh-CN.mdx b/contents/questions/algo/linked-list-rearrange/description/zh-CN.mdx new file mode 100644 index 000000000..745648ba8 --- /dev/null +++ b/contents/questions/algo/linked-list-rearrange/description/zh-CN.mdx @@ -0,0 +1,39 @@ +--- +title: 重排链表 +excerpt: 实现一个函数来重新排列链表中的节点 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个[链表](https://en.wikipedia.org/wiki/Linked_list)的头节点`head`,重新排列列表,使列表从头节点和尾节点交替出现。重新排序应该通过重新排列节点本身来执行,而无需修改存储在节点中的值。 + +原始结构如下: + +`L0 → L1 → ... → Ln-1 → Ln` + +将列表重新组织成以下结构: + +`L0 → Ln → L1 → Ln-1 → L2 → Ln-2 → …` + +链表由一系列`ListNode`表示,其中每个节点指向序列中的下一个节点,如果它是最后一个节点,则指向`null`。 + +一个`ListNode`具有以下接口: + +```ts +interface ListNode { + val: number; + next: ListNode | null; +} +``` + +### 输入 + +- `head: ListNode`: 链表的头节点。示例将每个链表显示为列表中的值数组 + + + +### 约束 + +- 1 <= 节点数 <= 1000 +- 1 <= `ListNode.val` <= 1000 diff --git a/contents/questions/algo/linked-list-rearrange/solution/en-US.langnostic.json b/contents/questions/algo/linked-list-rearrange/solution/en-US.langnostic.json new file mode 100644 index 000000000..5538c7d95 --- /dev/null +++ b/contents/questions/algo/linked-list-rearrange/solution/en-US.langnostic.json @@ -0,0 +1,40 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "94641d9e", + "1819a9bf", + "44d57c54", + "d2a6ec85", + "1df400f4", + "ae80af5e", + "72d1670a", + "b68df8f8", + "9ee2c373", + "ca7dd858", + "8e2de8c8", + "fcc5d95d" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "94641d9e", + "1819a9bf", + "44d57c54", + "d2a6ec85", + "1df400f4", + "ae80af5e", + "72d1670a", + "b68df8f8", + "9ee2c373", + "ca7dd858", + "8e2de8c8", + "fcc5d95d" + ] + } + } +} diff --git a/contents/questions/algo/linked-list-rearrange/solution/zh-CN.mdx b/contents/questions/algo/linked-list-rearrange/solution/zh-CN.mdx new file mode 100644 index 000000000..a5c2d42b5 --- /dev/null +++ b/contents/questions/algo/linked-list-rearrange/solution/zh-CN.mdx @@ -0,0 +1,42 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import rearrangeLinkedList from '../setup/src/linked-list-rearrange.ts'; + +## 1. 合并列表与反向子列表 + +该问题涉及重新排列链表,使得节点在列表的前半部分和后半部分之间交替。这种方法使用三个关键步骤的组合:定位列表的中间位置,反转列表的后半部分,以及合并这两个部分。 + +链表的中间位置使用双指针技术确定。`slow`指针一次移动一步,而`fast`指针移动两步。当`fast`指针到达末尾时,`slow`指针位于中间位置。这会将列表分成两半。 + +列表的后半部分就地反转。这会将链表转换为两部分:前半部分按原始顺序排列,后半部分按反向顺序排列。反转是为了方便交替合并。 + +通过交替选择来自前半部分和反向后半部分的节点来合并这两半。这会以所需的交替模式重新排列列表。 + +这种方法在线性时间内有效地解决了问题,并使用恒定空间来重新排序节点。 + +### 算法 + +1. 检查`head`是否为`null`。如果为真,则立即返回,因为没有什么可重新排列的。 +2. 初始化两个指针`slow`和`fast`,都设置为链表的`head`。 +3. 定位列表的中间位置: + 1. 每次移动`slow`一步,`fast`两步。 + 2. 当`fast`为`null`或`fast.next`为`null`时停止。`slow`指针现在将指向中间节点。 +4. 反转列表的后半部分: + 1. 将`prev`初始化为`null`,将`curr`初始化为`slow`。 + 2. 从`slow`遍历列表到末尾: + * 将下一个节点存储在临时变量`tmp`中。 + * 将`curr.next`更新为指向`prev`。 + * 将`prev`移动到`curr`,将`curr`移动到`tmp`。 +5. 合并列表的两半: + 1. 将`first`初始化为列表的`head`,将`second`初始化为`prev`(反向后半部分的头)。 + 2. 交替链接来自`first`和`second`的节点: + * 将`first`的下一个节点存储在`tmp1`中,将`second`的下一个节点存储在`tmp2`中。 + * 将`first.next`更新为指向`second`,将`second.next`更新为指向`tmp1`。 + * 将`first`移动到`tmp1`,将`second`移动到`tmp2`。 + + {rearrangeLinkedList} + +### Big-O 分析 + +* **时间复杂度:O(n)**。在三个步骤中,每个节点都会被访问一次:找到中间位置、反转后半部分和合并。 +* **空间复杂度:O(1)**。该算法使用恒定量的额外空间。 diff --git a/contents/questions/algo/linked-list-reversal/description/en-US.langnostic.json b/contents/questions/algo/linked-list-reversal/description/en-US.langnostic.json new file mode 100644 index 000000000..e92350fe4 --- /dev/null +++ b/contents/questions/algo/linked-list-reversal/description/en-US.langnostic.json @@ -0,0 +1,37 @@ +{ + "frontmatter": { + "title": "ae67383c", + "excerpt": "cd8d1eaf" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "cb72e942", + "14e22f81", + "6bd8b2c7", + "359939b4", + "2d96efbe", + "9680cdf6", + "d068a43f", + "b2065fc", + "d7af97a0" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "cb72e942", + "14e22f81", + "6bd8b2c7", + "359939b4", + "2d96efbe", + "9680cdf6", + "d068a43f", + "b2065fc", + "d7af97a0" + ] + } + } +} diff --git a/contents/questions/algo/linked-list-reversal/description/zh-CN.mdx b/contents/questions/algo/linked-list-reversal/description/zh-CN.mdx new file mode 100644 index 000000000..b0af20e65 --- /dev/null +++ b/contents/questions/algo/linked-list-reversal/description/zh-CN.mdx @@ -0,0 +1,31 @@ +--- +title: 链表反转 +excerpt: 实现一个反转链表的函数 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个[链表](https://en.wikipedia.org/wiki/Linked_list)的头节点,反转链表并返回反转后链表的新头节点。 + +链表由一系列`ListNode`表示,其中每个节点指向序列中的下一个节点,如果它是最后一个节点,则指向`null`。 + +一个`ListNode`具有以下接口: + +```ts +interface ListNode { + val: number; + next: ListNode | null; +} +``` + +### 输入 + +- `head: ListNode`: 链表的头节点。示例将每个链表显示为列表中的值数组 + + + +### 约束 + +- 1 <= 节点数 <= 1000 +- -1000 <= `ListNode.val` <= 1000 diff --git a/contents/questions/algo/linked-list-reversal/solution/en-US.langnostic.json b/contents/questions/algo/linked-list-reversal/solution/en-US.langnostic.json new file mode 100644 index 000000000..93a2b9d7a --- /dev/null +++ b/contents/questions/algo/linked-list-reversal/solution/en-US.langnostic.json @@ -0,0 +1,64 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "adb90e84", + "c902b578", + "e530f256", + "5666631a", + "ef6a9572", + "67ee226b", + "173d4405", + "684eb0ca", + "b68df8f8", + "7de45a9a", + "d0f39fd", + "8e2de8c8", + "d534ba28", + "93bc344c", + "398d839", + "c8c21577", + "a73af20c", + "ff037090", + "67cb75dd", + "b68df8f8", + "21253a0", + "3e17319d", + "8e2de8c8", + "c9a0896d" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "adb90e84", + "c902b578", + "e530f256", + "5666631a", + "ef6a9572", + "67ee226b", + "173d4405", + "684eb0ca", + "b68df8f8", + "7de45a9a", + "d0f39fd", + "8e2de8c8", + "d534ba28", + "93bc344c", + "398d839", + "c8c21577", + "a73af20c", + "ff037090", + "67cb75dd", + "b68df8f8", + "21253a0", + "3e17319d", + "8e2de8c8", + "c9a0896d" + ] + } + } +} diff --git a/contents/questions/algo/linked-list-reversal/solution/zh-CN.mdx b/contents/questions/algo/linked-list-reversal/solution/zh-CN.mdx new file mode 100644 index 000000000..e63856a2b --- /dev/null +++ b/contents/questions/algo/linked-list-reversal/solution/zh-CN.mdx @@ -0,0 +1,70 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import linkedListReversal from '../setup/src/linked-list-reversal.ts'; +import linkedListReversalUsingRecursion from '../setup/src/linked-list-reversal-using-recursion.ts'; + +## 1. 使用迭代方法 + +反转链表涉及翻转所有节点的 `next` 指针,使其指向前一个节点而不是下一个节点。迭代方法使用两个指针 `prev` 和 `curr` 分别跟踪前一个节点和当前节点。这确保了列表在原地反转,而无需额外的内存。 + +每个节点的 `next` 指针被反转以指向前一个节点。此操作对列表中的所有节点进行迭代。 + +`curr` 指针从头到尾遍历列表,而 `prev` 指针滞后,逐步构建列表的反转部分。 + +通过仅使用几个指针 (`prev`、`curr` 和一个用于下一个节点的临时指针),该算法实现了反转,而无需为新列表分配额外的空间。 + +当 `curr` 指针变为 `null` 时,该过程结束,这表明所有节点都已被反转。此时,`prev` 指针指向反转列表的新头部。 + +这种方法在线性时间内有效地反转列表,同时保持恒定的空间复杂度。 + +### 算法 + +1. 初始化两个指针: + * `prev` 初始化为 `null`,表示前一个节点。 + * `curr` 初始化为 `head`,表示当前节点。 +2. 当 `curr` 不为 `null` 时,遍历列表: + 1. 将下一个节点存储在临时变量 `nextTemp` (`curr.next`) 中。 + 2. 反转当前节点的 `next` 指针 (`curr.next = prev`)。 + 3. 将 `prev` 指针移动到当前节点 (`prev = curr`)。 + 4. 将 `curr` 指针移动到下一个节点 (`curr = nextTemp`)。 +3. 循环结束后,`prev` 指针将指向反转列表的新头部。 +4. 返回 `prev` 作为新头部。 + + + {linkedListReversal} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。列表中的每个节点都会被访问一次。 +* **空间复杂度:O(1)**。该算法使用恒定量的额外空间。 + +## 2. 使用递归方法 + +递归地反转链表涉及将问题分解为更小的子问题,首先反转列表的尾部,并在递归调用时调整指针。关键是在递归沿调用堆栈向上传播时,一次一步地反转节点的 `next` 指针。 + +该问题被分解为反转从第二个节点开始的子列表 (`head.next`)。基本情况发生在列表为空或只有一个节点时,在这种情况下,反转完成。 + +在每次递归调用期间,后续节点的 `next` 指针被更新以指回当前节点 (`head`)。这会反转每个节点的 `next` 指针的方向。 + +递归调用返回反转子列表的新头部,该头部传播回顶层调用者。这确保了返回反转列表的最终头部。 + +该算法直接在列表的节点上运行,而无需为新列表或辅助数据结构分配额外的空间。 + +### 算法 + +1. 检查基本情况: + * 如果 `head` 为 `null` 或 `head.next` 为 `null`,则返回 `head` 作为反转后的列表。 +2. 递归调用 `reverseLinkedList`,使用 `head.next` 反转列表的其余部分。 + * 将结果存储在变量 `p` 中,它表示反转列表的新头。 +3. 调整指针: + * 将 `head.next.next` 设置为 `head`,反转当前节点的 `next` 指针。 + * 将 `head.next` 设置为 `null`,以断开当前节点与原始列表结构的连接。 +4. 返回 `p` 作为反转列表的新头。 + + {linkedListReversalUsingRecursion} + +### Big-O 分析 + +* **时间复杂度:O(n)**。在递归期间,每个节点只访问一次。 +* **空间复杂度:O(n)**。递归深度与列表的大小成正比,需要额外的堆栈空间。 diff --git a/contents/questions/algo/linked-list/description/en-US.langnostic.json b/contents/questions/algo/linked-list/description/en-US.langnostic.json new file mode 100644 index 000000000..cbf147f54 --- /dev/null +++ b/contents/questions/algo/linked-list/description/en-US.langnostic.json @@ -0,0 +1,25 @@ +{ + "frontmatter": { + "title": "f41dc02d", + "excerpt": "a68ad447" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "880fa27a", + "1faea8b1", + "493e8bd0", + "f0a6eb8a" + ] + }, + "targets": { + "zh-CN": [ + "880fa27a", + "1faea8b1", + "493e8bd0", + "f0a6eb8a" + ] + } + } +} diff --git a/contents/questions/algo/linked-list/description/zh-CN.mdx b/contents/questions/algo/linked-list/description/zh-CN.mdx new file mode 100644 index 000000000..47e44ba50 --- /dev/null +++ b/contents/questions/algo/linked-list/description/zh-CN.mdx @@ -0,0 +1,31 @@ +--- +title: 链表 +excerpt: 实现一个包含常见链表方法的链表数据结构 +--- + +在 JavaScript 中实现一个链表数据结构,其中包含以下操作: + +* `new LinkedList()`:创建一个不包含任何项目的 `LinkedList` 类的实例。构造函数不接受任何参数。 +* `get()`:接受一个整数参数 `i`,以返回第 `i` 个节点的值。如果索引超出范围,则返回 `undefined`。 +* `insertHead()`:接受一个参数 `value`,并将 `value` 插入到列表的头部。 +* `insertTail()`:接受一个参数 `value`,并将 `value` 插入到列表的尾部。 +* `remove()`:接受一个整数参数 `i`,并删除第 `i` 个索引处的项目,同时返回其值。如果索引超出范围,则返回 `undefined`。 +* `toArray()`:返回一个数组,其中包含链表中从头(数组中的第一个元素)到尾(数组中的最后一个元素)的所有项目。 +* `length()`:返回链表中的元素数。 + +## 例子 + +```js +const linkedlist = new LinkedList(); +linkedlist.toArray(); // [] +linkedlist.insertTail(1); +linkedlist.insertHead(2); +linkedlist.toArray(); // [2, 1] +linkedlist.insertTail(3); +linkedlist.toArray(); // [2, 1, 3] +linkedlist.length(); // 3 +linkedlist.get(1); // 1 +linkedlist.get(2); // 3 +linkedlist.remove(1); // 1 +linkedlist.toArray(); // [2, 3] +``` diff --git a/contents/questions/algo/linked-list/solution/en-US.langnostic.json b/contents/questions/algo/linked-list/solution/en-US.langnostic.json new file mode 100644 index 000000000..752408d55 --- /dev/null +++ b/contents/questions/algo/linked-list/solution/en-US.langnostic.json @@ -0,0 +1,68 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "180b900f", + "26e3ffe5", + "a556b55a", + "4951eff7", + "c8b9dc1b", + "b9603e29", + "3551d1c7", + "28279ca", + "e0528fff", + "1debebc2", + "45e4cfb6", + "93789371", + "e46d1e82", + "a47a5740", + "f83e28cf", + "f15c5073", + "c998b811", + "a34a2355", + "bb1b042d", + "57e2fe9b", + "5b6426bb", + "7170bb7e", + "1f814185", + "dd457b8c", + "d87b3100", + "625ad27d" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "180b900f", + "26e3ffe5", + "a556b55a", + "4951eff7", + "c8b9dc1b", + "b9603e29", + "3551d1c7", + "28279ca", + "e0528fff", + "1debebc2", + "45e4cfb6", + "93789371", + "e46d1e82", + "a47a5740", + "f83e28cf", + "f15c5073", + "c998b811", + "a34a2355", + "bb1b042d", + "57e2fe9b", + "5b6426bb", + "7170bb7e", + "1f814185", + "dd457b8c", + "d87b3100", + "625ad27d" + ] + } + } +} diff --git a/contents/questions/algo/linked-list/solution/zh-CN.mdx b/contents/questions/algo/linked-list/solution/zh-CN.mdx new file mode 100644 index 000000000..2759321ee --- /dev/null +++ b/contents/questions/algo/linked-list/solution/zh-CN.mdx @@ -0,0 +1,57 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import linkedListJs from '../setup/src/linked-list.js'; +import linkedListTs from '../setup/src/linked-list.ts'; + +## 解决方案 + +链表是连接节点的链,其中每个节点包含一个 `value` 和一个对 `next` 节点的引用。每个节点中的 `next` 形成了制作链表所需的链接。 + +在 `LinkedList` 类中,`head` 和 `tail` 用于指示列表的开始和结束。虽然仅使用 `head` 是可能的,但维护一个 `tail` 指针可以提高 `insertTail()` 等操作的时间复杂度,并实现高效的用例,例如实现队列。 + +### 插入 + +`insertHead()` 和 `insertTail()` 涉及更新列表的 `head` 或 `tail` 以指向一个新节点。 + +![Insert Head](/img/questions/linked-list/insert-head.png) + +![Insert Tail](/img/questions/linked-list/insert-tail.png) + +### 删除 + +`remove()` 修改节点 `i-1` 的 `next` 引用以指向节点 `i+1`,从而有效地从列表中删除节点 `i`。如果删除的节点位于头部或尾部,则 `head` 或 `tail` 指针也会相应地更新。 + +![Remove](/img/questions/linked-list/remove.png) + +### 获取和 toArray + +`get()` 和 `toArray()` 从 `head` 节点遍历列表。`get()` 在指定的索引处停止,而 `toArray()` 继续到 `tail`,收集所有值。 + +### 长度 + +`length()` 遍历整个链表以计算元素的数量。或者,可以维护一个长度变量来跟踪每次插入/删除节点时链表的长度。 + + + +## Big-O 分析 + +让我们分析一下算法的时间和空间复杂度。 + +### 时间复杂度 + +* `insertHead()` 和 `insertTail()`:O(1),因为我们可以立即访问 `head` 和 `tail`。 +* `get()`、`remove()`、`toArray()`:O(n),因为最坏的情况是遍历整个链表以搜索 `get()` 和 `remove()` 的特定索引。 +* `length()`:O(n),如果遍历整个数组来计算长度,O(1) 如果维护一个长度变量。 + +### 空间复杂度 + +* 所有方法都需要 O(1) 空间,因为没有创建随输入大小增长的额外数据结构。 + +## 边缘情况 + +* **空列表**:在空列表上操作时,`insertHead()` 和 `insertTail()` 必须同时设置 `head` 和 `tail`。 +* **无效索引**:在 `get()` 和 `remove()` 中,必须妥善处理小于 0 或大于或等于列表长度的索引值。 一种常见的方法是返回 `undefined`,如本问题中所使用。 + +## 技术 + +* 面向对象编程。 diff --git a/contents/questions/algo/longest-common-subsequence/description/en-US.langnostic.json b/contents/questions/algo/longest-common-subsequence/description/en-US.langnostic.json new file mode 100644 index 000000000..fd43065d1 --- /dev/null +++ b/contents/questions/algo/longest-common-subsequence/description/en-US.langnostic.json @@ -0,0 +1,35 @@ +{ + "frontmatter": { + "title": "1e3c6f8e", + "excerpt": "13e49c48" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "a28266d3", + "6567023e", + "84a5037e", + "2d96efbe", + "5824f498", + "d068a43f", + "b2065fc", + "614dbb16" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "a28266d3", + "6567023e", + "84a5037e", + "2d96efbe", + "5824f498", + "d068a43f", + "b2065fc", + "614dbb16" + ] + } + } +} diff --git a/contents/questions/algo/longest-common-subsequence/description/zh-CN.mdx b/contents/questions/algo/longest-common-subsequence/description/zh-CN.mdx new file mode 100644 index 000000000..34deb5f49 --- /dev/null +++ b/contents/questions/algo/longest-common-subsequence/description/zh-CN.mdx @@ -0,0 +1,25 @@ +--- +title: 最长公共子序列 +excerpt: 实现一个函数来查找两个字符串中最长的公共子序列 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定两个字符串 `str1` 和 `str2`,找到它们最长公共子序列的长度。如果不存在公共子序列,则返回 `0`。 + +子序列是从另一个序列派生的序列,通过删除一些或不删除任何元素而不改变剩余元素的顺序。例如,`abc` 的子序列是 \`\`, `a`, `b`, `c`, `ab`, `ac`, `bc` 和 `abc`。 + +两个字符串之间的公共子序列是指以相同相对顺序出现在两个字符串序列中的子序列。例如,在字符串 `xyz` 和 `axabz` 中,最长的公共子序列是 `xz`,因此,最长公共子序列的长度是 2。 + +### 输入 + +- `str1: string`: 字符串 +- `str2: string`: 字符串 + + + +### 约束 + +- 1 <= `str1.length`, `str2.length` <= 1000 +- `str1` 和 `str2` 仅由小写英文字符组成 diff --git a/contents/questions/algo/longest-common-subsequence/solution/en-US.langnostic.json b/contents/questions/algo/longest-common-subsequence/solution/en-US.langnostic.json new file mode 100644 index 000000000..861de05a6 --- /dev/null +++ b/contents/questions/algo/longest-common-subsequence/solution/en-US.langnostic.json @@ -0,0 +1,62 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "83d353aa", + "eb582080", + "e7daa9cf", + "b68df8f8", + "1dcb9db2", + "65d47f30", + "8e2de8c8", + "24506b35", + "adb1a0d0", + "47255197", + "5c01cb49", + "b68df8f8", + "a1ab7717", + "edf0b1e", + "8e2de8c8", + "3c696536", + "b83daf4", + "eef25ccc", + "b68df8f8", + "3537aeb8", + "2f5e88d2", + "8e2de8c8", + "68636b3f" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "83d353aa", + "eb582080", + "e7daa9cf", + "b68df8f8", + "1dcb9db2", + "65d47f30", + "8e2de8c8", + "24506b35", + "adb1a0d0", + "47255197", + "5c01cb49", + "b68df8f8", + "a1ab7717", + "edf0b1e", + "8e2de8c8", + "3c696536", + "b83daf4", + "eef25ccc", + "b68df8f8", + "3537aeb8", + "2f5e88d2", + "8e2de8c8", + "68636b3f" + ] + } + } +} diff --git a/contents/questions/algo/longest-common-subsequence/solution/zh-CN.mdx b/contents/questions/algo/longest-common-subsequence/solution/zh-CN.mdx new file mode 100644 index 000000000..372d23e51 --- /dev/null +++ b/contents/questions/algo/longest-common-subsequence/solution/zh-CN.mdx @@ -0,0 +1,78 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import longestCommonSubsequence from '../setup/src/longest-common-subsequence.ts'; +import longestCommonSubsequenceDP from '../setup/src/longest-common-subsequence-dp.ts'; +import longestCommonSubsequenceDPOptimizedSpace from '../setup/src/longest-common-subsequence-dp-space-optimized.ts'; + +## 1. 使用动态规划 + +解决最长公共子序列问题的动态规划方法构建了一个二维网格(`dpGrid`),其中每个单元格表示两个输入字符串的相应子字符串的最长公共子序列的长度。该解决方案从右下角到左上角迭代地填充网格,利用较小子问题的结果来计算较大子问题的结果。这种方法避免了冗余计算,并通过系统地考虑所有可能性来确保最佳解决方案。 + +### 算法 + +1. 使用零初始化一个二维数组`dpGrid`,其维度为`(str1.length + 1) x (str2.length + 1)`。 +2. 从右下角开始遍历网格: + 1. 对于`str2`中的每个字符(列,从右到左): + * 对于`str1`中的每个字符(行,从下到上): + 1. 如果两个字符串中当前位置的字符相等,则将`dpGrid`中的当前单元格设置为`1 + dpGrid[row + 1][col + 1]`。 + 2. 否则,将当前单元格设置为`dpGrid[row + 1][col]`(下方)和`dpGrid[row][col + 1]`(右侧)之间的最大值。 +3. `dpGrid`的左上角单元格包含`str1`和`str2`的最长公共子序列的长度。 +4. 返回`dpGrid[0][0]`中的值。 + + + {longestCommonSubsequenceDP} + + +### Big-O 分析 + +* **时间复杂度:O(m.n)**。该解决方案涉及填充一个大小为`m x n`的网格,其中`m`是`str1`的长度,`n`是`str2`的长度。 +* **空间复杂度:O(m.n)**。`dpGrid`所需的空间与两个字符串的长度的乘积成正比。 + +## 2. 使用动态规划优化空间 + +使用完整的DP表,不如一次只维护两行来存储中间结果。传统的DP解决方案使用大小为`(m+1) x (n+1)`的二维表来存储`str1`和`str2`的所有子字符串的结果,导致空间复杂度为O(m.n)。然而,在任何时候,只需要当前行和前一行来计算下一行的值。这导致了一个优化的解决方案,通过重复使用行,空间复杂度为O(n)。 + +优化的方法通过维护两行来消除不必要的存储:`currentRow`用于存储当前状态的结果,`nextRow`用于存储前一个状态的结果。该算法以相反的顺序遍历字符串,有效地更新行。通过利用`currentRow`和`nextRow`之间的关系,该解决方案在不构建整个DP表的情况下计算LCS。 + +### 算法 + +1. 初始化两个数组`currentRow`和`nextRow`,用零填充,每个数组的大小为`str2.length + 1`。 +2. 从下到上遍历`str1`(索引`row`从`str1.length - 1`开始并递减到`0`)。 +3. 交换`currentRow`和`nextRow`的角色。这确保了`currentRow`保存当前迭代的结果,而`nextRow`保存前一次迭代的结果。 +4. 对于`str2`的每个字符,从右到左迭代(索引`col`从`str2.length - 1`开始并递减到`0`): + * 如果`str1[row] === str2[col]`,则将`currentRow[col]`设置为`1 + nextRow[col + 1]`,表示对角线值加一。 + * 否则,将`currentRow[col]`设置为`nextRow[col]`和`currentRow[col + 1]`的最大值,表示跳过`str1`或`str2`的当前字符之间的最大值。 +5. 完成迭代后,结果存储在`currentRow[0]`中。 + + + {longestCommonSubsequenceDPOptimizedSpace} + + +### Big-O 分析 + +* **时间复杂度:O(m.n)**。使用两个嵌套循环:一个循环遍历`str1`的长度(m),另一个循环遍历`str2`的长度(n)。 +* **空间复杂度:O(n)**。仅使用两行,每行大小为`n+1`,用于计算,将空间使用从O(m.n)减少到O(n)。 + +## 3. 使用记忆化 + +解决最长公共子序列问题的记忆化方法背后的关键直觉是通过存储先前已解决的子问题的结果来避免冗余计算。这确保了仅处理两个字符串的每个唯一索引对一次。通过将问题分解为较小的重叠子问题并存储其结果,该解决方案有效地组合了这些结果以找到整体最长公共子序列。 + +### 算法 + +1. 创建一个用`-1`初始化的二维`dp`数组,用于存储子问题的结果。 +2. 定义一个递归函数`lcs`,该函数接受两个字符串`str1`和`str2`以及索引`index1`和`index2`作为参数: + 1. 检查当前索引的结果是否已在`dp`数组中计算。如果是,则返回存储的值。 + 2. 如果任一索引到达其各自字符串的末尾,则返回`0`,因为在该点之后没有公共子序列。 + 3. 如果当前索引处的字符匹配,则将结果计算为`1 + lcs(str1, str2, index1 + 1, index2 + 1)`并将其存储在`dp`数组中。 + 4. 如果字符不匹配,则计算跳过任一字符串中的一个字符的最大值,并将其存储在`dp`数组中。 +3. 从`str1`和`str2`的索引`0`和`0`开始调用`lcs`函数。 +4. 返回`lcs`为完整字符串计算的值。 + + + {longestCommonSubsequence} + + +### Big-O 分析 + +* **时间复杂度:O(m.n)**。每个子问题最多只解决一次,其中`m`是`str1`的长度,`n`是`str2`的长度。 +* **空间复杂度:O(m.n)**。`dp`数组所需的空间与两个字符串的长度的乘积成正比。 diff --git a/contents/questions/algo/longest-consecutive-number-sequence/description/en-US.langnostic.json b/contents/questions/algo/longest-consecutive-number-sequence/description/en-US.langnostic.json new file mode 100644 index 000000000..41c68727a --- /dev/null +++ b/contents/questions/algo/longest-consecutive-number-sequence/description/en-US.langnostic.json @@ -0,0 +1,35 @@ +{ + "frontmatter": { + "title": "3e49741f", + "excerpt": "39a94cca" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "601450a4", + "2d96efbe", + "d9c0d67b", + "40808d83", + "47bd6b53", + "d068a43f", + "b2065fc", + "d2ea49a6" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "601450a4", + "2d96efbe", + "d9c0d67b", + "40808d83", + "47bd6b53", + "d068a43f", + "b2065fc", + "d2ea49a6" + ] + } + } +} diff --git a/contents/questions/algo/longest-consecutive-number-sequence/description/zh-CN.mdx b/contents/questions/algo/longest-consecutive-number-sequence/description/zh-CN.mdx new file mode 100644 index 000000000..cb5a1dd95 --- /dev/null +++ b/contents/questions/algo/longest-consecutive-number-sequence/description/zh-CN.mdx @@ -0,0 +1,24 @@ +--- +title: 最长连续数字序列 +excerpt: 实现一个函数来查找最长连续数字序列的长度 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个未排序的整数数组 `numbers`,确定最长序列的长度,其中整数连续出现,这意味着数字一个接一个出现,没有任何间隙。 + +### 输入 + +- `numbers: number[]`: 整数数组 + +### 注意事项 + +- 解决方案应具有 O(n) 的时间复杂度 + + + +### 约束 + +- 0 <= `numbers.length` <= 100,000 +- -1,000,000,000 <= `numbers[i]` <= 1,000,000,000 diff --git a/contents/questions/algo/longest-consecutive-number-sequence/solution/en-US.langnostic.json b/contents/questions/algo/longest-consecutive-number-sequence/solution/en-US.langnostic.json new file mode 100644 index 000000000..d64018303 --- /dev/null +++ b/contents/questions/algo/longest-consecutive-number-sequence/solution/en-US.langnostic.json @@ -0,0 +1,64 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "dfe0b69b", + "dfacf1c9", + "72f6c3e3", + "e5b3a163", + "d4c341d8", + "b68df8f8", + "e99770cb", + "8e2de8c8", + "a1c54584", + "500ba04b", + "917d02cd", + "1e76b77b", + "b68df8f8", + "35f51ee9", + "86949149", + "8e2de8c8", + "a55bfcab", + "771b03ea", + "420f4ad6", + "b68df8f8", + "3e741aac", + "6bb4bf30", + "8e2de8c8", + "f4947747" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "dfe0b69b", + "dfacf1c9", + "72f6c3e3", + "e5b3a163", + "d4c341d8", + "b68df8f8", + "e99770cb", + "8e2de8c8", + "a1c54584", + "500ba04b", + "917d02cd", + "1e76b77b", + "b68df8f8", + "35f51ee9", + "86949149", + "8e2de8c8", + "a55bfcab", + "771b03ea", + "420f4ad6", + "b68df8f8", + "3e741aac", + "6bb4bf30", + "8e2de8c8", + "f4947747" + ] + } + } +} diff --git a/contents/questions/algo/longest-consecutive-number-sequence/solution/zh-CN.mdx b/contents/questions/algo/longest-consecutive-number-sequence/solution/zh-CN.mdx new file mode 100644 index 000000000..13d1b3001 --- /dev/null +++ b/contents/questions/algo/longest-consecutive-number-sequence/solution/zh-CN.mdx @@ -0,0 +1,84 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import longestConsecutiveNumberSequence from '../setup/src/longest-consecutive-number-sequence.ts'; +import longestConsecutiveNumberSequenceUsingSorting from '../setup/src/longest-consecutive-number-sequence-sorting.ts'; +import longestConsecutiveNumberSequenceBruteForce from '../setup/src/longest-consecutive-number-sequence-brute-force.ts'; + +## 1. 蛮力法 + +目标是找到数组中最长连续整数序列的长度。这种蛮力方法遍历每个元素,并通过重复搜索数组来检查连续的数字。 + +该逻辑首先假设当前数字是潜在序列的开始,并使用`includes`方法检查下一个连续数字是否存在。该过程持续进行,直到序列中没有更多连续数字。然后,将此序列的长度与到目前为止找到的最长序列进行比较,以更新结果。 + + + {longestConsecutiveNumberSequenceBruteForce} + + +### 算法 + +1. 检查数组是否为空。如果是,则返回`0`,因为没有数字。 +2. 初始化一个变量`longestStreak`来跟踪到目前为止找到的最长连续序列。 +3. 使用`for`循环遍历数组中的每个数字: + 1. 将`currentNum`设置为当前数字,并将`currentStreak`初始化为`1`。 + 2. 使用`while`循环检查下一个连续数字(`currentNum + 1`)是否存在于数组中: + * 如果存在,则递增`currentNum`并将`currentStreak`增加`1`。 + 3. 将`longestStreak`更新为`longestStreak`和`currentStreak`之间的最大值。 +4. 循环结束之后,返回`longestStreak`的值。 + +### Big-O 分析 + +* **时间复杂度:O(n2)**。`includes`方法执行线性搜索,这使得这种方法是二次的,因为它嵌套在循环中,循环遍历所有`n`个元素。 +* **空间复杂度:O(1)**。没有使用额外的数据结构;只分配了几个变量。 + +## 2. 使用排序 + +此解决方案通过对输入数组进行排序来改进蛮力方法,以简化查找连续数字的过程。排序将所有元素按升序排列,这使得连续数字彼此相邻出现。这消除了重复搜索序列中下一个数字的需要,从而显着减少了冗余操作。 + +该算法遍历排序后的数组,并跟踪当前连续数字序列的长度。每当序列中断时(一个数字与前一个数字不连续),将当前条纹的长度与到目前为止找到的最长条纹进行比较,并更新最大值。 + +### 算法 + +1. 检查数组是否为空。如果是,则返回`0`。 +2. 使用`sort`方法按升序对数组进行排序。 +3. 初始化两个变量:`longestStreak`为`1`,用于跟踪最长序列,`currentStreak`为`1`,用于当前连续序列长度。 +4. 从第二个元素开始遍历排序后的数组: + 1. 如果当前数字等于前一个数字,则跳过它以避免重复。 + 2. 如果当前数字正好比前一个数字大 1,则递增`currentStreak`。 + 3. 如果当前数字既不等于前一个数字,也不与前一个数字连续: + * 使用`longestStreak`和`currentStreak`之间的最大值更新`longestStreak`。 + * 将`currentStreak`重置为`1`。 +5. 循环结束后,最后一次将`longestStreak`与`currentStreak`进行比较,并返回最大值。 + + + {longestConsecutiveNumberSequenceUsingSorting} + + +### Big-O 分析 + +* **时间复杂度:O(n log n)**。对数组进行排序主导了运行时,需要 O(n log n)。随后对数组的单次遍历是 O(n),使总复杂度为 O(n log n)。 +* **空间复杂度:O(1)**。排序是就地执行的,并且仅使用几个变量来跟踪条纹。 + +## 3. 使用哈希 + +此解决方案通过使用`Set`存储输入数字来改进运行时复杂度。`Set`为查找提供了 O(1) 的平均时间复杂度,这消除了重复搜索数组的需要。该方法通过检查当前数字在集合中是否没有前一个数字(`num - 1`)来标识潜在序列的开始。一旦确定了序列的开始,它就会计算连续的数字,直到序列结束。 + +### 算法 + +1. 从输入数组创建一个`Set`,以删除重复项并允许 O(1) 查找。 +2. 将`longestStreak`初始化为`0`,以跟踪最长序列长度。 +3. 遍历`Set`中的每个数字: + 1. 通过验证`num - 1`不在`Set`中来检查当前数字是否为序列的开始。 + 2. 如果是开始,则将`currentNum`初始化为当前数字,将`currentStreak`初始化为`1`。 + 3. 使用`while`循环检查下一个数字(`currentNum + 1`)是否存在于`Set`中: + * 如果存在,则递增`currentNum`和`currentStreak`。 + 4. 将`longestStreak`更新为`longestStreak`和`currentStreak`之间的最大值。 +4. 将`longestStreak`作为最长连续序列的长度返回。 + + + {longestConsecutiveNumberSequence} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。每个数字最多处理两次:一次是检查它是否是序列的开始,另一次是在`while`循环中扩展序列。 +* **空间复杂度:O(n)**。`Set`需要与输入数组中唯一元素的数量成比例的空间。 diff --git a/contents/questions/algo/longest-increasing-subsequence/description/en-US.langnostic.json b/contents/questions/algo/longest-increasing-subsequence/description/en-US.langnostic.json new file mode 100644 index 000000000..d430f312e --- /dev/null +++ b/contents/questions/algo/longest-increasing-subsequence/description/en-US.langnostic.json @@ -0,0 +1,33 @@ +{ + "frontmatter": { + "title": "dfdf6c54", + "excerpt": "2b9a5f75" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "dce89cda", + "4c3d0f6c", + "2d96efbe", + "d9c0d67b", + "d068a43f", + "b2065fc", + "8b04f32b" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "dce89cda", + "4c3d0f6c", + "2d96efbe", + "d9c0d67b", + "d068a43f", + "b2065fc", + "8b04f32b" + ] + } + } +} diff --git a/contents/questions/algo/longest-increasing-subsequence/description/zh-CN.mdx b/contents/questions/algo/longest-increasing-subsequence/description/zh-CN.mdx new file mode 100644 index 000000000..a49fbd8a2 --- /dev/null +++ b/contents/questions/algo/longest-increasing-subsequence/description/zh-CN.mdx @@ -0,0 +1,22 @@ +--- +title: 最长递增子序列 +excerpt: 实现一个函数来查找最长递增子序列的长度 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个整数数组 `numbers`,确定最长子序列的长度,其中每个数字都严格大于它前面的数字。 + +一个**子序列**是从另一个序列中派生的序列,通过删除一些或没有元素而不改变剩余元素的顺序。例如,`[1, 2, 3]` 的子序列是 `[1]`、`[2]`、`[3]`、`[1, 2]`、`[2, 3]`、`[1, 3]` 和 `[1, 2, 3]`。 + +### 输入 + +- `numbers: number[]`: 整数数组 + + + +### 约束 + +- 1 <= `numbers.length` <= 2500 +- -10,000 <= `numbers[i]` <= 10,000 diff --git a/contents/questions/algo/longest-increasing-subsequence/solution/en-US.langnostic.json b/contents/questions/algo/longest-increasing-subsequence/solution/en-US.langnostic.json new file mode 100644 index 000000000..b39f0b387 --- /dev/null +++ b/contents/questions/algo/longest-increasing-subsequence/solution/en-US.langnostic.json @@ -0,0 +1,54 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "3a706154", + "eb582080", + "d3548822", + "3f9867f5", + "b68df8f8", + "bd2fb42c", + "4bf57a63", + "8e2de8c8", + "43ec9e6c", + "b5aaca04", + "41a17871", + "65d52a1d", + "286c119a", + "9e84736e", + "b68df8f8", + "fd77b674", + "dbe8e785", + "8e2de8c8", + "ddb50062" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "3a706154", + "eb582080", + "d3548822", + "3f9867f5", + "b68df8f8", + "bd2fb42c", + "4bf57a63", + "8e2de8c8", + "43ec9e6c", + "b5aaca04", + "41a17871", + "65d52a1d", + "286c119a", + "9e84736e", + "b68df8f8", + "fd77b674", + "dbe8e785", + "8e2de8c8", + "ddb50062" + ] + } + } +} diff --git a/contents/questions/algo/longest-increasing-subsequence/solution/zh-CN.mdx b/contents/questions/algo/longest-increasing-subsequence/solution/zh-CN.mdx new file mode 100644 index 000000000..124994567 --- /dev/null +++ b/contents/questions/algo/longest-increasing-subsequence/solution/zh-CN.mdx @@ -0,0 +1,60 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import longestIncreasingSubsequence from '../setup/src/longest-increasing-subsequence.ts'; +import longestIncreasingSubsequenceDP from '../setup/src/longest-increasing-subsequence-dp.ts'; + +## 1. 使用动态规划 + +此解决方案使用动态规划来查找数组中最长递增子序列 (LIS) 的长度。子序列可以通过删除一些或不删除任何元素而派生出来,而不会改变剩余元素的顺序。动态规划方法通过存储中间结果来消除冗余计算。 + +该算法维护一个 `dp` 数组,其中 `dp[i]` 表示以索引 `i` 结尾的 LIS 的长度。对于数组中的每个元素,该算法检查所有先前的元素,以确定当前元素是否可以扩展递增子序列。这确保了解决方案是逐步构建的,同时避免了重复计算。 + +### 算法 + +1. 初始化一个大小为 `numbers.length` 的 `dp` 数组,所有值都设置为 `1`。每个元素最初都是它自己的子序列。 +2. 从第二个元素开始遍历 `numbers` 数组: + 1. 对于索引 `i` 处的每个元素,遍历所有先前的元素(索引 `j`,其中 `j < i`)。 + 2. 如果 `numbers[i]` 大于 `numbers[j]`,则将 `dp[i]` 更新为 `dp[i]` 和 `dp[j] + 1` 的最大值,以将当前元素包含在以 `j` 结尾的子序列中。 +3. 将变量 `longest` 初始化为 `0`,并遍历 `dp` 数组以找到最大值,该值表示 LIS。 +4. 返回 `longest` 的值。 + + + {longestIncreasingSubsequenceDP} + + +### Big-O 分析 + +* **时间复杂度:O(n2)**。对于数组中的每个元素,算法都会遍历所有先前的元素,从而导致嵌套循环。 +* **空间复杂度:O(n)**。`dp` 数组所需的空间与输入数组中的元素数量成正比。 + +## 2. 使用贪心和二分查找 + +此解决方案结合了贪心和二分查找技术,以有效地计算最长递增子序列 (LIS) 的长度。核心思想是维护一个名为 `sub` 的辅助数组。此数组表示不同长度的递增子序列的最小结束值。例如,如果 `sub` 有三个元素,则表明已确定长度为 3 的递增子序列,并且其结束值存储为 `sub` 的最后一个元素。 + +`sub` 数组并不直接表示 LIS 本身,但有助于跟踪序列长度。在任何时候,`sub` 的大小都对应于到目前为止找到的 LIS 的长度。处理一个数字时: + +* 如果该数字大于 `sub` 中的最大值,则它会扩展 LIS 并附加到 `sub`。 +* 如果该数字小于或等于 `sub` 中的一个元素,则它会替换 `sub` 中大于或等于它的最小数字。此替换可确保 `sub` 保持最佳状态,以便稍后扩展 LIS。 + +为了有效地确定在 `sub` 中插入或替换的位置,使用了二分查找。这确保了算法以 O(n log n) 时间运行,因为二分查找允许快速确定位置。 + +### 算法 + +1. 定义一个辅助函数 `binarySearch`: + 1. 初始化两个指针 `left` 和 `right` 以表示 `sub` 数组中的搜索空间。 + 2. 使用循环执行二分查找,根据比较更新 `left` 或 `right` 指针。 + 3. 返回应插入或替换该数字的索引。 +2. 使用 `numbers` 的第一个元素初始化数组 `sub` 以存储当前的 LIS。 +3. 从第二个元素开始遍历 `numbers` 数组: + 1. 如果当前数字大于 `sub` 的最后一个元素,则将其附加到 `sub`。 + 2. 否则,使用 `binarySearch` 在 `sub` 中找到该数字应替换现有值的索引以维护 LIS。 +4. 将 `sub` 数组的长度作为 LIS 的长度返回。 + + + {longestIncreasingSubsequence} + + +### Big-O 分析 + +* **时间复杂度:O(n log n)**。每个数字只处理一次,并且在 `sub` 数组上进行二分查找需要 O(log n) 的时间。 +* **空间复杂度:O(n)**。在最坏的情况下,`sub` 数组所需的空间与输入数组中的元素数量成正比。 diff --git a/contents/questions/algo/longest-non-repeating-substring/description/en-US.langnostic.json b/contents/questions/algo/longest-non-repeating-substring/description/en-US.langnostic.json new file mode 100644 index 000000000..e6dd826b3 --- /dev/null +++ b/contents/questions/algo/longest-non-repeating-substring/description/en-US.langnostic.json @@ -0,0 +1,33 @@ +{ + "frontmatter": { + "title": "f8351d4f", + "excerpt": "b3f1626f" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "1c107f0d", + "6ff8539a", + "2d96efbe", + "7f86a7c3", + "d068a43f", + "b2065fc", + "55e592ba" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "1c107f0d", + "6ff8539a", + "2d96efbe", + "7f86a7c3", + "d068a43f", + "b2065fc", + "55e592ba" + ] + } + } +} diff --git a/contents/questions/algo/longest-non-repeating-substring/description/zh-CN.mdx b/contents/questions/algo/longest-non-repeating-substring/description/zh-CN.mdx new file mode 100644 index 000000000..3b0698c59 --- /dev/null +++ b/contents/questions/algo/longest-non-repeating-substring/description/zh-CN.mdx @@ -0,0 +1,22 @@ +--- +title: 最长不重复子串 +excerpt: 实现一个函数来查找具有唯一字符的最长子串的长度 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个字符串`str`,确定不包含任何重复字符的最长子串的长度。 + +一个**子串**是字符串中任意连续的字符序列。例如,字符串`abc`的子串是`a`、`b`、`c`、`ab`、`bc`和`abc`。子串是通过选择一个起始点和一个结束点,并且不跳过中间的字符而形成的。 + +### 输入 + +- `str: string`: 字符串 + + + +### 约束 + +- 0 <= `str.length` <= 10,000 +- `str` 仅包含小写英文字母 diff --git a/contents/questions/algo/longest-non-repeating-substring/solution/en-US.langnostic.json b/contents/questions/algo/longest-non-repeating-substring/solution/en-US.langnostic.json new file mode 100644 index 000000000..abea572c2 --- /dev/null +++ b/contents/questions/algo/longest-non-repeating-substring/solution/en-US.langnostic.json @@ -0,0 +1,50 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "a2382dcc", + "dfacf1c9", + "54b5d446", + "b68df8f8", + "4e648b4c", + "43dc2cad", + "8e2de8c8", + "56e8185", + "5275689b", + "de20f2b4", + "5dc45282", + "f90e53d8", + "b68df8f8", + "68ea0f94", + "dfa1bd29", + "8e2de8c8", + "72727536" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "a2382dcc", + "dfacf1c9", + "54b5d446", + "b68df8f8", + "4e648b4c", + "43dc2cad", + "8e2de8c8", + "56e8185", + "5275689b", + "de20f2b4", + "5dc45282", + "f90e53d8", + "b68df8f8", + "68ea0f94", + "dfa1bd29", + "8e2de8c8", + "72727536" + ] + } + } +} diff --git a/contents/questions/algo/longest-non-repeating-substring/solution/zh-CN.mdx b/contents/questions/algo/longest-non-repeating-substring/solution/zh-CN.mdx new file mode 100644 index 000000000..ef1f2e9f2 --- /dev/null +++ b/contents/questions/algo/longest-non-repeating-substring/solution/zh-CN.mdx @@ -0,0 +1,55 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import longestSubstringWithoutRepeatingCharacters from '../setup/src/longest-non-repeating-substring.ts'; +import longestSubstringWithoutRepeatingCharactersBruteForce from '../setup/src/longest-non-repeating-substring-bruteforce.ts'; + +## 1. 暴力解法 + +任务是找到给定字符串中最长无重复字符子串的长度。暴力解法遍历所有可能的子串,确保每个子串包含唯一的字符。通过使用 `visited` 数组来跟踪遇到的字符,该算法确保在当前子串中检测到重复项。每当找到一个更大的无重复字符子串时,结果就会更新。 + +### 算法 + +1. 初始化一个变量 `res` 来存储最长无重复字符子串的长度,并将其设置为 `0`。 +2. 遍历子串的每个可能的起始索引 `i`: + * 初始化一个大小为 `256` 的 `visited` 数组(表示所有 ASCII 字符),并将所有条目设置为 `false`。 +3. 对于每个起始索引 `i`,遍历所有可能的结束索引 `j`: + * 如果索引 `j` 处的字符已被标记为已访问,则中断内循环。 + * 否则,将当前子串长度计算为 `j - i + 1`,并使用 `res` 和当前子串长度之间的最大值来更新 `res`。 + * 将索引 `j` 处的字符标记为在 `visited` 数组中已访问。 +4. 在完成所有迭代后,返回 `res` 的值。 + + + {longestSubstringWithoutRepeatingCharactersBruteForce} + + +### Big-O 分析 + +* **时间复杂度:O(n2)**。外循环迭代 `n` 次,对于每个起始索引,内循环在最坏情况下可能迭代多达 `n` 次。 +* **空间复杂度:O(1)**。`visited` 数组的大小固定为 256,这不取决于输入大小。 + +## 2. 使用滑动窗口 + +滑动窗口不是遍历所有子串,而是根据重复字符的位置动态调整其大小。这降低了时间复杂度,从 O(n2) 降至 O(n)。 + +暴力解法需要嵌套循环来生成所有子串并检查重复项,导致效率低下。这会导致冗余检查和重复计算重叠的子串。 + +滑动窗口方法通过维护一个唯一字符的窗口来消除不必要的重新计算。`map` 用于存储每个字符的最后一次出现位置,从而可以有效地更新窗口边界。当遇到重复字符时,窗口的起始索引 (`left`) 会进行调整以排除重复项。这确保了所有子串都在线性时间内被检查。 + +### 算法 + +1. 初始化一个 `map` 来存储字符串中字符的最后一次出现位置。 +2. 初始化变量 `maxLen` 以跟踪最长子串的长度,并初始化 `left` 以表示当前窗口的起始索引。 +3. 使用 `right` 作为窗口的结束索引,遍历字符串: + * 如果当前字符存在于 `map` 中,并且其最后一次出现位置在当前窗口内,则将 `left` 更新为 `Math.max(map.get(str[right]), left)` 以排除重复项。 + * 将 `maxLen` 更新为 `Math.max(maxLen, right - left + 1)` 以存储到目前为止找到的最长子串的长度。 + * 使用当前字符的位置 `right + 1` 更新 `map`,以处理基于 0 的索引。 +4. 迭代完成后,返回 `maxLen`。 + + + {longestSubstringWithoutRepeatingCharacters} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。当移动 `right` 指针时,每个字符都会被处理一次,当调整 `left` 指针时,每个重复字符都会被处理一次。 +* **空间复杂度:O(n)**。`map` 存储字符的最后一次出现位置,这可能需要与输入字符串大小成比例的空间。 diff --git a/contents/questions/algo/longest-palindromic-substring/description/en-US.langnostic.json b/contents/questions/algo/longest-palindromic-substring/description/en-US.langnostic.json new file mode 100644 index 000000000..daef2d6fc --- /dev/null +++ b/contents/questions/algo/longest-palindromic-substring/description/en-US.langnostic.json @@ -0,0 +1,35 @@ +{ + "frontmatter": { + "title": "2a5b9fe5", + "excerpt": "f5b058ff" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "7689e847", + "d304c3e9", + "6ff8539a", + "2d96efbe", + "7f86a7c3", + "d068a43f", + "b2065fc", + "de1a3d3c" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "7689e847", + "d304c3e9", + "6ff8539a", + "2d96efbe", + "7f86a7c3", + "d068a43f", + "b2065fc", + "de1a3d3c" + ] + } + } +} diff --git a/contents/questions/algo/longest-palindromic-substring/description/zh-CN.mdx b/contents/questions/algo/longest-palindromic-substring/description/zh-CN.mdx new file mode 100644 index 000000000..5ec027509 --- /dev/null +++ b/contents/questions/algo/longest-palindromic-substring/description/zh-CN.mdx @@ -0,0 +1,24 @@ +--- +title: 查找最长回文子串 +excerpt: 实现一个函数来查找最长回文子串 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个字符串`str`,返回最长的连续回文子串。如果有多个这样的子串,则返回其中任何一个。 + +一个**回文**是指从前往后和从后往前读都一样的字符序列(例如,`racecar`)。 + +一个**子串**是字符串中任意连续的字符序列。例如,字符串`abc`的子串是`a`、`b`、`c`、`ab`、`bc`和`abc`。子串是通过选择一个起始点和一个结束点,并且不跳过中间的字符而形成的。 + +### 输入 + +- `str: string`: 字符串 + + + +### 约束 + +- 1 <= `str.length` <= 1000 +- `str` 仅包含小写英文字母 diff --git a/contents/questions/algo/longest-palindromic-substring/solution/en-US.langnostic.json b/contents/questions/algo/longest-palindromic-substring/solution/en-US.langnostic.json new file mode 100644 index 000000000..2655caa20 --- /dev/null +++ b/contents/questions/algo/longest-palindromic-substring/solution/en-US.langnostic.json @@ -0,0 +1,64 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "68599b49", + "64b44543", + "46176184", + "b68df8f8", + "5115311d", + "ceb2eab2", + "8e2de8c8", + "28f64289", + "e5dc1bc8", + "7ae16fe7", + "8416c394", + "b68df8f8", + "ad46c347", + "ff9bf187", + "8e2de8c8", + "698371ad", + "751af28e", + "e4f7f285", + "60295ba", + "b68df8f8", + "712a4f06", + "c38a7f5d", + "8e2de8c8", + "921076a2" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "68599b49", + "64b44543", + "46176184", + "b68df8f8", + "5115311d", + "ceb2eab2", + "8e2de8c8", + "28f64289", + "e5dc1bc8", + "7ae16fe7", + "8416c394", + "b68df8f8", + "ad46c347", + "ff9bf187", + "8e2de8c8", + "698371ad", + "751af28e", + "e4f7f285", + "60295ba", + "b68df8f8", + "712a4f06", + "c38a7f5d", + "8e2de8c8", + "921076a2" + ] + } + } +} diff --git a/contents/questions/algo/longest-palindromic-substring/solution/zh-CN.mdx b/contents/questions/algo/longest-palindromic-substring/solution/zh-CN.mdx new file mode 100644 index 000000000..e5998a33e --- /dev/null +++ b/contents/questions/algo/longest-palindromic-substring/solution/zh-CN.mdx @@ -0,0 +1,86 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import longestPalindromicSubstring from '../setup/src/longest-palindromic-substring.ts'; +import longestPalindromicSubstringBruteForce from '../setup/src/longest-palindromic-substring-bruteforce.ts'; +import longestPalindromicSubstringExpandCenters from '../setup/src/longest-palindromic-substring-centers.ts'; + +## 1. BruteForce + +该问题需要找到给定字符串中最长的回文子串。暴力方法系统地检查所有可能的子串,并检查每个子串是否为回文。这确保了算法正确地识别回文并返回最长的回文。 + +### Algorithm + +1. 定义一个辅助函数 `check(i, j)` 来确定从索引 `i` 到 `j-1` 的子串是否为回文: + * 初始化两个指针,`left` 在 `i`,`right` 在 `j-1`。 + * 比较 `left` 和 `right` 处的字符,同时将指针向中心移动。 + * 如果任何一对字符不匹配,则返回 `false`;否则,如果指针相遇或交叉,则返回 `true`。 +2. 按照降序遍历子串的可能长度: + * 从字符串的最大可能长度开始,将长度减少到 `1`。 + * 对于每个长度,遍历子串的所有可能的起始索引。 +3. 对于每个子串,调用辅助函数 `check` 来确定它是否为回文: + * 如果子串是回文,则立即返回它作为最长的回文。 +4. 如果未找到回文,则返回一个空字符串(这种情况不会在有效输入中发生)。 + + + {longestPalindromicSubstringBruteForce} + + +### Big-O analysis + +* **时间复杂度:O(n3)**。该算法使用两个嵌套循环检查所有子串,并且回文检查需要 O(n) 时间用于每个子串。 +* **空间复杂度:O(1)**。无论输入大小如何,该算法都使用恒定量的额外空间。 + +## 2. Using Dynamic Programming + +动态规划 (DP) 方法通过减少冗余检查来优化暴力方法。DP 方法不是重新评估重叠的子串,而是将中间结果存储在表 `dp` 中,其中 `dp[i][j]` 在子串 `s[i..j]` 是回文时为 `true`。 + +动态规划方法通过考虑递增长度的子串来迭代地构建解决方案。它首先将单个字符标记为回文,然后检查连续的字符对,最后评估长度为 3 或更长的子串。DP 表通过确保在评估更大的子串时重用较小子串的结果,从而消除了重复计算的需要。 + +### Algorithm + +1. 初始化一个大小为 `n x n` 的二维数组 `dp`,其中 `n` 是字符串的长度。将所有值设置为 `false`。 +2. 通过设置 `dp[i][i] = true`(对于所有 `i`)将所有单字符子串标记为回文。 +3. 检查双字符子串: + * 对于索引 `i` 和 `i + 1`,如果 `str[i] === str[i + 1]`,则设置 `dp[i][i + 1] = true` 并更新最长回文的索引。 +4. 迭代从 3 开始的子串的可能长度: + * 对于每个长度,迭代可能的起始索引 `i`。 + * 计算结束索引 `j = i + length - 1`。 + * 如果 `str[i] === str[j]` 且 `dp[i + 1][j - 1]` 为 `true`,则设置 `dp[i][j] = true` 并更新最长回文的索引。 +5. 使用存储在变量 `ans` 中的最长回文的索引提取子串。 +6. 返回提取的子串。 + + + {longestPalindromicSubstring} + + +### Big-O analysis + +* **时间复杂度:O(n2)**。该算法遍历字符串的所有子串,并且由于使用了 DP 表,每个子串评估都需要恒定的时间。 +* **空间复杂度:O(n2)**。DP 表需要的存储空间与字符串长度的平方成正比。 + +## 3. Expanding from Centers + +中心扩展方法是一种有效的解决方案,它避免了构造动态规划表或检查所有子串。关键思想是将每个字符(或字符对)视为潜在回文的中心,并向外扩展以找到该中心周围最大的回文。 + +此方法通过使用回文的属性来避免不必要的工作,回文围绕中心对称扩展。对于每个字符(或偶数长度回文的字符对),算法向外扩展,直到出现不匹配。这种方法减少了冗余检查,并消除了存储中间结果的需要。 + +### Algorithm + +1. 定义一个辅助函数 `expand(i, j)`: + * 初始化两个指针,`left` 在 `i`,`right` 在 `j`。 + * 当 `left` 为非负数、`right` 在范围内且 `left` 和 `right` 处的字符相等时,向外扩展指针。 + * 返回由 `left + 1` 和 `right` 组成的子串作为回文。 +2. 初始化一个变量 `ans` 以存储找到的最长回文子串。 +3. 遍历字符串中的每个字符: + * 将索引 `i` 处的字符视为奇数长度回文的中心。调用 `expand(i, i)` 并在返回的回文比 `ans` 的当前值长时更新 `ans`。 + * 将索引 `i` 和 `i + 1` 处的字符视为偶数长度回文的中心。调用 `expand(i, i + 1)` 并在返回的回文比 `ans` 的当前值长时更新 `ans`。 +4. 处理完所有字符后,返回 `ans` 的值。 + + + {longestPalindromicSubstringExpandCenters} + + +### Big-O analysis + +* **时间复杂度:O(n2)**。对于每个字符,扩展在最坏情况下可能以 O(n) 运行,从而导致总共 O(n2)。 +* **空间复杂度:O(1)**。该算法使用恒定的额外空间,不包括输出所需的空间。 diff --git a/contents/questions/algo/longest-repeating-substring-after-replacements/description/en-US.langnostic.json b/contents/questions/algo/longest-repeating-substring-after-replacements/description/en-US.langnostic.json new file mode 100644 index 000000000..9e316e87c --- /dev/null +++ b/contents/questions/algo/longest-repeating-substring-after-replacements/description/en-US.langnostic.json @@ -0,0 +1,33 @@ +{ + "frontmatter": { + "title": "597d820d", + "excerpt": "df5fc9b2" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "62796271", + "6ff8539a", + "2d96efbe", + "cbee2adc", + "d068a43f", + "b2065fc", + "5be15675" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "62796271", + "6ff8539a", + "2d96efbe", + "cbee2adc", + "d068a43f", + "b2065fc", + "5be15675" + ] + } + } +} diff --git a/contents/questions/algo/longest-repeating-substring-after-replacements/description/zh-CN.mdx b/contents/questions/algo/longest-repeating-substring-after-replacements/description/zh-CN.mdx new file mode 100644 index 000000000..a824438ab --- /dev/null +++ b/contents/questions/algo/longest-repeating-substring-after-replacements/description/zh-CN.mdx @@ -0,0 +1,23 @@ +--- +title: 替换后最长重复子串 +excerpt: 实现一个函数,在最多进行 k 次替换后,找到最长的统一子串 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个由大写英文字母组成的字符串 `str` 和一个整数 `k`,确定可以形成的最长子串的长度,其中所有字符都相同。为了实现这一点,最多可以进行 `k` 次字符替换。 + +一个**子串**是字符串中任何连续的字符序列。例如,字符串 `abc` 的子串是 `a`、`b`、`c`、`ab`、`bc` 和 `abc`。子串是通过选择一个起始点和结束点形成的,中间没有跳过字符。 + +### 输入 + +- `str: string`: 字符串 +- `k`: 一个整数 + + + +### 约束 + +- 1 <= `str.length` <= 10,000 +- `str` 仅包含大写英文字母 diff --git a/contents/questions/algo/longest-repeating-substring-after-replacements/solution/en-US.langnostic.json b/contents/questions/algo/longest-repeating-substring-after-replacements/solution/en-US.langnostic.json new file mode 100644 index 000000000..adec7165f --- /dev/null +++ b/contents/questions/algo/longest-repeating-substring-after-replacements/solution/en-US.langnostic.json @@ -0,0 +1,50 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "6bbb7cc2", + "9a62c624", + "aa29f707", + "6a6fdce5", + "b68df8f8", + "26beb7e3", + "ac9aa568", + "8e2de8c8", + "3d886a0c", + "ebf0242a", + "f4956522", + "d28aba4b", + "b68df8f8", + "1434120", + "8c0f9ec2", + "8e2de8c8", + "c03f5005" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "6bbb7cc2", + "9a62c624", + "aa29f707", + "6a6fdce5", + "b68df8f8", + "26beb7e3", + "ac9aa568", + "8e2de8c8", + "3d886a0c", + "ebf0242a", + "f4956522", + "d28aba4b", + "b68df8f8", + "1434120", + "8c0f9ec2", + "8e2de8c8", + "c03f5005" + ] + } + } +} diff --git a/contents/questions/algo/longest-repeating-substring-after-replacements/solution/zh-CN.mdx b/contents/questions/algo/longest-repeating-substring-after-replacements/solution/zh-CN.mdx new file mode 100644 index 000000000..0c1ea7672 --- /dev/null +++ b/contents/questions/algo/longest-repeating-substring-after-replacements/solution/zh-CN.mdx @@ -0,0 +1,68 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import longestRepeatingSubstringAfterReplacement from '../setup/src/longest-repeating-substring-after-replacements.ts'; +import longestRepeatingSubstringAfterReplacementBS from '../setup/src/longest-repeating-substring-after-replacements-binary-search.ts'; + +## 1. 使用滑动窗口 + +该任务是找到在给定字符串中替换最多 `k` 个字符后具有相同字符的最长子字符串的长度。 使用滑动窗口方法动态管理有效子字符串的窗口。 解决方案侧重于保持当前窗口中任何字符的最大频率与允许的替换次数 (`k`) 之间的平衡。 + +滑动窗口不是检查所有可能的子字符串,而是动态调整窗口大小以确保有效性。 频率映射跟踪当前窗口内每个字符的出现次数,`maxFrequency` 变量有助于确定使窗口中所有字符相同的所需最少替换次数。 如果替换次数超过 `k`,则通过移动 `start` 指针来调整窗口大小。 + +### 算法 + +1. 将 `start` 指针初始化为 `0`,将大小为 `26` 的频率映射 `frequencyMap`(用于所有大写英文字母)填充为 `0`,将 `maxFrequency` 初始化为跟踪当前窗口中任何字符的最高频率,并将 `longestSubstringLength` 初始化为存储找到的最长有效子字符串的长度。 +2. 使用 `end` 指针遍历字符串: + * 计算当前字符在频率映射中的相对索引。 + * 增加频率映射中当前字符的频率。 + * 将 `maxFrequency` 更新为当前窗口中观察到的最大频率。 +3. 通过检查所需替换次数 (`end + 1 - start - maxFrequency`) 是否小于或等于 `k` 来确定当前窗口是否有效。 + * 如果窗口无效,则移动 `start` 指针: + * 减少移出窗口的字符的频率。 + * 增加 `start` 指针。 +4. 使用当前有效窗口的大小 (`end + 1 - start`) 更新 `longestSubstringLength`。 +5. 返回 `longestSubstringLength` 的值。 + + + {longestRepeatingSubstringAfterReplacement} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。 `end` 指针遍历字符串一次,`start` 指针根据需要进行调整,从而产生线性时间。 +* **空间复杂度:O(1)**。 `frequencyMap` 的大小是恒定的 (`26`),与输入字符串的长度无关。 + +## 2. 使用二分查找和滑动窗口 + +该解决方案将二分查找与滑动窗口优化相结合,以有效地确定结果。 二分查找用于探索有效子字符串的可能长度。 通过检查给定长度的子字符串是否可以使用最多 `k` 次替换使其有效,可以对可能的长度范围进行对数减少。 滑动窗口技术通过维护当前窗口中字符的频率并确定所需的替换是否在允许的 `k` 范围内来验证每个长度的有效性。 + +核心思想是在确保窗口大小不超过允许的替换次数的同时,最大化窗口中任何字符的频率。 如果可以使所需长度的窗口有效,则会探索更大的长度。 否则,将检查较小的长度。 这种二分查找和滑动窗口的组合确保了解决方案的高效性和可扩展性。 + +### 算法 + +1. 初始化二分查找边界: + * 将 `low` 设置为 `1`,表示最小可能的子字符串长度。 + * 将 `high` 设置为 `str.length + 1`,表示超出输入字符串长度的无效子字符串长度。 +2. 执行二分查找: + * 计算当前范围的中点 `mid`。 + * 检查是否可以使用辅助函数 `canMakeValidSubstring` 创建长度为 `mid` 的有效子字符串。 + * 如果有效,将 `low` 移动到 `mid` 以探索更大的子字符串。 + * 否则,将 `high` 移动到 `mid` 以探索更小的子字符串。 +3. 返回 `low`,它表示最大的有效子字符串长度。 +4. 使用 `canMakeValidSubstring` 函数验证给定长度: + * 维护一个频率映射 `freqMap` 以跟踪当前窗口中的字符出现次数。 + * 使用滑动窗口遍历字符串: + * 将当前字符添加到频率映射中。 + * 如果窗口大小超过候选子字符串长度,则删除窗口开头的字符。 + * 使用当前窗口中观察到的最高频率更新 `maxFrequency`。 + * 检查当前窗口是否可以使用最多 `k` 次替换使其有效。如果有效,则返回 `true`。 + * 如果未找到给定长度的有效子字符串,则返回 `false`。 + + + {longestRepeatingSubstringAfterReplacementBS} + + +### Big-O 分析 + +* **时间复杂度:O(n log n)**。 二分查找执行 `O(log n)` 次迭代,并且每次迭代都会调用 `canMakeValidSubstring`,该函数以 O(n) 运行。 +* **空间复杂度:O(1)**。 频率映射的大小是固定的 (`26`),与输入大小无关。 diff --git a/contents/questions/algo/matrix-rotation/description/en-US.langnostic.json b/contents/questions/algo/matrix-rotation/description/en-US.langnostic.json new file mode 100644 index 000000000..cb6f4e885 --- /dev/null +++ b/contents/questions/algo/matrix-rotation/description/en-US.langnostic.json @@ -0,0 +1,31 @@ +{ + "frontmatter": { + "title": "98254c9e", + "excerpt": "99a9baef" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "1f648e9", + "2d96efbe", + "a7548267", + "d068a43f", + "b2065fc", + "7afffb1c" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "1f648e9", + "2d96efbe", + "a7548267", + "d068a43f", + "b2065fc", + "7afffb1c" + ] + } + } +} diff --git a/contents/questions/algo/matrix-rotation/description/zh-CN.mdx b/contents/questions/algo/matrix-rotation/description/zh-CN.mdx new file mode 100644 index 000000000..aee18a14f --- /dev/null +++ b/contents/questions/algo/matrix-rotation/description/zh-CN.mdx @@ -0,0 +1,22 @@ +--- +title: 矩阵旋转 +excerpt: 实现一个函数,将给定的矩阵旋转 90 度 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个 `n` x `n` 的二维数组 `matrix`,将矩阵顺时针旋转 90 度。这意味着应该直接修改输入的二维矩阵,而无需使用任何额外的二维矩阵。 + +### 输入 + +- `matrix: number[][]`: 大小为 `n` x `n` 的二维数组 `matrix` + + + +### 约束 + +- `n = matrix.length = matrix[i].length` +- 1 <= `n` <= 20 +- -1000 <= `matrix[row][col]` <= 1000 +- 使用 O(1) 额外空间 diff --git a/contents/questions/algo/matrix-rotation/solution/en-US.langnostic.json b/contents/questions/algo/matrix-rotation/solution/en-US.langnostic.json new file mode 100644 index 000000000..d5622a064 --- /dev/null +++ b/contents/questions/algo/matrix-rotation/solution/en-US.langnostic.json @@ -0,0 +1,56 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "81746b52", + "cc13fb53", + "be33d6a7", + "c49f5473", + "25749375", + "42729f0b", + "b68df8f8", + "e1199cc1", + "f6ad4490", + "8e2de8c8", + "e3eb9687", + "bca364d8", + "a753b375", + "c1c83bd3", + "f0a826fe", + "b68df8f8", + "66e15934", + "5792c7ce", + "8e2de8c8", + "43592e88" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "81746b52", + "cc13fb53", + "be33d6a7", + "c49f5473", + "25749375", + "42729f0b", + "b68df8f8", + "e1199cc1", + "f6ad4490", + "8e2de8c8", + "e3eb9687", + "bca364d8", + "a753b375", + "c1c83bd3", + "f0a826fe", + "b68df8f8", + "66e15934", + "5792c7ce", + "8e2de8c8", + "43592e88" + ] + } + } +} diff --git a/contents/questions/algo/matrix-rotation/solution/zh-CN.mdx b/contents/questions/algo/matrix-rotation/solution/zh-CN.mdx new file mode 100644 index 000000000..1fb7bfa5b --- /dev/null +++ b/contents/questions/algo/matrix-rotation/solution/zh-CN.mdx @@ -0,0 +1,72 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import matrixRotation from '../setup/src/matrix-rotation.ts'; +import matrixRotationUsingTranspose from '../setup/src/matrix-rotation-transpose.ts'; + +## 1. 旋转四组单元格 + +该任务涉及将一个正方形矩阵顺时针旋转 90 度。这意味着变换不能使用额外的内存来存储另一个矩阵。该解决方案使用分组旋转方法来移动矩阵每一层中的值。 + +直觉是,对于 90 度顺时针旋转: + +* 左上角的元素移动到右上角。 +* 右上角的元素移动到右下角。 +* 右下角的元素移动到左下角。 +* 左下角的元素移动到左上角。 + +这种变换可以通过逐层遍历矩阵来实现。每一层代表一组嵌套的正方形,从最外层开始,向中心移动。对于每一层,元素以四组为单位进行交换,有效地执行旋转,而无需额外的内存使用。 + +### 算法 + +1. 获取矩阵的大小 `n`。 +2. 逐层遍历矩阵: + * 外循环处理从外到中心的每一层。层数为 `Math.floor((n + 1) / 2)`。 + * 内循环处理层内的元素。每层中的元素数量由 `Math.floor(n / 2)` 决定。 +3. 对于当前层中的每组四个单元格: + * 临时存储左上角元素。 + * 将左下角元素移动到左上角位置。 + * 将右下角元素移动到左下角位置。 + * 将右上角元素移动到右下角位置。 + * 将存储的左上角值分配给右上角位置。 +4. 对所有层重复此过程。 + + + {matrixRotation} + + +### Big-O 分析 + +* **时间复杂度:O(n2)**。在逐层遍历期间,矩阵中的每个元素都会被访问一次。 +* **空间复杂度:O(1)**。旋转是在原地执行的,没有使用额外的内存。 + +## 2. 使用矩阵转置 + +该任务涉及将一个正方形矩阵顺时针旋转 90 度。这种变换可以通过两个步骤实现:转置矩阵,然后水平反射它。 + +1. **转置**:转置操作通过将位置 `(i, j)` 处的元素与 `(j, i)` 处的元素交换来交换行和列。此步骤将原始矩阵的行转换为结果矩阵的列。 + +2. **水平反射**:转置后,水平反射矩阵会交换每一行中的元素,将最左边的元素与最右边的元素交换。这完成了 90 度顺时针旋转。 + +这种方法有效地在原地操作矩阵,而无需为另一个矩阵分配额外的空间。 + +### 算法 + +1. 检索矩阵的大小 `n`。 +2. 执行转置操作: + * 遍历矩阵的每一行 `i`。 + * 对于每一行,遍历列 `j`,其中 `j > i` 以避免冗余交换。 + * 交换 `(i, j)` 和 `(j, i)` 处的元素。 +3. 执行水平反射: + * 遍历矩阵的每一行 `i`。 + * 对于每一行,遍历前一半的列 `j`。 + * 交换 `(i, j)` 和 `(i, n-1-j)` 处的元素。 +4. 现在矩阵顺时针旋转 90 度。 + + + {matrixRotationUsingTranspose} + + +### Big-O 分析 + +* **时间复杂度:O(n2)**。转置和反射操作都涉及访问矩阵的每个元素一次。 +* **空间复杂度:O(1)**。旋转是在原地执行的,没有使用额外的内存。 diff --git a/contents/questions/algo/matrix-spiral-traversal/description/en-US.langnostic.json b/contents/questions/algo/matrix-spiral-traversal/description/en-US.langnostic.json new file mode 100644 index 000000000..f5fb1554a --- /dev/null +++ b/contents/questions/algo/matrix-spiral-traversal/description/en-US.langnostic.json @@ -0,0 +1,31 @@ +{ + "frontmatter": { + "title": "88c7f4a0", + "excerpt": "5cdfb39c" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "c4450918", + "2d96efbe", + "240c418d", + "d068a43f", + "b2065fc", + "89e0604f" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "c4450918", + "2d96efbe", + "240c418d", + "d068a43f", + "b2065fc", + "89e0604f" + ] + } + } +} diff --git a/contents/questions/algo/matrix-spiral-traversal/description/zh-CN.mdx b/contents/questions/algo/matrix-spiral-traversal/description/zh-CN.mdx new file mode 100644 index 000000000..a5c88e0eb --- /dev/null +++ b/contents/questions/algo/matrix-spiral-traversal/description/zh-CN.mdx @@ -0,0 +1,20 @@ +--- +title: 矩阵螺旋遍历 +excerpt: 实现一个函数,以螺旋顺序遍历矩阵 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个大小为 `m` x `n` 的 `matrix`,编写一个函数以螺旋顺序返回矩阵的元素。 + +### 输入 + +- `matrix: number[][]`: 大小为 `m` x `n` 的二维数组 `matrix` + + + +### 约束 + +- 1 <= `m`, `n` <= 100 +- -1,000 <= `matrix[row][col]` <= 1,000 diff --git a/contents/questions/algo/matrix-spiral-traversal/solution/en-US.langnostic.json b/contents/questions/algo/matrix-spiral-traversal/solution/en-US.langnostic.json new file mode 100644 index 000000000..1f7f1f03d --- /dev/null +++ b/contents/questions/algo/matrix-spiral-traversal/solution/en-US.langnostic.json @@ -0,0 +1,56 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "7d97a17c", + "e12c5a58", + "e3050ae4", + "87b09529", + "a13a96df", + "6f808eb3", + "b68df8f8", + "b96e5dad", + "3638efc0", + "8e2de8c8", + "1a29ae68", + "45cb6906", + "5f179273", + "2f9ea144", + "8855f51", + "b68df8f8", + "39d0c563", + "5beee0a8", + "8e2de8c8", + "1a29ae68" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "7d97a17c", + "e12c5a58", + "e3050ae4", + "87b09529", + "a13a96df", + "6f808eb3", + "b68df8f8", + "b96e5dad", + "3638efc0", + "8e2de8c8", + "1a29ae68", + "45cb6906", + "5f179273", + "2f9ea144", + "8855f51", + "b68df8f8", + "39d0c563", + "5beee0a8", + "8e2de8c8", + "1a29ae68" + ] + } + } +} diff --git a/contents/questions/algo/matrix-spiral-traversal/solution/zh-CN.mdx b/contents/questions/algo/matrix-spiral-traversal/solution/zh-CN.mdx new file mode 100644 index 000000000..a1dd79285 --- /dev/null +++ b/contents/questions/algo/matrix-spiral-traversal/solution/zh-CN.mdx @@ -0,0 +1,82 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import matrixSpiralTraversal from '../setup/src/matrix-spiral-traversal.ts'; +import matrixSpiralTraversalUsingMarkVisited from '../setup/src/matrix-spiral-traversal-mark-visited.ts'; + +## 1. 设置边界 + +该任务要求以螺旋顺序遍历二维矩阵,从左上角开始,按顺时针方向进行。 解决方案使用边界变量来定义当前的遍历限制,并迭代地向内移动。 + +直觉是将矩阵视为层,从最外层开始并向内移动。 对于每一层: + +1. 沿上边界从左向右遍历。 +2. 沿右边界从上到下遍历。 +3. 沿下边界从右向左遍历,确保它不与上行重叠。 +4. 沿左边界从下到上遍历,确保它不与右列重叠。 + +每次遍历后,边界向内调整,该过程持续进行,直到遍历完所有元素。 + +### 算法 + +1. 初始化结果数组 `result` 以存储螺旋顺序。 +2. 定义边界: + * `up` 作为最顶行索引,从 `0` 开始。 + * `down` 作为最底行索引,从 `rows - 1` 开始。 + * `left` 作为最左列索引,从 `0` 开始。 + * `right` 作为最右列索引,从 `columns - 1` 开始。 +3. 当 `result` 的大小小于矩阵中元素的总数时: + * 沿 `up` 行从 `left` 遍历到 `right`,并将元素添加到 `result`。 + * 沿 `right` 列从 `up + 1` 遍历到 `down`,并将元素添加到 `result`。 + * 如果 `up` 不等于 `down`,则沿 `down` 行从 `right - 1` 遍历到 `left`,并将元素添加到 `result`。 + * 如果 `left` 不等于 `right`,则沿 `left` 列从 `down - 1` 遍历到 `up`,并将元素添加到 `result`。 + * 向内移动边界: + * 递增 `up` 和 `left`。 + * 递减 `down` 和 `right`。 +4. 返回 `result`。 + + + {matrixSpiralTraversal} + + +### Big-O 分析 + +* **时间复杂度:O(m.n)**。 矩阵中的每个元素只访问一次。 +* **空间复杂度:O(1)**。 忽略 `result` 数组,所需的额外空间是恒定的。 + +## 2. 标记已访问的元素 + +该任务涉及以螺旋顺序遍历二维矩阵,从左上角开始,按顺时针方向进行。 此解决方案使用标记来标识已访问的单元格,并确保遍历继续进行,直到所有元素都添加到结果中。 + +矩阵以四种可能的方向遍历:右、下、左和上。 该算法跟踪当前位置和方向。 当遇到边界或先前访问过的单元格时,方向会发生变化。 此过程一直持续到算法循环两次方向变化而未添加任何新元素,这表明所有元素都已被访问。 + +这种方法消除了通过动态检查下一个单元格的有效性来显式跟踪边界的需要。 + +### 算法 + +1. 初始化变量: + * 将 `VISITED` 定义为已访问单元格的标记。 + * 检索矩阵中的行数和列数。 + * 创建 `result` 数组,从左上角元素开始。 + * 通过为其分配 `VISITED` 值来将左上角单元格标记为已访问。 +2. 定义遍历的四个可能方向:右、下、左和上。 +3. 将 `currentDirection` 初始化为 `0`(右),将 `changeDirection` 初始化为 `0`,以跟踪连续的方向变化,而无需添加元素。 +4. 遍历矩阵: + * 当 `changeDirection` 小于 `2` 时: + * 沿当前方向移动,直到遇到边界或已访问的单元格。 + * 对于每次有效移动: + * 更新当前位置。 + * 将当前位置的元素添加到 `result` 数组。 + * 将单元格标记为已访问。 + * 将 `changeDirection` 重置为 `0`。 + * 通过将 `currentDirection` 更新为序列中的下一个值来更改方向。 + * 递增 `changeDirection`。 +5. 返回 `result` 数组。 + + + {matrixSpiralTraversalUsingMarkVisited} + + +### Big-O 分析 + +* **时间复杂度:O(m.n)**。 矩阵中的每个元素只访问一次。 +* **空间复杂度:O(1)**。 忽略 `result` 数组,所需的额外空间是恒定的。 diff --git a/contents/questions/algo/matrix-zeroing/description/en-US.langnostic.json b/contents/questions/algo/matrix-zeroing/description/en-US.langnostic.json new file mode 100644 index 000000000..08e70b018 --- /dev/null +++ b/contents/questions/algo/matrix-zeroing/description/en-US.langnostic.json @@ -0,0 +1,31 @@ +{ + "frontmatter": { + "title": "c86c2099", + "excerpt": "7b08833" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "1d230949", + "2d96efbe", + "240c418d", + "d068a43f", + "b2065fc", + "1effe889" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "1d230949", + "2d96efbe", + "240c418d", + "d068a43f", + "b2065fc", + "1effe889" + ] + } + } +} diff --git a/contents/questions/algo/matrix-zeroing/description/zh-CN.mdx b/contents/questions/algo/matrix-zeroing/description/zh-CN.mdx new file mode 100644 index 000000000..3d7a42046 --- /dev/null +++ b/contents/questions/algo/matrix-zeroing/description/zh-CN.mdx @@ -0,0 +1,21 @@ +--- +title: 矩阵置零 +excerpt: 实现一个将矩阵的行和列设置为零的函数 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个大小为 `m` x `n` 的 `matrix`,修改矩阵,使得如果一个元素是 `0`,则其整行和整列都设置为 `0`。更改应就地进行,即直接对原始矩阵进行更改。 + +### 输入 + +- `matrix: number[][]`: 大小为 `m` x `n` 的二维数组 `matrix` + + + +### 约束 + +- 1 <= `m`, `n` <= 100 +- -1000 <= `matrix[row][col]` <= 1000 +- 挑战:仅使用 O(1) 额外空间 diff --git a/contents/questions/algo/matrix-zeroing/solution/en-US.langnostic.json b/contents/questions/algo/matrix-zeroing/solution/en-US.langnostic.json new file mode 100644 index 000000000..bcf9cd85c --- /dev/null +++ b/contents/questions/algo/matrix-zeroing/solution/en-US.langnostic.json @@ -0,0 +1,58 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "1a8aba9", + "433fabd7", + "abba0b28", + "44729cd2", + "a11bd03f", + "e0397400", + "b68df8f8", + "3a053242", + "516f8a29", + "8e2de8c8", + "aed2ebd8", + "446adba1", + "b0ecd7ce", + "456f3c7b", + "ac251d7a", + "9512c10b", + "b68df8f8", + "bd5ebdc6", + "632a1a7f", + "8e2de8c8", + "cbd19797" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "1a8aba9", + "433fabd7", + "abba0b28", + "44729cd2", + "a11bd03f", + "e0397400", + "b68df8f8", + "3a053242", + "516f8a29", + "8e2de8c8", + "aed2ebd8", + "446adba1", + "b0ecd7ce", + "456f3c7b", + "ac251d7a", + "9512c10b", + "b68df8f8", + "bd5ebdc6", + "632a1a7f", + "8e2de8c8", + "cbd19797" + ] + } + } +} diff --git a/contents/questions/algo/matrix-zeroing/solution/zh-CN.mdx b/contents/questions/algo/matrix-zeroing/solution/zh-CN.mdx new file mode 100644 index 000000000..7a38c4358 --- /dev/null +++ b/contents/questions/algo/matrix-zeroing/solution/zh-CN.mdx @@ -0,0 +1,70 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import matrixZeroing from '../setup/src/matrix-zeroing.ts'; +import matrixZeroingUsingExtraSpace from '../setup/src/matrix-zeroing-extra-space.ts'; + +## 1. 使用额外空间 + +该问题需要修改矩阵,使得如果任何单元格包含 `0`,则同一行和列中的所有单元格都设置为 `0`。此解决方案使用额外的集合来跟踪需要清零的行和列。 + +该方法涉及对矩阵进行两次遍历: + +1. 在第一次遍历中,识别包含至少一个 `0` 的所有行和列,并将它们存储在单独的集合中。这避免了立即修改矩阵,这可能会干扰后续检查。 +2. 在第二次遍历中,根据存储在集合中的信息,通过将已识别的行和列中的所有单元格设置为 `0` 来更新矩阵。 + +这种识别和修改的分离确保了正确性,并避免了过早地将可能影响后续计算的元素清零。 + +### 算法 + +1. 初始化两个集合: + * `rows` 用于跟踪包含至少一个 `0` 的行索引。 + * `cols` 用于跟踪包含至少一个 `0` 的列索引。 +2. 对矩阵进行第一次遍历: + * 对于每个单元格 `(i, j)`,如果单元格包含 `0`,则将 `i` 添加到 `rows`,将 `j` 添加到 `cols`。 +3. 对矩阵进行第二次遍历: + * 对于每个单元格 `(i, j)`,检查 `i` 是否在 `rows` 中或 `j` 是否在 `cols` 中。 + * 如果任一条件为真,则将 `matrix[i][j]` 设置为 `0`。 +4. 现在,矩阵已更新,所有相关的行和列都已清零。 + + + {matrixZeroingUsingExtraSpace} + + +### Big-O 分析 + +* **时间复杂度:O(m.n)**。该算法涉及对矩阵进行两次遍历,每次访问所有 `m.n` 个元素。 +* **空间复杂度:O(m + n)**。额外的集合 `rows` 和 `cols` 最多存储 `m` 个行索引和 `n` 个列索引。 + +## 2. 空间高效的解决方案 + +该任务需要修改矩阵,使得如果任何单元格包含 `0`,则同一行和列中的所有单元格都设置为 `0`。此解决方案通过使用矩阵的第一行和第一列作为标记而不是分配额外的空间,以空间高效的方式实现了目标。 + +该方法涉及三个主要步骤: + +1. 遍历矩阵并使用第一行和第一列来标记需要清零的行和列。使用一个单独的标志来确定是否需要将第一列清零。 +2. 再次遍历矩阵,排除第一行和第一列,并根据标记更新元素。 +3. 如果需要,根据标记和单独的标志更新第一行和第一列。 + +此方法确保不需要输入矩阵之外的额外空间,使其具有空间效率。 + +### 算法 + +1. 将标志 `isCol` 初始化为 `false`,以跟踪是否需要将第一列清零。 +2. 对矩阵进行第一次遍历: + * 对于每个单元格 `(i, j)`: + * 如果单元格在第一列中并包含 `0`,则将 `isCol` 设置为 `true`。 + * 如果单元格不在第一列中并包含 `0`,则将相应的第一个行和第一个列标记设置为 `0`。 +3. 对矩阵进行第二次遍历: + * 对于每个单元格 `(i, j)`,其中 `i > 0` 且 `j > 0`: + * 如果第一行或第一列中的相应标记为 `0`,则将 `matrix[i][j]` 设置为 `0`。 +4. 如果矩阵的第一个单元格 (`matrix[0][0]`) 为 `0`,则将整个第一行设置为 `0`。 +5. 如果 `isCol` 为 `true`,则将整个第一列设置为 `0`。 + + + {matrixZeroing} + + +### Big-O 分析 + +* **时间复杂度:O(m.n)**。该算法涉及对矩阵进行两次遍历,每次访问所有 `m.n` 个元素。 +* **空间复杂度:O(1)**。除了输入矩阵和单个标志外,没有使用额外的空间。 diff --git a/contents/questions/algo/maximum-water-between-walls/description/en-US.langnostic.json b/contents/questions/algo/maximum-water-between-walls/description/en-US.langnostic.json new file mode 100644 index 000000000..92ebc9a7f --- /dev/null +++ b/contents/questions/algo/maximum-water-between-walls/description/en-US.langnostic.json @@ -0,0 +1,31 @@ +{ + "frontmatter": { + "title": "963a99a3", + "excerpt": "c5557d6b" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "a35ab9ba", + "2d96efbe", + "e78fcff3", + "d068a43f", + "b2065fc", + "e49454f4" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "a35ab9ba", + "2d96efbe", + "e78fcff3", + "d068a43f", + "b2065fc", + "e49454f4" + ] + } + } +} diff --git a/contents/questions/algo/maximum-water-between-walls/description/zh-CN.mdx b/contents/questions/algo/maximum-water-between-walls/description/zh-CN.mdx new file mode 100644 index 000000000..8e7c54f65 --- /dev/null +++ b/contents/questions/algo/maximum-water-between-walls/description/zh-CN.mdx @@ -0,0 +1,20 @@ +--- +title: 墙壁之间的最大蓄水 +excerpt: 实现一个函数,用于查找墙壁数组中两个墙壁之间的最大蓄水体积 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个墙壁高度数组`walls`,计算在倾盆大雨后,**两个墙壁**和x轴之间将捕获的最大蓄水体积。 + +### 输入 + +- `walls: number[]`: 整数数组 + + + +### 约束 + +- 2 <= `walls.length` <= 1000 +- 0 <= `walls[i]` <= 10,000 diff --git a/contents/questions/algo/maximum-water-between-walls/solution/en-US.langnostic.json b/contents/questions/algo/maximum-water-between-walls/solution/en-US.langnostic.json new file mode 100644 index 000000000..8d0caff68 --- /dev/null +++ b/contents/questions/algo/maximum-water-between-walls/solution/en-US.langnostic.json @@ -0,0 +1,50 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "2022f09e", + "4ce347d1", + "d401c4e4", + "c347e5cc", + "b68df8f8", + "3859df09", + "3b8d4594", + "8e2de8c8", + "498bf04d", + "440f169f", + "4b19c414", + "f08fb9f6", + "b68df8f8", + "95908d9a", + "ade24920", + "8e2de8c8", + "30265f1a" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "2022f09e", + "4ce347d1", + "d401c4e4", + "c347e5cc", + "b68df8f8", + "3859df09", + "3b8d4594", + "8e2de8c8", + "498bf04d", + "440f169f", + "4b19c414", + "f08fb9f6", + "b68df8f8", + "95908d9a", + "ade24920", + "8e2de8c8", + "30265f1a" + ] + } + } +} diff --git a/contents/questions/algo/maximum-water-between-walls/solution/zh-CN.mdx b/contents/questions/algo/maximum-water-between-walls/solution/zh-CN.mdx new file mode 100644 index 000000000..254528d36 --- /dev/null +++ b/contents/questions/algo/maximum-water-between-walls/solution/zh-CN.mdx @@ -0,0 +1,58 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import maximumWaterBetweenWalls from '../setup/src/maximum-water-between-walls.ts'; +import maximumWaterBetweenWallsBruteForce from '../setup/src/maximum-water-between-walls-brute-force.ts'; + +## 1. 暴力解法 + +暴力解法是找到两个墙之间可以截留的最大水量。 想法是评估输入数组中每对可能的墙,并计算它们之间可以容纳的水量。 容纳的水量由该对中较短的墙和两个墙之间的距离决定。 + +暴力解法确保考虑了所有墙对。 该算法使用嵌套循环遍历每对可能的墙,并计算每对墙的面积。 在此过程中找到的最大面积作为结果返回。 + +### 算法 + +1. 将变量 `maxArea` 初始化为 `0`,以跟踪找到的最大水域面积。 +2. 使用嵌套循环遍历所有墙对: + 1. 外循环代表左墙,从第一堵墙迭代到倒数第二堵墙。 + 2. 内循环代表右墙,从左墙之后的一堵墙迭代到最后一堵墙。 +3. 对于每对墙,计算墙之间的宽度为 `right - left`。 +4. 使用较短的墙通过调用 `Math.min(walls[left], walls[right])` 来确定容器的高度。 +5. 通过将高度和宽度相乘来计算可以容纳的水域面积。 +6. 使用当前 `maxArea` 和新计算的面积之间的较大值更新 `maxArea`。 +7. 完成嵌套循环后,返回 `maxArea` 作为结果。 + + + {maximumWaterBetweenWallsBruteForce} + + +### Big-O 分析 + +* **时间复杂度:O(n2)**。 嵌套循环遍历所有墙对,导致二次时间复杂度。 +* **空间复杂度:O(1)**。 除了用于跟踪最大面积和计算值的一些变量外,没有使用额外的空间。 + +## 2. 使用双指针 + +此解决方案使用双指针技术来优化查找两个墙之间可以截留的最大水量的过程。 想法是使用两个指针,一个从最左边的墙开始,另一个从最右边的墙开始,并计算它们之间的面积。 面积由较短的墙决定,因为它限制了高度,以及两个墙之间的宽度。 + +与暴力解法一样,不是评估每对可能的墙,双指针技术通过移动指针消除了不必要的比较。 通过始终将较短墙的指针向内移动,该算法确保宽度减小,同时尝试找到可能增加面积的较高墙。 这种方法避免了不必要或重复的工作,将时间复杂度从 O(n2) 降低到 O(n)。 + +### 算法 + +1. 将两个指针初始化,`left` 在数组的开头,`right` 在数组的结尾。 +2. 初始化一个变量 `maxWaterArea` 来存储找到的最大水域面积。 +3. 使用 `while` 循环进行迭代,只要 `left` 小于 `right`: + 1. 计算由 `left` 和 `right` 指向的墙之间的面积。 高度是两堵墙中较小的一堵,宽度是指针之间的距离 (`right - left`)。 + 2. 使用当前 `maxWaterArea` 和新计算的面积之间的较大值更新 `maxWaterArea`。 + 3. 将较短墙的指针向内移动: + * 如果 `walls[left]` 较小,则递增 `left` 以找到更高的墙。 + * 否则,递减 `right` 以在右侧找到更高的墙。 +4. 返回 `maxWaterArea` 作为找到的最大水域面积。 + + + {maximumWaterBetweenWalls} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。 每个指针最多移动 `n` 步,导致线性运行时。 +* **空间复杂度:O(1)**。 除了用于跟踪指针和面积计算的几个变量外,不需要额外的空间。 diff --git a/contents/questions/algo/merge-sort/description/en-US.langnostic.json b/contents/questions/algo/merge-sort/description/en-US.langnostic.json new file mode 100644 index 000000000..ee72464a8 --- /dev/null +++ b/contents/questions/algo/merge-sort/description/en-US.langnostic.json @@ -0,0 +1,33 @@ +{ + "frontmatter": { + "title": "5737d021", + "excerpt": "67c5db95" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c401713", + "25c60222", + "493e8bd0", + "56c73505", + "a8f76cea", + "8bf6f648", + "1b096b69", + "ea7620e3" + ] + }, + "targets": { + "zh-CN": [ + "c401713", + "25c60222", + "493e8bd0", + "56c73505", + "a8f76cea", + "8bf6f648", + "1b096b69", + "ea7620e3" + ] + } + } +} diff --git a/contents/questions/algo/merge-sort/description/zh-CN.mdx b/contents/questions/algo/merge-sort/description/zh-CN.mdx new file mode 100644 index 000000000..de3287720 --- /dev/null +++ b/contents/questions/algo/merge-sort/description/zh-CN.mdx @@ -0,0 +1,23 @@ +--- +title: 归并排序 +excerpt: 实现一个执行递归归并排序的函数 +--- + +实现一个执行递归归并排序的函数。该函数应该是递归的,并接受一个整数数组。输出应该是一个按升序排序的数组。 + +![递归归并排序的预期输入和输出](/img/questions/merge-sort/merge-sort-input-output.png) + +## 例子 + +```js +mergeSort([9, 3, 6, 2, 1, 11]); // [1, 2, 3, 6, 9, 11] +mergeSort([12, 16, 14, 1, 2, 3]); // [1, 2, 3, 12, 14, 16] +``` + +## 回顾 + +归并排序是一种递归算法,它分而治之——它不断地将输入数组分成两半,直到它不能再分(即达到数组“<= 1”个元素的基本情况——根据定义,它是有序的)。然后,算法的“合并”部分重复地将单独排序的子数组合并成更大的数组,直到整个数组被合并。 + +合并过程涉及创建一个新的空数组,并重复地从第一半或第二半中取最小的元素。当一半为空时,我们将另一半的所有元素附加到新数组中并返回它。 + +![递归归并排序说明](/img/questions/merge-sort/merge-sort-explanation.png) diff --git a/contents/questions/algo/merge-sort/solution/en-US.langnostic.json b/contents/questions/algo/merge-sort/solution/en-US.langnostic.json new file mode 100644 index 000000000..a03dee4ea --- /dev/null +++ b/contents/questions/algo/merge-sort/solution/en-US.langnostic.json @@ -0,0 +1,54 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "459c0ed", + "eccb0a22", + "4cd64b66", + "ef0e1931", + "83c89232", + "26e3ffe5", + "c93816ee", + "c1d557ec", + "499e5031", + "c5556e1", + "c998b811", + "a34a2355", + "bb1b042d", + "2d16912c", + "f98c8674", + "4260a574", + "b640de90", + "5b6426bb", + "2c2a9d2e" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "459c0ed", + "eccb0a22", + "4cd64b66", + "ef0e1931", + "83c89232", + "26e3ffe5", + "c93816ee", + "c1d557ec", + "499e5031", + "c5556e1", + "c998b811", + "a34a2355", + "bb1b042d", + "2d16912c", + "f98c8674", + "4260a574", + "b640de90", + "5b6426bb", + "2c2a9d2e" + ] + } + } +} diff --git a/contents/questions/algo/merge-sort/solution/zh-CN.mdx b/contents/questions/algo/merge-sort/solution/zh-CN.mdx new file mode 100644 index 000000000..8c5907061 --- /dev/null +++ b/contents/questions/algo/merge-sort/solution/zh-CN.mdx @@ -0,0 +1,48 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import mergeSortJs from '../setup/src/merge-sort.js'; +import mergeSortTs from '../setup/src/merge-sort.ts'; + +归并排序是一种基于比较的稳定算法,在所有情况下,其时间复杂度均为 O(nlog(n))。它通常在实践中用作对各种大小的数组进行排序的通用算法。 + +## 澄清问题 + +如果未指定: + +* 数据应该按升序还是降序排序? +* 数据应该就地排序还是可以使用其他数据结构? +* 我们需要处理什么样的输入? + * 它只是一个整数数组,还是我们应该处理其他数据类型? + * 是否存在大量重复元素? + * 应该如何处理负数? + +## 解决方案 + +注意:这个问题处理的是标准的归并排序,它是递归的,并且对于升序输出不是“就地”的。 + + + +## 边缘情况 + +* 非整数元素输入:如果输入数组包含不同数据类型的元素,您可能需要返回一个错误,尝试进行最佳排序,例如,仅对输入数据的子集进行排序,甚至为非整数定义自定义比较函数。 +* 单个元素/空输入:返回原始数据结构、引发错误或澄清所需处理。 +* 已排序的输入:您可能需要检测排序并原样返回输入。 +* 无效输入:如果输入不是数组,请考虑抛出错误。 + +## Big-O 分析 + +让我们分析一下算法的时间和空间复杂度。 + +### 时间复杂度 + +对于归并排序,最佳、平均和最坏情况下的时间复杂度均为 O(nlog(n))。这意味着排序所需的时间与数组大小和数组大小的对数的乘积成正比。 + +划分步骤的时间复杂度与由于输入数组被反复对半分而创建的二叉树的高度成正比,并且步数最多为 log(n) + 1。找到任何子数组的中间值是一个单步操作,成本为 O(1)。因此,我们预计它的时间复杂度为 O(log(n))。 + +合并步骤需要 O(n) 时间,用于由划分创建的每个子数组,因为它需要将 n 个元素组合成一个已排序的列表。 + +总的来说,归并排序的时间复杂度为 n(log(n) + 1) = O(nlog(n))。 + +### 空间复杂度 + +在空间复杂度方面,对于递归且非就地的标准归并排序,它是 O(n)。合并步骤需要创建一个新数组来存储 2 个部分的合并结果。在最后一个合并步骤中,我们希望数组与输入数组一样大。因此,空间需求是线性的。 diff --git a/contents/questions/algo/neighborhood-theft-circular/description/en-US.langnostic.json b/contents/questions/algo/neighborhood-theft-circular/description/en-US.langnostic.json new file mode 100644 index 000000000..5f72dc0e2 --- /dev/null +++ b/contents/questions/algo/neighborhood-theft-circular/description/en-US.langnostic.json @@ -0,0 +1,37 @@ +{ + "frontmatter": { + "title": "a53267", + "excerpt": "17af2d62" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "8417d7f", + "afb2272b", + "2d96efbe", + "d9c0d67b", + "40808d83", + "32b10cad", + "d068a43f", + "b2065fc", + "d6270910" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "8417d7f", + "afb2272b", + "2d96efbe", + "d9c0d67b", + "40808d83", + "32b10cad", + "d068a43f", + "b2065fc", + "d6270910" + ] + } + } +} diff --git a/contents/questions/algo/neighborhood-theft-circular/description/zh-CN.mdx b/contents/questions/algo/neighborhood-theft-circular/description/zh-CN.mdx new file mode 100644 index 000000000..880b6c466 --- /dev/null +++ b/contents/questions/algo/neighborhood-theft-circular/description/zh-CN.mdx @@ -0,0 +1,26 @@ +--- +title: 邻里盗窃(环形) +excerpt: 实现一个函数,用于在环形房屋中找到在不惊动警察的情况下抢劫的最大金额 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +一位经验丰富的窃贼正计划在一条环形街道上进行抢劫。每所房子里都装着一定数量的钱,所有房子都排成一个圆圈,这意味着第一所房子与最后一所房子相邻。此外,相邻的房屋有连接的安全系统,如果两个相邻的房屋在同一天晚上被抢劫,就会提醒警察。 + +给定一个整数数组 `numbers`,其中每个元素代表一所房子里的钱的数量,返回窃贼在不触发警报的情况下可以偷窃的最大金额。 + +### 输入 + +- `numbers: number[]`: 整数数组 + +### 注意事项 + +- 窃贼不能从相邻的两所房子里偷东西 + + + +### 约束 + +- 1 <= `numbers.length` <= 100 +- 0 <= `numbers[i]` <= 400 diff --git a/contents/questions/algo/neighborhood-theft-circular/solution/en-US.langnostic.json b/contents/questions/algo/neighborhood-theft-circular/solution/en-US.langnostic.json new file mode 100644 index 000000000..cfa04bb12 --- /dev/null +++ b/contents/questions/algo/neighborhood-theft-circular/solution/en-US.langnostic.json @@ -0,0 +1,62 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "42c86db2", + "758cfdef", + "c7f708ca", + "7cd59ffd", + "ba4c2d94", + "fb99716e", + "87a4d3c2", + "b68df8f8", + "c839a4d", + "29ddf337", + "8e2de8c8", + "1e1c19ee", + "31c3b347", + "e2d926d2", + "24522862", + "ca2b7a33", + "49a6f562", + "153c0a7b", + "b68df8f8", + "864e490b", + "e6e943c0", + "8e2de8c8", + "971b7691" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "42c86db2", + "758cfdef", + "c7f708ca", + "7cd59ffd", + "ba4c2d94", + "fb99716e", + "87a4d3c2", + "b68df8f8", + "c839a4d", + "29ddf337", + "8e2de8c8", + "1e1c19ee", + "31c3b347", + "e2d926d2", + "24522862", + "ca2b7a33", + "49a6f562", + "153c0a7b", + "b68df8f8", + "864e490b", + "e6e943c0", + "8e2de8c8", + "971b7691" + ] + } + } +} diff --git a/contents/questions/algo/neighborhood-theft-circular/solution/zh-CN.mdx b/contents/questions/algo/neighborhood-theft-circular/solution/zh-CN.mdx new file mode 100644 index 000000000..8420e345b --- /dev/null +++ b/contents/questions/algo/neighborhood-theft-circular/solution/zh-CN.mdx @@ -0,0 +1,87 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import neighborhoodTheftCircular from '../setup/src/neighborhood-theft-circular.ts'; +import neighborhoodTheftCircularTopDownApproach from '../setup/src/neighborhood-theft-circular-top-down.ts'; + +## 1. 自顶向下动态规划 + +此解决方案将邻里盗窃问题扩展到房屋的环形排列。在这种情况下,第一个和最后一个房屋是相邻的,因此它们不能同时被抢劫。该解决方案使用分治法,将循环问题分解为两个线性子问题: + +1. 排除第一个房屋并计算其余房屋的最大金额。 +2. 排除最后一个房屋并计算其余房屋的最大金额。 + +这些子问题使用自顶向下的动态规划方法和记忆化来解决。辅助函数 `robWithMemo` 通过递归地探索每个房屋的两个选项来计算可以从给定范围的房屋中抢劫的最大金额: + +* 抢劫当前房屋并跳过下一个房屋。 +* 跳过当前房屋并移至下一个房屋。 + +记忆化确保缓存中间结果,避免冗余计算并提高效率。最终结果是两个子问题的最大值,代表循环排列的最优解。 + +### 算法 + +1. 处理特殊情况: + * 如果没有房屋,则返回 `0`。 + * 如果只有一个房屋,则返回其值。 +2. 定义一个辅助函数 `robWithMemo` 来计算可以从给定范围的房屋中抢劫的最大金额: + 1. 初始化一个 `memo` 数组来存储中间结果,用 `-1` 填充以指示未计算的值。 + 2. 定义一个递归函数 `dp(i)`: + * 如果 `i` 超过范围的末尾,则返回 `0`,因为没有房屋可以抢劫。 + * 如果已计算,则返回 `memo[i]` 中的缓存值。 + * 通过选择以下选项来计算当前房屋的最大金额: + * 抢劫当前房屋并添加跳过下一个房屋的结果 (`numbers[i] + dp(i + 2)`)。 + * 跳过当前房屋并移至下一个房屋 (`dp(i + 1)`)。 + * 将结果缓存在 `memo[i]` 中并返回。 + 3. 从给定范围的起始索引开始递归,并返回结果。 +3. 计算两个子问题: + * 排除第一个房屋的最大金额 (`robWithMemo(numbers, 1, numbers.length - 1)`)。 + * 排除最后一个房屋的最大金额 (`robWithMemo(numbers, 0, numbers.length - 2)`)。 +4. 返回两个结果的最大值。 + + + {neighborhoodTheftCircularTopDownApproach} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。每个子问题在其范围内处理所有房屋一次,从而产生线性时间复杂度。 +* **空间复杂度:O(n)**。记忆化数组需要与范围内的房屋数量成比例的空间。 + +## 2. 自底向上动态规划 + +循环邻里盗窃问题需要处理第一个和最后一个房屋是邻居的附加约束。当同时考虑抢劫这两个房屋时,这会产生冲突,因为同时抢劫它们会违反问题的约束。为了解决这个问题,将问题分为两个独立的场景: + +1. 从第二个房屋抢劫到最后一个房屋,不包括第一个房屋。 +2. 从第一个房屋抢劫到倒数第二个房屋,不包括最后一个房屋。 + +通过独立地解决这两个线性子问题,可以有效地处理循环约束。然后比较这两种情况的结果,以确定可以抢劫的最大金额。 + +这些子问题中的每一个都使用空间优化的动态规划方法来解决。不是维护一个完整的 `dp` 数组来存储所有房屋的最大金额,而是使用两个变量来跟踪当前房屋和前一个房屋的结果。这降低了空间复杂度,同时确保有效地计算每个子问题的最优解。 + +核心思想是使用一个观察结果,即在线性房屋排列中,抢劫或跳过每个房屋的决定仅取决于可以从前两个房屋抢劫的最大金额。这里采用了这一原则,通过解决两个单独的线性情况并结合它们的结果来处理循环排列。 + +### 算法 + +1. 检查 `numbers` 数组是否为空。如果是,则返回 `0`,因为没有房屋可以抢劫。 +2. 检查 `numbers` 数组是否只有一个房屋。如果是,则返回该房屋的值。 +3. 解决两个线性子问题: + * 使用从索引 `0` 到 `n - 2`(不包括最后一个房屋)的范围调用 `robSimple`。 + * 使用从索引 `1` 到 `n - 1`(不包括第一个房屋)的范围调用 `robSimple`。 +4. 返回两个结果的最大值。 +5. 定义辅助函数 `robSimple` 来解决线性抢劫问题: + 1. 将两个变量 `t1` 和 `t2` 初始化为 `0`。这些变量表示可以抢劫到当前房屋和前一个房屋的最大金额。 + 2. 遍历从 `start` 到 `end` 的房屋范围: + * 将当前房屋可以抢劫的最大金额计算为以下各项的最大值: + * 抢劫当前房屋并添加 `t2`(表示抢劫到两个房屋之前的最大金额)。 + * 跳过当前房屋并使用 `t1`(表示抢劫到前一个房屋的最大金额)。 + * 将 `t2` 更新为 `t1` 的值。 + * 将 `t1` 更新为计算出的最大值。 + 3. 循环结束后,返回 `t1`,其中包含在该范围内可以抢劫的最大金额。 + + + {neighborhoodTheftCircular} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。在辅助函数的两次线性迭代中,每个房屋只处理一次。 +* **空间复杂度:O(1)**。仅使用两个变量 `t1` 和 `t2` 来跟踪中间结果。 diff --git a/contents/questions/algo/neighborhood-theft/description/en-US.langnostic.json b/contents/questions/algo/neighborhood-theft/description/en-US.langnostic.json new file mode 100644 index 000000000..e12630ed0 --- /dev/null +++ b/contents/questions/algo/neighborhood-theft/description/en-US.langnostic.json @@ -0,0 +1,37 @@ +{ + "frontmatter": { + "title": "3555baf6", + "excerpt": "46dc3ed6" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "47aeea21", + "32f60341", + "2d96efbe", + "d9c0d67b", + "40808d83", + "32b10cad", + "d068a43f", + "b2065fc", + "d6270910" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "47aeea21", + "32f60341", + "2d96efbe", + "d9c0d67b", + "40808d83", + "32b10cad", + "d068a43f", + "b2065fc", + "d6270910" + ] + } + } +} diff --git a/contents/questions/algo/neighborhood-theft/description/zh-CN.mdx b/contents/questions/algo/neighborhood-theft/description/zh-CN.mdx new file mode 100644 index 000000000..801c39460 --- /dev/null +++ b/contents/questions/algo/neighborhood-theft/description/zh-CN.mdx @@ -0,0 +1,26 @@ +--- +title: 邻里盗窃 +excerpt: 实现一个函数,找到在不惊动警察的情况下抢劫的最大金额 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +一位经验丰富的窃贼的目标是偷取街道上房屋里的钱。每所房子都藏有一定数量的钱,但有一个问题:相邻房屋中的安全系统是相互连接的。如果窃贼闯入两栋相邻的房屋,警察就会被惊动。 + +给定一个整数数组 `numbers`,其中每个元素代表一所房子里的钱的数量,确定窃贼在不触发警报的情况下可以偷取的最大金额。 + +### 输入 + +- `numbers: number[]`: 一个整数数组 + +### 注意事项 + +- 窃贼不能从两栋相邻的房屋中偷窃 + + + +### 约束 + +- 1 <= `numbers.length` <= 100 +- 0 <= `numbers[i]` <= 400 diff --git a/contents/questions/algo/neighborhood-theft/solution/en-US.langnostic.json b/contents/questions/algo/neighborhood-theft/solution/en-US.langnostic.json new file mode 100644 index 000000000..41cf2d793 --- /dev/null +++ b/contents/questions/algo/neighborhood-theft/solution/en-US.langnostic.json @@ -0,0 +1,76 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "5f90aef7", + "758cfdef", + "75018e49", + "637f43cc", + "76b12bb8", + "74b5da8d", + "b68df8f8", + "f4c80ba4", + "4e315035", + "8e2de8c8", + "7332d204", + "31c3b347", + "4132c4cd", + "d16435f7", + "c83a673e", + "ad61246d", + "b68df8f8", + "a34a74d1", + "e7a86234", + "8e2de8c8", + "fcad0104", + "800cc78d", + "246c6f3f", + "9accc9a2", + "42271bc3", + "b68df8f8", + "b80e0f00", + "8a6a0d71", + "8e2de8c8", + "c2e03c86" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "5f90aef7", + "758cfdef", + "75018e49", + "637f43cc", + "76b12bb8", + "74b5da8d", + "b68df8f8", + "f4c80ba4", + "4e315035", + "8e2de8c8", + "7332d204", + "31c3b347", + "4132c4cd", + "d16435f7", + "c83a673e", + "ad61246d", + "b68df8f8", + "a34a74d1", + "e7a86234", + "8e2de8c8", + "fcad0104", + "800cc78d", + "246c6f3f", + "9accc9a2", + "42271bc3", + "b68df8f8", + "b80e0f00", + "8a6a0d71", + "8e2de8c8", + "c2e03c86" + ] + } + } +} diff --git a/contents/questions/algo/neighborhood-theft/solution/zh-CN.mdx b/contents/questions/algo/neighborhood-theft/solution/zh-CN.mdx new file mode 100644 index 000000000..f6c4198cb --- /dev/null +++ b/contents/questions/algo/neighborhood-theft/solution/zh-CN.mdx @@ -0,0 +1,104 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import neighborhoodTheft from '../setup/src/neighborhood-theft.ts'; +import neighborhoodTheftTopDownApproach from '../setup/src/neighborhood-theft-top-down.ts'; +import neighborhoodTheftBottomUpSpaceOptimized from '../setup/src/neighborhood-theft-bottom-up-space-optimized.ts'; + +## 1. 自顶向下动态规划 + +此解决方案使用自顶向下的动态规划方法和记忆化来解决“邻居盗窃”问题。该问题涉及在确保不抢劫相邻房屋的情况下,最大化从房屋中偷走的金额。 + +该算法从第一所房子开始,并递归地探索两个选项: + +1. 跳过当前房屋并移至下一所房屋。 +2. 抢劫当前房屋并移至下一所房屋之后的房屋。 + +记忆化用于存储已计算的子问题的结果。这避免了冗余计算,并显着降低了运行时复杂度。通过缓存每个房屋的结果,该解决方案仅计算每个子问题一次,与纯递归方法相比,优化了性能。 + +### 算法 + +1. 初始化一个大小与输入数组相同的 `memo` 数组,并用 `-1` 填充,以指示未计算的值。 +2. 定义一个辅助函数 `robFrom`,该函数递归地计算从第 `i` 个房屋开始可以抢劫的最大金额。 + 1. 检查基本情况,其中 `i` 超过数组的边界,返回 `0`,因为没有房屋可以抢劫。 + 2. 如果房屋 `i` 的结果已计算并存储在 `memo[i]` 中,则返回缓存值。 + 3. 计算以下两者之间的最大值: + * 跳过当前房屋,调用 `robFrom(i + 1, numbers)`。 + * 抢劫当前房屋,并将其值添加到 `robFrom(i + 2, numbers)` 的结果中。 + 4. 将计算结果存储在 `memo[i]` 中以备将来使用。 +3. 通过调用 `robFrom(0, numbers)` 来处理所有房屋,开始计算。 +4. 返回计算结果,该结果表示在不触发警报的情况下可以抢劫的最大金额。 + + + {neighborhoodTheftTopDownApproach} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。每个房屋最多处理一次,结果存储在 `memo` 数组中,避免了冗余的递归调用。 +* **空间复杂度:O(n)**。`memo` 数组所需的空间与房屋数量成正比,并且递归堆栈在最坏的情况下可能达到 `n` 的深度。 + +## 2. 自底向上动态规划 + +这种方法通过迭代地从最后一个房屋到第一个房屋构建 `dp` 表(或数组)来消除递归,确保所有子问题都按顺序解决。 + +`dp` 数组 `maxRobbedAmount` 存储了可以抢劫的最大金额,考虑从当前索引到最后一个房屋的房屋。对于每个房屋,考虑两个选项: + +1. 跳过当前房屋并获取为下一所房屋存储的结果 (`maxRobbedAmount[i + 1]`)。 +2. 抢劫当前房屋并将其值添加到为跳过下一所房屋存储的结果 (`maxRobbedAmount[i + 2] + numbers[i]`)。 + +每个房屋的决策是通过选择提供最大金额的选项来做出的。这避免了冗余计算,并确保了有效的解决方案。 + +### 算法 + +1. 处理输入数组为空的基本情况。如果没有房屋,则返回 `0`。 +2. 初始化大小为 `N + 1` 的 `dp` 数组 `maxRobbedAmount`,并用 `0` 填充。此数组将存储从每个房屋开始可以抢劫的最大金额。 +3. 设置最后两所房屋的基本情况: + * `maxRobbedAmount[N]` 为 `0`,表示没有房屋可以抢劫。 + * `maxRobbedAmount[N - 1]` 设置为最后一个房屋的值 (`numbers[N - 1]`),因为对于最后一个房屋没有其他选项。 +4. 从倒数第二个房屋 (`N - 2`) 向后迭代到第一个房屋 (`0`): + * 对于每个房屋 `i`,通过在以下两者之间进行选择来计算可以抢劫的最大金额: + 1. 跳过当前房屋:`maxRobbedAmount[i + 1]`。 + 2. 抢劫当前房屋并跳过下一所房屋:`maxRobbedAmount[i + 2] + numbers[i]`。 + * 将最大值存储在 `maxRobbedAmount[i]` 中。 +5. 返回 `maxRobbedAmount[0]`,它表示从第一个房屋开始可以抢劫的最大金额。 + + + {neighborhoodTheft} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。该算法在向后迭代中恰好处理每个房屋一次。 +* **空间复杂度:O(n)**。`dp` 数组 `maxRobbedAmount` 所需的空间与房屋数量成正比。 + +## 3. 自底向上动态规划,优化空间 + +此解决方案基于前一个问题中使用的自底向上动态规划方法,但将空间复杂度从 O(n) 优化到 O(1)。在之前的解决方案中,使用 `dp` 数组来存储从每个房屋开始可以抢劫的最大金额,这需要额外的空间,与房屋数量成正比。但是,在任何给定时间,只需要该数组的最后两个值来计算当前结果。 + +为了消除不必要的存储,此解决方案用两个变量 `prev1` 和 `prev2` 替换了 `dp` 数组,这两个变量存储了下一个房屋(`i + 1`)和之后房屋(`i + 2`)的最大金额。这确保了算法仍然计算相同的结果,但大大减少了空间使用。 + +该算法向后遍历数组,在每一步更新这两个变量。使用两个变量而不是整个数组消除了空间开销,同时保留了先前方法的时间效率。当处理大量房屋时,这种改进尤其有益。 + +### 算法 + +1. 处理特殊情况: + 1. 如果没有房屋,则返回 `0`。 + 2. 如果只有一个房屋,则返回其值,因为不存在其他选项。 +2. 初始化两个变量: + * `prev1` 为 `0`,表示从下一个房屋(`i + 1`)开始可以抢劫的最大金额。 + * `prev2` 为 `0`,表示从下一个房屋(`i + 2`)之后的房屋开始可以抢劫的最大金额。 +3. 向后遍历房屋: + 1. 计算可以从当前房屋抢劫的最大金额,即以下两者的最大值: + * 跳过当前房屋(`prev1`)。 + * 抢劫当前房屋并加上 `prev2` 的值。 + 2. 将 `prev2` 更新为 `prev1` 的当前值,并将 `prev1` 更新为新计算的最大值。 +4. 循环结束后,`prev1` 包含从第一个房屋开始可以抢劫的最大金额。返回此值。 + + + {neighborhoodTheftBottomUpSpaceOptimized} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。每个房屋在向后迭代中只处理一次。 +* **空间复杂度:O(1)**。仅使用两个变量来跟踪中间结果,无需额外的数组。 diff --git a/contents/questions/algo/number-stream-median/description/en-US.langnostic.json b/contents/questions/algo/number-stream-median/description/en-US.langnostic.json new file mode 100644 index 000000000..562ca6440 --- /dev/null +++ b/contents/questions/algo/number-stream-median/description/en-US.langnostic.json @@ -0,0 +1,43 @@ +{ + "frontmatter": { + "title": "1a865816", + "excerpt": "6f702ab7" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "ca485f6c", + "a2cf7bc1", + "2e9af128", + "d12cf7de", + "39f9415a", + "2d96efbe", + "9b1c4ed2", + "6909b30b", + "a46e2dce", + "d068a43f", + "b2065fc", + "f78d2710" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "ca485f6c", + "a2cf7bc1", + "2e9af128", + "d12cf7de", + "39f9415a", + "2d96efbe", + "9b1c4ed2", + "6909b30b", + "a46e2dce", + "d068a43f", + "b2065fc", + "f78d2710" + ] + } + } +} diff --git a/contents/questions/algo/number-stream-median/description/zh-CN.mdx b/contents/questions/algo/number-stream-median/description/zh-CN.mdx new file mode 100644 index 000000000..54b74d2d4 --- /dev/null +++ b/contents/questions/algo/number-stream-median/description/zh-CN.mdx @@ -0,0 +1,36 @@ +--- +title: 数字流的中位数 +excerpt: 实现一个函数来查找动态整数流的中位数 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +一组数字的中位数定义为排序列表中间的那个值。当列表有偶数个元素时,中位数是中间两个值的平均值。 + +例如: + +- 对于列表 `[1, 2, 3]`,中位数是 2 +- 对于列表 `[1, 2]`,中位数是 (1 + 2) / 2 = 1.5 + +实现一个具有以下方法的 `NumberStream` 类: + +- `add(num: number): void`: 将一个整数 num 添加到数据结构中 +- `getMedian(): number`: 返回到目前为止添加的所有数字的中位数 + +### 输入 + +`NumberStream` 实例将根据以下内容调用其方法,并使用各种参数: + +- `methods: string[]`: `NumberStream` 方法名称的数组 +- `params: (number | null)[]`: 整数数组 + +`methods[i]` 将使用 `params[i]` 调用。 + + + +### 约束 + +- 1 <= `num` <= 100,000 +- 1 <= `methods.length` <= 1000 +- 在调用 `getMedian()` 之前,数据结构中将至少有一个元素 diff --git a/contents/questions/algo/number-stream-median/solution/en-US.langnostic.json b/contents/questions/algo/number-stream-median/solution/en-US.langnostic.json new file mode 100644 index 000000000..b3af26ad7 --- /dev/null +++ b/contents/questions/algo/number-stream-median/solution/en-US.langnostic.json @@ -0,0 +1,66 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "5ce55c02", + "c09911b7", + "b853c4d4", + "d3816db5", + "cae0c965", + "4f356f5", + "f08cc7a4", + "b68df8f8", + "5012f940", + "16d35ff2", + "8e2de8c8", + "37912af5", + "16aaad96", + "cbb3c5ad", + "b02ffacd", + "1b3c9c26", + "3649d32d", + "c1e33c5f", + "f23fe926", + "c536abba", + "b68df8f8", + "d68e53c8", + "bc151028", + "8e2de8c8", + "f932be58" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "5ce55c02", + "c09911b7", + "b853c4d4", + "d3816db5", + "cae0c965", + "4f356f5", + "f08cc7a4", + "b68df8f8", + "5012f940", + "16d35ff2", + "8e2de8c8", + "37912af5", + "16aaad96", + "cbb3c5ad", + "b02ffacd", + "1b3c9c26", + "3649d32d", + "c1e33c5f", + "f23fe926", + "c536abba", + "b68df8f8", + "d68e53c8", + "bc151028", + "8e2de8c8", + "f932be58" + ] + } + } +} diff --git a/contents/questions/algo/number-stream-median/solution/zh-CN.mdx b/contents/questions/algo/number-stream-median/solution/zh-CN.mdx new file mode 100644 index 000000000..fe6c2eb47 --- /dev/null +++ b/contents/questions/algo/number-stream-median/solution/zh-CN.mdx @@ -0,0 +1,82 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import getMedianFromDataStream from '../setup/src/number-stream-median.ts'; +import getMedianFromDataStreamBruteForce from '../setup/src/number-stream-median-brute-force.ts'; + +## 1. 使用排序的暴力方法 + +此问题的目标是动态地计算数字流的中位数。暴力方法维护一个到目前为止收到的所有数字的列表,并在每次请求中位数时对列表进行排序后计算中位数。 + +中位数定义为: + +* 如果数字总数为奇数,则为中间元素。 +* 如果数字总数为偶数,则为两个中间元素的平均值。 + +此方法通过以下方式工作: + +1. 将所有传入的数字存储在一个数组中。 +2. 每次调用 `getMedian` 方法时对数组进行排序,以确保数字按升序排列。 +3. 根据排序后的数组计算中位数。 + +### 算法 + +1. 创建一个 `NumberStream` 类,其中包含一个私有数组 `store`,用于保存所有传入的数字。 +2. 定义一个 `add` 方法,用于将数字追加到 `store` 数组中。 +3. 定义一个 `getMedian` 方法来计算中位数: + 1. 按升序对 `store` 数组进行排序。 + 2. 确定数组的大小 (`n`)。 + 3. 如果 `n` 为奇数,则返回中间元素。 + 4. 如果 `n` 为偶数,则计算两个中间元素的平均值并返回结果。 + + + {getMedianFromDataStreamBruteForce} + + +### Big-O 分析 + +* **时间复杂度:O(n log n)**。对数组进行排序主导了 `getMedian` 方法的运行时。将数字添加到 `store` 数组需要 O(1) 的时间。 +* **空间复杂度:O(n)**。`store` 数组随流中元素的数量线性增长。 + +## 2. 使用两个堆 + +此解决方案通过使用两个堆来优化在动态数据流中查找中位数的过程:一个最大堆和一个最小堆。核心思想是维护两个平衡的堆: + +1. 一个最大堆 (`maxHeap`),包含较小的一半数字。 +2. 一个最小堆 (`minHeap`),包含较大的一半数字。 + +堆的结构使得最大堆的顶部表示较小一半中的最大数字,最小堆的顶部表示较大一半中的最小数字。这种结构允许高效地检索中位数: + +* 如果堆的大小是平衡的,则中位数是两个堆的顶部的平均值。 +* 如果最大堆比最小堆多一个元素,则中位数是最大堆的顶部。 + +该方法确保堆在每次插入后保持平衡: + +1. 首先将一个新数字添加到最大堆中。 +2. 将最大堆中的最大数字移动到最小堆中以保持顺序。 +3. 如果最小堆增长到大于最大堆,则将最小堆中的最小数字移回最大堆。 + +通过使用堆属性,该解决方案避免了暴力方法中的 O(n log n) 排序步骤,实现了插入和中位数计算的 O(log n) 时间复杂度。 + +### 算法 + +1. 初始化两个堆: + * `maxHeap` 用于较小的一半数字。 + * `minHeap` 用于较大的一半数字。 +2. 定义一个 `add` 方法,用于将新数字插入数据流: + 1. 将数字添加到 `maxHeap`。 + 2. 将 `maxHeap` 中最大的数字移动到 `minHeap` 以保持顺序。 + 3. 如果 `minHeap` 增长大于 `maxHeap`,则将 `minHeap` 中最小的数字移回 `maxHeap`。 +3. 定义一个 `getMedian` 方法来计算中位数: + 1. 如果 `maxHeap` 的元素多于 `minHeap`,则返回 `maxHeap` 的顶部元素。 + 2. 否则,返回两个堆顶部的平均值。 +4. 使用堆操作的实用函数: + * `addNumberToHeap` 用于在保持堆属性的同时插入数字。 + * `removeTopFromHeap` 用于在恢复堆属性的同时删除顶部元素。 + * `heapify` 用于确保从给定索引向下的堆属性。 + +{getMedianFromDataStream} + +### Big-O 分析 + +* **时间复杂度:O(n log n)**。每次插入都涉及 O(log n) 的时间复杂度来维护堆属性。 +* **空间复杂度:O(n)**。堆一起存储数据流中的所有元素。 diff --git a/contents/questions/algo/ocean-flow/description/en-US.langnostic.json b/contents/questions/algo/ocean-flow/description/en-US.langnostic.json new file mode 100644 index 000000000..20aa727c3 --- /dev/null +++ b/contents/questions/algo/ocean-flow/description/en-US.langnostic.json @@ -0,0 +1,37 @@ +{ + "frontmatter": { + "title": "ccd9c6f8", + "excerpt": "ab2b5054" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "8eb30e64", + "a1fbd703", + "2c73b023", + "2d96efbe", + "d447ef14", + "40808d83", + "d068a43f", + "b2065fc", + "2428b93" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "8eb30e64", + "a1fbd703", + "2c73b023", + "2d96efbe", + "d447ef14", + "40808d83", + "d068a43f", + "b2065fc", + "2428b93" + ] + } + } +} diff --git a/contents/questions/algo/ocean-flow/description/zh-CN.mdx b/contents/questions/algo/ocean-flow/description/zh-CN.mdx new file mode 100644 index 000000000..f9821643e --- /dev/null +++ b/contents/questions/algo/ocean-flow/description/zh-CN.mdx @@ -0,0 +1,26 @@ +--- +title: 海洋流动 +excerpt: 实现一个函数,返回可以流向两个大洋的单元格 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个 `m` x `n` 的二维 `matrix`,表示由两个不同大洋(一个在左侧和顶部边缘,另一个在右侧和底部边缘)接壤的岛屿,确定哪些单元格可以使雨水流向两个大洋。每个单元格包含一个整数,表示其高于海平面的高度。 + +如果相邻单元格的高度小于或等于当前单元格的高度,则水可以从一个单元格流向另一个单元格。相邻单元格是指一个单元格的正北、正南、正西和正东方向的单元格。 + +返回一个列表,其中包含所有可以流向两个大洋的单元格,并按其在从左上角到右下角遍历矩阵时的位置排序 + +### 输入 + +- `matrix: number[][]`: 一个二维整数数组 + +### 注意事项 + + + +### 约束 + +- 1 <= `m`, `n` <= 100 +- 0 <= `matrix[row][col]` <= 100,000 diff --git a/contents/questions/algo/ocean-flow/solution/en-US.langnostic.json b/contents/questions/algo/ocean-flow/solution/en-US.langnostic.json new file mode 100644 index 000000000..4eddbf2a2 --- /dev/null +++ b/contents/questions/algo/ocean-flow/solution/en-US.langnostic.json @@ -0,0 +1,58 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "495a525d", + "d2f84373", + "4c50738d", + "e89a9472", + "7575de3f", + "d8467fc2", + "b68df8f8", + "ba6d8de9", + "511c40bc", + "8e2de8c8", + "29fff002", + "182071da", + "fb3e9c3b", + "14ba8e80", + "3e0082b3", + "7a722fde", + "b68df8f8", + "5fd49e6c", + "fb006202", + "8e2de8c8", + "2740f6f4" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "495a525d", + "d2f84373", + "4c50738d", + "e89a9472", + "7575de3f", + "d8467fc2", + "b68df8f8", + "ba6d8de9", + "511c40bc", + "8e2de8c8", + "29fff002", + "182071da", + "fb3e9c3b", + "14ba8e80", + "3e0082b3", + "7a722fde", + "b68df8f8", + "5fd49e6c", + "fb006202", + "8e2de8c8", + "2740f6f4" + ] + } + } +} diff --git a/contents/questions/algo/ocean-flow/solution/zh-CN.mdx b/contents/questions/algo/ocean-flow/solution/zh-CN.mdx new file mode 100644 index 000000000..0c94aa47f --- /dev/null +++ b/contents/questions/algo/ocean-flow/solution/zh-CN.mdx @@ -0,0 +1,83 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import oceanFlow from '../setup/src/ocean-flow.ts'; +import oceanFlowUsingBFS from '../setup/src/ocean-flow-bfs.ts'; + +## 1. 使用深度优先搜索 + +该问题涉及在矩阵中找到水可以流到太平洋(顶部和左侧边缘)和大西洋(底部和右侧边缘)的单元格。 解决方案使用深度优先搜索 (DFS) 来探索从每个海洋的边界开始的可到达单元格。 + +这种方法的直觉是将问题视为一个连通性图: + +* 如果水可以流到该海洋,则一个单元格“连接”到该海洋。 +* 如果一个单元格流向的所有相邻单元格的高度大于或等于其自身,则认为该单元格是可到达的。 + +该算法使用两个布尔矩阵来跟踪太平洋和大西洋的可达性。 从各自的海洋边界开始 DFS 可确保仅探索有效路径。 处理后,两个可达性矩阵的交集给出了所需的单元格。 + +### 算法 + +1. 定义 `DIRECTIONS` 数组以表示四种可能的移动(上、下、左、右)。 +2. 初始化两个二维布尔矩阵:`oceanTopLeftReachable` 和 `oceanBottomRightReachable`,以分别标记从太平洋和大西洋可到达的单元格。 +3. 定义 `dfs` 函数: + * 将当前单元格标记为在给定的布尔矩阵中可到达。 + * 探索所有有效的相邻单元格: + * 在范围内。 + * 尚未访问。 + * 高度大于或等于当前单元格。 +4. 从太平洋的边界开始 DFS: + * 遍历矩阵的顶行和左列。 +5. 从大西洋的边界开始 DFS: + * 遍历矩阵的底行和右列。 +6. 遍历矩阵中的所有单元格: + * 如果一个单元格在 `oceanTopLeftReachable` 和 `oceanBottomRightReachable` 中都被标记为可到达,则将其添加到结果中。 +7. 返回可以流到两个海洋的单元格列表。 + + + {oceanFlow} + + +### Big-O 分析 + +* **时间复杂度:O(m.n)**。 在 DFS 期间,每个单元格最多访问一次,并且矩阵有 `m.n` 个单元格。 +* **空间复杂度:O(m.n)**。 使用两个大小为 `m.n` 的布尔矩阵来跟踪可达性,并且 DFS 的调用堆栈在最坏的情况下可以达到 `m.n`。 + +## 2. 使用广度优先搜索 + +该问题涉及识别矩阵中水可以流到太平洋(顶部和左侧边缘)和大西洋(底部和右侧边缘)的单元格。 使用广度优先搜索 (BFS) 可确保在探索所有有效单元格时满足流量约束。 每个单元格的高度必须大于或等于其相邻单元格,水才能反向流动。 + +此解决方案使用两个 BFS 遍历: + +* 一个从太平洋的边界开始。 +* 另一个从大西洋的边界开始。 + +从两个 BFS 遍历都可到达的单元格是所需的结果。 + +### 算法 + +1. 定义 `DIRECTIONS` 数组以表示四种可能的移动(上、下、左、右)。 +2. 实现 `bfs` 函数: + * 初始化一个 `reachable` 布尔矩阵来跟踪遍历期间可访问的单元格。 + * 使用队列迭代处理单元格。 + * 对于每个单元格: + * 将其标记为可到达。 + * 将所有有效的相邻单元格排队: + * 确保邻居在范围内。 + * 确保邻居尚未被访问。 + * 确保邻居的高度大于或等于当前单元格。 + * 返回 `reachable` 矩阵。 +3. 为 BFS 准备队列: + * 太平洋队列从顶行和左列开始。 + * 大西洋队列从底行和右列开始。 +4. 使用 `bfs` 函数对两个海洋执行 BFS。 +5. 遍历矩阵中的所有单元格: + * 如果单元格可以从太平洋和大西洋到达,则将其添加到结果中。 +6. 返回公共单元格的列表。 + + + {oceanFlowUsingBFS} + + +### Big-O 分析 + +* **时间复杂度:O(m.n)**。 在 BFS 期间,每个单元格最多处理一次。 +* **空间复杂度:O(m.n)**。 使用两个布尔矩阵来跟踪可达性,并且 BFS 使用一个可能增长到矩阵大小的队列。 diff --git a/contents/questions/algo/optimal-stock-trading/description/en-US.langnostic.json b/contents/questions/algo/optimal-stock-trading/description/en-US.langnostic.json new file mode 100644 index 000000000..b21b4914d --- /dev/null +++ b/contents/questions/algo/optimal-stock-trading/description/en-US.langnostic.json @@ -0,0 +1,31 @@ +{ + "frontmatter": { + "title": "d7726c29", + "excerpt": "e2477bf" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "71a522ce", + "2d96efbe", + "c6bd11ed", + "d068a43f", + "b2065fc", + "dd31bb58" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "71a522ce", + "2d96efbe", + "c6bd11ed", + "d068a43f", + "b2065fc", + "dd31bb58" + ] + } + } +} diff --git a/contents/questions/algo/optimal-stock-trading/description/zh-CN.mdx b/contents/questions/algo/optimal-stock-trading/description/zh-CN.mdx new file mode 100644 index 000000000..7225bb693 --- /dev/null +++ b/contents/questions/algo/optimal-stock-trading/description/zh-CN.mdx @@ -0,0 +1,20 @@ +--- +title: 最佳股票交易 +excerpt: 实现一个函数,通过买入和卖出股票一次来找到可实现的最大利润 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个`prices`列表,其中每个元素`prices[i]`代表特定股票在第`i`天的价格,确定通过购买股票并在未来日期卖出股票可以获得的最大利润。如果无法产生利润,则返回`0`。 + +### 输入 + +- `prices: number[]`: 一个整数数组,表示每天的股票价格 + + + +### 约束 + +- 1 <= `prices.length` <= 10,000 +- 0 <= `prices[i]` <= 10,000 diff --git a/contents/questions/algo/optimal-stock-trading/solution/en-US.langnostic.json b/contents/questions/algo/optimal-stock-trading/solution/en-US.langnostic.json new file mode 100644 index 000000000..c19758e1a --- /dev/null +++ b/contents/questions/algo/optimal-stock-trading/solution/en-US.langnostic.json @@ -0,0 +1,54 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "90910a42", + "4ce347d1", + "94fc49d9", + "570ccaf5", + "b68df8f8", + "6477100e", + "c8da1ad0", + "8e2de8c8", + "10869105", + "63064d8b", + "c59d90e1", + "f3119d1a", + "b576af65", + "1cffeedf", + "b68df8f8", + "2900f7e2", + "41a3144", + "8e2de8c8", + "3d9e882d" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "90910a42", + "4ce347d1", + "94fc49d9", + "570ccaf5", + "b68df8f8", + "6477100e", + "c8da1ad0", + "8e2de8c8", + "10869105", + "63064d8b", + "c59d90e1", + "f3119d1a", + "b576af65", + "1cffeedf", + "b68df8f8", + "2900f7e2", + "41a3144", + "8e2de8c8", + "3d9e882d" + ] + } + } +} diff --git a/contents/questions/algo/optimal-stock-trading/solution/zh-CN.mdx b/contents/questions/algo/optimal-stock-trading/solution/zh-CN.mdx new file mode 100644 index 000000000..fa1603690 --- /dev/null +++ b/contents/questions/algo/optimal-stock-trading/solution/zh-CN.mdx @@ -0,0 +1,60 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import optimalStockTrading from '../setup/src/optimal-stock-trading.ts'; +import optimalStockTradingBruteForce from '../setup/src/optimal-stock-trading-brute-force.ts'; + +## 1. 暴力破解方法 + +此解决方案使用暴力破解方法计算通过在不同日期买卖股票可以获得的最大利润。 想法是评估所有可能的日期对,并计算每对的利润。 最大利润通过比较所有计算出的利润来确定。 + +对于每一天,该算法假设它是买入日,并遍历所有后续日期以检查可能的卖出日。 每对的利润计算为卖出价和买入价之间的差额。 在这些比较期间遇到的最大利润被存储并作为结果返回。 + +### 算法 + +1. 将变量 `maxProfit` 初始化为 `0`,以存储遇到的最大利润。 +2. 使用嵌套循环遍历所有可能的日期对: + 1. 外循环代表买入日 (`i`),从第一天迭代到倒数第二天。 + 2. 内循环代表卖出日 (`j`),从 `i` 之后的一天迭代到最后一天。 +3. 对于每一对日期: + 1. 计算利润,即卖出日 (`prices[j]`) 的价格与买入日 (`prices[i]`) 的价格之差。 + 2. 如果计算出的利润大于 `maxProfit`,则使用新的利润值更新 `maxProfit`。 +4. 在所有迭代之后,返回 `maxProfit` 作为可以实现的最大利润。 + + + {optimalStockTradingBruteForce} + + +### Big-O 分析 + +* **时间复杂度:O(n2)**。嵌套循环遍历所有日对,导致二次方时间复杂度。 +* **空间复杂度:O(1)**。没有使用额外的数据结构;仅需要几个变量进行计算。 + +## 2. 贪心方法 + +此解决方案使用贪心方法计算通过在不同日期买卖股票可以获得的最大利润。 该算法侧重于通过跟踪到目前为止遇到的最低价格并在迭代过程中动态计算利润来最大限度地减少不必要的计算。 + +关键思想是维护两个变量: + +1. `lowestPrice`,它跟踪到目前为止在数组中遇到的最低价格。 +2. `maxProfit`,它跟踪基于当前的 `lowestPrice` 和当前价格可能获得的最大利润。 + +对于数组中的每个价格,如果当前价格较低,则算法会更新 `lowestPrice`。 然后,它通过从当前价格中减去 `lowestPrice` 来计算潜在利润,如果计算出的利润更大,则更新 `maxProfit`。 与暴力破解方法相比,这种方法消除了比较所有价格对的需要,从而显着降低了时间复杂度。 + +### 算法 + +1. 将 `maxProfit` 初始化为 `0`,以存储遇到的最大利润。 +2. 将 `lowestPrice` 初始化为一个非常大的值 (`Number.MAX_SAFE_INTEGER`),以跟踪到目前为止遇到的最小价格。 +3. 遍历 `prices` 数组中的每个价格: + 1. 使用 `lowestPrice` 和当前价格中较小的值更新 `lowestPrice`。 + 2. 计算潜在利润,即当前价格与 `lowestPrice` 之间的差额。 + 3. 使用 `maxProfit` 和潜在利润中较大的值更新 `maxProfit`。 +4. 完成迭代后,返回 `maxProfit` 作为可以实现的最大利润。 + + + {optimalStockTrading} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。该算法遍历价格列表一次,为每个价格以恒定时间更新 `lowestPrice` 并计算 `maxProfit`。 +* **空间复杂度:O(1)**。仅使用两个变量 `lowestPrice` 和 `maxProfit` 来跟踪中间结果。 diff --git a/contents/questions/algo/pair-sum/description/en-US.langnostic.json b/contents/questions/algo/pair-sum/description/en-US.langnostic.json new file mode 100644 index 000000000..6110cdaeb --- /dev/null +++ b/contents/questions/algo/pair-sum/description/en-US.langnostic.json @@ -0,0 +1,35 @@ +{ + "frontmatter": { + "title": "e32f8f89", + "excerpt": "95119b3" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "c41d601c", + "2d96efbe", + "4d1fce3c", + "40808d83", + "eeffc1be", + "d068a43f", + "b2065fc", + "a4aa7148" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "c41d601c", + "2d96efbe", + "4d1fce3c", + "40808d83", + "eeffc1be", + "d068a43f", + "b2065fc", + "a4aa7148" + ] + } + } +} diff --git a/contents/questions/algo/pair-sum/description/zh-CN.mdx b/contents/questions/algo/pair-sum/description/zh-CN.mdx new file mode 100644 index 000000000..b959ff5c0 --- /dev/null +++ b/contents/questions/algo/pair-sum/description/zh-CN.mdx @@ -0,0 +1,27 @@ +--- +title: Pair sum +excerpt: 实现一个函数,用于查找整数数组中两个相加等于目标整数的数字 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个整数数组 `numbers`,编写一个函数,该函数返回 `numbers` 数组中两个整数的索引,这两个整数的和等于一个 `target` 整数。较小的索引应首先出现。 + +### 输入 + +- `numbers: number[]`: 整数数组 +- `target: number`: 一个整数 + +### 注意事项 + +- 对于给定的输入,将始终只有一个解决方案 +- 不应多次使用同一元素 + + + +### 约束 + +- 2 <= `numbers.length` <= 100 +- -1000 <= `numbers[i]` <= 1000 +- -1000 <= `target` <= 1000 diff --git a/contents/questions/algo/pair-sum/solution/en-US.langnostic.json b/contents/questions/algo/pair-sum/solution/en-US.langnostic.json new file mode 100644 index 000000000..749ce9175 --- /dev/null +++ b/contents/questions/algo/pair-sum/solution/en-US.langnostic.json @@ -0,0 +1,68 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "f410f9a", + "dfacf1c9", + "fa6f95cb", + "b68df8f8", + "44fc3bd7", + "883c3144", + "8e2de8c8", + "3d7fdc7c", + "e739bb8f", + "c04c9c2e", + "b17e19c5", + "c30037d9", + "b68df8f8", + "efab08d7", + "4ff88045", + "8e2de8c8", + "84745017", + "3c92531a", + "3fd868b2", + "d4b1edbf", + "e1b5e7a4", + "b68df8f8", + "2e46e57c", + "1434fc2a", + "8e2de8c8", + "429f4f82" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "f410f9a", + "dfacf1c9", + "fa6f95cb", + "b68df8f8", + "44fc3bd7", + "883c3144", + "8e2de8c8", + "3d7fdc7c", + "e739bb8f", + "c04c9c2e", + "b17e19c5", + "c30037d9", + "b68df8f8", + "efab08d7", + "4ff88045", + "8e2de8c8", + "84745017", + "3c92531a", + "3fd868b2", + "d4b1edbf", + "e1b5e7a4", + "b68df8f8", + "2e46e57c", + "1434fc2a", + "8e2de8c8", + "429f4f82" + ] + } + } +} diff --git a/contents/questions/algo/pair-sum/solution/zh-CN.mdx b/contents/questions/algo/pair-sum/solution/zh-CN.mdx new file mode 100644 index 000000000..023baf06b --- /dev/null +++ b/contents/questions/algo/pair-sum/solution/zh-CN.mdx @@ -0,0 +1,82 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import pairSum from '../setup/src/pair-sum.ts'; +import pairSumBruteForce from '../setup/src/pair-sum-brute-force.ts'; +import pairSumTwoPassHash from '../setup/src/pair-sum-two-pass-hash.ts'; + +## 1. 暴力解法 + +对和问题涉及识别数组中的两个索引,使得它们的值相加等于指定的 target。暴力解法检查数组中所有可能的元素对。对于索引 `i` 处的每个元素,检查索引 `j > i` 处的所有后续元素,以确定它们的总和是否与 target 匹配。这确保了考虑所有可能的对,使得解决方案直接但对于大型数组效率低下。 + +### 算法 + +1. 使用索引 `i` 的循环遍历 `numbers` 数组的每个元素。 +2. 对于索引 `i` 处的每个元素,使用另一个索引为 `j` 的循环遍历 `i` 之后的元素 (`j > i`)。 +3. 检查 `numbers[i]` 和 `numbers[j]` 的总和是否等于 `target`: + * 如果条件为真,则返回索引 `[i, j]`。 +4. 如果在检查所有对之后未找到这样的对,则返回一个空数组。 + + + {pairSumBruteForce} + + +### Big-O 分析 + +* **时间复杂度:O(n2)**。外循环运行 `n` 次,并且对于每次迭代,内循环最多运行 `n - 1` 次,导致二次方时间复杂度。 +* **空间复杂度:O(1)**。没有使用额外的数据结构,空间需求是恒定的。 + +## 2. 使用两遍哈希映射 + +之前的暴力解法涉及检查所有元素对,由于重复比较元素对,导致 O(n2) 的时间复杂度。因此,这种方法通过用高效的 O(1) 哈希表查找替换嵌套循环来消除冗余工作,从而将时间复杂度降低到 O(n)。 + +这种优化的解决方案使用**两遍哈希映射**方法: + +1. 第一遍构造一个哈希表,将每个元素的值存储为键,其索引存储为值。 +2. 在第二遍中,算法检查当前元素的补数(即 `target - numbers[i]`)是否存在于哈希表中。 + +### 算法 + +1. 初始化一个空哈希表 `hash` 以存储数字及其索引。 +2. 执行数组的第一遍: + * 对于每个元素 `numbers[i]`,将其存储在哈希表中,其索引作为值 (`hash[numbers[i]] = i`)。 +3. 执行数组的第二遍: + * 计算 `complement` 作为 `target - numbers[i]`。 + * 检查 `complement` 是否存在于哈希表中,并确保其索引与当前索引不同。 + * 如果满足条件,则返回索引 `[i, hash[complement]]`。 +4. 如果未找到有效对,则返回一个空数组。 + + + {pairSumTwoPassHash} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。该算法遍历数组两次,并且每个哈希表操作(插入或查找)需要 O(1) 时间。 +* **空间复杂度:O(n)**。在最坏的情况下,所有 `n` 个元素都存储在哈希映射中。 + +## 3. 使用一遍哈希映射 + +两遍解法中不必要的工作是需要对数组进行两次迭代。优化的单遍哈希表方法通过将这两个步骤合并为单个迭代来消除此缺点: + +* 在迭代期间,算法计算当前数字的补数。 +* 如果补数已存在于哈希表中,则找到该对,并返回索引。 +* 如果不是,则将当前数字及其索引添加到哈希表中以供将来查找。 + +这消除了对第二遍的需求,减少了不必要的工作并提高了运行时效率。 + +### 算法 + +1. 初始化一个空的哈希表 `hash` 来存储数字及其对应的索引。 +2. 遍历数组 `numbers`: + * 计算 `complement` 为 `target - numbers[i]`。 + * 检查 `complement` 是否存在于哈希表中: + * 如果存在,则返回索引 `[hash[complement], i]`。 + * 否则,将当前数字及其索引添加到哈希表中。 +3. 如果未找到有效对,则返回一个空数组。 + + {pairSum} + +### Big-O 分析 + +* **时间复杂度:O(n)**。该算法仅处理数组的每个元素一次,并且哈希表中的每次查找或插入都需要 O(1)。 +* **空间复杂度:O(n)**。在最坏的情况下,所有 `n` 个元素都存储在哈希映射中。 diff --git a/contents/questions/algo/queue/description/en-US.langnostic.json b/contents/questions/algo/queue/description/en-US.langnostic.json new file mode 100644 index 000000000..7075a3387 --- /dev/null +++ b/contents/questions/algo/queue/description/en-US.langnostic.json @@ -0,0 +1,25 @@ +{ + "frontmatter": { + "title": "ca7be533", + "excerpt": "b524a5d8" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "da5e6087", + "202fc0e0", + "493e8bd0", + "e0e33c5c" + ] + }, + "targets": { + "zh-CN": [ + "da5e6087", + "202fc0e0", + "493e8bd0", + "e0e33c5c" + ] + } + } +} diff --git a/contents/questions/algo/queue/description/zh-CN.mdx b/contents/questions/algo/queue/description/zh-CN.mdx new file mode 100644 index 000000000..e76284dd4 --- /dev/null +++ b/contents/questions/algo/queue/description/zh-CN.mdx @@ -0,0 +1,29 @@ +--- +title: 队列 +excerpt: 实现一个包含常见队列方法的队列数据结构 +--- + +用 JavaScript 实现一个队列数据结构,其中包含以下操作: + +* `new Queue()`:创建一个不包含任何项目的 `Queue` 类的实例。构造函数不接受任何参数。 +* `enqueue()`:将一个项目添加到队列的末尾。所需的时间复杂度:O(1)。 +* `dequeue()`:从队列的前面删除一个项目。所需的时间复杂度:O(1)。 +* `isEmpty()`:确定队列是否为空。所需的时间复杂度:O(1)。 +* `front()`:返回队列前面的项目,而不将其从队列中删除。所需的时间复杂度:O(1)。 +* `back()`:返回队列后面的项目,而不将其从队列中删除。所需的时间复杂度:O(1)。 +* `length()`:返回队列中的项目数。所需的时间复杂度:O(1)。 + +## 例子 + +```js +const queue = new Queue(); +queue.isEmpty(); // true +queue.enqueue(1); +queue.enqueue(2); +queue.length(); // 2 +queue.enqueue(3); +queue.front(); // 1 +queue.back(); // 3 +queue.dequeue(); // 1 +queue.isEmpty(); // false +``` diff --git a/contents/questions/algo/queue/solution/en-US.langnostic.json b/contents/questions/algo/queue/solution/en-US.langnostic.json new file mode 100644 index 000000000..1a90e8ade --- /dev/null +++ b/contents/questions/algo/queue/solution/en-US.langnostic.json @@ -0,0 +1,48 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "118cc46e", + "26e3ffe5", + "debcea69", + "11b0198a", + "fe990531", + "f114c8eb", + "7db2848d", + "81ca4dab", + "d2ab9d5a", + "ce3d3f71", + "4ffaba84", + "fbc7b835", + "499e5031", + "a2473ee", + "d87b3100", + "621508cd" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "118cc46e", + "26e3ffe5", + "debcea69", + "11b0198a", + "fe990531", + "f114c8eb", + "7db2848d", + "81ca4dab", + "d2ab9d5a", + "ce3d3f71", + "4ffaba84", + "fbc7b835", + "499e5031", + "a2473ee", + "d87b3100", + "621508cd" + ] + } + } +} diff --git a/contents/questions/algo/queue/solution/zh-CN.mdx b/contents/questions/algo/queue/solution/zh-CN.mdx new file mode 100644 index 000000000..84029321e --- /dev/null +++ b/contents/questions/algo/queue/solution/zh-CN.mdx @@ -0,0 +1,37 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import queueJs from '../setup/src/queue.js'; +import queueTs from '../setup/src/queue.ts'; + +## 解决方案 + +队列应该用链表来实现,链表本质上是一系列连接的节点。为了简化空队列的链表操作,我们使用双向链表(节点同时具有 `prev` 和 `next` 指针)和虚拟/哨兵头/尾节点。通过使用虚拟节点,链表将永远不会是“空的”,我们不必单独处理入队到空队列和出队只有一个项目的队列的情况。 + +![Empty Queue](/img/questions/queue/empty-queue.png) + +`enqueue()` 涉及创建一个新的 `Node` 并在 `_dummyTail` 节点和 `_dummyTail.next`(在空队列的情况下是 `_dummyHead`)之间添加它。 + +![Enqueue one item](/img/questions/queue/enqueue-a.png) + +![Enqueue second item](/img/questions/queue/enqueue-b.png) + +`dequeue()` 涉及删除 `_dummyHead` 节点和 `_dummyHead.prev` 之间的节点。如果队列为空,则这应该是一个 no-op,否则 `_dummyTail` 将被出队。 + +![Dequeue](/img/questions/queue/dequeue.png) + +由于 `length()` 的时间复杂度必须是 O(1),并且计算链表中项目的数量将需要 O(n),因此我们需要使用 `_length` 实例属性单独跟踪列表中项目的数量,并在 `enqueue()` 和 `dequeue()` 方法中更新它。 + +请注意,自动评分器不会检查你的 `enqueue()` 和 `dequeue()` 操作的时间复杂度是否为 O(1),但如果你只使用单个 JavaScript 数组来解决这个问题,那么它几乎肯定无法实现这两个操作的 O(1) 时间复杂度。 + + + +## 边缘情况 + +* 在空栈上调用 `dequeue()`。 +* 在空栈上调用 `front()`。 +* 在空栈上调用 `back()`。 + +## 技术 + +* 面向对象编程。 +* 链表操作。 diff --git a/contents/questions/algo/quick-sort/description/en-US.langnostic.json b/contents/questions/algo/quick-sort/description/en-US.langnostic.json new file mode 100644 index 000000000..2b0855ce6 --- /dev/null +++ b/contents/questions/algo/quick-sort/description/en-US.langnostic.json @@ -0,0 +1,31 @@ +{ + "frontmatter": { + "title": "5ee20351", + "excerpt": "6bd957ad" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "742eb78e", + "493e8bd0", + "1aac6faf", + "a8f76cea", + "45cae131", + "4ed31632", + "246ba997" + ] + }, + "targets": { + "zh-CN": [ + "742eb78e", + "493e8bd0", + "1aac6faf", + "a8f76cea", + "45cae131", + "4ed31632", + "246ba997" + ] + } + } +} diff --git a/contents/questions/algo/quick-sort/description/en-US.mdx b/contents/questions/algo/quick-sort/description/en-US.mdx index 3dd27f101..6f1bd8622 100644 --- a/contents/questions/algo/quick-sort/description/en-US.mdx +++ b/contents/questions/algo/quick-sort/description/en-US.mdx @@ -3,7 +3,7 @@ title: Quick Sort excerpt: Implement a function that performs a recursive quick sort --- -Implement a function that performs a recursive quick sort. The function should take in an array of integers. The output should be an array with the input sorted in ascending order. +Implement a function that performs a **recursive, in-place** quick sort. The function should take in an array of integers. The output should be an array with the input sorted in ascending order. ## Examples diff --git a/contents/questions/algo/quick-sort/description/zh-CN.mdx b/contents/questions/algo/quick-sort/description/zh-CN.mdx new file mode 100644 index 000000000..e1434185f --- /dev/null +++ b/contents/questions/algo/quick-sort/description/zh-CN.mdx @@ -0,0 +1,21 @@ +--- +title: 快速排序 +excerpt: 实现一个执行递归快速排序的函数 +--- + +实现一个执行**递归、就地**快速排序的函数。该函数应接收一个整数数组。输出应该是一个按升序排序的数组。 + +## 例子 + +```js +quickSort([9, 3, 6, 2, 1, 11]); // [1, 2, 3, 6, 9, 11] +quickSort([12, 16, 14, 1, 2, 3]); // [1, 2, 3, 12, 14, 16] +``` + +## 回顾 + +快速排序是一种高效的、就地的、递归的排序算法,它选择一个“枢轴”元素,并将所有其他元素分成 2 个子数组: + +1. 小于枢轴的元素被添加到位于枢轴之前的 1 个子数组中。 + +然后将快速排序递归地应用于每个子数组。一旦子数组被排序,它们就会按照上述方式与它们之间的枢轴元素合并。 diff --git a/contents/questions/algo/quick-sort/solution/en-US.langnostic.json b/contents/questions/algo/quick-sort/solution/en-US.langnostic.json new file mode 100644 index 000000000..6d8016e93 --- /dev/null +++ b/contents/questions/algo/quick-sort/solution/en-US.langnostic.json @@ -0,0 +1,72 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "f33226dc", + "dd98bed2", + "4cd64b66", + "ef0e1931", + "83c89232", + "26e3ffe5", + "f8dc6574", + "c3936fed", + "499e5031", + "c5556e1", + "c998b811", + "a34a2355", + "bb1b042d", + "6395cb80", + "289ae2b5", + "3da540d9", + "b3e28665", + "fb627ca7", + "d3c4900c", + "5de45380", + "f05b12c5", + "b89d5135", + "5b6426bb", + "7a30734", + "b50c9b31", + "b4d22542", + "c7b2072c", + "bf975393" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "f33226dc", + "dd98bed2", + "4cd64b66", + "ef0e1931", + "83c89232", + "26e3ffe5", + "f8dc6574", + "c3936fed", + "499e5031", + "c5556e1", + "c998b811", + "a34a2355", + "bb1b042d", + "6395cb80", + "289ae2b5", + "3da540d9", + "b3e28665", + "fb627ca7", + "d3c4900c", + "5de45380", + "f05b12c5", + "b89d5135", + "5b6426bb", + "7a30734", + "b50c9b31", + "b4d22542", + "c7b2072c", + "bf975393" + ] + } + } +} diff --git a/contents/questions/algo/quick-sort/solution/en-US.mdx b/contents/questions/algo/quick-sort/solution/en-US.mdx index a088a6b0e..b23b0d8be 100644 --- a/contents/questions/algo/quick-sort/solution/en-US.mdx +++ b/contents/questions/algo/quick-sort/solution/en-US.mdx @@ -3,7 +3,7 @@ import MDXCodeBlock from 'MDXCodeBlock'; import quickSortJs from '../setup/src/quick-sort.js'; import quickSortTs from '../setup/src/quick-sort.ts'; -Quick sort is generally regarded as the most efficient general-purpose sorting algorithm for any array size, being faster than merge sort on average. The standard form of quick sort is generally done recursively and in-place. However, it is an unstable sort and hence merge sort could be preferred in cases where stability is important. +Quick sort is generally regarded as the most efficient general-purpose sorting algorithm for any array size, being faster than merge sort on average. The standard form of quick sort is generally done **recursively** and **in-place**. However, it is an unstable sort and hence merge sort could be preferred in cases where stability is important. ## Clarification questions diff --git a/contents/questions/algo/quick-sort/solution/zh-CN.mdx b/contents/questions/algo/quick-sort/solution/zh-CN.mdx new file mode 100644 index 000000000..831686175 --- /dev/null +++ b/contents/questions/algo/quick-sort/solution/zh-CN.mdx @@ -0,0 +1,72 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import quickSortJs from '../setup/src/quick-sort.js'; +import quickSortTs from '../setup/src/quick-sort.ts'; + +快速排序通常被认为是任何数组大小最有效的通用排序算法,平均速度比合并排序快。快速排序的标准形式通常是**递归**和**就地**完成的。然而,它是一种不稳定的排序,因此在稳定性很重要的情况下,可能更喜欢合并排序。 + +## 澄清问题 + +如果未指定: + +* 数据应该按升序还是降序排序? +* 数据应该就地排序还是可以使用其他数据结构? +* 我们需要处理什么样的输入? + * 它只是一个整数数组,还是我们应该处理其他数据类型? + * 是否存在大量重复元素? + * 应该如何处理负数? + +## 解决方案 + +注意:这个问题处理的是一个标准的快速排序,它对升序输出是递归和就地的。 + + + +## 边缘情况 + +* 非整数元素输入:如果输入数组包含不同数据类型的元素,您可能需要返回一个错误,满足于尽力排序,例如,仅对输入数据的子集进行排序,甚至为非整数定义自定义比较函数。 +* 单个元素/空输入:返回原始数据结构、引发错误或澄清所需处理。 +* 已经排序的输入:您可能需要检测排序并原样返回输入。 +* 无效输入:如果输入不是数组,请考虑抛出错误。 + +## Big-O 分析 + +让我们分析一下算法的时间和空间复杂度。 + +### 时间复杂度 + +对于快速排序,最佳和平均情况下的时间复杂度为 O(nlog(n)),而最坏情况下的时间复杂度为 O(n2)。尽管如此,快速排序通常比合并排序更快,因为最坏或最佳情况时间复杂度的条件使其极其罕见。 + +快速排序的时间复杂度取决于每次递归调用时枢轴元素的选择。枢轴越接近数组或子数组的中位数,算法就越快。这是因为它会影响每次递归调用的分区时间,指的是扫描每个子数组并将其放置在较小或较大子数组中的时间。 + +在最坏的情况下,对于每次递归调用,我们恰好选择了离中位数最远的枢轴元素——即数组或子数组中最大或最小的元素。这意味着分区时间对于第一次递归调用是*c(n)*(c为某个常数),对于第二次递归调用是*c(n-1)*(在选择1个枢轴元素之后),依此类推。当我们加总n次递归调用的分区时间时,它大约为O(n2)的运行时间。 + +在最佳情况下,每次递归调用的枢轴元素非常接近中位数,因此分区始终尽可能均匀地平衡。在这种情况下,我们希望每次将每个子数组均匀地减半,这意味着我们只需要*2 \* (n/2)*分区时间用于每次递归调用(其中n指的是要分区的子数组的大小)。鉴于还需要进行log(n) + 1次递归调用,我们预计总共有cn(log(n) + 1)的运行时间,用大O表示法表示为O(nlog(n))。 + +正如我们从上面看到的,最佳和最坏情况需要非常具体的条件才能发生。 + +同时,平均情况更有可能发生在快速排序中。平均情况源于以下事实:任何恒定比例的分割都会产生深度为O(log(n))的递归树,其中每个递归级别的分区成本为O(log(n))。因此,时间复杂度往往为O(nlog(n))。 + +使用一个例子,我们假设部分不平衡的分割比例为 (9:1): + +1. 递归的左子树将以 1/10 的因子递减,这使得它的深度为 log10(n)。 +2. 递归的右子树将以 9/10 的因子递减,这使得它的深度为 log10/9(n) = O(log(n))。 +3. 在递归的每一层进行分区的成本大约为 *c(n)*。 + +综上所述,我们看到成本大约为 O(nlog(n))。 + +### 空间复杂度 + +在空间复杂度方面,尽管快速排序是一种原地算法,但作为递归函数,它仍然使用调用栈。因此,空间复杂度将取决于递归调用栈的大小,也就是递归树的高度。 + +在最坏的情况下,每次递归调用中枢轴的选择都很糟糕,因此在递归的每一层只有 1 个调用。这导致递归树的高度为 O(n)。 + +在最好的情况下,空间复杂度往往是 O(log(n)),在每个递归级别都有 2 个递归调用。当枢轴始终是中位数或接近中位数时,就会发生这种情况,这样递归树是平衡的。 + +为了避免最坏情况下的时间和空间复杂度,我们可以使用更好的枢轴选择策略。这种策略的一个例子是随机枢轴选择策略。通过随机选择枢轴元素,我们可以确保枢轴并不总是在数组中最小或最大的元素,这降低了最坏情况时间复杂度发生的可能性。 + +```js +// 随机选择一个枢轴元素 +const pivotIndex = Math.floor(Math.random() * arr.length); +const pivot = arr[pivotIndex]; +``` diff --git a/contents/questions/algo/selection-sort/description/en-US.langnostic.json b/contents/questions/algo/selection-sort/description/en-US.langnostic.json new file mode 100644 index 000000000..acb228475 --- /dev/null +++ b/contents/questions/algo/selection-sort/description/en-US.langnostic.json @@ -0,0 +1,35 @@ +{ + "frontmatter": { + "title": "4dc66aea", + "excerpt": "43cdbf60" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "95f6e0e0", + "ad25fab9", + "493e8bd0", + "412b685", + "a8f76cea", + "ad82db9", + "400d570", + "b948456e", + "bbcaf4f7" + ] + }, + "targets": { + "zh-CN": [ + "95f6e0e0", + "ad25fab9", + "493e8bd0", + "412b685", + "a8f76cea", + "ad82db9", + "400d570", + "b948456e", + "bbcaf4f7" + ] + } + } +} diff --git a/contents/questions/algo/selection-sort/description/zh-CN.mdx b/contents/questions/algo/selection-sort/description/zh-CN.mdx new file mode 100644 index 000000000..a9e81bd08 --- /dev/null +++ b/contents/questions/algo/selection-sort/description/zh-CN.mdx @@ -0,0 +1,29 @@ +--- +title: 选择排序 +excerpt: 实现一个执行选择排序的函数 +--- + +实现一个执行选择排序的函数。该函数应接收一个整数数组,并返回一个按升序排序的整数数组。 + +![Selection Sort expected input and output](/img/questions/selection-sort/selection-sort-input-output.png) + +## 例子 + +```js +selectionSort([9, 3, 6, 2, 1, 11]); // [1, 2, 3, 6, 9, 11] +selectionSort([12, 16, 14, 1, 2, 3]); // [1, 2, 3, 12, 14, 16] +``` + +## 回顾 + +选择排序是一种排序算法,它重复扫描一个未排序的数组,并在每次迭代中找到最小的元素来构建一个已排序的数组。 + +以下是选择排序背后的基本思想: + +1. 在数组中找到最小的元素。 +2. 将其与第一个位置的元素交换。 +3. 在数组中找到第二个最小的元素。 +4. 将其与第二个位置的元素交换。 +5. 重复此过程,直到整个数组排序完毕。 + +![Selection Sort explanation](/img/questions/selection-sort/selection-sort-explanation.png) diff --git a/contents/questions/algo/selection-sort/solution/en-US.langnostic.json b/contents/questions/algo/selection-sort/solution/en-US.langnostic.json new file mode 100644 index 000000000..3e0ae5e88 --- /dev/null +++ b/contents/questions/algo/selection-sort/solution/en-US.langnostic.json @@ -0,0 +1,60 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "344d43a3", + "27a8bb73", + "cc660089", + "4cd64b66", + "ef0e1931", + "83c89232", + "26e3ffe5", + "23d3fcc7", + "7dea68e4", + "499e5031", + "f8f69c87", + "add698fb", + "b318f68c", + "fc9b89c2", + "dd7799a6", + "c998b811", + "a34a2355", + "bb1b042d", + "31c4567f", + "5b6426bb", + "a8c78b3a", + "903d55ef" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "344d43a3", + "27a8bb73", + "cc660089", + "4cd64b66", + "ef0e1931", + "83c89232", + "26e3ffe5", + "23d3fcc7", + "7dea68e4", + "499e5031", + "f8f69c87", + "add698fb", + "b318f68c", + "fc9b89c2", + "dd7799a6", + "c998b811", + "a34a2355", + "bb1b042d", + "31c4567f", + "5b6426bb", + "a8c78b3a", + "903d55ef" + ] + } + } +} diff --git a/contents/questions/algo/selection-sort/solution/zh-CN.mdx b/contents/questions/algo/selection-sort/solution/zh-CN.mdx new file mode 100644 index 000000000..71fc33715 --- /dev/null +++ b/contents/questions/algo/selection-sort/solution/zh-CN.mdx @@ -0,0 +1,59 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import selectionSortJs from '../setup/src/selection-sort.js'; +import selectionSortTs from '../setup/src/selection-sort.ts'; + +选择排序是一种排序算法,非常适用于小型数组或已经基本排序的数组。 + +它的时间复杂度为 O(n2),这意味着不建议使用它来对大型数组进行排序。它通常不用于实践中。 + +## 澄清问题 + +如果未指定: + +* 数据应该按升序还是降序排序? +* 数据应该就地排序还是可以使用其他数据结构? +* 我们需要处理什么样的输入? + * 它只是一个整数数组,还是我们应该处理其他数据类型? + * 是否存在大量重复元素? + * 应该如何处理负数? + +## 解决方案 + +注意:此问题处理的是按升序输出的排序。请参阅下面的“注释”部分,了解如何处理其他情况。 + + + +## 边缘情况 + +* 非整数元素输入:如果输入数组包含不同数据类型的元素,您可能需要返回一个错误,尝试进行最佳排序,例如,仅对输入数据的子集进行排序,甚至为非整数定义自定义比较函数。 +* 单个元素/空输入:返回原始数据结构、引发错误或澄清所需处理。 +* 已经排序的输入:您可能需要检测排序并原样返回输入。 +* 重复元素:特别是如果数组有大量重复元素,您可能需要进一步优化您的实现以避免不必要的比较。 +* 无效输入:如果输入不是数组,请考虑抛出错误。 + +## 笔记 + +* 如果要求按降序排序,请更改比较以找到 `maxIndex` 而不是 `minIndex`,方法是在相关比较中使用 `>=` 而不是 `<`,如下所示: + +```js +if (arr[j] >= arr[maxIndex]) { + maxIndex = j; +} +``` + +* 如果要求使用其他数据结构或编写纯函数而不是就地排序数据,请使用扩展运算符在应用排序之前创建一个新数组。 + +## Big-O 分析 + +让我们分析一下算法的时间和空间复杂度。 + +### 时间复杂度 + +选择排序的时间复杂度为 O(n2) - 在所有情况下都相同。这可以通过观察循环次数来推导。有 2 个循环,因此复杂度为 O(n2)。 + +### 空间复杂度 + +选择排序的空间复杂度为 O(1),当它在原位执行时,因为它只需要常量大小的额外空间来存储变量。 + +但是,如果排序算法不是在原位执行的,那么空间复杂度将是 O(n),因为需要额外的内存来存储已排序的元素。 diff --git a/contents/questions/algo/stack/description/en-US.langnostic.json b/contents/questions/algo/stack/description/en-US.langnostic.json new file mode 100644 index 000000000..57d2eb642 --- /dev/null +++ b/contents/questions/algo/stack/description/en-US.langnostic.json @@ -0,0 +1,25 @@ +{ + "frontmatter": { + "title": "42d0453f", + "excerpt": "1819f431" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "21939d2", + "426087bd", + "493e8bd0", + "779a35d4" + ] + }, + "targets": { + "zh-CN": [ + "21939d2", + "426087bd", + "493e8bd0", + "779a35d4" + ] + } + } +} diff --git a/contents/questions/algo/stack/description/zh-CN.mdx b/contents/questions/algo/stack/description/zh-CN.mdx new file mode 100644 index 000000000..ffa1c72b7 --- /dev/null +++ b/contents/questions/algo/stack/description/zh-CN.mdx @@ -0,0 +1,27 @@ +--- +title: 栈 +excerpt: 实现一个包含常见栈方法的栈数据结构 +--- + +用 JavaScript 实现一个栈数据结构,它包含以下操作: + +* `new Stack()`:创建一个不包含任何项目的 `Stack` 类的实例。构造函数不接受任何参数。 +* `push()`:将一个项目推到栈的顶部,并返回栈的新长度。所需的时间复杂度:O(1)。 +* `pop()`:移除栈顶的一个项目并返回该项目。所需的时间复杂度:O(1)。 +* `isEmpty()`:确定栈是否为空。所需的时间复杂度:O(1)。 +* `peek()`:返回栈顶的项目,而不将其从栈中移除。所需的时间复杂度:O(1)。 +* `length()`:返回栈中项目的数量。所需的时间复杂度:O(1)。 + +## 例子 + +```js +const stack = new Stack(); +stack.isEmpty(); // true +stack.push(1); +stack.push(2); +stack.length(); // 2 +stack.push(3); +stack.peek(); // 3 +stack.pop(); // 3 +stack.isEmpty(); // false +``` diff --git a/contents/questions/algo/stack/solution/en-US.langnostic.json b/contents/questions/algo/stack/solution/en-US.langnostic.json new file mode 100644 index 000000000..7b83d264a --- /dev/null +++ b/contents/questions/algo/stack/solution/en-US.langnostic.json @@ -0,0 +1,44 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "569d69b4", + "26e3ffe5", + "1dfdb492", + "4a3e44e8", + "68cf10ba", + "6563c0e", + "e48b32e3", + "6cf2fd7c", + "d58e05de", + "8230039f", + "499e5031", + "fd552188", + "d87b3100", + "1ab886d1" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "569d69b4", + "26e3ffe5", + "1dfdb492", + "4a3e44e8", + "68cf10ba", + "6563c0e", + "e48b32e3", + "6cf2fd7c", + "d58e05de", + "8230039f", + "499e5031", + "fd552188", + "d87b3100", + "1ab886d1" + ] + } + } +} diff --git a/contents/questions/algo/stack/solution/zh-CN.mdx b/contents/questions/algo/stack/solution/zh-CN.mdx new file mode 100644 index 000000000..4c52ea79a --- /dev/null +++ b/contents/questions/algo/stack/solution/zh-CN.mdx @@ -0,0 +1,35 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import stackJs from '../setup/src/stack.js'; +import stackTs from '../setup/src/stack.ts'; +import linkedListSolution from '../setup/src/linkedListSolution'; + +## 解决方案 + +### 基于数组的解决方案 + +栈抽象数据类型可以用 JavaScript `Array` 轻松地在 JavaScript 中实现。在实现栈时需要注意的主要事项是,这些操作应该是 O(1)。值得庆幸的是,JavaScript `Array` 的 `push()` 和 `pop()` 操作是 O(1),并且方法签名与 `Stack` 的匹配。许多方法只是围绕 `Array` 方法的简单包装器。 + + + +### 基于链表的解决方案 + +栈也可以用单链表来实现,单链表本质上是一系列连接的节点。为此,我们需要创建一个 `Node` 类,该类具有一个 `prev` 指针,如果它不是栈的底部项,则引用下面的 `Node`。 + +`push()` 涉及创建一个新的 `Node`,并将栈的当前顶部指向该新 `Node` 的 `prev` 字段,并更新对栈的新顶部的引用。`pop()` 与之相反,我们在其中找到当前顶部的 `prev` 节点,并将其设置为栈的新顶部。 + +由于 `length()` 的时间复杂度必须为 O(1),并且计算链表中项目的数量将需要 O(n),因此我们需要使用 `_length` 实例属性单独跟踪列表中项目的数量,并在 `push()` 和 `pop()` 方法中更新它。 + + + {linkedListSolution} + + +## 边缘情况 + +* 在空栈上调用 `pop()`。 +* 在空栈上调用 `peek()`。 + +## 技术 + +* 熟悉 JavaScript 数组。 +* 面向对象编程。 diff --git a/contents/questions/algo/staircase-climbing-combinations/description/en-US.langnostic.json b/contents/questions/algo/staircase-climbing-combinations/description/en-US.langnostic.json new file mode 100644 index 000000000..f084c1ec4 --- /dev/null +++ b/contents/questions/algo/staircase-climbing-combinations/description/en-US.langnostic.json @@ -0,0 +1,31 @@ +{ + "frontmatter": { + "title": "1f76b7cc", + "excerpt": "e5cd2210" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "65cc660f", + "2d96efbe", + "622611fb", + "d068a43f", + "b2065fc", + "22611856" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "65cc660f", + "2d96efbe", + "622611fb", + "d068a43f", + "b2065fc", + "22611856" + ] + } + } +} diff --git a/contents/questions/algo/staircase-climbing-combinations/description/zh-CN.mdx b/contents/questions/algo/staircase-climbing-combinations/description/zh-CN.mdx new file mode 100644 index 000000000..6ef26dd7d --- /dev/null +++ b/contents/questions/algo/staircase-climbing-combinations/description/zh-CN.mdx @@ -0,0 +1,19 @@ +--- +title: 爬楼梯组合 +excerpt: 实现一个函数,找到到达楼梯顶部的不同方式的数量 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个长度为 `steps` 的楼梯,您每次可以走 1 步或 2 步,找到从楼梯底部到达楼梯顶部的不同组合的数量。 + +### 输入 + +- `steps: number`: 一个整数 + + + +### 约束 + +- 1 <= `steps` <= 45 diff --git a/contents/questions/algo/staircase-climbing-combinations/solution/en-US.langnostic.json b/contents/questions/algo/staircase-climbing-combinations/solution/en-US.langnostic.json new file mode 100644 index 000000000..92dd9964b --- /dev/null +++ b/contents/questions/algo/staircase-climbing-combinations/solution/en-US.langnostic.json @@ -0,0 +1,62 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "cdb08c30", + "4ce347d1", + "d9d3a647", + "6e4f9b6", + "42c19ca8", + "d2afdf16", + "b68df8f8", + "a7b06407", + "bcd3f60f", + "8e2de8c8", + "88196a94", + "e5dc1bc8", + "3cb03a30", + "929f8f15", + "b8e42d73", + "c6856909", + "a1897a48", + "b8e0415a", + "b68df8f8", + "aa91bb1f", + "e7d2c2ef", + "8e2de8c8", + "70cbe592" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "cdb08c30", + "4ce347d1", + "d9d3a647", + "6e4f9b6", + "42c19ca8", + "d2afdf16", + "b68df8f8", + "a7b06407", + "bcd3f60f", + "8e2de8c8", + "88196a94", + "e5dc1bc8", + "3cb03a30", + "929f8f15", + "b8e42d73", + "c6856909", + "a1897a48", + "b8e0415a", + "b68df8f8", + "aa91bb1f", + "e7d2c2ef", + "8e2de8c8", + "70cbe592" + ] + } + } +} diff --git a/contents/questions/algo/staircase-climbing-combinations/solution/zh-CN.mdx b/contents/questions/algo/staircase-climbing-combinations/solution/zh-CN.mdx new file mode 100644 index 000000000..f84ea6ef5 --- /dev/null +++ b/contents/questions/algo/staircase-climbing-combinations/solution/zh-CN.mdx @@ -0,0 +1,71 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import staircaseClimbingCombinations from '../setup/src/staircase-climbing-combinations.ts'; +import staircaseClimbingCombinationsBruteForce from '../setup/src/staircase-climbing-combinations-bruteforce.ts'; + +## 1. 暴力解法 + +此解决方案使用递归计算爬楼梯的不同方式的数量,给定楼梯的步数。在每一步,爬楼梯的人可以选择走 1 步或 2 步。通过递归计算从当前步数到达顶部的总方式数来解决该问题。 + +该算法使用一个辅助函数来探索所有可能的步数组合: + +1. 如果当前步数超过总步数,则路径无效,因此返回 0。 +2. 如果当前步数等于总步数,则表示有效路径,因此返回 1。 +3. 对于所有其他情况,它通过从当前步数走 1 步或 2 步来递归计算到达顶部的总方式数。 + +这种暴力方法探索所有可能的路径以找到组合的总数。但是,它会进行冗余计算,因为多次解决相同的子问题,这会增加其计算成本。 + +### 算法 + +1. 定义一个函数 `staircaseClimbingCombinations`,该函数从第 `0` 步开始调用辅助函数 `climbFromStep`。 +2. 辅助函数 `climbFromStep` 将当前步数和总步数作为输入: + 1. 如果当前步数超过总步数,则返回 `0`,因为它无效。 + 2. 如果当前步数等于总步数,则返回 `1`,因为它表示有效路径。 + 3. 通过求和递归计算总方式数: + * 走 1 步的结果 (`climbFromStep(currentStep + 1, totalSteps)`)。 + * 走 2 步的结果 (`climbFromStep(currentStep + 2, totalSteps)`)。 +3. 返回辅助函数的结果。 + + + {staircaseClimbingCombinationsBruteForce} + + +### Big-O 分析 + +* **时间复杂度:O(2n)**。每一步都分支为两个递归调用,导致指数级的函数调用。 +* **空间复杂度:O(n)**。递归堆栈最多可以增长到 `n` 的深度,其中 `n` 是总步数。 + +## 2. 使用动态规划 + +此解决方案使用动态规划 (DP) 计算爬楼梯的不同方式的数量,给定楼梯的步数。通过将其分解为较小的子问题并将这些子问题的结果存储在 `dp` 数组中以避免冗余计算来解决该问题。 + +直觉是,要到达第 `i` 步,有两种可能的方式: + +1. 从第 `i-1` 步走一步。 +2. 从第 `i-2` 步走两步。 + +这种关系导致了递归公式:`dp[i] = dp[i-1] + dp[i-2]`。使用此公式,该解决方案迭代地构建 `dp` 数组,从基本情况开始: + +* 停留在第 `0` 步只有 1 种方式(什么都不做)。 +* 到达第 `1` 步只有 1 种方式(一步)。 + +`dp[steps]` 中的最终值给出了到达楼梯顶部的总方式数。 + +### 算法 + +1. 创建一个大小为 `steps + 1` 的 `dp` 数组,初始化为 `-1`,用于存储到达每一步的方式数。 +2. 初始化基本情况: + 1. 设置 `dp[0] = 1`,因为停留在第 `0` 步有一种方式。 + 2. 设置 `dp[1] = 1`,因为到达第 `1` 步有一种方式(一步)。 +3. 使用循环从第 `2` 步到 `steps` 填充 `dp` 数组: + 1. 对于每一步 `i`,将 `dp[i]` 计算为 `dp[i-1]`(从前一步到达的方式)和 `dp[i-2]`(从前两步到达的方式)的总和。 +4. 返回 `dp[steps]` 中的值,作为到达楼梯顶部的不同方式的总数。 + + + {staircaseClimbingCombinations} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。`dp` 数组在从 `0` 到 `steps` 的单次遍历中被填充。 +* **空间复杂度:O(n)**。`dp` 数组需要额外的空间,与步数成正比。 diff --git a/contents/questions/algo/string-anagram-groups/description/en-US.langnostic.json b/contents/questions/algo/string-anagram-groups/description/en-US.langnostic.json new file mode 100644 index 000000000..668796c01 --- /dev/null +++ b/contents/questions/algo/string-anagram-groups/description/en-US.langnostic.json @@ -0,0 +1,33 @@ +{ + "frontmatter": { + "title": "708b5a41", + "excerpt": "4344d91e" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "ee1a6006", + "446a44fc", + "2d96efbe", + "35d38339", + "d068a43f", + "b2065fc", + "cc8febfe" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "ee1a6006", + "446a44fc", + "2d96efbe", + "35d38339", + "d068a43f", + "b2065fc", + "cc8febfe" + ] + } + } +} diff --git a/contents/questions/algo/string-anagram-groups/description/zh-CN.mdx b/contents/questions/algo/string-anagram-groups/description/zh-CN.mdx new file mode 100644 index 000000000..28a98d616 --- /dev/null +++ b/contents/questions/algo/string-anagram-groups/description/zh-CN.mdx @@ -0,0 +1,23 @@ +--- +title: 字符串异位词分组 +excerpt: 实现一个函数,将字符串数组分组为异位词 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个字符串数组`strs`,将彼此互为异位词的字符串分组。结果可以按任何顺序返回。 + +异位词是由另一个单词或短语的字母重新排列而成的单词或短语,使用所有原始字母且仅使用一次。 + +### 输入 + +- `strs: string[]`: 字符串数组 + + + +### 约束 + +- 1 <= `strs.length` <= 1000 +- 1 <= `strs[i].length` <= 100 +- 每个字符串`strs[i]`仅包含小写英文字母 diff --git a/contents/questions/algo/string-anagram-groups/solution/en-US.langnostic.json b/contents/questions/algo/string-anagram-groups/solution/en-US.langnostic.json new file mode 100644 index 000000000..fcfe33019 --- /dev/null +++ b/contents/questions/algo/string-anagram-groups/solution/en-US.langnostic.json @@ -0,0 +1,48 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "a598d008", + "1d923e00", + "e0f6365e", + "b68df8f8", + "d839822b", + "2d002735", + "8e2de8c8", + "c5a450de", + "b3b3c370", + "4b08e14e", + "3060eb81", + "b68df8f8", + "e52feadd", + "d69cd5ab", + "8e2de8c8", + "8f4c164b" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "a598d008", + "1d923e00", + "e0f6365e", + "b68df8f8", + "d839822b", + "2d002735", + "8e2de8c8", + "c5a450de", + "b3b3c370", + "4b08e14e", + "3060eb81", + "b68df8f8", + "e52feadd", + "d69cd5ab", + "8e2de8c8", + "8f4c164b" + ] + } + } +} diff --git a/contents/questions/algo/string-anagram-groups/solution/zh-CN.mdx b/contents/questions/algo/string-anagram-groups/solution/zh-CN.mdx new file mode 100644 index 000000000..24877f589 --- /dev/null +++ b/contents/questions/algo/string-anagram-groups/solution/zh-CN.mdx @@ -0,0 +1,60 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import anagramGroups from '../setup/src/string-anagram-groups.ts'; +import groupAnagramsUsingFreqCount from '../setup/src/string-anagram-groups-freq-count.ts'; + +## 1. 使用排序 + +一种朴素的方法可能涉及检查所有可能的字符串对,这将是低效的。然而,这种优化的解决方案使用每个字符串的排序版本作为分组的唯一键。排序确保所有字谜产生相同的键,简化了组的识别。对每个字符串进行排序将问题简化为键生成,使用 `Map` 处理起来很简单。 + +### 算法 + +1. 初始化一个空的 `Map` 来存储字谜组。 + * 键表示字符串的排序版本,值是原始字符串的数组。 +2. 遍历字符串的输入数组。 + * 对于每个字符串,将其转换为字符数组并按字母顺序排序。 + * 连接排序后的字符以创建键。 +3. 检查键是否已存在于 `Map` 中。 + * 如果键不存在,则使用一个空数组对其进行初始化。 + * 将原始字符串附加到与键对应的数组中。 +4. 将 `Map` 的值转换为数组的数组并返回。 + + + {anagramGroups} + + +### Big-O 分析 + +* **时间复杂度:O(n.m log m)**。对长度为 `m` 的每个字符串进行排序需要 O(m log m),并且有 `n` 个字符串。 +* **空间复杂度:O(n.m)**。`Map` 存储所有字符串,键和值所需的空间取决于输入中的总字符数。 + +## 2. 使用频率计数 + +与对字符串进行排序以生成键(如之前的解决方案)不同,使用固定大小的频率数组(对于英文字母为 26)来计算每个字符的出现次数。此解决方案通过使用其字符频率计数来表示每个字符串,从而优化了该过程。这消除了对排序的需要,而排序是基于排序的方法中的瓶颈。 + +每个组的键是从频率计数派生的,格式化为包含所有字符计数的连接字符串。这确保所有字谜都映射到相同的键,同时避免了排序开销,提高了解决方案的效率。 + +### 算法 + +1. 检查输入数组是否为空。 + * 如果数组为空,则返回一个空数组。 +2. 初始化一个空对象来存储字谜组。 + * 键表示字符计数模式,值是与该模式匹配的字符串数组。 +3. 遍历输入数组中的每个字符串。 + * 初始化一个大小为 26 的计数数组来表示字符频率。 + * 对于字符串中的每个字符,递增计数数组中对应的索引。 +4. 从计数数组生成一个键字符串。 + * 连接 `#` 和每个字符的计数以形成键。 +5. 检查该键是否存在于对象中。 + * 如果该键不存在,则使用一个空数组对其进行初始化。 + * 将字符串附加到与该键对应的数组中。 +6. 将对象的值作为字谜组的数组返回。 + + + {groupAnagramsUsingFreqCount} + + +### Big-O 分析 + +* **时间复杂度:O(n.m)**。计算每个长度为 `m` 的字符串的字符需要 O(m),并且有 `n` 个字符串。 +* **空间复杂度:O(n.m)**。对象存储所有字符串,并为字符计数和键使用额外的空间。 diff --git a/contents/questions/algo/string-anagram/description/en-US.langnostic.json b/contents/questions/algo/string-anagram/description/en-US.langnostic.json new file mode 100644 index 000000000..c1eabde22 --- /dev/null +++ b/contents/questions/algo/string-anagram/description/en-US.langnostic.json @@ -0,0 +1,33 @@ +{ + "frontmatter": { + "title": "74274e89", + "excerpt": "caf8895e" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "8de69639", + "16c83e9c", + "2d96efbe", + "1400e8de", + "d068a43f", + "b2065fc", + "f8780109" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "8de69639", + "16c83e9c", + "2d96efbe", + "1400e8de", + "d068a43f", + "b2065fc", + "f8780109" + ] + } + } +} diff --git a/contents/questions/algo/string-anagram/description/zh-CN.mdx b/contents/questions/algo/string-anagram/description/zh-CN.mdx new file mode 100644 index 000000000..b5fdbc32f --- /dev/null +++ b/contents/questions/algo/string-anagram/description/zh-CN.mdx @@ -0,0 +1,23 @@ +--- +title: 字符串异位词 +excerpt: 实现一个函数来确定两个字符串是否互为异位词 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定两个字符串`str1`和`str2`,确定`str2`是否是`str1`的异位词,如果是则返回`true`,否则返回`false`。 + +异位词是指通过重新排列另一个单词或短语的字母而形成的单词或短语,使用所有原始字母且仅使用一次。例如,单词`listen`和`silent`是异位词,因为它们使用相同的字母,具有相同的频率,但顺序不同。 + +### 输入 + +- `str1`:一个字符串 +- `str2`:一个字符串 + + + +### 约束 + +- 1 <= `str1.length`,`str2.length` <= 1000 +- `str1`和`str2`仅由小写英文字母组成 diff --git a/contents/questions/algo/string-anagram/solution/en-US.langnostic.json b/contents/questions/algo/string-anagram/solution/en-US.langnostic.json new file mode 100644 index 000000000..d646eeb9e --- /dev/null +++ b/contents/questions/algo/string-anagram/solution/en-US.langnostic.json @@ -0,0 +1,50 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "6392bdae", + "1d923e00", + "d3ce4624", + "61274c15", + "b68df8f8", + "7cc718be", + "1d010507", + "8e2de8c8", + "2310faaa", + "b3b3c370", + "46d402b4", + "a1b26816", + "b68df8f8", + "627daff6", + "a2123a4", + "8e2de8c8", + "e6baa717" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "6392bdae", + "1d923e00", + "d3ce4624", + "61274c15", + "b68df8f8", + "7cc718be", + "1d010507", + "8e2de8c8", + "2310faaa", + "b3b3c370", + "46d402b4", + "a1b26816", + "b68df8f8", + "627daff6", + "a2123a4", + "8e2de8c8", + "e6baa717" + ] + } + } +} diff --git a/contents/questions/algo/string-anagram/solution/zh-CN.mdx b/contents/questions/algo/string-anagram/solution/zh-CN.mdx new file mode 100644 index 000000000..633fc67e0 --- /dev/null +++ b/contents/questions/algo/string-anagram/solution/zh-CN.mdx @@ -0,0 +1,55 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import isStringAnagram from '../setup/src/string-anagram.ts'; +import isStringAnagramUsingFrequency from '../setup/src/string-anagram-frequency-check.ts'; + +## 1. 使用排序 + +问题是确定两个字符串是否互为字谜。如果两个字符串包含相同字符,且每个字符的出现频率也相同,但顺序可以不同,则它们互为字谜。这种方法的核心在于,对两个字符串进行排序后,如果它们是字谜,则会按照相同的顺序重新排列字符。排序后,简单地比较两个已排序的数组就可以确定这些字符串是否互为字谜。 + +排序提供了一种直接的方式来对齐两个字符串中的字符,从而便于检查是否相等。 + +### 算法 + +1. 检查 `str1` 和 `str2` 的长度是否不同。如果不同,则返回 `false`,因为长度不同的字符串不可能互为字谜。 +2. 使用 `split` 方法将 `str1` 和 `str2` 分割成字符数组。 +3. 使用 `sort` 方法对字符数组进行排序。 +4. 遍历已排序的数组,并比较每个索引处的字符。 + * 如果两个数组中的任何字符不匹配,则返回 `false`。 +5. 如果所有字符都匹配,则返回 `true`。 + + + {isStringAnagram} + + +### Big-O 分析 + +* **时间复杂度:O(n log n)**。对字符数组进行排序是最昂贵的操作,并且在运行时占据主导地位。 +* **空间复杂度:O(n)**。需要空间来存储从输入字符串创建的字符数组。 + +## 2. 使用频率计数 + +此解决方案通过使用频率计数方法来优化字谜检查过程。该解决方案没有对字符串进行排序(需要 O(n log n) 时间),而是使用固定大小的数组(对于英文字母,大小为 26)来计算字符的出现次数。对于每个字符串,都会更新频率表:一个字符串递增,另一个字符串递减。如果最后所有字符的计数都为零,则这些字符串互为字谜。 + +这种方法避免了不必要的排序,并直接针对前一个解决方案中的排序瓶颈,从而将时间复杂度从 O(n log n) 降低到 O(n)。 + +### 算法 + +1. 检查两个字符串的长度是否不同。 + * 如果不同,则返回 `false`,因为这些字符串不可能互为字谜。 +2. 初始化一个大小为 26 的数组,并将所有元素设置为 0,以充当频率表。 +3. 遍历第一个字符串。 + * 对于每个字符,递增其在频率表中的相应位置。 +4. 遍历第二个字符串。 + * 对于每个字符,递减其在频率表中的相应位置。 + * 如果表中任何计数变为负数,则返回 `false`。 +5. 在两次迭代之后,如果没有计数为负数,则返回 `true`,因为这些字符串互为字谜。 + + + {isStringAnagramUsingFrequency} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。该解决方案恰好遍历两个字符串一次。 +* **空间复杂度:O(1)**。频率表的大小是固定的(26),与输入大小无关。 diff --git a/contents/questions/algo/string-decode-message/description/en-US.langnostic.json b/contents/questions/algo/string-decode-message/description/en-US.langnostic.json new file mode 100644 index 000000000..72b6450dc --- /dev/null +++ b/contents/questions/algo/string-decode-message/description/en-US.langnostic.json @@ -0,0 +1,43 @@ +{ + "frontmatter": { + "title": "6bf0d2d2", + "excerpt": "3e5cfb6c" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "de23e69d", + "7d2f4ef", + "bb6f9502", + "f43b1ea0", + "cfcb27be", + "2d96efbe", + "c64ee8d4", + "40808d83", + "1effa0ba", + "d068a43f", + "b2065fc", + "397ef21d" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "de23e69d", + "7d2f4ef", + "bb6f9502", + "f43b1ea0", + "cfcb27be", + "2d96efbe", + "c64ee8d4", + "40808d83", + "1effa0ba", + "d068a43f", + "b2065fc", + "397ef21d" + ] + } + } +} diff --git a/contents/questions/algo/string-decode-message/description/zh-CN.mdx b/contents/questions/algo/string-decode-message/description/zh-CN.mdx new file mode 100644 index 000000000..39d3d6b28 --- /dev/null +++ b/contents/questions/algo/string-decode-message/description/zh-CN.mdx @@ -0,0 +1,35 @@ +--- +title: 解码消息 +excerpt: 实现一个函数来计算解码数字字符串的方法 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +一个秘密消息被编码为一串数字,其中每个数字或一对数字代表一个字母,根据以下映射: + +`'1' → 'A', '2' → 'B', ..., '26' → 'Z'` + +消息可以根据数字的分组方式以多种方式解码。例如,字符串“226”可以解释为: + +- "2 26" → 'BZ' +- "22 6" → 'VF' +- "2 2 6" → 'BBF' + +给定一个只包含数字的字符串`str`,找出它可以被解码的方式有多少种。如果字符串无法以任何有效方式解码,则返回`0`。 + +### 输入 + +- `str: string`: 仅由要解码的数字组成的字符串 + +### 注意事项 + +- 测试用例的设计使得答案适合 32 位整数 +- 可能存在无法解码的字符串 +- 并非所有数字分组都有效。例如,“06”无效,因为数字不能有前导零 + + + +### 约束 + +- 1 <= `str.length` <= 100 diff --git a/contents/questions/algo/string-decode-message/solution/en-US.langnostic.json b/contents/questions/algo/string-decode-message/solution/en-US.langnostic.json new file mode 100644 index 000000000..82f48519d --- /dev/null +++ b/contents/questions/algo/string-decode-message/solution/en-US.langnostic.json @@ -0,0 +1,66 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "d5a93ad7", + "758cfdef", + "c8f1ab22", + "4cd2e078", + "b68df8f8", + "8dce52e7", + "39a9930", + "8e2de8c8", + "863ed3fb", + "31c3b347", + "218ec446", + "52ee4037", + "b68df8f8", + "1e4012f", + "7dc52b5c", + "8e2de8c8", + "c1beda10", + "697e0266", + "71272781", + "8c579a07", + "b68df8f8", + "57c3aecb", + "db5c78c4", + "8e2de8c8", + "e406842b" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "d5a93ad7", + "758cfdef", + "c8f1ab22", + "4cd2e078", + "b68df8f8", + "8dce52e7", + "39a9930", + "8e2de8c8", + "863ed3fb", + "31c3b347", + "218ec446", + "52ee4037", + "b68df8f8", + "1e4012f", + "7dc52b5c", + "8e2de8c8", + "c1beda10", + "697e0266", + "71272781", + "8c579a07", + "b68df8f8", + "57c3aecb", + "db5c78c4", + "8e2de8c8", + "e406842b" + ] + } + } +} diff --git a/contents/questions/algo/string-decode-message/solution/zh-CN.mdx b/contents/questions/algo/string-decode-message/solution/zh-CN.mdx new file mode 100644 index 000000000..a86199f21 --- /dev/null +++ b/contents/questions/algo/string-decode-message/solution/zh-CN.mdx @@ -0,0 +1,88 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import decodeMessage from '../setup/src/string-decode-message.ts'; +import decodeMessageTopDown from '../setup/src/string-decode-message-top-down.ts'; +import decodeMessageBottomUpConstantSpace from '../setup/src/string-decode-message-bottom-up-constant-space.ts'; + +## 1. 自顶向下动态规划 + +将字符串解码成可能的字母组合的问题可以被可视化为导航决策树。字符串中的每一步都提供两种选择:解码单个字符或解码两个字符(如果它们构成 `10` 到 `26` 之间的有效数字)。目标是计算从字符串开头到结尾的所有有效解码路径。 + +使用蛮力递归方法会导致冗余计算,因为同一个子问题(例如,解码从特定索引开始的子字符串)会被多次解决。这种冗余可以通过将先前计算的子问题的结果存储在备忘录映射中来避免。备忘录解决方案以最佳方式导航决策树,确保每个子问题只解决一次,从而显着提高效率。 + +### 算法 + +1. 定义一个递归函数 `recursiveWithMemo`,它: + * 接受当前索引、输入字符串和备忘录映射作为参数。 + * 检查当前索引的结果是否存在于 `memo` 中,如果找到则返回它。 + * 如果索引到达字符串的末尾(有效解码),则返回 `1`。 + * 如果当前字符是 `'0'`(无效解码),则返回 `0`。 + * 如果当前索引指向最后一个字符(有效解码),则返回 `1`。 +2. 使用 `recursiveWithMemo` 以 `index + 1` 调用,初始化一个变量 `ans`,结果是解码当前索引处的单个字符。 +3. 检查接下来的两个字符是否构成 `10` 到 `26` 之间的有效数字: + * 如果有效,通过使用 `index + 2` 调用 `recursiveWithMemo` 来添加解码两个字符的结果。 +4. 将当前索引的计算结果存储在 `memo` 映射中。 +5. 返回存储在 `memo` 中当前索引的值。 +6. 实现一个包装函数 `decodeMessage`,它: + * 初始化一个空的 `Map` 用于备忘录。 + * 使用初始索引 `0` 和输入字符串调用 `recursiveWithMemo`。 + + + {decodeMessageTopDown} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。由于备忘录,每个索引只处理一次。 +* **空间复杂度:O(n)**。`Map` 最多存储 `n` 个条目,并且递归堆栈在最坏情况下需要 O(n) 空间。 + +## 2. 自底向上动态规划 + +这种方法不是递归地解决子问题,而是通过使用较小子字符串的结果来迭代地计算解码字符串的方式的数量。直觉是维护一个 `dp` 数组,其中每个条目表示解码到该索引的子字符串的方式的数量。 + +这种方法通过在单次传递中迭代地填充 `dp` 数组来避免递归和备忘录的开销。迭代性质确保每个子问题只解决一次,从而显着优化时间和空间。 + +### 算法 + +1. 使用所有值设置为 `0` 初始化大小为 `str.length + 1` 的 `dp` 数组。 + * 将 `dp[0]` 设置为 `1`,因为有一种方法可以解码一个空字符串。 + * 如果第一个字符不是 `'0'`,则将 `dp[1]` 设置为 `1`,否则将其设置为 `0`。 +2. 从索引 `2` 迭代到 `str.length`: + * 如果当前字符不是 `'0'`,则将 `dp[i - 1]` 添加到 `dp[i]` 以进行单数字解码。 + * 提取最后两个字符作为两位数。如果它在 `10` 和 `26` 之间,则将 `dp[i - 2]` 添加到 `dp[i]` 以进行两位数解码。 +3. 返回 `dp[str.length]` 中的值,它表示解码整个字符串的方式的数量。 + + + {decodeMessage} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。该算法遍历字符串一次。 +* **空间复杂度:O(n)**。`dp` 数组存储字符串每个索引的中间结果。 + +## 3. 具有恒定空间的自底向上动态规划 + +此解决方案通过将空间复杂度降低到 O(1) 来改进自底向上的动态规划方法。此方法不是维护一个 `dp` 数组来存储所有索引的结果,而是仅跟踪最后两个结果 (`dp[i-2]` 和 `dp[i-1]`)。这种优化是可能的,因为在任何位置解码字符串的方式都仅取决于前两个位置的结果。 + +之前的自底向上解决方案使用了一个需要 O(n) 空间的数组。通过用两个变量替换数组,此解决方案减少了空间使用,而不会影响正确性或时间复杂度。当处理大型字符串时,此改进特别有用。 + +### 算法 + +1. 通过返回 `0` 来处理字符串为空的边缘情况。 +2. 初始化两个变量: + * `prev` 表示 `dp[i-2]`,对于空字符串的基本情况,设置为 `1`。 + * `curr` 表示 `dp[i-1]`,如果第一个字符不是 `'0'`,则设置为 `1`,否则设置为 `0`。 +3. 从索引 `2` 迭代到 `str.length`: + * 初始化一个临时变量 `temp` 来存储当前结果。 + * 如果当前字符不是 `'0'`,则将 `curr` 添加到 `temp` 以进行单数字解码。 + * 提取最后两个字符作为两位数。如果它在 `10` 和 `26` 之间,则将 `prev` 添加到 `temp` 以进行两位数解码。 + * 将 `prev` 更新为 `curr`,将 `curr` 更新为 `temp` 以进行下一次迭代。 +4. 返回 `curr` 的值,其中包含解码整个字符串的方式的数量。 + + {decodeMessageBottomUpConstantSpace} + +### Big-O 分析 + +* **时间复杂度:O(n)**。该解决方案遍历字符串一次。 +* **空间复杂度:O(1)**。仅使用两个变量来存储中间结果。 diff --git a/contents/questions/algo/string-palindrome/description/en-US.langnostic.json b/contents/questions/algo/string-palindrome/description/en-US.langnostic.json new file mode 100644 index 000000000..d7eaf684e --- /dev/null +++ b/contents/questions/algo/string-palindrome/description/en-US.langnostic.json @@ -0,0 +1,33 @@ +{ + "frontmatter": { + "title": "6e500bff", + "excerpt": "92049ab4" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "38f706a", + "9b32b375", + "2d96efbe", + "7f86a7c3", + "d068a43f", + "b2065fc", + "2cb8fded" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "38f706a", + "9b32b375", + "2d96efbe", + "7f86a7c3", + "d068a43f", + "b2065fc", + "2cb8fded" + ] + } + } +} diff --git a/contents/questions/algo/string-palindrome/description/zh-CN.mdx b/contents/questions/algo/string-palindrome/description/zh-CN.mdx new file mode 100644 index 000000000..a0a995917 --- /dev/null +++ b/contents/questions/algo/string-palindrome/description/zh-CN.mdx @@ -0,0 +1,22 @@ +--- +title: 字符串回文 +excerpt: 实现一个函数来确定一个字符串是否是回文 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个字符串 `str`,确定它是否是回文。如果是,则返回 `true`,否则返回 `false`。 + +如果一个字符串在将所有大写字母更改为小写字母并丢弃所有非字母数字字符后,正向和反向读取时保持相同,则该字符串是回文。字母数字字符由字母和数字组成。 + +### 输入 + +- `str: string`: 字符串 + + + +### 约束 + +- 1 <= `str.length` <= 1000 +- 字符串 `str` 仅由可打印的 ASCII 字符组成 diff --git a/contents/questions/algo/string-palindrome/solution/en-US.langnostic.json b/contents/questions/algo/string-palindrome/solution/en-US.langnostic.json new file mode 100644 index 000000000..75f0d8204 --- /dev/null +++ b/contents/questions/algo/string-palindrome/solution/en-US.langnostic.json @@ -0,0 +1,46 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "b18bc1f6", + "ad69302a", + "fd37fcb5", + "b68df8f8", + "1d817dc7", + "fa9da9c3", + "8e2de8c8", + "6982aae4", + "5a8b6354", + "5c148b9f", + "b68df8f8", + "dacb2402", + "a7d9db2b", + "8e2de8c8", + "f15aaaa2" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "b18bc1f6", + "ad69302a", + "fd37fcb5", + "b68df8f8", + "1d817dc7", + "fa9da9c3", + "8e2de8c8", + "6982aae4", + "5a8b6354", + "5c148b9f", + "b68df8f8", + "dacb2402", + "a7d9db2b", + "8e2de8c8", + "f15aaaa2" + ] + } + } +} diff --git a/contents/questions/algo/string-palindrome/solution/zh-CN.mdx b/contents/questions/algo/string-palindrome/solution/zh-CN.mdx new file mode 100644 index 000000000..5af6ba232 --- /dev/null +++ b/contents/questions/algo/string-palindrome/solution/zh-CN.mdx @@ -0,0 +1,52 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import isStringPalindrome from '../setup/src/string-palindrome.ts'; +import isStringPalindromeUsingTwoPointers from '../setup/src/string-palindrome-using-two-pointers.ts'; + +## 1. 比较逆序 + +该解决方案通过仅关注字符串的字母数字字符并忽略大小写敏感度来确定字符串是否为回文。关键的直觉是,回文的字符序列在反转时必须相同。因此,此方法将反转输入字符串,并将反转后的字符串与原始字符串进行比较,以检查它们是否相似。为了简化比较,该解决方案通过过滤掉非字母数字字符并将剩余字符转换为小写来预处理字符串。这创建了字符串的规范化版本,使得反向比较变得简单。 + +### 算法 + +1. 初始化一个空字符串 `filteredChars`,用于存储小写的字母数字字符。 +2. 遍历输入字符串的每个字符: + * 如果该字符是字母数字,则将其转换为小写并追加到 `filteredChars`。 +3. 使用 `split`、`reverse` 和 `join` 反转 `filteredChars` 字符串。 +4. 将原始的 `filteredChars` 与反转后的版本进行比较。 + * 如果它们相同,则返回 `true`,因为该字符串是回文。 + * 否则,返回 `false`。 + + + {isStringPalindrome} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。过滤字符和反转字符串都需要线性时间。 +* **空间复杂度:O(n)**。`filteredChars` 和 `reversedChars` 字符串都需要 O(n) 空间。 + +## 2. 使用双指针 + +此解决方案通过避免创建反转字符串来改进前一个解决方案,这需要额外的时间和空间。双指针方法通过使用两个索引(一个从字符串的开头开始,另一个从结尾开始,并向中心移动)来确定字符串是否为回文。这消除了反转字符串的需要,因为可以直接在对应的字符之间进行比较。 + +### 算法 + +1. 初始化两个指针: + * 一个 (`left`) 在字符串的开头。 + * 另一个 (`right`) 在字符串的结尾。 +2. 当 `left` 小于 `right` 时: + * 通过将 `left` 向前移动并将 `right` 向后移动,跳过非字母数字字符,直到找到有效的字符。 + * 将两个字符转换为小写,以进行不区分大小写的比较。 + * 如果 `left` 和 `right` 的字符不相等,则返回 `false`。 + * 否则,将 `left` 向前移动并将 `right` 向后移动以继续比较。 +3. 如果所有字符都匹配,则返回 `true`。 + + + {isStringPalindromeUsingTwoPointers} + + +### Big-O 分析 + +* **时间复杂度:O(n)**。字符串中的每个字符都会被处理一次。 +* **空间复杂度:O(1)**。双指针方法使用常量额外空间用于变量。 diff --git a/contents/questions/algo/string-palindromic-substrings/description/en-US.langnostic.json b/contents/questions/algo/string-palindromic-substrings/description/en-US.langnostic.json new file mode 100644 index 000000000..fc0bca7ae --- /dev/null +++ b/contents/questions/algo/string-palindromic-substrings/description/en-US.langnostic.json @@ -0,0 +1,35 @@ +{ + "frontmatter": { + "title": "15b0e3bd", + "excerpt": "2294301f" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "4cb1a838", + "d304c3e9", + "6ff8539a", + "2d96efbe", + "7f86a7c3", + "d068a43f", + "b2065fc", + "de1a3d3c" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "4cb1a838", + "d304c3e9", + "6ff8539a", + "2d96efbe", + "7f86a7c3", + "d068a43f", + "b2065fc", + "de1a3d3c" + ] + } + } +} diff --git a/contents/questions/algo/string-palindromic-substrings/description/zh-CN.mdx b/contents/questions/algo/string-palindromic-substrings/description/zh-CN.mdx new file mode 100644 index 000000000..4cb7cd079 --- /dev/null +++ b/contents/questions/algo/string-palindromic-substrings/description/zh-CN.mdx @@ -0,0 +1,24 @@ +--- +title: 回文子串 +excerpt: 实现一个函数来计算字符串中所有回文子串的数量 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个字符串`str`,确定作为回文的子串的总数。 + +一个**回文**是指从前往后和从后往前读都一样的字符序列(例如,`racecar`)。 + +一个**子串**是字符串中任何连续的字符序列。例如,字符串`abc`的子串是`a`、`b`、`c`、`ab`、`bc`和`abc`。子串是通过选择一个起始点和一个结束点形成的,中间没有跳过字符。 + +### 输入 + +- `str: string`: 字符串 + + + +### 约束 + +- 1 <= `str.length` <= 1000 +- `str` 仅包含小写英文字母 diff --git a/contents/questions/algo/string-palindromic-substrings/solution/en-US.langnostic.json b/contents/questions/algo/string-palindromic-substrings/solution/en-US.langnostic.json new file mode 100644 index 000000000..ed75bc3da --- /dev/null +++ b/contents/questions/algo/string-palindromic-substrings/solution/en-US.langnostic.json @@ -0,0 +1,68 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "74a51600", + "a8823c9b", + "ac1d2954", + "b68df8f8", + "d4e125ce", + "d9787568", + "8e2de8c8", + "db9896a9", + "e5dc1bc8", + "a0061bd0", + "2e3a5bad", + "b68df8f8", + "1853b2ac", + "f124ee8b", + "8e2de8c8", + "2ffe0cfd", + "13c70c97", + "4f41f53a", + "cb963ccb", + "b68df8f8", + "134915", + "b1d03266", + "171641b8", + "cfb135ea", + "8e2de8c8", + "cdac5d" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "74a51600", + "a8823c9b", + "ac1d2954", + "b68df8f8", + "d4e125ce", + "d9787568", + "8e2de8c8", + "db9896a9", + "e5dc1bc8", + "a0061bd0", + "2e3a5bad", + "b68df8f8", + "1853b2ac", + "f124ee8b", + "8e2de8c8", + "2ffe0cfd", + "13c70c97", + "4f41f53a", + "cb963ccb", + "b68df8f8", + "134915", + "b1d03266", + "171641b8", + "cfb135ea", + "8e2de8c8", + "cdac5d" + ] + } + } +} diff --git a/contents/questions/algo/string-palindromic-substrings/solution/zh-CN.mdx b/contents/questions/algo/string-palindromic-substrings/solution/zh-CN.mdx new file mode 100644 index 000000000..d1b6594a5 --- /dev/null +++ b/contents/questions/algo/string-palindromic-substrings/solution/zh-CN.mdx @@ -0,0 +1,98 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import palindromicSubstrings from '../setup/src/string-palindromic-substrings.ts'; +import palindromicSubstringsUsingDP from '../setup/src/string-palindromic-substrings-dp.ts'; +import palindromicSubstringsUsingBruteForce from '../setup/src/string-palindromic-substrings-bruteforce.ts'; + +## 1. 使用暴力方法 + +暴力方法会检查每个可能的子串,以确定它是否是回文。这是通过遍历所有可能的子串的起始和结束索引,并使用辅助函数来验证子串是否是回文来实现的。如果子串正向和反向读取相同,则该子串是回文。 + +### 算法 + +1. 定义一个辅助函数 `isPalindrome`: + * 接受字符串 `str`、起始索引 `low` 和结束索引 `high`。 + * 使用 `while` 循环比较 `low` 和 `high` 处的字符。 + * 如果字符不匹配,则返回 `false`。 + * 递增 `low` 并递减 `high` 以向中心移动。 + * 如果所有字符都匹配,则返回 `true`。 +2. 初始化一个变量 `ans` 来存储回文子串的计数。 +3. 使用嵌套循环: + * 外循环遍历子串的所有可能的起始索引 `low`。 + * 内循环遍历当前起始索引的所有可能的结束索引 `high`。 + * 对于每一对索引,使用 `isPalindrome` 函数检查子串是否是回文。 + * 如果子串是回文,则将 `ans` 增加 `1`。 +4. 将 `ans` 的值作为回文子串的总数返回。 + + + {palindromicSubstringsUsingBruteForce} + + +### Big-O 分析 + +* **时间复杂度:O(n3)**。有 O(n2) 个子串,并且检查每个子串是否为回文需要 O(n) 时间。 +* **空间复杂度:O(1)**。除了输入字符串和循环变量外,该算法使用恒定空间。 + +## 2. 使用动态规划 + +动态规划方法通过避免重复检查重叠的子串来改进朴素的暴力方法。关键的直觉是,如果一个子串的两个最外面的字符相同,并且内部子串(不包括外部字符)也是回文,则该子串是回文。使用动态规划表可以有效地捕获此递归属性。 + +`dp` 表存储了以索引 `i` 开头并以索引 `j` 结尾的子串是否是回文。这通过从较小的子串开始并使用它们的结果来求解较大的子串,从而消除了冗余的重新计算。 + +### 算法 + +1. 通过返回 `0` 来处理空字符串的基本情况。 +2. 初始化一个大小为 `n x n` 的二维数组 `dp`,并将所有值设置为 `false`。 +3. 遍历长度为 `1` 的子串的字符串: + * 对于所有索引 `i`,将 `dp[i][i]` 设置为 `true`,因为单字符子串始终是回文。 + * 增加每个单字符回文的计数 `ans`。 +4. 遍历长度为 `2` 的子串的字符串: + * 如果索引 `i` 和 `i + 1` 处的两个字符相等,则将 `dp[i][i + 1]` 设置为 `true`。 + * 增加每个双字符回文的计数 `ans`。 +5. 使用嵌套循环来评估长度为 `3` 或更大的子串: + * 对于以索引 `i` 开头并以索引 `j` 结尾的每个子串,如果满足以下条件,则将 `dp[i][j]` 设置为 `true`: + * `i` 和 `j` 处的字符相同。 + * `i` 和 `j` 之间的子串 (`dp[i + 1][j - 1]`) 也是回文。 + * 增加找到的每个回文的计数 `ans`。 +6. 将 `ans` 作为回文子串的总数返回。 + + + {palindromicSubstringsUsingDP} + + +### Big-O 分析 + +* **时间复杂度:O(n2)**。外循环遍历子串长度,内循环遍历子串的所有起始索引。 +* **空间复杂度:O(n2)**。`dp` 表需要 O(n2) 空间来存储所有子串的结果。 + +## 3. 使用回文的中心 + +从中心扩展方法通过关注回文的潜在中心来优化查找所有回文子串的过程。关键的直觉是,每个回文都可以从其中心向外扩展。中心可以是单个字符(对于奇数长度的回文)或一对连续字符(对于偶数长度的回文)。通过从每个中心迭代地扩展,这种方法避免了冗余计算,并且不需要使用额外的空间来存储动态规划表。 + +此方法通过减少空间使用来改进先前动态规划方法。它没有预先计算所有可能长度的回文子串,而是在扩展过程中直接计算回文。 + +### 算法 + +1. 初始化一个变量 `ans` 来存储回文子串的总数。 +2. 遍历字符串中的每个字符: + * 将当前索引处的字符视为奇数长度回文的中心,并使用相同的起始和结束索引调用辅助函数 `countPalindromesAroundCenter`。 + * 将当前字符和下一个字符视为偶数长度回文的中心,并使用连续索引作为起始和结束点调用辅助函数 `countPalindromesAroundCenter`。 +3. 将 `ans` 作为回文子串的总数返回。 + +#### 辅助函数:`countPalindromesAroundCenter` + +1. 接受字符串`str`、起始索引`low`和结束索引`high`作为输入。 +2. 初始化一个变量`ans`,用于存储扩展过程中找到的回文串的计数。 +3. 使用`while`循环向外扩展,只要: + * 索引`low`和`high`在字符串的范围内。 + * `low`和`high`处的字符匹配。 +4. 对于每个有效回文串,递增`ans`。 +5. 递减`low`并递增`high`以继续扩展。 +6. 返回计数`ans`。 + + {palindromicSubstrings} + +### Big-O 分析 + +* **时间复杂度:O(n2)**。对于每个字符,扩展在最坏的情况下可以跨越整个字符串,导致O(n)个中心有O(n)次扩展。 +* **空间复杂度:O(1)**。该算法使用常量额外空间用于变量,不需要额外的数据结构。 diff --git a/contents/questions/algo/string-segment-words/description/en-US.langnostic.json b/contents/questions/algo/string-segment-words/description/en-US.langnostic.json new file mode 100644 index 000000000..244a5fefe --- /dev/null +++ b/contents/questions/algo/string-segment-words/description/en-US.langnostic.json @@ -0,0 +1,37 @@ +{ + "frontmatter": { + "title": "aff925a6", + "excerpt": "af7ee255" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "b83ea59a", + "e54d0c33", + "2d96efbe", + "fce3c626", + "40808d83", + "7298b68", + "d068a43f", + "b2065fc", + "c719b66c" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "b83ea59a", + "e54d0c33", + "2d96efbe", + "fce3c626", + "40808d83", + "7298b68", + "d068a43f", + "b2065fc", + "c719b66c" + ] + } + } +} diff --git a/contents/questions/algo/string-segment-words/description/zh-CN.mdx b/contents/questions/algo/string-segment-words/description/zh-CN.mdx new file mode 100644 index 000000000..26f86248c --- /dev/null +++ b/contents/questions/algo/string-segment-words/description/zh-CN.mdx @@ -0,0 +1,29 @@ +--- +title: 单词分割 +excerpt: 实现一个函数来检查一个字符串是否可以由字典中的单词组成 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个字符串`str`和一个单词列表`dict`,确定`str`是否可以被分割成来自`dict`的一个或多个单词的序列。来自`dict`的单词可以在分割中重复使用。 + +如果可以分割`str`,则返回`true`,否则返回`false`。 + +### 输入 + +- `str: string`: 一个表示要分割的字符串的字符串 +- `dict: string[]`: 一个表示可用单词字典的字符串数组 + +### 注意事项 + +- 来自`dict`的单词可以在分割中多次使用 + + + +### 约束 + +- 1 <= `str.length` <= 300 +- 0 <= `dict.length` <= 300 +- 0 <= `dict[i].length` <= 300 +- `str` 和 `dict[i]` 仅由小写英文字母组成 diff --git a/contents/questions/algo/string-segment-words/solution/en-US.langnostic.json b/contents/questions/algo/string-segment-words/solution/en-US.langnostic.json new file mode 100644 index 000000000..ee8ea3b37 --- /dev/null +++ b/contents/questions/algo/string-segment-words/solution/en-US.langnostic.json @@ -0,0 +1,50 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "c50b1d5f", + "eb582080", + "5cd01342", + "adedb186", + "b68df8f8", + "f7701978", + "a2900b24", + "8e2de8c8", + "d7786bb0", + "bc315569", + "287df509", + "5876b813", + "b68df8f8", + "5d515ad0", + "97cc2b55", + "8e2de8c8", + "de9e52dd" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "c50b1d5f", + "eb582080", + "5cd01342", + "adedb186", + "b68df8f8", + "f7701978", + "a2900b24", + "8e2de8c8", + "d7786bb0", + "bc315569", + "287df509", + "5876b813", + "b68df8f8", + "5d515ad0", + "97cc2b55", + "8e2de8c8", + "de9e52dd" + ] + } + } +} diff --git a/contents/questions/algo/string-segment-words/solution/zh-CN.mdx b/contents/questions/algo/string-segment-words/solution/zh-CN.mdx new file mode 100644 index 000000000..d2a2fcd79 --- /dev/null +++ b/contents/questions/algo/string-segment-words/solution/zh-CN.mdx @@ -0,0 +1,60 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import segmentWords from '../setup/src/string-segment-words.ts'; +import segmentWordsBFS from '../setup/src/string-segment-words-bfs.js'; + +## 1. 使用动态规划 + +动态规划方法通过将字符串分割成更小的子问题来解决将字符串分割成给定字典中的单词的问题。 关键的直觉是,如果字符串的前缀可以被分割,并且剩余的子字符串存在于字典中,那么整个字符串就可以被分割。 使用 `dp` 数组来存储以每个位置结尾的子字符串是否可以被分割。 + +`dp[i]` 表示子字符串 `str[0...i-1]` 是否可以被分割成字典中的有效单词。 这种方法确保了重叠的子问题只被解决一次,避免了冗余的计算。 + +### 算法 + +1. 将单词字典转换为 `Set` 以便快速查找单词。 +2. 创建一个大小为 `str.length + 1` 的 `dp` 数组,并初始化为 `false`。 + * 将 `dp[0]` 设置为 `true`,因为空字符串总是可以被分割。 +3. 遍历字符串以检查以每个位置 `end` 结尾的子字符串: + * 对于每个 `end`,遍历子字符串的可能起始位置 `start`。 + * 检查子字符串 `str[start...end-1]` 是否存在于字典中,以及 `dp[start]` 是否为 `true`。 + * 如果两个条件都满足,则将 `dp[end]` 设置为 `true` 并跳出内循环。 +4. 返回 `dp[str.length]` 的值,该值指示整个字符串是否可以被分割。 + + + {segmentWords} + + +### Big-O 分析 + +* **时间复杂度:O(n.m.k)**。 检查子字符串是否存在于字典中的成本为 O(m.k),其中 `m` 是字典的大小,`k` 是平均单词长度。 由于有 O(n) 个状态需要计算,因此总的时间复杂度为 O(n.m.k)。 +* **空间复杂度:O(n)**。 `dp` 数组需要 O(n) 空间。 + +## 2. 使用 BFS + +广度优先搜索 (BFS) 方法通过将所有可能的分割作为图中的层来解决字符串分割问题。 关键的直觉是,该问题可以表示为从字符串的开头到结尾的导航,其中每个有效的子字符串对应于连接两个节点(索引)的边。 使用队列执行 BFS,从索引 `0` 开始,并探索字典中存在的所有可能的子字符串。 + +BFS 的使用确保了解决方案系统地检查所有有效路径。 为了防止冗余计算,使用 `seen` 集合来跟踪已访问的索引。 + +### 算法 + +1. 将字典 `dict` 转换为 `Set`,以实现 O(1) 平均时间复杂度查找。 +2. 检查字符串为空的基本情况。 如果字符串为空,则返回 `true`。 +3. 使用起始索引 `0` 和 `seen` 集合初始化一个队列,以跟踪已访问的索引。 +4. 执行 BFS: + * 出队队列的前一个元素,表示当前的起始索引。 + * 如果起始索引等于字符串的长度,则返回 `true`,因为字符串可以被分割。 + * 遍历从 `start + 1` 到 `str.length` 的所有可能的结束索引: + * 跳过已经在 `seen` 集合中的索引。 + * 如果从 `start` 到 `end` 的子字符串存在于字典中: + * 将 `end` 索引添加到队列中。 + * 将 `end` 索引标记为在 `seen` 集合中已访问。 +5. 如果队列已耗尽且未找到有效的分割,则返回 `false`。 + + + {segmentWordsBFS} + + +### Big-O 分析 + +* **时间复杂度:O(n3 + m⋅k)**。 有 O(n) 个节点,并且由于 `seen` 集合,每个节点最多访问一次。 在每个节点,算法遍历当前节点之前的节点 (O(n)) 并创建子字符串 (O(n)),从而导致每个节点 O(n2)。 因此,BFS 的成本为 O(n3)。 此外,从字典创建 `words` 集合的成本为 O(m⋅k),其中 `m` 是字典的大小,`k` 是平均单词长度。 +* **空间复杂度:O(n + m⋅k)**。 `queue` 和 `seen` 集合需要 O(n) 空间,而 `words` 集合需要 O(m⋅k) 空间。 diff --git a/contents/questions/algo/string-shortest-substring-containing-characters/description/en-US.langnostic.json b/contents/questions/algo/string-shortest-substring-containing-characters/description/en-US.langnostic.json new file mode 100644 index 000000000..f00330ee6 --- /dev/null +++ b/contents/questions/algo/string-shortest-substring-containing-characters/description/en-US.langnostic.json @@ -0,0 +1,37 @@ +{ + "frontmatter": { + "title": "9022aecf", + "excerpt": "e40f08cd" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "f42d4ffe", + "6ff8539a", + "2d96efbe", + "1400e8de", + "40808d83", + "ab0b19af", + "d068a43f", + "b2065fc", + "ec172cbf" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "f42d4ffe", + "6ff8539a", + "2d96efbe", + "1400e8de", + "40808d83", + "ab0b19af", + "d068a43f", + "b2065fc", + "ec172cbf" + ] + } + } +} diff --git a/contents/questions/algo/string-shortest-substring-containing-characters/description/zh-CN.mdx b/contents/questions/algo/string-shortest-substring-containing-characters/description/zh-CN.mdx new file mode 100644 index 000000000..881eb33bb --- /dev/null +++ b/contents/questions/algo/string-shortest-substring-containing-characters/description/zh-CN.mdx @@ -0,0 +1,27 @@ +--- +title: 包含字符的最短子字符串 +excerpt: 实现一个函数,返回包含来自另一个字符串的所有字符(包括重复字符)的字符串的最小子字符串 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定两个字符串`str1`和`str2`,返回`str1`的最小子字符串,该子字符串包含`str2`中的每个字符(包括重复字符)。如果不存在这样的子字符串,则返回一个空字符串。 + +一个**子字符串**是字符串中任何连续的字符序列。例如,字符串`abc`的子字符串是`a`、`b`、`c`、`ab`、`bc`和`abc`。子字符串是通过选择一个起始点和一个结束点形成的,中间没有跳过字符。 + +### 输入 + +- `str1`:一个字符串 +- `str2`:一个字符串 + +### 注意事项 + +- 如果存在多个解决方案,您可以返回其中任何一个 + + + +### 约束 + +- 1 <= `str1.length`,`str2.length` <= 10,000 +- `str1`和`str2`仅包含大写英文字母 diff --git a/contents/questions/algo/string-shortest-substring-containing-characters/solution/en-US.langnostic.json b/contents/questions/algo/string-shortest-substring-containing-characters/solution/en-US.langnostic.json new file mode 100644 index 000000000..b7485ffe9 --- /dev/null +++ b/contents/questions/algo/string-shortest-substring-containing-characters/solution/en-US.langnostic.json @@ -0,0 +1,50 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "fba60704", + "9669c350", + "9a62c624", + "78997b43", + "b68df8f8", + "bca345a1", + "7f6e6851", + "8e2de8c8", + "ae461c95", + "9e2b1d78", + "5eaf50aa", + "5f09076d", + "b68df8f8", + "a163ea0b", + "19517b81", + "8e2de8c8", + "476fc24d" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "fba60704", + "9669c350", + "9a62c624", + "78997b43", + "b68df8f8", + "bca345a1", + "7f6e6851", + "8e2de8c8", + "ae461c95", + "9e2b1d78", + "5eaf50aa", + "5f09076d", + "b68df8f8", + "a163ea0b", + "19517b81", + "8e2de8c8", + "476fc24d" + ] + } + } +} diff --git a/contents/questions/algo/string-shortest-substring-containing-characters/solution/zh-CN.mdx b/contents/questions/algo/string-shortest-substring-containing-characters/solution/zh-CN.mdx new file mode 100644 index 000000000..848292b02 --- /dev/null +++ b/contents/questions/algo/string-shortest-substring-containing-characters/solution/zh-CN.mdx @@ -0,0 +1,69 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import shortestSubstringContainingCharacters from '../setup/src/string-shortest-substring-containing-characters.ts'; + +import shortestSubstringContainingCharactersOptimized from '../setup/src/string-shortest-substring-containing-characters-optimized.ts'; + +## 1. 使用滑动窗口 + +该解决方案使用滑动窗口技术来查找 `str1` 中包含 `str2` 所有字符的最短子字符串。 关键的直觉是维护一个动态窗口,该窗口根据其是否满足包含 `str2` 中所有字符及其正确频率的要求来调整其大小和位置。 该算法动态地扩展或缩小窗口以找到最小的有效子字符串。 + +### 算法 + +1. 处理边缘情况: + * 如果任一字符串为空,则返回一个空字符串。 +2. 创建一个 `Map` `dictT` 来存储 `str2` 中每个字符的频率。 +3. 初始化变量: + * `required` 用于存储 `str2` 中唯一字符的数量。 + * 两个指针 `left` 和 `right` 用于滑动窗口。 + * `formed` 用于跟踪当前窗口中满足所需频率的唯一字符的数量。 + * `windowCounts` 用于跟踪当前窗口中的字符计数。 + * `ans` 用于存储找到的最小有效窗口,初始化为 `[-1, 0, 0]`(长度、左侧索引、右侧索引)。 +4. 通过递增 `right` 指针来扩展窗口: + * 将 `right` 处的字符添加到 `windowCounts`。 + * 如果当前字符的计数与其在 `dictT` 中的计数匹配,则递增 `formed`。 +5. 当 `formed` 等于 `required` 时,通过递增 `left` 指针来收缩窗口: + * 检查当前窗口是否小于先前找到的最小窗口。 如果是,则更新 `ans`。 + * 从 `windowCounts` 中删除 `left` 处的字符。 + * 如果字符的计数低于其在 `dictT` 中的计数,则递减 `formed`。 +6. 继续扩展和收缩,直到 `right` 到达 `str1` 的末尾。 +7. 返回与 `ans` 中最小窗口对应的子字符串,如果不存在有效窗口,则返回一个空字符串。 + + + {shortestSubstringContainingCharacters} + + +### Big-O 分析 + +* **时间复杂度:O(n + m)**。 `right` 指针遍历 `str1` (O(n)),`left` 指针根据需要收缩窗口。 `Map` 操作用于检查和更新计数,平均为 O(1)。 构造 `str2` 的频率映射需要 O(m),其中 `m` 是 `str2` 的长度。 +* **空间复杂度:O(n + m)**。 `windowCounts` 和 `dictT` 映射需要 O(n + m) 空间来存储字符频率。 + +## 2. 使用优化的滑动窗口 + +优化的滑动窗口方法通过过滤 `str1` 以仅包含 `str2` 中存在的字符来提高效率。 这减少了滑动窗口过程中所需的迭代和比较次数。 关键的直觉是,可以忽略 `str1` 中不相关的字符,因为它们不会有助于形成所需的子字符串。 通过使用过滤后的 `str1` 版本,该算法仅处理相关字符,这使其比之前的实现更快。 + +这种优化对于 `str1` 包含许多 `str2` 中不存在的字符的大型输入尤其有影响。 扩展和收缩窗口的逻辑保持不变,但由于过滤,操作次数减少了。 + +### 算法 + +1. 处理基本情况: + * 如果 `str1` 或 `str2` 为空,则返回一个空字符串。 +2. 为 `str2` 构建频率映射 `dictT`,以跟踪每个字符的所需计数。 +3. 过滤 `str1` 以仅包含 `str2` 中存在的字符,将它们存储为它们的索引和 `filteredStr1` 中的字符的元组。 +4. 初始化滑动窗口指针 `left` 和 `right`,一个变量 `formed` 用于跟踪满足其所需频率的字符,以及一个 `windowCounts` 映射以计算当前窗口中的字符。 +5. 使用滑动窗口: + * 通过递增 `right` 指针来扩展窗口。 + * 更新 `windowCounts` 并在 `right` 处的字符满足 `dictT` 中所需的计数时递增 `formed`。 + * 只要存在所有必需的字符,就通过递增 `left` 指针来收缩窗口: + * 如果当前窗口小于先前找到的窗口,则更新结果。 + * 减少从 `windowCounts` 中删除的字符的计数,如果它低于所需计数,则递减 `formed`。 +6. 返回与最小窗口对应的子字符串,如果未找到有效窗口,则返回一个空字符串。 + + + {shortestSubstringContainingCharactersOptimized} + + +### Big-O 分析 + +* **时间复杂度:O(n + m)**。 过滤 `str1` 所需的时间与 `str1` 的长度成正比,滑动窗口在过滤后的字符串上运行,其长度与 `str2` 中的字符数成正比。 +* **空间复杂度:O(n + m)**。 用于频率映射和窗口计数的空间与 `str2` 中的字符数成正比,而过滤后的 `str1` 版本使用的空间与 `str1` 的长度成正比。 diff --git a/contents/questions/algo/sum-without-addition/description/en-US.langnostic.json b/contents/questions/algo/sum-without-addition/description/en-US.langnostic.json new file mode 100644 index 000000000..99f208190 --- /dev/null +++ b/contents/questions/algo/sum-without-addition/description/en-US.langnostic.json @@ -0,0 +1,31 @@ +{ + "frontmatter": { + "title": "5b7fbc19", + "excerpt": "52a8eb36" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "6e5a2a3e", + "2d96efbe", + "b3b965b9", + "d068a43f", + "b2065fc", + "d38838d6" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "6e5a2a3e", + "2d96efbe", + "b3b965b9", + "d068a43f", + "b2065fc", + "d38838d6" + ] + } + } +} diff --git a/contents/questions/algo/sum-without-addition/description/zh-CN.mdx b/contents/questions/algo/sum-without-addition/description/zh-CN.mdx new file mode 100644 index 000000000..5596491db --- /dev/null +++ b/contents/questions/algo/sum-without-addition/description/zh-CN.mdx @@ -0,0 +1,20 @@ +--- +title: 无加法求和 +excerpt: 实现一个函数,无需使用 + 和 - 运算符即可找到两个整数的和 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定两个整数 `a` 和 `b`,在不使用加法或减法运算符的情况下计算它们的和。 + +### 输入 + +- `a: number`: 一个整数 +- `b: number`: 一个整数 + + + +### 约束 + +- -1000 <= `a`, `b` <= 1000 diff --git a/contents/questions/algo/sum-without-addition/solution/en-US.langnostic.json b/contents/questions/algo/sum-without-addition/solution/en-US.langnostic.json new file mode 100644 index 000000000..4ca577f33 --- /dev/null +++ b/contents/questions/algo/sum-without-addition/solution/en-US.langnostic.json @@ -0,0 +1,36 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "89fa7c40", + "2a3f6900", + "a8c0e6dd", + "b686252e", + "5f2b4ff6", + "b68df8f8", + "4006e6a", + "ab4c7dc6", + "8e2de8c8", + "9b231aed" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "89fa7c40", + "2a3f6900", + "a8c0e6dd", + "b686252e", + "5f2b4ff6", + "b68df8f8", + "4006e6a", + "ab4c7dc6", + "8e2de8c8", + "9b231aed" + ] + } + } +} diff --git a/contents/questions/algo/sum-without-addition/solution/zh-CN.mdx b/contents/questions/algo/sum-without-addition/solution/zh-CN.mdx new file mode 100644 index 000000000..874daeb4e --- /dev/null +++ b/contents/questions/algo/sum-without-addition/solution/zh-CN.mdx @@ -0,0 +1,32 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import sumWithoutAddition from '../setup/src/sum-without-addition.ts'; + +## 1. 使用位运算 + +给定的解决方案使用位运算来计算两个数字的和,而不使用加法运算符。 关键思想依赖于理解二进制加法的原理: + +* XOR 运算 (`^`) 执行加法,但不产生进位。 例如,在二进制中 `1 ^ 1 = 0` 且 `0 ^ 1 = 1`。 +* AND 运算 (`&`) 确定产生进位位的位置。 例如,在二进制中 `1 & 1 = 1` 且 `0 & 1 = 0`。 +* 左移运算 (`<<`) 将进位位移动到下一个更高的位置,以便在后续迭代中进行加法。 + +通过迭代地应用这些操作,算法处理进位位,直到没有进位,从而得到总和。 + +### 算法 + +1. 初始化 `carry` 变量以保存每次迭代中产生的进位位。 +2. 只要 `b` 中有要处理的位或有进位位,就继续循环。 +3. 使用 `a & b` 运算提取进位位并将结果存储在 `carry` 中。 +4. 使用 XOR 运算 (`a ^ b`) 计算和,不带进位位,并更新 `a`。 +5. 将 `carry` 左移一位 (`carry << 1`) 以使其与下一个更高的位对齐,并将结果分配给 `b`。 +6. 重复步骤 3–5,直到 `b` 和 `carry` 都为零。 +7. 返回 `a`,它保存最终的和。 + + + {sumWithoutAddition} + + +### Big-O 分析 + +* **时间复杂度:O(1)**。 每个整数包含 32 位。 +* **空间复杂度:O(1)**。 算法使用恒定空间,因为它直接对输入变量进行操作。 diff --git a/contents/questions/algo/task-coordination/description/en-US.langnostic.json b/contents/questions/algo/task-coordination/description/en-US.langnostic.json new file mode 100644 index 000000000..ce5ee0b7d --- /dev/null +++ b/contents/questions/algo/task-coordination/description/en-US.langnostic.json @@ -0,0 +1,33 @@ +{ + "frontmatter": { + "title": "d74e5355", + "excerpt": "2ac4164d" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "1643276", + "6e2ebdf3", + "2d96efbe", + "5c61e28b", + "d068a43f", + "b2065fc", + "97917793" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "1643276", + "6e2ebdf3", + "2d96efbe", + "5c61e28b", + "d068a43f", + "b2065fc", + "97917793" + ] + } + } +} diff --git a/contents/questions/algo/task-coordination/description/zh-CN.mdx b/contents/questions/algo/task-coordination/description/zh-CN.mdx new file mode 100644 index 000000000..7f746aa54 --- /dev/null +++ b/contents/questions/algo/task-coordination/description/zh-CN.mdx @@ -0,0 +1,24 @@ +--- +title: 任务协调 +excerpt: 实现一个函数,用于查找具有冷却时间的任务的最小间隔 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个任务列表,每个任务由一个字母(从 A 到 Z)表示,以及一个冷却时间 `k`。冷却时间指定同一任务的两次执行之间必须至少间隔 `k` 个时间单位。 + +确定完成所有任务所需的最小间隔数,同时确保在冷却期过去之前不会再次执行同一任务。 + +### 输入 + +- `tasks: string[]`: 字符数组,其中每个任务由一个字母 (A-Z) 表示 +- `k: number`: 一个整数,表示冷却时间,即同一任务两次执行之间的最小间隔数 + + + +### 约束 + +- 1 <= `tasks.length` <= 1000 +- `tasks[i]` 是一个大写英文字母 +- 0 <= `k` <= 100 diff --git a/contents/questions/algo/task-coordination/solution/en-US.langnostic.json b/contents/questions/algo/task-coordination/solution/en-US.langnostic.json new file mode 100644 index 000000000..3606d9851 --- /dev/null +++ b/contents/questions/algo/task-coordination/solution/en-US.langnostic.json @@ -0,0 +1,50 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "c883b7e3", + "1d11ee9b", + "3953c6b3", + "41eacdb8", + "1d3408f4", + "b68df8f8", + "634f6c02", + "41de6dd6", + "8e2de8c8", + "6b90da5a", + "2c57ee80", + "5329d62f", + "b68df8f8", + "9140543", + "74175296", + "8e2de8c8", + "108632fa" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "c883b7e3", + "1d11ee9b", + "3953c6b3", + "41eacdb8", + "1d3408f4", + "b68df8f8", + "634f6c02", + "41de6dd6", + "8e2de8c8", + "6b90da5a", + "2c57ee80", + "5329d62f", + "b68df8f8", + "9140543", + "74175296", + "8e2de8c8", + "108632fa" + ] + } + } +} diff --git a/contents/questions/algo/task-coordination/solution/zh-CN.mdx b/contents/questions/algo/task-coordination/solution/zh-CN.mdx new file mode 100644 index 000000000..042340812 --- /dev/null +++ b/contents/questions/algo/task-coordination/solution/zh-CN.mdx @@ -0,0 +1,56 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import taskCoordinator from '../setup/src/task-coordination.ts'; +import taskCoordinatorHeap from '../setup/src/task-coordination-heap.ts'; + +## 1. 使用贪心算法 + +此解决方案最大限度地减少了使用冷却期 `k` 执行一系列任务所需的时间,确保在 `k` 个间隔内不执行两个相同的任务。 核心思想是关注频率最高的任务,因为它们在调度过程中占主导地位。 这些任务必须尽可能均匀地分布,从而在调度中创建“分区”。 剩余的任务填补了这些分区之间的空白,减少了空闲时间。 + +频率最高的任务定义了调度的框架,因为它们的分布决定了所有其他任务的放置。 这些任务的每次出现至少间隔 `k` 个间隔。 如果有其他任务来填补这些空白,则空闲时间会减少;否则,空闲时隙仍然存在,从而增加了总时间。 + +贪心算法确保调度通过首先填补由最频繁的任务创建的空白来压缩。 这避免了不必要的空闲时间,并确保调度在保持尽可能短的同时遵守冷却约束。 + +### 算法 + +1. 初始化一个大小为 26 的数组 `counter` 以计算每个任务的频率。 +2. 遍历 `tasks` 数组以填充 `counter` 数组: + 1. 对于每个任务,增加其在 `counter` 中的频率计数。 + 2. 更新 `maximum` 以跟踪任何任务的最高频率。 + 3. 更新 `maxCount` 以计算有多少任务具有此最大频率。 +3. 计算分区数,即 `maximum - 1`。 +4. 计算每个分区的长度,即 `k - (maxCount - 1)`。 +5. 计算空槽总数,即 `partCount * partLength`。 +6. 计算可用任务数,即任务总数减去具有最大频率的任务。 +7. 计算空闲槽数,即 `Math.max(0, emptySlots - availableTasks)`。 +8. 将所需总时间作为 `tasks.length + idles` 返回。 + + {taskCoordinator} + +### Big-O 分析 + +* **时间复杂度:O(n)**。 遍历 `tasks` 数组和更新 `counter` 数组都需要线性时间。 +* **空间复杂度:O(1)**。 无论输入大小如何,`counter` 数组的大小都固定为 26。 + +## 2. 使用堆 + +关键思想是通过始终首先执行最频繁的任务来最大限度地减少空闲时间。 使用最大堆可以有效地检索剩余频率最高的任务。 这确保了以更高的频率执行任务,从而减少了空闲周期的可能性。 + +### 算法 + +1. 构建一个频率映射来计算每个任务的出现次数。 +2. 使用任务频率填充最大堆。堆的结构优先考虑最高频率的任务。 +3. 将总时间计数器初始化为 `0`。 +4. 当堆不为空时: + 1. 执行一个冷却周期(`n + 1` 次)的任务,或者直到堆为空。 + 2. 减少已执行任务的频率并存储更新后的频率。 + 3. 周期结束后,将更新后的任务频率重新插入堆中。 + 4. 更新总时间计数器。如果一个周期后堆为空,则仅添加该周期内执行的任务;否则,添加 `n + 1` 个时间单位,用于整个周期。 +5. 将总时间计数器作为结果返回。 + + {taskCoordinatorHeap} + +### Big-O 分析 + +* **时间复杂度:O(n log k)**。 迭代 `tasks` 数组并构建频率映射为 O(n)。 堆上的操作(插入和删除)为 O(log k),其中 `k` 是唯一任务的数量。 +* **空间复杂度:O(k)**。 堆和频率映射所需的存储空间与唯一任务的数量成正比,即 `k`。 diff --git a/contents/questions/algo/topological-sort/description/en-US.langnostic.json b/contents/questions/algo/topological-sort/description/en-US.langnostic.json new file mode 100644 index 000000000..1e8a604b3 --- /dev/null +++ b/contents/questions/algo/topological-sort/description/en-US.langnostic.json @@ -0,0 +1,45 @@ +{ + "frontmatter": { + "title": "d172af64", + "excerpt": "20a61bd3" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "1d67bd2b", + "493e8bd0", + "779cd401", + "cd258827", + "6f85802e", + "a8f76cea", + "b6e65f1e", + "c07043f8", + "9ce22eb3", + "d304c24", + "75b0ea57", + "207ecff9", + "40808d83", + "13b31c2d" + ] + }, + "targets": { + "zh-CN": [ + "1d67bd2b", + "493e8bd0", + "779cd401", + "cd258827", + "6f85802e", + "a8f76cea", + "b6e65f1e", + "c07043f8", + "9ce22eb3", + "d304c24", + "75b0ea57", + "207ecff9", + "40808d83", + "13b31c2d" + ] + } + } +} diff --git a/contents/questions/algo/topological-sort/description/zh-CN.mdx b/contents/questions/algo/topological-sort/description/zh-CN.mdx new file mode 100644 index 000000000..fdf3007d8 --- /dev/null +++ b/contents/questions/algo/topological-sort/description/zh-CN.mdx @@ -0,0 +1,69 @@ +--- +title: 拓扑排序 +excerpt: 实现一个执行拓扑排序的函数 +--- + +实现一个对有向图(邻接表格式)执行拓扑排序的函数,其中键表示节点,值是具有指向当前节点的传出边的节点数组。 + +## 例子 + +```js +const graph1 = { + A: ['B', 'C'], + B: ['C', 'D', 'E'], + C: ['F'], + D: [], + E: ['F'], + F: [], +}; +topologicalSort(graph1); // ['A', 'B', 'C', 'D', 'E', 'F'] + +const graph2 = { + A: ['B', 'C'], + B: ['C', 'D'], + C: ['D'], + D: ['E'], + E: ['F'], + F: [], +}; +topologicalSort(graph2); // ['A', 'B', 'C', 'D', 'E', 'F'] + +const graph3 = { + A: [], + B: ['A'], + C: ['B'], + D: ['C'], + E: ['D'], + F: ['E'], +}; +topologicalSort(graph3); // ['F', 'E', 'D', 'C', 'B', 'A'] +``` + +请注意,对于有向图,可以有多个有效的拓扑排序,但对于我们的测试用例,只有一个有效的解决方案。 + +在骨架代码的底部也为您提供了一个 `Queue` 数据结构。 + +## 回顾 + +拓扑排序是一种算法,用于以线性顺序对有向无环图 (DAG) 的元素进行排序,使得顺序遵循图中边定义的顺序。 + +理解这一点的一种简单方法是将图的节点视为任务,从节点 A 到节点 B 的边表示节点 B 依赖于节点 A。拓扑排序所做的是从图中生成一个节点数组,使得数组中节点的顺序遵循图中定义的所有依赖关系。 + +为什么拓扑排序只适用于 DAG 而不是任何图?这是因为图必须具有有向边才能表示依赖关系,并且是无环的(无环),因为任何环都将表示节点之间无法解析的依赖关系。 + +拓扑排序通常用于调度问题,例如调度具有依赖关系的作业,或在编译中,编译顺序由模块之间的依赖关系决定。 + +有很多方法可以实现拓扑排序,但一种简单直观的方法是使用 Kahn 算法,其工作原理如下: + +1. 初始化一个队列和一个列表来存储排序后的节点。 +2. 对于图中的每个节点,如果它没有入边,则将其添加到队列中。 +3. 当队列不为空时: +4. 从队列的前面取出一个节点。 +5. 将此节点添加到已排序节点的列表中。 +6. 对于此节点的每个子节点,将其入度(入边的数量)减 1。 +7. 如果子节点的入度变为 0,则将其添加到队列中。 +8. 如果排序列表的长度小于图中的节点数,这意味着图中存在一个循环,并且无法进行拓扑排序。 + +### 笔记 + +* 严格来说,我们也可以使用一个集合而不是一个队列。 diff --git a/contents/questions/algo/topological-sort/solution/en-US.langnostic.json b/contents/questions/algo/topological-sort/solution/en-US.langnostic.json new file mode 100644 index 000000000..d67ac8cd4 --- /dev/null +++ b/contents/questions/algo/topological-sort/solution/en-US.langnostic.json @@ -0,0 +1,54 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "f1d8300a", + "b8a2be1c", + "4cd64b66", + "ef0e1931", + "efaec79f", + "26e3ffe5", + "757bcc34", + "499e5031", + "f0ff4262", + "c998b811", + "a34a2355", + "bb1b042d", + "3aa1aede", + "dfae00c4", + "5de7759d", + "5b6426bb", + "7b475d47", + "83bc1f52", + "fa886d7a" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "f1d8300a", + "b8a2be1c", + "4cd64b66", + "ef0e1931", + "efaec79f", + "26e3ffe5", + "757bcc34", + "499e5031", + "f0ff4262", + "c998b811", + "a34a2355", + "bb1b042d", + "3aa1aede", + "dfae00c4", + "5de7759d", + "5b6426bb", + "7b475d47", + "83bc1f52", + "fa886d7a" + ] + } + } +} diff --git a/contents/questions/algo/topological-sort/solution/zh-CN.mdx b/contents/questions/algo/topological-sort/solution/zh-CN.mdx new file mode 100644 index 000000000..2d96251b8 --- /dev/null +++ b/contents/questions/algo/topological-sort/solution/zh-CN.mdx @@ -0,0 +1,48 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import topologicalSortJs from '../setup/src/topological-sort.js'; +import topologicalSortTs from '../setup/src/topological-sort.ts'; + +拓扑排序是一种算法,它产生有向无环图(DAG)的顶点的线性排序,使得对于每个有向边(u,v),顶点u在排序中位于顶点v之前。使用Kahn算法实现的拓扑排序具有线性时间复杂度,这使得它对于大型图相对有效。 + +## 澄清问题 + +如果未指定: + +* 输入和输出格式: + * 输入图应该表示为邻接矩阵、邻接表还是其他数据结构? + * 输出应该是拓扑顺序的节点列表还是表示节点拓扑顺序的整数数组? + +## 解决方案 + + + +## 边缘情况 + +* 没有边的图:返回一个空数组或适当的错误消息。 +* 带有循环的图:返回错误或空数组。 + +## Big-O 分析 + +让我们分析一下算法的时间和空间复杂度。 + +### 时间复杂度 + +使用Kahn算法实现的拓扑排序始终以O(V + E)的时间复杂度运行,其中V是图中顶点的数量(或节点),E是图中边的数量。 + +* 初始化`Map`对象以存储每个节点的传入和传出边的循环的时间复杂度为O(V),因为它访问了图的所有顶点(节点)一次。 +* 遍历输入图中的所有键,并且对于每个节点,将其邻居节点的`in`属性增加1的循环的时间复杂度为O(E),因为它访问了图的所有边一次。 +* 遍历节点,将所有`in: 0`的节点添加到队列中的循环的时间复杂度也为O(V),因为它访问了图的所有顶点一次。 +* while循环迭代直到队列不为空,其最大时间复杂度为O(V + E),因为它正在处理图的所有顶点和边。 + +总的来说,Kahn算法实现的的时间复杂度为O(V + E)。 + +### 空间复杂度 + +使用Kahn算法实现的拓扑排序的空间复杂度为O(V),其中V是图中顶点的数量(或节点)。 + +* Map数据结构“nodes”存储每个节点的属性,并占用O(V)空间。 +* 输出数组“order”占用O(V)空间,因为它存储所有节点的拓扑顺序。 +* 队列数据结构“queue”存储入度等于0的节点,这需要与输入数据成线性关系的空间,因此占用O(V)空间。 + +因此,该算法的空间复杂度为O(V)。 diff --git a/contents/questions/algo/trie-prefix-tree/description/en-US.langnostic.json b/contents/questions/algo/trie-prefix-tree/description/en-US.langnostic.json new file mode 100644 index 000000000..0b1d0a999 --- /dev/null +++ b/contents/questions/algo/trie-prefix-tree/description/en-US.langnostic.json @@ -0,0 +1,39 @@ +{ + "frontmatter": { + "title": "8816732b", + "excerpt": "bfb6359b" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "e86b01d", + "523889fd", + "f3f0813e", + "2d96efbe", + "fd93838c", + "4a4f0b47", + "a46e2dce", + "d068a43f", + "b2065fc", + "b890ebe7" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "e86b01d", + "523889fd", + "f3f0813e", + "2d96efbe", + "fd93838c", + "4a4f0b47", + "a46e2dce", + "d068a43f", + "b2065fc", + "b890ebe7" + ] + } + } +} diff --git a/contents/questions/algo/trie-prefix-tree/description/zh-CN.mdx b/contents/questions/algo/trie-prefix-tree/description/zh-CN.mdx new file mode 100644 index 000000000..5fcea5bb8 --- /dev/null +++ b/contents/questions/algo/trie-prefix-tree/description/zh-CN.mdx @@ -0,0 +1,33 @@ +--- +title: Trie(前缀树) +excerpt: 实现一个具有插入、搜索和以...开头功能的 trie 前缀树 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +一个 [trie](https://en.wikipedia.org/wiki/Trie)(发音为“try”),也称为前缀树,是一种树状数据结构,旨在有效地管理和查询字符串。它对于自动完成和拼写检查等任务特别有用。 + +实现一个具有以下方法的 `Trie` 类: + +- `insert(word: string): void`: 将给定的单词添加到 `Trie` +- `search(word: string): boolean`: 检查指定的单词是否存在于 trie 中,如果存在则返回 `true`,否则返回 `false` +- `startsWith(prefix: string): boolean`: 检查 Trie 中是否有以给定前缀开头的单词,如果存在这样的单词则返回 `true`,否则返回 `false` + +### 输入 + +`Trie` 实例将根据这些参数调用其方法: + +- `methods: string[]`: `Trie` 方法名称的数组 +- `params: string[]`: 字符串数组 + +`methods[i]` 将使用 `params[i]` 调用。 + + + +### 约束 + +- 1 <= `word.length` <= 100 +- 1 <= `prefix.length` <= 100 +- `word` 和 `prefix` 仅包含小写英文字母 +- 1 <= `methods.length` <= 1000 diff --git a/contents/questions/algo/trie-prefix-tree/solution/en-US.langnostic.json b/contents/questions/algo/trie-prefix-tree/solution/en-US.langnostic.json new file mode 100644 index 000000000..f45520843 --- /dev/null +++ b/contents/questions/algo/trie-prefix-tree/solution/en-US.langnostic.json @@ -0,0 +1,34 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "b0111e74", + "751e921d", + "1bbde372", + "594afe45", + "b68df8f8", + "801d60ec", + "679fa5a0", + "8e2de8c8", + "3a1ff224" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "b0111e74", + "751e921d", + "1bbde372", + "594afe45", + "b68df8f8", + "801d60ec", + "679fa5a0", + "8e2de8c8", + "3a1ff224" + ] + } + } +} diff --git a/contents/questions/algo/trie-prefix-tree/solution/zh-CN.mdx b/contents/questions/algo/trie-prefix-tree/solution/zh-CN.mdx new file mode 100644 index 000000000..81b677a67 --- /dev/null +++ b/contents/questions/algo/trie-prefix-tree/solution/zh-CN.mdx @@ -0,0 +1,41 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import trie from '../setup/src/trie-prefix-tree.ts'; + +## 1. 使用 Trie 数据结构 + +Trie(前缀树)是一种树状数据结构,用于高效存储和检索字符串,尤其是在处理前缀时。Trie 中的每个节点代表一个字符,并存储对其子节点的引用。这种结构可以实现快速操作,例如插入单词、搜索单词以及检查任何单词是否以给定前缀开头。 + +Trie 使用具有指向其子节点的链接的根节点进行初始化。每个链接对应于从 'a' 到 'z' 的一个字符。单词逐个字符地插入到 Trie 中,如果字符不存在,则创建新的子节点。搜索操作遍历 Trie 以检查单词或前缀的所有字符是否存在,而每个节点的 `isEnd` 标志指示该节点是否标记单词的结尾。该设计有效地处理涉及前缀的操作,因为共享前缀仅存储一次。 + +### 算法 + +1. **插入**: + + * 从根节点开始。 + * 对于单词中的每个字符,检查节点是否包含该字符的链接。 + * 如果没有,创建一个新节点并将其添加为子节点。 + * 移动到子节点,并对所有字符重复。 + * 使用 `isEnd` 标志将最后一个节点标记为单词的结尾。 + +2. **搜索**: + + * 使用单词的字符遍历 Trie。 + * 如果未找到任何字符,则该单词不存在。 + * 检查最后一个节点是否代表单词的结尾。 + +3. **StartsWith**: + * 使用前缀的字符遍历 Trie。 + * 如果找到所有字符,则前缀存在于 Trie 中。 + + + {trie} + + +### Big-O 分析 + +* **时间复杂度**: + * 插入:O(m),其中 `m` 是要插入的单词的长度。 + * 搜索:O(m),其中 `m` 是要搜索的单词的长度。 + * StartsWith:O(m),其中 `m` 是前缀的长度。 +* **空间复杂度**:O(n),其中 `n` 是所有插入单词中的字符总数。每个字符都需要在 Trie 中有一个节点,并且共享前缀可以减少冗余。 diff --git a/contents/questions/algo/triplet-sum/description/en-US.langnostic.json b/contents/questions/algo/triplet-sum/description/en-US.langnostic.json new file mode 100644 index 000000000..a1aadb98e --- /dev/null +++ b/contents/questions/algo/triplet-sum/description/en-US.langnostic.json @@ -0,0 +1,35 @@ +{ + "frontmatter": { + "title": "816a6b6a", + "excerpt": "e63b0800" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "1e074a42", + "2d96efbe", + "d9c0d67b", + "40808d83", + "c2fb8d3d", + "d068a43f", + "b2065fc", + "b1a3677b" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "1e074a42", + "2d96efbe", + "d9c0d67b", + "40808d83", + "c2fb8d3d", + "d068a43f", + "b2065fc", + "b1a3677b" + ] + } + } +} diff --git a/contents/questions/algo/triplet-sum/description/zh-CN.mdx b/contents/questions/algo/triplet-sum/description/zh-CN.mdx new file mode 100644 index 000000000..378069f9e --- /dev/null +++ b/contents/questions/algo/triplet-sum/description/zh-CN.mdx @@ -0,0 +1,24 @@ +--- +title: 三元组之和 +excerpt: 实现一个函数,找到所有和为 0 且索引不同的唯一三元组。 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +给定一个整数数组 `numbers`,返回所有三元组 `[numbers[i], numbers[j], numbers[k]]`,使得 `i`、`j` 和 `k` 是不同的索引,并且它们的值总和为 0。确保解集中不包含重复的三元组。 + +### 输入 + +- `numbers: number[]`: 整数数组 + +### 注意事项 + +- 输出应按排序顺序排列 + + + +### 约束 + +- 3 <= `numbers.length` <= 1000 +- -10,000 <= `numbers[i]` <= 10,000 diff --git a/contents/questions/algo/triplet-sum/solution/en-US.langnostic.json b/contents/questions/algo/triplet-sum/solution/en-US.langnostic.json new file mode 100644 index 000000000..8def32ade --- /dev/null +++ b/contents/questions/algo/triplet-sum/solution/en-US.langnostic.json @@ -0,0 +1,46 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "6a5ef292", + "63eea27e", + "4e760160", + "b68df8f8", + "f4510094", + "55f0d33", + "8e2de8c8", + "92e3237e", + "2873f17a", + "d1179d89", + "b68df8f8", + "8da231ed", + "27d43b37", + "8e2de8c8", + "2ab0d7c5" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "6a5ef292", + "63eea27e", + "4e760160", + "b68df8f8", + "f4510094", + "55f0d33", + "8e2de8c8", + "92e3237e", + "2873f17a", + "d1179d89", + "b68df8f8", + "8da231ed", + "27d43b37", + "8e2de8c8", + "2ab0d7c5" + ] + } + } +} diff --git a/contents/questions/algo/triplet-sum/solution/zh-CN.mdx b/contents/questions/algo/triplet-sum/solution/zh-CN.mdx new file mode 100644 index 000000000..5f0d340b2 --- /dev/null +++ b/contents/questions/algo/triplet-sum/solution/zh-CN.mdx @@ -0,0 +1,59 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import tripletSum from '../setup/src/triplet-sum.ts'; +import tripletSumBruteForce from '../setup/src/triplet-sum-brute-force.ts'; + +## 1. 暴力解法 + +目标是在一个数组中找到所有和为零的唯一三元组。 这种方法是使用三个嵌套循环来探索三个数字的每一种组合。 检查每个组合是否总和为零。 使用 `Set` 通过将它们转换为字符串来存储唯一的三元组,确保避免重复。 对三元组进行排序有助于保持顺序,并确保在添加到 `Set` 时正确检测到重复项。 + +### 算法 + +1. 初始化一个 `Set` 来存储唯一的三元组。 +2. 使用三个嵌套循环遍历数组: + 1. 最外层循环固定三元组的第一个数字。 + 2. 第二个循环固定三元组的第二个数字。 + 3. 最内层循环选择三元组的第三个数字。 +3. 对于每一种三个数字的组合,检查它们的总和是否等于零。 +4. 如果总和为零,对三元组进行排序以保持顺序,并将其转换为字符串以存储在 `Set` 中。 +5. 完成迭代后,通过解析存储的字符串将 `Set` 转换回数组。 +6. 对生成的三元组数组进行排序,以满足有序结果的要求。 +7. 返回已排序的三元组数组。 + + + {tripletSumBruteForce} + + +### Big-O 分析 + +* **时间复杂度:O(n3)**。 三个嵌套循环遍历数组中所有可能的三个数字的组合。 +* **空间复杂度:O(k)**。 用于存储唯一三元组的 `Set` 和生成的数组所需的空间与唯一三元组的数量成正比,即 `k`。 + +## 2. 双指针 + +双指针方法通过减少不必要的计算来改进暴力解法。 对数组进行排序可以通过使用两个指针(`j` 和 `k`)根据当前总和相互移动来有效地搜索总和为零的三元组。 这消除了对第三个嵌套循环的需求,并通过跳过重复项来避免冗余检查。 通过专注于补充固定起始元素(`i`)的数字对,该解决方案显着降低了时间复杂度。 + +### 算法 + +1. 对输入数组进行升序排序,以允许有效的双指针遍历。 +2. 初始化一个空数组 `ans` 来存储三元组。 +3. 使用索引 `i` 遍历排序后的数组: + 1. 跳过重复元素,以确保每个起始元素都是唯一的。 + 2. 设置两个指针:`j` 在 `i` 之后的索引处,`k` 在数组的最后一个索引处。 +4. 当 `j` 小于 `k` 时: + 1. 计算 `numbers[i]`、`numbers[j]` 和 `numbers[k]` 的总和。 + 2. 如果总和等于零: + * 将三元组 `[numbers[i], numbers[j], numbers[k]]` 添加到 `ans`。 + * 移动 `j` 向前,移动 `k` 向后,跳过重复元素。 + 3. 如果总和小于零,则递增 `j` 以增加总和。 + 4. 如果总和大于零,则递减 `k` 以减少总和。 +5. 返回包含所有唯一三元组的 `ans` 数组。 + + + {tripletSum} + + +### Big-O 分析 + +* **时间复杂度:O(n2)**。 对数组进行排序需要 O(n log n),并且对每个元素进行双指针遍历需要 O(n),结果为 O(n2)。 +* **空间复杂度:O(1)**。 除了输出数组之外,该解决方案使用恒定量的额外空间。 diff --git a/contents/questions/algo/word-finder/description/en-US.langnostic.json b/contents/questions/algo/word-finder/description/en-US.langnostic.json new file mode 100644 index 000000000..7f7b19429 --- /dev/null +++ b/contents/questions/algo/word-finder/description/en-US.langnostic.json @@ -0,0 +1,37 @@ +{ + "frontmatter": { + "title": "89374ebd", + "excerpt": "93816c1a" + }, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c1f3c799", + "7e4c2c54", + "dcb9519f", + "2d96efbe", + "eefad215", + "8173d4a6", + "a46e2dce", + "d068a43f", + "b2065fc", + "9bd3a4a6" + ] + }, + "targets": { + "zh-CN": [ + "c1f3c799", + "7e4c2c54", + "dcb9519f", + "2d96efbe", + "eefad215", + "8173d4a6", + "a46e2dce", + "d068a43f", + "b2065fc", + "9bd3a4a6" + ] + } + } +} diff --git a/contents/questions/algo/word-finder/description/zh-CN.mdx b/contents/questions/algo/word-finder/description/zh-CN.mdx new file mode 100644 index 000000000..9b1802df3 --- /dev/null +++ b/contents/questions/algo/word-finder/description/zh-CN.mdx @@ -0,0 +1,30 @@ +--- +title: 单词查找器 +excerpt: 实现一个可以添加单词并支持通配符搜索的数据结构 +--- + +import MDXTestExamples from 'MDXTestExamples'; +import runTestCases from '../setup/src/run.tests.json'; + +实现允许添加单词和搜索单词的 `WordFinder` 类。它具有以下方法: + +- `addWord(word: string)`: 将一个单词添加到数据结构中 +- `search(query: string)`: 检查任何已添加的单词是否与给定的单词匹配。`query` 可以包含点 `.`,它可以匹配任何字母 + +### 输入 + +`WordFinder` 实例将根据以下内容使用各种参数调用其方法: + +- `methods: string[]`: 方法名称数组 +- `params: string[]`: 字符串数组 + +`methods[i]` 将使用 `params[i]` 调用。 + + + +### 约束 + +- 1 <= `word.length` <= 25 +- 1 <= `methods.length` <= 1000 +- 搜索查询可能包含 `.` 和小写英文字母,每个查询最多 2 个点 +- 每个单词仅包含小写英文字母 diff --git a/contents/questions/algo/word-finder/solution/en-US.langnostic.json b/contents/questions/algo/word-finder/solution/en-US.langnostic.json new file mode 100644 index 000000000..04f97e513 --- /dev/null +++ b/contents/questions/algo/word-finder/solution/en-US.langnostic.json @@ -0,0 +1,34 @@ +{ + "frontmatter": {}, + "content": { + "source": { + "locale": "en-US", + "hashes": [ + "c340c67a", + "d7d2ac5d", + "bd1e8138", + "dc638", + "52d9224", + "b68df8f8", + "9f8bb211", + "cdd031f6", + "8e2de8c8", + "5e29f4d2" + ] + }, + "targets": { + "zh-CN": [ + "c340c67a", + "d7d2ac5d", + "bd1e8138", + "dc638", + "52d9224", + "b68df8f8", + "9f8bb211", + "cdd031f6", + "8e2de8c8", + "5e29f4d2" + ] + } + } +} diff --git a/contents/questions/algo/word-finder/solution/zh-CN.mdx b/contents/questions/algo/word-finder/solution/zh-CN.mdx new file mode 100644 index 000000000..fbb3a514e --- /dev/null +++ b/contents/questions/algo/word-finder/solution/zh-CN.mdx @@ -0,0 +1,36 @@ +import MDXCodeBlock from 'MDXCodeBlock'; + +import designAddAndSearchWordsDataStructure from '../setup/src/word-finder.ts'; + +## 1. 使用Trie + +使用Trie(前缀树)构建`WordFinder`,以高效地存储和搜索单词。`TrieNode`结构由一个`Map`组成,用于存储子节点,以及一个布尔标志,指示该节点是否代表单词的结尾。这种设计对于解决涉及使用`.`进行精确匹配或通配符模式的单词搜索问题特别有效。 + +主要思想是逐个节点地将单词添加到Trie中,其中每个字符代表Trie中的一个路径。搜索是递归完成的,对`.`字符进行特殊处理,它充当通配符。`.`可以匹配任何字符,并递归地探索所有可能的子节点以找到匹配项。 + +### 算法 + +1. **添加单词**: + + * 从根节点开始。 + * 对于单词中的每个字符,检查它是否存在于当前节点的`children`映射中。 + * 如果不存在,创建一个新的`TrieNode`并将其添加到映射中。 + * 移动到下一个节点并重复,直到完全添加单词。 + * 通过将`word`标志设置为`true`,将最终节点标记为单词的结尾。 + +2. **搜索**: + * 使用辅助函数`searchInNode`递归遍历Trie。 + * 对于每个字符: + * 如果它存在于当前节点的`children`中,则移动到子节点。 + * 如果字符是`.`,则迭代所有子节点并递归搜索剩余的子字符串。 + * 如果字符不存在且不是`.`,则返回`false`。 + * 在单词的末尾,如果当前节点标记单词的结尾,则返回`true`。 + + + {designAddAndSearchWordsDataStructure} + + +### Big-O 分析 + +* **时间复杂度**: O(m),对于没有点的明确定义的单词,其中`m`是单词的长度。对于“未定义”的单词,时间复杂度为O(n.26m),其中n是键的数量,m是未定义单词的长度。这表示搜索未定义单词的最坏情况,其中包含m个递归调用,因为该单词比所有插入的键长一个字符。 +* **空间复杂度**: O(1) 用于搜索没有点的“定义明确”的单词。对于“未定义”的单词,空间复杂度可以增加到O(m)以适应递归堆栈。