Processing math: 100%
1 Star 2 Fork 1

mirrors/azl397985856-leetcode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
.github
.vscode
91
assets
backlog
collections
daily
problems
1.two-sum.en.md
1.two-sum.md
100.same-tree.md
1004.max-consecutive-ones-iii.md
101.symmetric-tree.md
101.symmetrical-tree.en.md
1011.capacity-to-ship-packages-within-d-days-en.md
1011.capacity-to-ship-packages-within-d-days.md
1014.best-sightseeing-pair.md
1015.smallest-integer-divisible-by-k.md
1019.next-greater-node-in-linked-list.md
102.binary-tree-level-order-traversal.md
1020.number-of-enclaves.md
1023.camelcase-matching.md
103.binary-tree-zigzag-level-order-traversal.md
1031.maximum-sum-of-two-non-overlapping-subarrays.md
1032.stream-of-characters.md
104.maximum-depth-of-binary-tree.en.md
104.maximum-depth-of-binary-tree.md
1043.partition-array-for-maximum-sum.md
1053.previous-permutation-with-one-swap.md
108.convert-sorted-array-to-binary-search-tree.en.md
108.convert-sorted-array-to-binary-search-tree.md
109.Convert-Sorted-List-to-Binary-Search-Tree.md
11.container-with-most-water.md
1104.path-in-zigzag-labelled-binary-tree.md
1128.number-of-equivalent-domino-pairs.md
1129.shortest-path-with-alternating-colors.md
113.path-sum-ii.md
1131.maximum-of-absolute-value-expression.md
1138.alphabet-board-path.md
1168.optimize-water-distribution-in-a-village-en.md
1168.optimize-water-distribution-in-a-village.md
1178.number-of-valid-words-for-each-puzzle.md
1186.maximum-subarray-sum-with-one-deletion.md
1203.sort-items-by-groups-respecting-dependencies.md
121.best-time-to-buy-and-sell-stock.en.md
121.best-time-to-buy-and-sell-stock.md
1218.longest-arithmetic-subsequence-of-given-difference.md
122.best-time-to-buy-and-sell-stock-ii.en.md
122.best-time-to-buy-and-sell-stock-ii.md
1227.airplane-seat-assignment-probability.md
124.binary-tree-maximum-path-sum.md
125.valid-palindrome.en.md
125.valid-palindrome.md
1255.maximum-score-words-formed-by-letters.md
1260.shift-2d-grid.en.md
1260.shift-2d-grid.md
1261.find-elements-in-a-contaminated-binary-tree.md
1262.greatest-sum-divisible-by-three.md
128.longest-consecutive-sequence.md
129.sum-root-to-leaf-numbers.md
1297.maximum-number-of-occurrences-of-a-substring.md
130.surrounded-regions.md
131.palindrome-partitioning.md
1310.xor-queries-of-a-subarray.md
132.palindrome-partitioning-ii.md
1332.remove-palindromic-sequences.en.md
1332.remove-palindromic-subsequences.md
1334.find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance.md
136.single-number.en.md
136.single-number.md
1371.find-the-longest-substring-containing-vowels-in-even-counts.en.md
1371.find-the-longest-substring-containing-vowels-in-even-counts.md
1381.design-a-stack-with-increment-operation.md
139.word-break.md
140.word-break-ii.md
142.Linked-List-Cycle-II.md
1423.maximum-points-you-can-obtain-from-cards.md
1435.jump-game-iv.md
1438.longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit.md
144.binary-tree-preorder-traversal.md
1449.form-largest-integer-with-digits-that-add-up-to-target.md
145.binary-tree-postorder-traversal.md
146.lru-cache.md
147.insertion-sort-list.md
1494.parallel-courses-ii.md
15.3sum.md
150.evaluate-reverse-polish-notation.md
152.maximum-product-subarray.md
1521.find-a-value-of-a-mysterious-function-closest-to-target.md
1526.minimum-number-of-increments-on-subarrays-to-form-a-target-array.md
153.find-minimum-in-rotated-sorted-array.md
154.find-minimum-in-rotated-sorted-array-ii.md
155.min-stack.en.md
155.min-stack.md
1558.minimum-numbers-of-function-calls-to-make-target-array.md
1574.shortest-subarray-to-be-removed-to-make-array-sorted.md
1589.maximum-sum-obtained-of-any-permutation.md
160.Intersection-of-Two-Linked-Lists.en.md
160.Intersection-of-Two-Linked-Lists.md
1631.path-with-minimum-effort.md
1638.count-substrings-that-differ-by-one-character.md
1639.number-of-ways-to-form-a-target-string-given-a-dictionary.md
1649.create-sorted-array-through-instructions.md
1658.minimum-operations-to-reduce-x-to-zero.md
167.two-sum-ii-input-array-is-sorted.en.md
167.two-sum-ii-input-array-is-sorted.md
1671.minimum-number-of-removals-to-make-mountain-array.md
169.majority-element.en.md
169.majority-element.md
1697.checking-existence-of-edge-length-limited-paths.md
17.Letter-Combinations-of-a-Phone-Number.md
1713.minimum-operations-to-make-a-subsequence.md
172.factorial-trailing-zeroes.en.md
172.factorial-trailing-zeroes.md
1723.find-minimum-time-to-finish-all-jobs.md
1737.change-minimum-characters-to-satisfy-one-of-three-conditions.md
1770.maximum-score-from-performing-multiplication-operations.md
1787.make-the-xor-of-all-segments-equal-to-zero.md
1793.maximum-score-of-a-good-subarray.md
1834.single-threaded-cpu.md
1835.find-xor-sum-of-all-pairs-bitwise-and.md
1871.jump-game-vii.md
1872.stone-game-viii.md
1899.merge-triplets-to-form-target-triplet.md
19.removeNthNodeFromEndofList.md
190.reverse-bits.en.md
190.reverse-bits.md
1904.the-number-of-full-rounds-you-have-played.md
1906.minimum-absolute-difference-queries.md
191.number-of-1-bits.en.md
191.number-of-1-bits.md
1970.last-day-where-you-can-still-cross.md
198.house-robber.en.md
198.house-robber.md
199.binary-tree-right-side-view.md
2.add-two-numbers.en.md
2.add-two-numbers.md
20.valid-parentheses.md
20.valid-parents.en.md
200.number-of-islands.md
2007.find-original-array-from-doubled-array.md
2008.maximum-earnings-from-taxi.md
2009.minimum-number-of-operations-to-make-array-continuous.md
201.bitwise-and-of-numbers-range.md
2025.maximum-number-of-ways-to-partition-an-array.md
203.remove-linked-list-elements.en.md
203.remove-linked-list-elements.md
2030.smallest-k-length-subsequence-with-occurrences-of-a-letter.md
206.reverse-linked-list.en.md
206.reverse-linked-list.md
208.implement-trie-prefix-tree.md
209.minimum-size-subarray-sum.md
21.merge-two-sorted-lists.en.md
21.merge-two-sorted-lists.md
2102.sequentially-ordinal-rank-tracker.md
211.add-and-search-word-data-structure-design.md
212.word-search-ii.md
2141.maximum-running-time-of-n-computers.md
215.kth-largest-element-in-an-array.md
2172.count-good-triplets-in-an-array.md
219.contains-duplicate-ii.en.md
219.contains-duplicate-ii.md
22.generate-parentheses.md
220.contains-duplicate-iii.md
2209.minimum-white-tiles-after-covering-with-carpets.md
221.maximal-square.md
226.invert-binary-tree.en.md
226.invert-binary-tree.md
227.basic-calculator-ii.md
2281.sum-of-total-strength-of-wizards.md
229.majority-element-ii.md
23.merge-k-sorted-lists.md
230.kth-smallest-element-in-a-bst.md
2306.naming-a-company.md
2312.selling-pieces-of-wood.md
232.implement-queue-using-stacks.en.md
232.implement-queue-using-stacks.md
236.lowest-common-ancestor-of-a-binary-tree.md
238.product-of-array-except-self.md
239.sliding-window-maximum.md
24.swapNodesInPairs.md
240.search-a-2-d-matrix-ii.md
25.reverse-nodes-in-k-groups-en.md
25.reverse-nodes-in-k-groups.md
2591.distribute-money-to-maximum-children.md
2592.maximize-greatness-of-an-array.md
2593.find-score-of-an-array-after-marking-all-elements.md
26.remove-duplicates-from-sorted-array.en.md
26.remove-duplicates-from-sorted-array.md
263.ugly-number.en.md
263.ugly-number.md
279.perfect-squares.md
2817.minimum-absolute-difference-between-elements-with-constraint.md
283.move-zeroes.en.md
283.move-zeroes.md
2842.count-k-subsequences-of-a-string-with-maximum-beauty.md
2865.beautiful-towers-i.md
2866.beautiful-towers-ii.md
29.divide-two-integers.md
2939.maximum-xor-product.md
295.find-median-from-data-stream.md
297.serialize-and-deserialize-binary-tree.md
2972.count-the-number-of-incremovable-subarrays-ii.md
3.longest-substring-without-repeating-characters.md
30.substring-with-concatenation-of-all-words.md
301.remove-invalid-parentheses.md
3027.find-the-number-of-ways-to-place-people-ii.md
3041.maximize-consecutive-elements-in-an-array-after-modification.md
3082.find-the-sum-of-the-power-of-all-subsequences.md
309.best-time-to-buy-and-sell-stock-with-cooldown.md
31.next-permutation.md
3108.minimum-cost-walk-in-weighted-graph.md
312.burst-balloons.md
32.longest-valid-parentheses.md
322.coin-change.md
3229.minimum-operations-to-make-array-equal-to-target.md
324.wiggle-sort-ii.md
328.odd-even-linked-list.md
33.search-in-rotated-sorted-array.md
330.patching-array.md
331.verify-preorder-serialization-of-a-binary-tree.md
3336.find-the-number-of-subsequences-with-equal-gcd.md
334.increasing-triplet-subsequence.md
3347.maximum-frequency-of-an-element-after-performing-operations-ii.md
335.self-crossing.md
337.house-robber-iii.md
3377.digit-operations-to-make-two-integers-equal.md
342.power-of-four.en.md
342.power-of-four.md
343.integer-break.md
349.intersection-of-two-arrays.en.md
349.intersection-of-two-arrays.md
365.water-and-jug-problem.md
371.sum-of-two-integers.en.md
371.sum-of-two-integers.md
378.kth-smallest-element-in-a-sorted-matrix.md
380.insert-delete-getrandom-o1.md
385.mini-parser.md
39.combination-sum.md
394.decode-string.md
4.median-of-two-sorted-arrays.md
40.combination-sum-ii.md
401.binary-watch.en.md
401.binary-watch.md
416.partition-equal-subset-sum.md
42.trapping-rain-water.en.md
42.trapping-rain-water.md
424.longest-repeating-character-replacement.md
437.path-sum-iii.en.md
437.path-sum-iii.md
438.find-all-anagrams-in-a-string.md
445.add-two-numbers-ii.md
454.4-Sum-ii.en.md
454.4-sum-ii.md
455.AssignCookies.en.md
455.AssignCookies.md
456.132-pattern.md
457.circular-array-loop.md
46.permutations.md
460.lfu-cache.md
464.can-i-win.md
47.permutations-ii.md
470.implement-rand10-using-rand7.md
472.concatenated-words.md
473.matchsticks-to-square.md
474.ones-and-zeros-en.md
48.rotate-image.md
480.sliding-window-median.md
483.smallest-good-base.md
488.zuma-game.md
49.group-anagrams.md
493.reverse-pairs.md
494.target-sum.md
5.longest-palindromic-substring.md
50.pow-x-n.md
501.Find-Mode-in-Binary-Search-Tree-en.md
504.base-7.md
513.find-bottom-left-tree-value.md
516.longest-palindromic-subsequence.md
518.coin-change-2.md
52.N-Queens-II.md
525.contiguous-array.md
53.maximum-sum-subarray-cn.en.md
53.maximum-sum-subarray-cn.md
53.maximum-sum-subarray-en.md
547.friend-circles-en.md
547.number-of-provinces.md
55.jump-game.md
56.merge-intervals.md
560.subarray-sum-equals-k.en.md
560.subarray-sum-equals-k.md
5640.maximum-xor-with-an-element-from-array.md
57.insert-interval.md
575.distribute-candies.en.md
575.distribute-candies.md
5775.minimum-skips-to-arrive-at-meeting-on-time.md
5935.find-good-days-to-rob-the-bank.md
5936.detonate-the-maximum-bombs.md
5965.intervals-between-identical-elements.md
60.permutation-sequence.md
606.construct-string-from-binary-tree.md
609.find-duplicate-file-in-system.md
61.Rotate-List.md
611.valid-triangle-number.md
62.unique-paths.md
6201.maximize-number-of-subsequences-in-a-string.md
63.unique-paths-ii.md
65.valid-number.md
66.plus-one.en.md
66.plus-one.md
661.image-smoother.md
664.strange-printer.md
665.non-decreasing-array.md
673.number-of-longest-increasing-subsequence.md
679.24-game.md
686.repeated-string-match.md
710.random-pick-with-blacklist.md
714.best-time-to-buy-and-sell-stock-with-transaction-fee.md
715.range-module.md
718.maximum-length-of-repeated-subarray.md
721.accounts-merge.md
726.number-of-atoms.md
73.set-matrix-zeroes.md
735.asteroid-collision.md
75.sort-colors.md
754.reach-a-number.md
768.max-chunks-to-make-sorted-ii.md
78.subsets-en.md
78.subsets.md
785.is-graph-bipartite.md
79.word-search-en.md
79.word-search.md
790.domino-and-tromino-tiling.md
799.champagne-tower.md
80.remove-duplicates-from-sorted-array-ii.md
801.minimum-swaps-to-make-sequences-increasing.md
805.split-array-with-same-average.md
816.ambiguous-coordinates.md
820.short-encoding-of-words.md
821.shortest-distance-to-a-character.en.md
821.shortest-distance-to-a-character.md
838.push-dominoes.md
839.similar-string-groups.md
84.largest-rectangle-in-histogram.md
85.maximal-rectangle.md
86.partition-list.md
87.scramble-string.md
873.length-of-longest-fibonacci-subsequence.md
874.walking-robot-simulation.en.md
874.walking-robot-simulation.md
875.koko-eating-bananas.md
877.stone-game.md
88.merge-sorted-array.en.md
88.merge-sorted-array.md
886.possible-bipartition.md
887.super-egg-drop.md
895.maximum-frequency-stack.md
898.bitwise-ors-of-subarrays.md
90.subsets-ii-en.md
90.subsets-ii.md
900.rle-iterator.md
909.snakes-and-ladders.md
91.decode-ways.md
911.online-election.md
912.sort-an-array.md
918.maximum-sum-circular-subarray.md
92.reverse-linked-list-ii.md
932.beautiful-array.md
935.knight-dialer.md
94.binary-tree-inorder-traversal.md
947.most-stones-removed-with-same-row-or-column.md
95.unique-binary-search-trees-ii.md
959.regions-cut-by-slashes.md
96.unique-binary-search-trees.md
975.odd-even-jump.md
978.longest-turbulent-subarray.md
98.validate-binary-search-tree.md
987.vertical-order-traversal-of-a-binary-tree.md
995.minimum-number-of-k-consecutive-bit-flips.md
997.find-the-town-judge.md
Bus-Fare.md
Connected-Road-to-Destination.md
Every-Sublist-Min-Sum.md
Increasing-Digits.md
Kth-Pair-Distance.md
Largest-Equivalent-Set-of-Pairs.md
Longest-Contiguously-Strictly-Increasing-Sublist-After-Deletion.md
Longest-Matrix-Path-Length.md
Maximize-the-Number-of-Equivalent-Pairs-After-Swaps.md
Minimum-Dropping-Path-Sum.md
Minimum-Light-Radius.md
Number-Stream-to-Intervals.md
Number-of-Substrings-with-Single-Character-Difference.md
Sort-String-by-Flipping.md
Ticket-Order.md
Triple-Inversion.md
binode-lcci.en.md
binode-lcci.md
consecutive-wins.md
get-kth-magic-number-lcci.md
lcp20.meChtZ.md
lcp21.Za25hA.md
max-black-square-lcci.md
sub-sort-lcci.md
selected
templates
thinkings
.gitignore
.mdl_style.rb
.mdlrc
.nojekyll
CONTRIBUTING.en.md
CONTRIBUTING.md
Kapture 2020-08-19 at 11.37.36.gif
LICENSE.txt
README.en.md
README.md
SUMMARY.md
_config.yml
book.json
cover.jpg
donation.md
epilogue.md
introduction.md
package.json
thanksGiving.md
thanksGiving2.md
thanksGiving3.md
yarn.lock
克隆/下载
65.valid-number.md 8.61 KB
一键复制 编辑 原始数据 按行查看 历史
robot 提交于 2年前 . fix: 图床修复

