1 Star 2 Fork 5

LilithSangreal/LeetCode-Solutions

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
C++
Golang
Java
MySQL
Python
01-matrix.py
1-bit-and-2-bit-characters.py
132-pattern.py
2-keys-keyboard.py
24-game.py
3sum-closest.py
3sum-smaller.py
3sum-with-multiplicity.py
3sum.py
4-keys-keyboard.py
4sum-ii.py
4sum.py
accounts-merge.py
add-and-search-word-data-structure-design.py
add-binary.py
add-bold-tag-in-string.py
add-digits.py
add-one-row-to-tree.py
add-strings.py
add-to-array-form-of-integer.py
add-two-numbers-ii.py
add-two-numbers.py
adding-two-negabinary-numbers.py
additive-number.py
advantage-shuffle.py
alien-dictionary.py
all-nodes-distance-k-in-binary-tree.py
all-oone-data-structure.py
all-paths-from-source-lead-to-destination.py
all-paths-from-source-to-target.py
all-possible-full-binary-trees.py
ambiguous-coordinates.py
android-unlock-patterns.py
arithmetic-slices-ii-subsequence.py
arithmetic-slices.py
arranging-coins.py
array-nesting.py
array-of-doubled-pairs.py
array-partition-i.py
assign-cookies.py
asteroid-collision.py
available-captures-for-rook.py
average-of-levels-in-binary-tree.py
backspace-string-compare.py
bag-of-tokens.py
balanced-binary-tree.py
base-7.py
baseball-game.py
basic-calculator-ii.py
basic-calculator-iii.py
basic-calculator-iv.py
basic-calculator.py
battleships-in-a-board.py
beautiful-arrangement-ii.py
beautiful-arrangement.py
beautiful-array.py
best-meeting-point.py
best-sightseeing-pair.py
best-time-to-buy-and-sell-stock-ii.py
best-time-to-buy-and-sell-stock-iii.py
best-time-to-buy-and-sell-stock-iv.py
best-time-to-buy-and-sell-stock-with-cooldown.py
best-time-to-buy-and-sell-stock-with-transaction-fee.py
best-time-to-buy-and-sell-stock.py
binary-gap.py
binary-number-with-alternating-bits.py
binary-prefix-divisible-by-5.py
binary-search-tree-iterator.py
binary-search-tree-to-greater-sum-tree.py
binary-search.py
binary-string-with-substrings-representing-1-to-n.py
binary-subarrays-with-sum.py
binary-tree-cameras.py
binary-tree-inorder-traversal.py
binary-tree-level-order-traversal-ii.py
binary-tree-level-order-traversal.py
binary-tree-longest-consecutive-sequence-ii.py
binary-tree-longest-consecutive-sequence.py
binary-tree-maximum-path-sum.py
binary-tree-paths.py
binary-tree-postorder-traversal.py
binary-tree-preorder-traversal.py
binary-tree-pruning.py
binary-tree-right-side-view.py
binary-tree-tilt.py
binary-tree-upside-down.py
binary-tree-vertical-order-traversal.py
binary-tree-zigzag-level-order-traversal.py
binary-trees-with-factors.py
binary-watch.py
bitwise-and-of-numbers-range.py
bitwise-ors-of-subarrays.py
boats-to-save-people.py
bold-words-in-string.py
bomb-enemy.py
boundary-of-binary-tree.py
brick-wall.py
bricks-falling-when-hit.py
broken-calculator.py
buddy-strings.py
bulb-switcher-ii.py
bulb-switcher.py
bulls-and-cows.py
burst-balloons.py
bus-routes.py
camelcase-matching.py
campus-bikes-ii.py
campus-bikes.py
can-i-win.py
can-place-flowers.py
candy-crush.py
candy.py
capacity-to-ship-packages-within-d-days.py
car-fleet.py
card-flipping-game.py
cat-and-mouse.py
chalkboard-xor-game.py
champagne-tower.py
cheapest-flights-within-k-stops.py
check-completeness-of-a-binary-tree.py
check-if-word-is-valid-after-substitutions.py
cherry-pickup.py
circular-array-loop.py
climbing-stairs.py
clone-graph.py
closest-binary-search-tree-value-ii.py
closest-binary-search-tree-value.py
closest-leaf-in-a-binary-tree.py
clumsy-factorial.py
coin-change-2.py
coin-change.py
coin-path.py
coloring-a-border.py
combination-sum-ii.py
combination-sum-iii.py
combination-sum-iv.py
combination-sum.py
combinations.py
compare-version-numbers.py
complement-of-base-10-integer.py
complete-binary-tree-inserter.py
complex-number-multiplication.py
concatenated-words.py
confusing-number.py
consecutive-numbers-sum.py
construct-binary-search-tree-from-preorder-traversal.py
construct-binary-tree-from-inorder-and-postorder-traversal.py
construct-binary-tree-from-preorder-and-inorder-traversal.py
construct-binary-tree-from-preorder-and-postorder-traversal.py
construct-binary-tree-from-string.py
construct-quad-tree.py
construct-string-from-binary-tree.py
construct-the-rectangle.py
contain-virus.py
container-with-most-water.py
contains-duplicate-ii.py
contains-duplicate-iii.py
contains-duplicate.py
contiguous-array.py
continuous-subarray-sum.py
convert-a-number-to-hexadecimal.py
convert-binary-search-tree-to-sorted-doubly-linked-list.py
convert-bst-to-greater-tree.py
convert-sorted-array-to-binary-search-tree.py
convert-sorted-list-to-binary-search-tree.py
convert-to-base-2.py
convex-polygon.py
copy-list-with-random-pointer.py
count-and-say.py
count-binary-substrings.py
count-complete-tree-nodes.py
count-different-palindromic-subsequences.py
count-numbers-with-unique-digits.py
count-of-range-sum.py
count-of-smaller-numbers-after-self.py
count-primes.py
count-the-repetitions.py
count-univalue-subtrees.py
counting-bits.py
couples-holding-hands.py
course-schedule-ii.py
course-schedule-iii.py
course-schedule.py
cousins-in-binary-tree.py
cracking-the-safe.py
create-maximum-number.py
custom-sort-string.py
cut-off-trees-for-golf-event.py
daily-temperatures.py
data-stream-as-disjoint-intervals.py
decode-string.py
decode-ways-ii.py
decode-ways.py
decoded-string-at-index.py
degree-of-an-array.py
delete-and-earn.py
delete-columns-to-make-sorted-ii.py
delete-columns-to-make-sorted-iii.py
delete-columns-to-make-sorted.py
delete-node-in-a-bst.py
delete-node-in-a-linked-list.py
delete-operation-for-two-strings.py
design-circular-deque.py
design-circular-queue.py
design-compressed-string-iterator.py
design-excel-sum-formula.py
design-hashmap.py
design-hashset.py
design-hit-counter.py
design-in-memory-file-system.py
design-linked-list.py
design-log-storage-system.py
design-phone-directory.py
design-search-autocomplete-system.py
design-snake-game.py
design-tic-tac-toe.py
design-twitter.py
detect-capital.py
di-string-match.py
diagonal-traverse.py
diameter-of-binary-tree.py
different-ways-to-add-parentheses.py
digit-count-in-range.py
distant-barcodes.py
distinct-subsequences-ii.py
distinct-subsequences.py
distribute-candies.py
distribute-coins-in-binary-tree.py
divide-two-integers.py
divisor-game.py
domino-and-tromino-tiling.py
dota2-senate.py
dungeon-game.py
edit-distance.py
elimination-game.py
employee-free-time.py
employee-importance.py
encode-and-decode-strings.py
encode-and-decode-tinyurl.py
encode-n-ary-tree-to-binary-tree.py
encode-string-with-shortest-length.py
equal-rational-numbers.py
equal-tree-partition.py
erect-the-fence.py
escape-a-large-maze.py
escape-the-ghosts.py
evaluate-division.py
evaluate-reverse-polish-notation.py
exam-room.py
excel-sheet-column-number.py
excel-sheet-column-title.py
exclusive-time-of-functions.py
expression-add-operators.py
expressive-words.py
factor-combinations.py
factorial-trailing-zeroes.py
fair-candy-swap.py
falling-squares.py
fibonacci-number.py
find-all-anagrams-in-a-string.py
find-all-duplicates-in-an-array.py
find-all-numbers-disappeared-in-an-array.py
find-anagram-mappings.py
find-and-replace-in-string.py
find-and-replace-pattern.py
find-bottom-left-tree-value.py
find-common-characters.py
find-duplicate-file-in-system.py
find-duplicate-subtrees.py
find-eventual-safe-states.py
find-k-closest-elements.py
find-k-pairs-with-smallest-sums.py
find-k-th-smallest-pair-distance.py
find-largest-value-in-each-tree-row.py
find-leaves-of-binary-tree.py
find-median-from-data-stream.py
find-minimum-in-rotated-sorted-array-ii.py
find-minimum-in-rotated-sorted-array.py
find-mode-in-binary-search-tree.py
find-peak-element.py
find-permutation.py
find-pivot-index.py
find-right-interval.py
find-smallest-letter-greater-than-target.py
find-the-celebrity.py
find-the-closest-palindrome.py
find-the-derangement-of-an-array.py
find-the-difference.py
find-the-duplicate-number.py
find-the-shortest-superstring.py
find-the-town-judge.py
first-bad-version.py
first-missing-positive.py
first-unique-character-in-a-string.py
fixed-point.py
fizz-buzz.py
flatten-2d-vector.py
flatten-a-multilevel-doubly-linked-list.py
flatten-binary-tree-to-linked-list.py
flatten-nested-list-iterator.py
flip-binary-tree-to-match-preorder-traversal.py
flip-columns-for-maximum-number-of-equal-rows.py
flip-equivalent-binary-trees.py
flip-game-ii.py
flip-game.py
flip-string-to-monotone-increasing.py
flipping-an-image.py
flood-fill.py
flower-planting-with-no-adjacent.py
fraction-addition-and-subtraction.py
fraction-to-recurring-decimal.py
freedom-trail.py
friend-circles.py
friends-of-appropriate-ages.py
frog-jump.py
fruit-into-baskets.py
game-of-life.py
gas-station.py
generalized-abbreviation.py
generate-parentheses.py
generate-random-point-in-a-circle.py
global-and-local-inversions.py
goat-latin.py
graph-valid-tree.py
gray-code.py
greatest-common-divisor-of-strings.py
grid-illumination.py
group-anagrams.py
group-shifted-strings.py
groups-of-special-equivalent-strings.py
grumpy-bookstore-owner.py
guess-number-higher-or-lower-ii.py
guess-number-higher-or-lower.py
guess-the-word.py
h-index-ii.py
h-index.py
hamming-distance.py
hand-of-straights.py
happy-number.py
heaters.py
height-checker.py
house-robber-ii.py
house-robber-iii.py
house-robber.py
image-overlap.py
image-smoother.py
implement-magic-dictionary.py
implement-queue-using-stacks.py
implement-rand10-using-rand7.py
implement-stack-using-queues.py
implement-strstr.py
implement-trie-prefix-tree.py
increasing-order-search-tree.py
increasing-subsequences.py
increasing-triplet-subsequence.py
index-pairs-of-a-string.py
inorder-successor-in-bst-ii.py
inorder-successor-in-bst.py
insert-delete-getrandom-o1-duplicates-allowed.py
insert-delete-getrandom-o1.py
insert-interval.py
insert-into-a-binary-search-tree.py
insert-into-a-cyclic-sorted-list.py
insertion-sort-list.py
insufficient-nodes-in-root-to-leaf-paths.py
integer-break.py
integer-replacement.py
integer-to-english-words.py
integer-to-roman.py
interleaving-string.py
intersection-of-two-arrays-ii.py
intersection-of-two-arrays.py
intersection-of-two-linked-lists.py
interval-list-intersections.py
invert-binary-tree.py
ip-to-cidr.py
ipo.py
is-graph-bipartite.py
is-subsequence.py
island-perimeter.py
isomorphic-strings.py
jewels-and-stones.py
judge-route-circle.py
jump-game-ii.py
jump-game.py
k-closest-points-to-origin.py
k-diff-pairs-in-an-array.py
k-empty-slots.py
k-inverse-pairs-array.py
k-similar-strings.py
k-th-smallest-in-lexicographical-order.py
k-th-smallest-prime-fraction.py
k-th-symbol-in-grammar.py
keyboard-row.py
keys-and-rooms.py
kill-process.py
knight-dialer.py
knight-probability-in-chessboard.py
koko-eating-bananas.py
kth-largest-element-in-a-stream.py
kth-largest-element-in-an-array.py
kth-smallest-element-in-a-bst.py
kth-smallest-element-in-a-sorted-matrix.py
kth-smallest-number-in-multiplication-table.py
largest-bst-subtree.py
largest-component-size-by-common-factor.py
largest-divisible-subset.py
largest-number-at-least-twice-of-others.py
largest-number.py
largest-palindrome-product.py
largest-perimeter-triangle.py
largest-plus-sign.py
largest-rectangle-in-histogram.py
largest-sum-of-averages.py
largest-time-for-given-digits.py
largest-triangle-area.py
last-stone-weight-ii.py
last-stone-weight.py
leaf-similar-trees.py
least-operators-to-express-number.py
lemonade-change.py
length-of-last-word.py
length-of-longest-fibonacci-subsequence.py
letter-case-permutation.py
letter-combinations-of-a-phone-number.py
letter-tile-possibilities.py
lexicographical-numbers.py
lexicographically-smallest-equivalent-string.py
lfu-cache.py
license-key-formatting.py
line-reflection.py
linked-list-components.py
linked-list-cycle-ii.py
linked-list-cycle.py
linked-list-random-node.py
logger-rate-limiter.py
lonely-pixel-i.py
lonely-pixel-ii.py
long-pressed-name.py
longest-absolute-file-path.py
longest-arithmetic-sequence.py
longest-common-prefix.py
longest-consecutive-sequence.py
longest-continuous-increasing-subsequence.py
longest-duplicate-substring.py
longest-harmonious-subsequence.py
longest-increasing-path-in-a-matrix.py
longest-increasing-subsequence.py
longest-line-of-consecutive-one-in-matrix.py
longest-mountain-in-array.py
longest-palindrome.py
longest-palindromic-subsequence.py
longest-palindromic-substring.py
longest-repeating-character-replacement.py
longest-repeating-substring.py
longest-string-chain.py
longest-substring-with-at-least-k-repeating-characters.py
longest-substring-with-at-most-k-distinct-characters.py
longest-substring-with-at-most-two-distinct-characters.py
longest-substring-without-repeating-characters.py
longest-turbulent-subarray.py
longest-uncommon-subsequence-i.py
longest-uncommon-subsequence-ii.py
longest-univalue-path.py
longest-valid-parentheses.py
longest-word-in-dictionary-through-deleting.py
longest-word-in-dictionary.py
loud-and-rich.py
lowest-common-ancestor-of-a-binary-search-tree.py
lowest-common-ancestor-of-a-binary-tree.py
lru-cache.py
magic-squares-in-grid.py
magical-string.py
majority-element-ii.py
majority-element.py
making-a-large-island.py
map-sum-pairs.py
masking-personal-information.py
matchsticks-to-square.py
matrix-cells-in-distance-order.py
max-area-of-island.py
max-chunks-to-make-sorted-ii.py
max-chunks-to-make-sorted.py
max-consecutive-ones-ii.py
max-consecutive-ones-iii.py
max-consecutive-ones.py
max-increase-to-keep-city-skyline.py
max-points-on-a-line.py
max-stack.py
max-sum-of-sub-matrix-no-larger-than-k.py
maximal-rectangle.py
maximal-square.py
maximize-distance-to-closest-person.py
maximize-sum-of-array-after-k-negations.py
maximum-average-subarray-i.py
maximum-average-subarray-ii.py
maximum-binary-tree-ii.py
maximum-binary-tree.py
maximum-depth-of-binary-tree.py
maximum-depth-of-n-ary-tree.py
maximum-difference-between-node-and-ancestor.py
maximum-distance-in-arrays.py
maximum-frequency-stack.py
maximum-gap.py
maximum-length-of-pair-chain.py
maximum-length-of-repeated-subarray.py
maximum-product-of-three-numbers.py
maximum-product-of-word-lengths.py
maximum-product-subarray.py
maximum-size-subarray-sum-equals-k.py
maximum-subarray.py
maximum-sum-circular-subarray.py
maximum-sum-of-3-non-overlapping-subarrays.py
maximum-sum-of-two-non-overlapping-subarrays.py
maximum-swap.py
maximum-vacation-days.py
maximum-width-of-binary-tree.py
maximum-width-ramp.py
maximum-xor-of-two-numbers-in-an-array.py
median-of-two-sorted-arrays.py
meeting-rooms-ii.py
meeting-rooms.py
merge-intervals.py
merge-k-sorted-lists.py
merge-sorted-array.py
merge-two-binary-trees.py
merge-two-sorted-lists.py
middle-of-the-linked-list.py
min-cost-climbing-stairs.py
min-stack.py
minesweeper.py
mini-parser.py
minimize-malware-spread-ii.py
minimize-malware-spread.py
minimize-max-distance-to-gas-station.py
minimize-rounding-error-to-meet-target.py
minimum-absolute-difference-in-bst.py
minimum-add-to-make-parentheses-valid.py
minimum-area-rectangle-ii.py
minimum-area-rectangle.py
minimum-ascii-delete-sum-for-two-strings.py
minimum-cost-for-tickets.py
minimum-cost-to-hire-k-workers.py
minimum-cost-to-merge-stones.py
minimum-depth-of-binary-tree.py
minimum-distance-between-bst-nodes.py
minimum-domino-rotations-for-equal-row.py
minimum-factorization.py
minimum-falling-path-sum.py
minimum-genetic-mutation.py
minimum-height-trees.py
minimum-increment-to-make-array-unique.py
minimum-index-sum-of-two-lists.py
minimum-moves-to-equal-array-elements-ii.py
minimum-moves-to-equal-array-elements.py
minimum-number-of-arrows-to-burst-balloons.py
minimum-number-of-k-consecutive-bit-flips.py
minimum-number-of-refueling-stops.py
minimum-path-sum.py
minimum-score-triangulation-of-polygon.py
minimum-size-subarray-sum.py
minimum-swaps-to-make-sequences-increasing.py
minimum-time-difference.py
minimum-unique-word-abbreviation.py
minimum-window-subsequence.py
minimum-window-substring.py
mirror-reflection.py
missing-element-in-sorted-array.py
missing-number.py
missing-ranges.py
monotone-increasing-digits.py
monotonic-array.py
most-common-word.py
most-frequent-subtree-sum.py
most-profit-assigning-work.py
most-stones-removed-with-same-row-or-column.py
move-zeroes.py
moving-average-from-data-stream.py
moving-stones-until-consecutive-ii.py
moving-stones-until-consecutive.py
multiply-strings.py
my-calendar-i.py
my-calendar-ii.py
my-calendar-iii.py
n-ary-tree-level-order-traversal.py
n-ary-tree-postorder-traversal.py
n-ary-tree-preorder-traversal.py
n-queens-ii.py
n-queens.py
n-repeated-element-in-size-2n-array.py
nested-list-weight-sum-ii.py
nested-list-weight-sum.py
network-delay-time.py
next-closest-time.py
next-greater-element-i.py
next-greater-element-ii.py
next-greater-element-iii.py
next-greater-node-in-linked-list.py
next-permutation.py
nim-game.py
non-decreasing-array.py
non-negative-integers-without-consecutive-ones.py
non-overlapping-intervals.py
nth-digit.py
nth-magical-number.py
number-complement.py
number-of-1-bits.py
number-of-atoms.py
number-of-boomerangs.py
number-of-connected-components-in-an-undirected-graph.py
number-of-corner-rectangles.py
number-of-digit-one.py
number-of-distinct-islands-ii.py
number-of-distinct-islands.py
number-of-enclaves.py
number-of-islands-ii.py
number-of-islands.py
number-of-lines-to-write-string.py
number-of-longest-increasing-subsequence.py
number-of-matching-subsequences.py
number-of-music-playlists.py
number-of-recent-calls.py
number-of-segments-in-a-string.py
number-of-squareful-arrays.py
number-of-subarrays-with-bounded-maximum.py
number-of-submatrices-that-sum-to-target.py
number-of-valid-subarrays.py
numbers-at-most-n-given-digit-set.py
numbers-with-repeated-digits.py
numbers-with-same-consecutive-differences.py
occurrences-after-bigram.py
odd-even-jump.py
odd-even-linked-list.py
one-edit-distance.py
ones-and-zeroes.py
online-election.py
online-stock-span.py
open-the-lock.py
optimal-account-balancing.py
optimal-division.py
orderly-queue.py
out-of-boundary-paths.py
output-contest-matches.py
pacific-atlantic-water-flow.py
paint-fence.py
paint-house-ii.py
paint-house.py
pairs-of-songs-with-total-durations-divisible-by-60.py
palindrome-linked-list.py
palindrome-number.py
palindrome-pairs.py
palindrome-partitioning-ii.py
palindrome-partitioning.py
palindrome-permutation-ii.py
palindrome-permutation.py
palindromic-substrings.py
pancake-sorting.py
parse-lisp-expression.py
partition-array-for-maximum-sum.py
partition-array-into-disjoint-intervals.py
partition-array-into-three-parts-with-equal-sum.py
partition-equal-subset-sum.py
partition-labels.py
partition-list.py
partition-to-k-equal-sum-subsets.py
pascals-triangle-ii.py
pascals-triangle.py
patching-array.py
path-sum-ii.py
path-sum-iii.py
path-sum-iv.py
path-sum.py
peak-index-in-a-mountain-array.py
peeking-iterator.py
perfect-number.py
perfect-rectangle.py
perfect-squares.py
permutation-in-string.py
permutation-sequence.py
permutations-ii.py
permutations.py
plus-one-linked-list.py
plus-one.py
poor-pigs.py
populating-next-right-pointers-in-each-node-ii.py
populating-next-right-pointers-in-each-node.py
positions-of-large-groups.py
possible-bipartition.py
pour-water.py
power-of-four.py
power-of-three.py
power-of-two.py
powerful-integers.py
powx-n.py
predict-the-winner.py
prefix-and-suffix-search.py
preimage-size-of-factorial-zeroes-function.py
previous-permutation-with-one-swap.py
prime-number-of-set-bits-in-binary-representation.py
prime-palindrome.py
print-binary-tree.py
prison-cells-after-n-days.py
product-of-array-except-self.py
profitable-schemes.py
projection-area-of-3d-shapes.py
push-dominoes.py
pyramid-transition-matrix.py
quad-tree-intersection.py
queue-reconstruction-by-height.py
rabbits-in-forest.py
race-car.py
random-flip-matrix.py
random-pick-index.py
random-pick-with-blacklist.py
random-pick-with-weight.py
random-point-in-non-overlapping-rectangles.py
range-addition-ii.py
range-addition.py
range-module.py
range-sum-of-bst.py
range-sum-query-2d-immutable.py
range-sum-query-2d-mutable.py
range-sum-query-immutable.py
range-sum-query-mutable.py
ransom-note.py
reach-a-number.py
reachable-nodes-in-subdivided-graph.py
reaching-points.py
read-n-characters-given-read4-ii-call-multiple-times.py
read-n-characters-given-read4.py
rearrange-string-k-distance-apart.py
reconstruct-itinerary.py
reconstruct-original-digits-from-english.py
recover-a-tree-from-preorder-traversal.py
recover-binary-search-tree.py
rectangle-area-ii.py
rectangle-area.py
rectangle-overlap.py
redundant-connection-ii.py
redundant-connection.py
regions-cut-by-slashes.py
regular-expression-matching.py
relative-ranks.py
remove-9.py
remove-all-adjacent-duplicates-in-string.py
remove-boxes.py
remove-comments.py
remove-duplicate-letters.py
remove-duplicates-from-sorted-array-ii.py
remove-duplicates-from-sorted-array.py
remove-duplicates-from-sorted-list-ii.py
remove-duplicates-from-sorted-list.py
remove-element.py
remove-invalid-parentheses.py
remove-k-digits.py
remove-linked-list-elements.py
remove-nth-node-from-end-of-list.py
remove-outermost-parentheses.py
reorder-list.py
reorder-log-files.py
reordered-power-of-2.py
reorganize-string.py
repeated-dna-sequences.py
repeated-string-match.py
repeated-substring-pattern.py
replace-words.py
reshape-the-matrix.py
restore-ip-addresses.py
reveal-cards-in-increasing-order.py
reverse-bits.py
reverse-integer.py
reverse-linked-list-ii.py
reverse-linked-list.py
reverse-nodes-in-k-group.py
reverse-only-letters.py
reverse-pairs.py
reverse-string-ii.py
reverse-string.py
reverse-vowels-of-a-string.py
reverse-words-in-a-string-ii.py
reverse-words-in-a-string-iii.py
reverse-words-in-a-string.py
rle-iterator.py
robot-bounded-in-circle.py
robot-room-cleaner.py
roman-to-integer.py
rotate-array.py
rotate-function.py
rotate-image.py
rotate-list.py
rotate-string.py
rotated-digits.py
rotting-oranges.py
russian-doll-envelopes.py
same-tree.py
satisfiability-of-equality-equations.py
score-after-flipping-matrix.py
score-of-parentheses.py
scramble-string.py
search-a-2d-matrix-ii.py
search-a-2d-matrix.py
search-for-a-range.py
search-in-a-binary-search-tree.py
search-in-a-sorted-array-of-unknown-size.py
search-in-rotated-sorted-array-ii.py
search-in-rotated-sorted-array.py
search-insert-position.py
second-minimum-node-in-a-binary-tree.py
self-crossing.py
self-dividing-numbers.py
sentence-screen-fitting.py
sentence-similarity-ii.py
sentence-similarity.py
sequence-reconstruction.py
serialize-and-deserialize-binary-tree.py
serialize-and-deserialize-bst.py
serialize-and-deserialize-n-ary-tree.py
set-intersection-size-at-least-two.py
set-matrix-zeroes.py
set-mismatch.py
shifting-letters.py
shopping-offers.py
short-encoding-of-words.py
shortest-bridge.py
shortest-completing-word.py
shortest-distance-from-all-buildings.py
shortest-distance-to-a-character.py
shortest-palindrome.py
shortest-path-to-get-all-keys.py
shortest-path-visiting-all-nodes.py
shortest-subarray-with-sum-at-least-k.py
shortest-unsorted-continuous-subarray.py
shortest-way-to-form-string.py
shortest-word-distance-ii.py
shortest-word-distance-iii.py
shortest-word-distance.py
shuffle-an-array.py
similar-rgb-color.py
similar-string-groups.py
simplify-path.py
single-element-in-a-sorted-array.py
single-number-ii.py
single-number-iii.py
single-number.py
sliding-puzzle.py
sliding-window-maximum.py
smallest-good-base.py
smallest-integer-divisible-by-k.py
smallest-range-i.py
smallest-range-ii.py
smallest-range.py
smallest-rectangle-enclosing-black-pixels.py
smallest-rotation-with-highest-score.py
smallest-string-starting-from-leaf.py
smallest-subsequence-of-distinct-characters.py
smallest-subtree-with-all-the-deepest-nodes.py
snakes-and-ladders.py
solve-the-equation.py
sort-an-array.py
sort-array-by-parity-ii.py
sort-array-by-parity.py
sort-characters-by-frequency.py
sort-colors.py
sort-list.py
sort-transformed-array.py
soup-servings.py
sparse-matrix-multiplication.py
special-binary-string.py
spiral-matrix-ii.py
spiral-matrix-iii.py
spiral-matrix.py
split-array-into-consecutive-subsequences.py
split-array-into-fibonacci-sequence.py
split-array-largest-sum.py
split-array-with-equal-sum.py
split-array-with-same-average.py
split-bst.py
split-concatenated-strings.py
split-linked-list-in-parts.py
sqrtx.py
squares-of-a-sorted-array.py
squirrel-simulation.py
stamping-the-sequence.py
stickers-to-spell-word.py
stone-game.py
strange-printer.py
stream-of-characters.py
stream-of-characters2.py
string-compression.py
string-to-integer-atoi.py
string-without-aaa-or-bbb.py
strobogrammatic-number-ii.py
strobogrammatic-number-iii.py
strobogrammatic-number.py
strong-password-checker.py
student-attendance-record-i.py
student-attendance-record-ii.py
subarray-product-less-than-k.py
subarray-sum-equals-k.py
subarray-sums-divisible-by-k.py
subarrays-with-k-different-integers.py
subdomain-visit-count.py
subsets-ii.py
subsets.py
substring-with-concatenation-of-all-words.py
subtree-of-another-tree.py
sudoku-solver.py
sum-of-distances-in-tree.py
sum-of-even-numbers-after-queries.py
sum-of-left-leaves.py
sum-of-root-to-leaf-binary-numbers.py
sum-of-square-numbers.py
sum-of-subarray-minimums.py
sum-of-subsequence-widths.py
sum-of-two-integers.py
sum-root-to-leaf-numbers.py
summary-ranges.py
super-egg-drop.py
super-palindromes.py
super-pow.py
super-ugly-number.py
super-washing-machines.py
surface-area-of-3d-shapes.py
surrounded-regions.py
swap-adjacent-in-lr-string.py
swap-nodes-in-pairs.py
swim-in-rising-water.py
symmetric-tree.py
tag-validator.py
tallest-billboard.py
target-sum.py
task-scheduler.py
teemo-attacking.py
ternary-expression-parser.py
text-justification.py
the-maze-ii.py
the-maze-iii.py
the-maze.py
the-skyline-problem.py
third-maximum-number.py
three-equal-parts.py
time-based-key-value-store.py
to-lower-case.py
toeplitz-matrix.py
top-k-frequent-elements.py
top-k-frequent-words.py
total-hamming-distance.py
transform-to-chessboard.py
transpose-matrix.py
trapping-rain-water-ii.py
trapping-rain-water.py
triangle.py
trim-a-binary-search-tree.py
triples-with-bitwise-and-equal-to-zero.py
two-city-scheduling.py
two-sum-ii-input-array-is-sorted.py
two-sum-iii-data-structure-design.py
two-sum-iv-input-is-a-bst.py
two-sum.py
ugly-number-ii.py
ugly-number.py
uncommon-words-from-two-sentences.py
uncrossed-lines.py
unique-binary-search-trees-ii.py
unique-binary-search-trees.py
unique-email-addresses.py
unique-letter-string.py
unique-morse-code-words.py
unique-paths-ii.py
unique-paths-iii.py
unique-paths.py
unique-substrings-in-wraparound-string.py
unique-word-abbreviation.py
univalued-binary-tree.py
utf-8-validation.py
valid-anagram.py
valid-boomerang.py
valid-mountain-array.py
valid-number.py
valid-palindrome-ii.py
valid-palindrome.py
valid-parentheses.py
valid-parenthesis-string.py
valid-perfect-square.py
valid-permutations-for-di-sequence.py
valid-square.py
valid-sudoku.py
valid-tic-tac-toe-state.py
valid-triangle-number.py
valid-word-abbreviation.py
valid-word-square.py
validate-binary-search-tree.py
validate-ip-address.py
validate-stack-sequences.py
verify-preorder-sequence-in-binary-search-tree.py
verify-preorder-serialization-of-a-binary-tree.py
verifying-an-alien-dictionary.py
vertical-order-traversal-of-a-binary-tree.py
video-stitching.py
vowel-spellchecker.py
剩余 1 项被截断
Shell
.travis.yml
LICENSE.md
README.md
克隆/下载
construct-binary-search-tree-from-preorder-traversal.py 916 Bytes
一键复制 编辑 原始数据 按行查看 历史
# Time: O(n)
# Space: O(h)
# Definition for a binary tree node.
class TreeNode(object):
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution(object):
def bstFromPreorder(self, preorder):
"""
:type preorder: List[int]
:rtype: TreeNode
"""
def bstFromPreorderHelper(preorder, left, right, index):
if index[0] == len(preorder) or \
preorder[index[0]] < left or \
preorder[index[0]] > right:
return None
root = TreeNode(preorder[index[0]])
index[0] += 1
root.left = bstFromPreorderHelper(preorder, left, root.val, index)
root.right = bstFromPreorderHelper(preorder, root.val, right, index)
return root
return bstFromPreorderHelper(preorder, float("-inf"), float("inf"), [0])
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LilithSangreal/LeetCode-Solutions.git
git@gitee.com:LilithSangreal/LeetCode-Solutions.git
LilithSangreal
LeetCode-Solutions
LeetCode-Solutions
master

搜索帮助