leetcode

[Leetcode] Pascal's Triangle II 杨辉三角

Pascal's Triangle II Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3,3,1]. 从后往前覆盖法 复杂度 O(N) 时间 O(K) 空间 思路 一行一行地迭代,后面一行迭代覆盖前一行,窍门是:从后往前算

[Leetcode] Backtracking回溯法(又称DFS,递归)全解

回溯全集回溯是啥用爬山来比喻回溯,好比从山脚下找一条爬上山顶的路,起初有好几条道可走,当选择一条道走到某处时,又有几条岔道可供选择,只能选择其中一条道往前走,若能这样子顺利爬上山顶则罢了,否则走到一条绝路上时,只好返回到最近的一个路口,重新选择另一条没走过的道往前走。如果该路口的所有路都走不通,只得从该路口继续回返。照此规则走下去,要么找到一条到达山顶的路,要么最终试过所有

Sort Solors 解题思路

原文 : https://github.com/kbyyd24/bl...题目先把题目放上:链接:https://leetcode.com/problems...Given an array with n objects colored red, white or blue, sort them so that objects of the same color are

[Leetcode] Largest Number

Largest Number Given a list of non negative integers, arrange them such that they form the largest number. For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330. Note:

[Leetcode] First Missing Positive

First Missing PositiveGiven an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n)

[Leetcode] Permutation Sequence

Paint FenceThe set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order, We get thefollowing sequence (ie, for n = 3):"123" "132"

[Leetcode] Bulls and Cows 猜数字

Bulls and CowsYou are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a gue

[Leetcode] Paint Fence 栅栏涂色

Paint FenceThere is a fence with n posts, each post can be painted with one of the k colors.You have to paint all the posts such that no more than two adjacent fence posts have the same co