题目地址(65. 有效数字)

https://leetcode-cn.com/problems/valid-number/

题目描述

有效数字(按顺序)可以分成以下几个部分:

一个 小数 或者 整数
(可选)一个 'e' 或 'E' ,后面跟着一个 整数

小数(按顺序)可以分成以下几个部分:

(可选)一个符号字符('+' 或 '-')
下述格式之一:
至少一位数字,后面跟着一个点 '.'
至少一位数字,后面跟着一个点 '.' ,后面再跟着至少一位数字
一个点 '.' ,后面跟着至少一位数字

整数(按顺序)可以分成以下几个部分:

(可选)一个符号字符('+' 或 '-')
至少一位数字

部分有效数字列举如下:

["2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7", "+6e-1", "53.5e93", "-123.456e789"]

部分无效数字列举如下:

["abc", "1a", "1e", "e3", "99e2.5", "--6", "-+3", "95a54e53"]

给你一个字符串 s ,如果 s 是一个 有效数字 ,请返回 true 。

 

示例 1:

输入:s = "0"
输出:true


示例 2:

输入:s = "e"
输出:false


示例 3:

输入:s = "."
输出:false


示例 4:

输入:s = ".1"
输出:true


 

提示:

1 <= s.length <= 20
s 仅含英文字母(大写和小写),数字(0-9),加号 '+' ,减号 '-' ,或者点 '.' 。

