1 Star 0 Fork 0

yuhang2__2/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
add-two-polynomials-represented-as-linked-lists.py
adding-two-negabinary-numbers.py
additive-number.py
advantage-shuffle.py
airplane-seat-assignment-probability.py
alert-using-same-key-card-three-or-more-times-in-a-one-hour-period.py
alien-dictionary.py
all-elements-in-two-binary-search-trees.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
allocate-mailboxes.py
alphabet-board-path.py
ambiguous-coordinates.py
analyze-user-website-visit-pattern.py
android-unlock-patterns.py
angle-between-hands-of-a-clock.py
apply-discount-every-n-orders.py
arithmetic-slices-ii-subsequence.py
arithmetic-slices.py
arithmetic-subarrays.py
armstrong-number.py
arranging-coins.py
array-nesting.py
array-of-doubled-pairs.py
array-partition-i.py
array-transformation.py
as-far-from-land-as-possible.py
assign-cookies.py
asteroid-collision.py
available-captures-for-rook.py
average-of-levels-in-binary-tree.py
average-salary-excluding-the-minimum-and-maximum-salary.py
avoid-flood-in-the-city.py
backspace-string-compare.py
bag-of-tokens.py
balance-a-binary-search-tree.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
before-and-after-puzzle.py
best-meeting-point.py
best-position-for-a-service-centre.py
best-sightseeing-pair.py
best-team-with-no-conflicts.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-ii.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-coloring-game.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
brace-expansion-ii.py
brace-expansion.py
break-a-palindrome.py
brick-wall.py
bricks-falling-when-hit.py
broken-calculator.py
buddy-strings.py
build-an-array-with-stack-operations.py
build-array-where-you-can-find-the-maximum-exactly-k-comparisons.py
build-binary-expression-tree-from-infix-expression.py
building-h2o.py
bulb-switcher-ii.py
bulb-switcher-iii.py
bulb-switcher-iv.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-convert-string-in-k-moves.py
can-i-win.py
can-make-arithmetic-progression-from-sequence.py
can-make-palindrome-from-substring.py
can-place-flowers.py
candy-crush.py
candy.py
capacity-to-ship-packages-within-d-days.py
car-fleet.py
car-pooling.py
card-flipping-game.py
cat-and-mouse.py
cells-with-odd-values-in-a-matrix.py
chalkboard-xor-game.py
champagne-tower.py
change-the-root-of-a-binary-tree.py
cheapest-flights-within-k-stops.py
check-array-formation-through-concatenation.py
check-completeness-of-a-binary-tree.py
check-if-a-number-is-majority-element-in-a-sorted-array.py
check-if-a-string-can-break-another-string.py
check-if-a-string-contains-all-binary-codes-of-size-k.py
check-if-a-string-is-a-valid-sequence-from-root-to-leaves-path-in-a-binary-tree.py
check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.py
check-if-all-1s-are-at-least-length-k-places-away.py
check-if-array-pairs-are-divisible-by-k.py
check-if-it-is-a-good-array.py
check-if-it-is-a-straight-line.py
check-if-n-and-its-double-exist.py
check-if-string-is-transformable-with-substring-sort-operations.py
check-if-there-is-a-valid-path-in-a-grid.py
check-if-two-expression-trees-are-equivalent.py
check-if-two-string-arrays-are-equivalent.py
check-if-word-is-valid-after-substitutions.py
cherry-pickup-ii.py
cherry-pickup.py
cinema-seat-allocation.py
circle-and-rectangle-overlapping.py
circular-array-loop.py
circular-permutation-in-binary-representation.py
climbing-stairs.py
clone-binary-tree-with-random-pointer.py
clone-graph.py
clone-n-ary-tree.py
closest-binary-search-tree-value-ii.py
closest-binary-search-tree-value.py
closest-divisors.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-strings-by-frequency-of-the-smallest-character.py
compare-version-numbers.py
complement-of-base-10-integer.py
complete-binary-tree-inserter.py
complex-number-multiplication.py
concatenated-words.py
concatenation-of-consecutive-binary-numbers.py
confusing-number-ii.py
confusing-number.py
connecting-cities-with-minimum-cost.py
consecutive-characters.py
consecutive-numbers-sum.py
constrained-subset-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-k-palindrome-strings.py
construct-quad-tree.py
construct-string-from-binary-tree.py
construct-target-array-with-multiple-sums.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-number-in-a-linked-list-to-integer.py
convert-binary-search-tree-to-sorted-doubly-linked-list.py
convert-bst-to-greater-tree.py
convert-integer-to-the-sum-of-two-no-zero-integers.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
coordinate-with-maximum-network-quality.py
copy-list-with-random-pointer.py
corporate-flight-bookings.py
correct-a-binary-tree.py
count-all-possible-routes.py
count-all-valid-pickup-and-delivery-options.py
count-and-say.py
count-binary-substrings.py
count-complete-tree-nodes.py
count-different-palindromic-subsequences.py
count-good-nodes-in-binary-tree.py
count-good-triplets.py
count-largest-group.py
count-negative-numbers-in-a-sorted-matrix.py
count-number-of-nice-subarrays.py
count-number-of-teams.py
count-numbers-with-unique-digits.py
count-odd-numbers-in-an-interval-range.py
count-of-range-sum.py
count-of-smaller-numbers-after-self.py
count-primes.py
count-servers-that-communicate.py
count-sorted-vowel-strings.py
count-square-submatrices-with-all-ones.py
count-submatrices-with-all-ones.py
count-substrings-that-differ-by-one-character.py
count-substrings-with-only-one-distinct-letter.py
count-subtrees-with-max-distance-between-cities.py
count-the-repetitions.py
count-triplets-that-can-form-two-arrays-of-equal-xor.py
count-unhappy-friends.py
count-unique-characters-of-all-substrings-of-a-given-string.py
count-univalue-subtrees.py
count-vowels-permutation.py
counting-bits.py
counting-elements.py
couples-holding-hands.py
course-schedule-ii.py
course-schedule-iii.py
course-schedule-iv.py
course-schedule.py
cousins-in-binary-tree.py
cracking-the-safe.py
crawler-log-folder.py
create-maximum-number.py
create-sorted-array-through-instructions.py
create-target-array-in-the-given-order.py
critical-connections-in-a-network.py
custom-sort-string.py
cut-off-trees-for-golf-event.py
daily-temperatures.py
data-stream-as-disjoint-intervals.py
day-of-the-week.py
day-of-the-year.py
decode-string.py
decode-ways-ii.py
decode-ways.py
decoded-string-at-index.py
decompress-run-length-encoded-list.py
decrease-elements-to-make-array-zigzag.py
decrypt-string-from-alphabet-to-integer-mapping.py
deepest-leaves-sum.py
defanging-an-ip-address.py
defuse-the-bomb.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-leaves-with-a-given-value.py
delete-n-nodes-after-m-nodes-of-a-linked-list.py
delete-node-in-a-bst.py
delete-node-in-a-linked-list.py
delete-nodes-and-return-forest.py
delete-operation-for-two-strings.py
delete-tree-nodes.py
design-a-file-sharing-system.py
design-a-leaderboard.py
design-a-stack-with-increment-operation.py
design-an-expression-tree-with-evaluate-function.py
design-an-ordered-stream.py
design-bounded-blocking-queue.py
design-browser-history.py
design-circular-deque.py
design-circular-queue.py
design-compressed-string-iterator.py
design-excel-sum-formula.py
design-file-system.py
design-front-middle-back-queue.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-parking-system.py
design-phone-directory.py
design-search-autocomplete-system.py
design-skiplist.py
design-snake-game.py
design-tic-tac-toe.py
design-twitter.py
design-underground-system.py
destination-city.py
detect-capital.py
detect-cycles-in-2d-grid.py
detect-pattern-of-length-m-repeated-k-or-more-times.py
determine-if-two-strings-are-close.py
di-string-match.py
diagonal-traverse-ii.py
diagonal-traverse.py
diameter-of-binary-tree.py
diameter-of-n-ary-tree.py
dice-roll-simulation.py
diet-plan-performance.py
different-ways-to-add-parentheses.py
digit-count-in-range.py
dinner-plate-stacks.py
display-table-of-food-orders-in-a-restaurant.py
distance-between-bus-stops.py
distant-barcodes.py
distinct-echo-substrings.py
distinct-subsequences-ii.py
distinct-subsequences.py
distribute-candies-to-people.py
distribute-candies.py
distribute-coins-in-binary-tree.py
distribute-repeating-integers.py
divide-array-in-sets-of-k-consecutive-numbers.py
divide-array-into-increasing-sequences.py
divide-chocolate.py
divide-two-integers.py
divisor-game.py
domino-and-tromino-tiling.py
dot-product-of-two-sparse-vectors.py
dota2-senate.py
dungeon-game.py
duplicate-zeros.py
edit-distance.py
element-appearing-more-than-25-in-sorted-array.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-number.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
even-odd-tree.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
fancy-sequence.py
fibonacci-number.py
filling-bookcase-shelves.py
filter-restaurants-by-vegan-friendly-price-and-distance.py
final-prices-with-a-special-discount-in-a-shop.py
find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree.py
find-a-value-of-a-mysterious-function-closest-to-target.py
find-all-anagrams-in-a-string.py
find-all-duplicates-in-an-array.py
find-all-good-strings.py
find-all-numbers-disappeared-in-an-array.py
find-all-the-lonely-nodes.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-critical-and-pseudo-critical-edges-in-minimum-spanning-tree.py
find-duplicate-file-in-system.py
find-duplicate-subtrees.py
find-elements-in-a-contaminated-binary-tree.py
find-eventual-safe-states.py
find-in-mountain-array.py
find-k-closest-elements.py
find-k-length-substrings-with-no-repeated-characters.py
find-k-pairs-with-smallest-sums.py
find-k-th-smallest-pair-distance.py
find-kth-bit-in-nth-binary-string.py
find-largest-value-in-each-tree-row.py
find-latest-group-of-size-m.py
find-leaves-of-binary-tree.py
find-longest-awesome-substring.py
find-lucky-integer-in-an-array.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-n-unique-integers-sum-up-to-zero.py
find-nearest-right-node-in-binary-tree.py
find-numbers-with-even-number-of-digits.py
find-peak-element.py
find-permutation.py
find-pivot-index.py
find-positive-integer-solution-for-a-given-equation.py
find-right-interval.py
find-root-of-n-ary-tree.py
find-servers-that-handled-most-number-of-requests.py
find-smallest-common-element-in-all-rows.py
find-smallest-letter-greater-than-target.py
find-the-celebrity.py
find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance.py
find-the-closest-palindrome.py
find-the-derangement-of-an-array.py
find-the-difference.py
find-the-distance-value-between-two-arrays.py
find-the-duplicate-number.py
find-the-index-of-the-large-integer.py
find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows.py
find-the-longest-substring-containing-vowels-in-even-counts.py
find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k.py
find-the-most-competitive-subsequence.py
find-the-shortest-superstring.py
find-the-smallest-divisor-given-a-threshold.py
find-the-town-judge.py
find-the-winner-of-an-array-game.py
find-two-non-overlapping-sub-arrays-each-with-target-sum.py
find-valid-matrix-given-row-and-column-sums.py
find-winner-on-a-tic-tac-toe-game.py
find-words-that-can-be-formed-by-characters.py
first-bad-version.py
first-missing-positive.py
first-unique-character-in-a-string.py
first-unique-number.py
fixed-point.py
fizz-buzz-multithreaded.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
form-largest-integer-with-digits-that-add-up-to-target.py
four-divisors.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
frog-position-after-t-seconds.py
fruit-into-baskets.py
furthest-building-you-can-reach.py
game-of-life.py
gas-station.py
generalized-abbreviation.py
generate-a-string-with-characters-that-have-odd-counts.py
generate-parentheses.py
generate-random-point-in-a-circle.py
get-equal-substrings-within-budget.py
get-maximum-in-generated-array.py
get-the-maximum-score.py
get-watched-videos-by-your-friends.py
global-and-local-inversions.py
goal-parser-interpretation.py
goat-latin.py
graph-connectivity-with-threshold.py
graph-valid-tree.py
gray-code.py
greatest-common-divisor-of-strings.py
greatest-sum-divisible-by-three.py
grid-illumination.py
group-anagrams.py
group-shifted-strings.py
group-the-people-given-the-group-size-they-belong-to.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-majority-in-a-hidden-array.py
guess-the-word.py
h-index-ii.py
h-index.py
hamming-distance.py
hand-of-straights.py
handshakes-that-dont-cross.py
happy-number.py
heaters.py
height-checker.py
hexspeak.py
high-five.py
house-robber-ii.py
house-robber-iii.py
house-robber.py
how-many-apples-can-you-put-into-the-basket.py
how-many-numbers-are-smaller-than-the-current-number.py
html-entity-parser.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-decreasing-string.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-three-sorted-arrays.py
intersection-of-two-arrays-ii.py
intersection-of-two-arrays.py
intersection-of-two-linked-lists.py
interval-list-intersections.py
invalid-transactions.py
invert-binary-tree.py
ip-to-cidr.py
ipo.py
is-graph-bipartite.py
is-subsequence.py
island-perimeter.py
isomorphic-strings.py
iterator-for-combination.py
jewels-and-stones.py
jump-game-ii.py
jump-game-iii.py
jump-game-iv.py
jump-game-v.py
jump-game.py
k-closest-points-to-origin.py
k-concatenation-maximum-sum.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
kids-with-the-greatest-number-of-candies.py
kill-process.py
knight-dialer.py
knight-probability-in-chessboard.py
koko-eating-bananas.py
kth-ancestor-of-a-tree-node.py
kth-largest-element-in-a-stream.py
kth-largest-element-in-an-array.py
kth-missing-positive-number.py
kth-smallest-element-in-a-bst.py
kth-smallest-element-in-a-sorted-matrix.py
kth-smallest-instructions.py
kth-smallest-number-in-multiplication-table.py
largest-1-bordered-square.py
largest-bst-subtree.py
largest-component-size-by-common-factor.py
largest-divisible-subset.py
largest-multiple-of-three.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-substring-between-two-equal-characters.py
largest-sum-of-averages.py
largest-time-for-given-digits.py
largest-triangle-area.py
largest-unique-number.py
largest-values-from-labels.py
last-moment-before-all-ants-fall-out-of-a-plank.py
last-stone-weight-ii.py
last-stone-weight.py
last-substring-in-lexicographical-order.py
leaf-similar-trees.py
least-number-of-unique-integers-after-k-removals.py
least-operators-to-express-number.py
leftmost-column-with-at-least-a-one.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
lexicographically-smallest-string-after-applying-operations.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-in-binary-tree.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-arithmetic-subsequence-of-given-difference.py
longest-chunked-palindrome-decomposition.py
longest-common-prefix.py
longest-common-subsequence.py
longest-consecutive-sequence.py
longest-continuous-increasing-subsequence.py
longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit.py
longest-duplicate-substring.py
longest-happy-prefix.py
longest-happy-string.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-subarray-of-1s-after-deleting-one-element.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-well-performing-interval.py
longest-word-in-dictionary-through-deleting.py
longest-word-in-dictionary.py
longest-zigzag-path-in-a-binary-tree.py
loud-and-rich.py
lowest-common-ancestor-of-a-binary-search-tree.py
lowest-common-ancestor-of-a-binary-tree-ii.py
lowest-common-ancestor-of-a-binary-tree-iii.py
lowest-common-ancestor-of-a-binary-tree-iv.py
lowest-common-ancestor-of-a-binary-tree.py
lowest-common-ancestor-of-deepest-leaves.py
lru-cache.py
lucky-numbers-in-a-matrix.py
magic-squares-in-grid.py
magical-string.py
magnetic-force-between-two-balls.py
majority-element-ii.py
majority-element.py
make-array-strictly-increasing.py
make-sum-divisible-by-p.py
make-the-string-great.py
make-two-arrays-equal-by-reversing-sub-arrays.py
making-a-large-island.py
making-file-names-unique.py
map-sum-pairs.py
masking-personal-information.py
matchsticks-to-square.py
matrix-block-sum.py
matrix-cells-in-distance-order.py
matrix-diagonal-sum.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-difference-you-can-get-from-changing-an-integer.py
max-dot-product-of-two-subsequences.py
max-increase-to-keep-city-skyline.py
max-number-of-k-sum-pairs.py
max-points-on-a-line.py
max-stack.py
max-sum-of-sub-matrix-no-larger-than-k.py
max-value-of-equation.py
maximal-network-rank.py
maximal-rectangle.py
maximal-square.py
maximize-distance-to-closest-person.py
maximize-grid-happiness.py
maximize-sum-of-array-after-k-negations.py
maximum-69-number.py
maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts.py
maximum-average-subarray-i.py
maximum-average-subarray-ii.py
maximum-average-subtree.py
maximum-binary-tree-ii.py
maximum-binary-tree.py
maximum-candies-you-can-get-from-boxes.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-equal-frequency.py
maximum-font-to-fit-a-sentence-in-a-screen.py
maximum-frequency-stack.py
maximum-gap.py
maximum-length-of-a-concatenated-string-with-unique-characters.py
maximum-length-of-pair-chain.py
maximum-length-of-repeated-subarray.py
maximum-length-of-subarray-with-positive-product.py
maximum-level-sum-of-a-binary-tree.py
maximum-nesting-depth-of-the-parentheses.py
maximum-nesting-depth-of-two-valid-parentheses-strings.py
maximum-non-negative-product-in-a-matrix.py
maximum-number-of-achievable-transfer-requests.py
maximum-number-of-balloons.py
maximum-number-of-coins-you-can-get.py
maximum-number-of-darts-inside-of-a-circular-dartboard.py
maximum-number-of-events-that-can-be-attended.py
maximum-number-of-non-overlapping-subarrays-with-sum-equals-target.py
maximum-number-of-non-overlapping-substrings.py
maximum-number-of-occurrences-of-a-substring.py
maximum-number-of-ones.py
maximum-number-of-visible-points.py
maximum-number-of-vowels-in-a-substring-of-given-length.py
maximum-of-absolute-value-expression.py
maximum-performance-of-a-team.py
maximum-points-you-can-obtain-from-cards.py
maximum-product-of-splitted-binary-tree.py
maximum-product-of-three-numbers.py
maximum-product-of-two-elements-in-an-array.py
maximum-product-of-word-lengths.py
maximum-product-subarray.py
maximum-profit-in-job-scheduling.py
maximum-profit-of-operating-a-centennial-wheel.py
maximum-repeating-substring.py
maximum-score-after-splitting-a-string.py
maximum-score-words-formed-by-letters.py
maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold.py
maximum-size-subarray-sum-equals-k.py
maximum-students-taking-exam.py
maximum-subarray-sum-with-one-deletion.py
maximum-subarray.py
maximum-sum-bst-in-binary-tree.py
maximum-sum-circular-subarray.py
maximum-sum-obtained-of-any-permutation.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
mean-of-array-after-removing-some-elements.py
median-of-two-sorted-arrays.py
meeting-rooms-ii.py
meeting-rooms.py
meeting-scheduler.py
merge-in-between-linked-lists.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-cost-to-connect-all-points.py
min-stack.py
minesweeper.py
mini-parser.py
minimize-deviation-in-array.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-absolute-difference.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-connect-sticks.py
minimum-cost-to-connect-two-groups-of-points.py
minimum-cost-to-cut-a-stick.py
minimum-cost-to-hire-k-workers.py
minimum-cost-to-make-at-least-one-valid-path-in-a-grid.py
minimum-cost-to-merge-stones.py
minimum-cost-tree-from-leaf-values.py
minimum-deletion-cost-to-avoid-repeating-letters.py
minimum-deletions-to-make-character-frequencies-unique.py
minimum-deletions-to-make-string-balanced.py
minimum-depth-of-binary-tree.py
minimum-difference-between-largest-and-smallest-value-in-three-moves.py
minimum-difficulty-of-a-job-schedule.py
minimum-distance-between-bst-nodes.py
minimum-distance-to-type-a-word-using-two-fingers.py
minimum-domino-rotations-for-equal-row.py
minimum-factorization.py
minimum-falling-path-sum-ii.py
minimum-falling-path-sum.py
minimum-flips-to-make-a-or-b-equal-to-c.py
minimum-genetic-mutation.py
minimum-height-trees.py
minimum-incompatibility.py
minimum-increment-to-make-array-unique.py
minimum-index-sum-of-two-lists.py
minimum-initial-energy-to-finish-tasks.py
minimum-insertion-steps-to-make-a-string-palindrome.py
minimum-insertions-to-balance-a-parentheses-string.py
minimum-jumps-to-reach-home.py
minimum-knight-moves.py
minimum-moves-to-equal-array-elements-ii.py
minimum-moves-to-equal-array-elements.py
minimum-moves-to-make-array-complementary.py
minimum-moves-to-move-a-box-to-their-target-location.py
minimum-moves-to-reach-target-with-rotations.py
minimum-number-of-arrows-to-burst-balloons.py
minimum-number-of-days-to-disconnect-island.py
minimum-number-of-days-to-eat-n-oranges.py
minimum-number-of-days-to-make-m-bouquets.py
minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix.py
minimum-number-of-frogs-croaking.py
minimum-number-of-increments-on-subarrays-to-form-a-target-array.py
minimum-number-of-k-consecutive-bit-flips.py
minimum-number-of-refueling-stops.py
minimum-number-of-removals-to-make-mountain-array.py
minimum-number-of-steps-to-make-two-strings-anagram.py
minimum-number-of-taps-to-open-to-water-a-garden.py
minimum-number-of-vertices-to-reach-all-nodes.py
minimum-numbers-of-function-calls-to-make-target-array.py
minimum-one-bit-operations-to-make-integers-zero.py
minimum-operations-to-make-array-equal.py
minimum-operations-to-reduce-x-to-zero.py
minimum-path-sum.py
minimum-possible-integer-after-at-most-k-adjacent-swaps-on-digits.py
minimum-remove-to-make-valid-parentheses.py
minimum-score-triangulation-of-polygon.py
minimum-size-subarray-sum.py
minimum-subsequence-in-non-increasing-order.py
minimum-swaps-to-arrange-a-binary-grid.py
minimum-swaps-to-group-all-1s-together.py
minimum-swaps-to-make-sequences-increasing.py
minimum-swaps-to-make-strings-equal.py
minimum-time-difference.py
minimum-time-to-build-blocks.py
minimum-time-to-collect-all-apples-in-a-tree.py
minimum-time-visiting-all-points.py
minimum-unique-word-abbreviation.py
minimum-value-to-get-positive-step-by-step-sum.py
minimum-window-subsequence.py
minimum-window-substring.py
mirror-reflection.py
missing-element-in-sorted-array.py
missing-number-in-arithmetic-progression.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
most-visited-sector-in-a-circular-track.py
move-sub-tree-of-n-ary-tree.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
n-th-tribonacci-number.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-burgers-with-no-waste-of-ingredients.py
number-of-closed-islands.py
number-of-connected-components-in-an-undirected-graph.py
number-of-corner-rectangles.py
number-of-days-between-two-dates.py
number-of-days-in-a-month.py
number-of-dice-rolls-with-target-sum.py
number-of-digit-one.py
number-of-distinct-islands-ii.py
number-of-distinct-islands.py
number-of-distinct-subarrays-with-at-most-k-odd-integers.py
number-of-enclaves.py
number-of-equivalent-domino-pairs.py
number-of-good-leaf-nodes-pairs.py
number-of-good-pairs.py
number-of-good-ways-to-split-a-string.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-nodes-in-the-sub-tree-with-the-same-label.py
number-of-operations-to-make-network-connected.py
number-of-paths-with-max-score.py
number-of-recent-calls.py
number-of-segments-in-a-string.py
number-of-sets-of-k-non-overlapping-line-segments.py
number-of-ships-in-a-rectangle.py
number-of-squareful-arrays.py
number-of-steps-to-reduce-a-number-in-binary-representation-to-one.py
number-of-steps-to-reduce-a-number-to-zero.py
number-of-students-doing-homework-at-a-given-time.py
number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold.py
number-of-sub-arrays-with-odd-sum.py
number-of-subarrays-with-bounded-maximum.py
number-of-submatrices-that-sum-to-target.py
number-of-subsequences-that-satisfy-the-given-sum-condition.py
number-of-substrings-containing-all-three-characters.py
number-of-substrings-with-only-1s.py
number-of-valid-subarrays.py
number-of-valid-words-for-each-puzzle.py
number-of-ways-of-cutting-a-pizza.py
number-of-ways-to-form-a-target-string-given-a-dictionary.py
number-of-ways-to-paint-n-3-grid.py
number-of-ways-to-reorder-array-to-get-same-bst.py
剩余 1 项被截断
Shell
.travis.yml
LICENSE.md
README.md
bk3435_ble_app_merge_crc.bin
克隆/下载
cherry-pickup-ii.py 1.59 KB
一键复制 编辑 原始数据 按行查看 历史
kamyu 提交于 5年前 . Update cherry-pickup-ii.py
# Time: O(m * n^2)
# Space: O(n^2)
import itertools
class Solution(object):
def cherryPickup(self, grid):
"""
:type grid: List[List[int]]
:rtype: int
"""
dp = [[[float("-inf")]*(len(grid[0])+2) for _ in xrange(len(grid[0])+2)] for _ in xrange(2)]
dp[0][1][len(grid[0])] = grid[0][0] + grid[0][len(grid[0])-1]
for i in xrange(1, len(grid)):
for j in xrange(1, len(grid[0])+1):
for k in xrange(1, len(grid[0])+1):
dp[i%2][j][k] = max(dp[(i-1)%2][j+d1][k+d2] for d1 in xrange(-1, 2) for d2 in xrange(-1, 2)) + \
((grid[i][j-1]+grid[i][k-1]) if j != k else grid[i][j-1])
return max(itertools.imap(max, *dp[(len(grid)-1)%2]))
# Time: O(m * n^2)
# Space: O(n^2)
import itertools
class Solution2(object):
def cherryPickup(self, grid):
"""
:type grid: List[List[int]]
:rtype: int
"""
dp = [[[float("-inf")]*len(grid[0]) for _ in xrange(len(grid[0]))] for _ in xrange(2)]
dp[0][0][len(grid[0])-1] = grid[0][0] + grid[0][len(grid[0])-1]
for i in xrange(1, len(grid)):
for j in xrange(len(grid[0])):
for k in xrange(len(grid[0])):
dp[i%2][j][k] = max(dp[(i-1)%2][j+d1][k+d2] for d1 in xrange(-1, 2) for d2 in xrange(-1, 2)
if 0 <= j+d1 < len(grid[0]) and 0 <= k+d2 < len(grid[0])) + \
((grid[i][j]+grid[i][k]) if j != k else grid[i][j])
return max(itertools.imap(max, *dp[(len(grid)-1)%2]))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yuhang2__2/LeetCode-Solutions.git
git@gitee.com:yuhang2__2/LeetCode-Solutions.git
yuhang2__2
LeetCode-Solutions
LeetCode-Solutions
master

搜索帮助