前置知识

  • 暂无

公司

  • 暂无

三个变量一次遍历

思路

我们可以直接进行一次遍历,边遍历边判断是否合法。

如果要边遍历边判断是否合法则需要记录一些关键信息。比如,当我遍历途中遇到了 .,那么我实际上需要知道一些信息,比如前面是否已经出现过 . 了。如果已经出现过了,那么就可以得出结论,该数字非法。

除了前面是否出现 . 这样的信息,我们还需要关注其他信息。具体地,我们需要关注:

  • .
  • e/E
  • 前面是否有数字

以上三个信息。 我们可以用三个变量,分别表示上一次遇到其的位置(索引),用 -1 表示还没有遇到。

实际上,这道题的关键点就是分析出哪些是非法,这样不是非法的,那么就是合法的。 之所以如此是因为合法的实在是太多了,我们没有办法一一判断,而只能从非法的角度入手。而非法的情况比较多,如何分类是个问题,这也是本题是困难难度的原因。

让我们来分析一下非法的情景。

  • 点前面有 e 或者 点,比如 1.1.1 或者 3e5.2
  • e 前面有 e ,比如 e12e。或者 e 前面没有数字,比如 e123
  • + - 前面要么是 e,要么其位于第一位
  • 出现了非法字符。也就是出现了除了 +-eE 数字. 之外的字符

代码上,我们可以使用三个变量:

  1. last_dot 上一次遇到的 . 的位置
  2. last_e 上一次遇到的 e/E 的位置
  3. last_d 上一次遇到的数字的位置

接下来我们需要遍历字符串 s,遍历的同时记得更新三个变量。

  • 如果我们遇到了字符 ".",那么需要前面没有 ".",也不能有 e/E,否则就不合法。
  • 如果遇到了 e/E,那么前面不能有 e/E。除此之前前面还有有数字才行。
  • 如果遇到了 +-,要么它是第一个字符,要么它前面是 e/E,否则不能合法
  • 其他非数字字符均为不合法

关键点

  • 分析非法的情况,用三个变量记录上一次出现的点,指数,数字的位置来复制判断

代码

class Solution:
    def isNumber(self, s: str) -> bool:
        last_dot = last_e = last_d = -1
        for i, c in enumerate(s):
            if c.isdigit():
                last_d = i
            elif c == '.':
                if last_dot != -1 or last_e != -1: return False
                last_dot = i
            elif c.lower() == 'e':
                if last_d == -1 or last_e != -1: return False
                last_e = i
            elif c == '+' or c == '-':
                if i == 0 or s[i-1].lower() == 'e':
                    continue
                else:
                    return False
            else:
                return False

        return s[-1].isdigit() or (s[-1] == '.' and last_d != -1)

复杂度分析

令 n 为数组长度。

  • 时间复杂度:O(n)
  • 空间复杂度:O(1)

状态机

思路

对于状态机,我们需要解决的就是:

  1. 状态有哪些
  2. 选择有哪些

和动态规划是类似的

对于这道题来说,打底的状态就是各种字符的类型。即:

  • 数字
  • .
  • eE
  • +-

打底就是这四种。

我们没有必要将 eE 或者 +- 进行区分,这是因为在这里二者的逻辑不会有差别。

那么这四种就够了。这是不够的。这是因为题目描述决定的。比如题目说了 e 后面不能是小数。 那么对于 . 来说,

  • 我们就需要分裂 为两种状态: e 前面的 . 和 e 后面的 .。
  • 类似地,+- 号,我们需要区分是第一位还是 e 后面的(紧邻),这是因为第一位后面可以跟 . ,而 e 后面紧邻的不可以。
  • 数字也是一样。 由于 e 后面不能有点,也需要进行类似的分裂

最后一个比较容易漏掉,我们需要一种数字状态,这个数字状态后面只能跟数字,不能跟其他。比如 +2e+3 ,这个时候的 3 后面就只能是数字了,其他都是非法的。

对于这道题来说:

  • 图中黄色的四个部分就是选择。由于 +-,以及 [1-9] 对我们的算法没有影响,因此没有单独抽离出来,而是将其归为一类。
  • 图中虚线部分就是状态。

不难看出,"." 前后的状态选择是不同的。因此除了:"+-", "[1-9]", "e/E", "." 这几种基本状态,还要分别对 [1-9], e/E 进行区分是 “.”前还是后。从左到右我将其进行编号,靠左的是 1,靠右的是 2, 因此就有了 sign1,digit1, exp, D digit2 exp sign2 D 的状态命名。

注意这里是 D,不是 digit2。因为 digit2 可以接 E/e,因此需要单独定义一种状态

另外由于:dot 前面和后面必须有至少一个数字,并且有没有数字对选择也有影响,因此我们也需要对此区分。我这里用 dot1 表示前面有数字的 dot,dot2 表示前面没有数字的 dot

关于如何转化,我就不一一分析了,大家直接看代码吧。虽然思路不难理解,但是细节还是蛮多的,大家自己写写就知道了。

关键点

  • 建立状态机模型
  • 如果知道一共有多少状态

代码

代码上,我们 xxx1 表示前面的 xxx,xxx2 表示后面的 xxx。D 表示只能跟数字

  • 语言支持:Python3

Python3 Code:


class Solution:
    def isNumber(self, s: str) -> bool:
        # 任何状态机的核心都是建立如下的状态机模型
        states = {
            "start": {"SIGN":"sign1",  "DIGIT":"digit1",  "DOT":"dot1"},
            "sign1": {"DIGIT":"digit1",  "DOT":"dot1"},
            "sign2": {"DIGIT":"D"},
            "digit1": {"DIGIT":"digit1",  "DOT":"dot2",  "EXP":"exp",  "END": True},
            "digit2": {"DIGIT":"digit2",  "EXP":"exp",  "END": True},
            "dot1": {"DIGIT":"digit2"}, # 前面没数字
            "dot2": {"DIGIT":"digit2",  "EXP":"exp",  "END": True}, # 前面有数字
            "exp": {"SIGN":"sign2",  "DIGIT":"D"},
            "D": {"DIGIT":"D",  "END": True}
        }

        def get(ch):
            if ch == ".": return "DOT"
            elif ch in "+-": return "SIGN"
            elif ch in "Ee": return "EXP"
            elif ch.isdigit(): return "DIGIT"

        state = "start"
        for c in s:
            state = states[state].get(get(c))
            if not state: return False

        return "END" in states[state]

复杂度分析

令 n 为数组长度。

  • 时间复杂度:O(n)
  • 空间复杂度:虽然使用了 states 存放状态,但是其不会随着数字增大而变大,而是一个定值,因此空间复杂度为 O(1)

此题解由 力扣刷题插件 自动生成。

力扣的小伙伴可以关注我,这样就会第一时间收到我的动态啦~

以上就是本文的全部内容了。大家对此有何看法,欢迎给我留言,我有时间都会一一查看回答。更多算法套路可以访问我的 LeetCode 题解仓库:https://github.com/azl397985856/leetcode 。 目前已经 40K star 啦。大家也可以关注我的公众号《力扣加加》带你啃下算法这块硬骨头。

关注公众号力扣加加,努力用清晰直白的语言还原解题思路,并且有大量图解,手把手教你识别套路,高效刷题。

Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/minhanghuang/azl397985856-leetcode.git
git@gitee.com:minhanghuang/azl397985856-leetcode.git
minhanghuang
azl397985856-leetcode
azl397985856-leetcode
master

搜索帮助