每天一道题:LeetCode】的更多相关文章

这道题leetcode上面写着是DP问题,问题是我一开始写了个简单的递归结果直接超时,所以没办法只好拿迭代来做了.题目如下: You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? 这个基本就可以很简单的做成递归.如果楼层是…
因是个人总结,只列出对自己有用的或较难的: 下面这道题,第一次拿到,我尝试用 开窗函数 ROW_NUMBER()OVER() 编号,但是发现不能够处理好连续的问题, 上网查找了别人的解法记录下来,其实原理 是 把 Logs 看成 三张表,每张表之间关联 -1 ,然后筛选出 Num 相等的 编写一个 SQL 查询,查找所有至少连续出现三次的数字. +----+-----+ | Id | Num | +----+-----+ | 1 | 1 | | 2 | 1 | | 3 | 1 | | 4 | 2…
栈 先来看一道题 Leetcode 32 Longest Valid Parentheses (最长有效括号) 给定一个只包含 '(' 和 ')' 的字符串,找出最长的包含有效括号的子串的长度. 示例 1: 输入: "(()" 输出: 2 解释: 最长有效括号子串为 "()" 示例 2: 输入: ")()())" 输出: 4 解释: 最长有效括号子串为 "()()" 这道题可以用动态规划来做,也能用简洁明了的栈来解决. 什么是…
本人是研二程旭猿一枚,还有半年多就要找工作了,想想上一年度面试阿里的算法工程师挂了,心有不甘啊,主要还是准备不足,对一些常见的算法问题没有去组织准备,为了明年找一份好的实习,就从现在开始,好好准备吧,每天刷一道题. LeetCode,OJ系统,不用多说,国外的,题目也非常好,只有精选的152道,不像别的OJ系统有刷不完的题,而且题目有浅有深,测试用例也非常严格,并且对时间复杂.空间复杂度都有一定的要求,非常考验一个程序猿的思维完整性. 本栏目记录我对LeetCode题目的解题思路与完整程序,程序…
题目一: Longest Substring Without Repeating Characters Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the…
想要学习算法.应付笔试或者应付面试手撕算法题,相信大部分人都会去刷 Leetcode,有读者问?如果我在 leetcode 坚持刷它个 500 道题,以后笔试/面试稳吗? 这里我说下我的个人看法,我认为不稳.下面说说为啥不稳以及算法题应该如何刷.如何学才比较好,当然,也会推荐自己学过的资料. 一.先说说笔试题 在刷 leetcode 的时候,你会发现,每道题的题意都很短,你只需要花十几秒的时间,就知道这道题是要你干嘛了,并且每道题所用道的算法思想都很明确,动态规划.递归.二分查找等,你可能很快就…
在LeetCode上刷一道题,题目如下: 3. 无重复字符的最长子串 给定一个字符串,请你找出其中不含有重复字符的?最长子串?的长度. 示例?1: 输入: "abcabcbb"输出: 3 解释: 因为无重复字符的最长子串是 "abc",所以其长度为 3. 示例 2: 输入: "bbbbb"输出: 1解释: 因为无重复字符的最长子串是 "b",所以其长度为 1. 示例 3: 输入: "pwwkew"输出: 3…
前两天刷leetcode的时候,突发奇想,leetcode中最难的一道题是什么样子的呢? 于是,我就将所有题目(https://leetcode-cn.com/problemset/all/ )按照通过率排了个序(中英文网站题目不同),找到了它(截止到目前 2021年4月5日,它的通过率依然是最低的): 题目描述如下: 请你实现三个 API append,addAll 和 multAll 来实现奇妙序列. 请实现 Fancy 类 : Fancy() 初始化一个空序列对象. void append…
刷题路线参考:https://github.com/chefyuan/algorithm-base 大家好,我是拿输出博客督促自己刷题的老三,前面学习了十大排序:万字长文|十大基本排序,一次搞定!,接下来我们看看力扣上有没有什么能拿排序解决的题目吧! 排序基础 简单了解一下基本的排序-- 基本排序分类: 基本排序性能: 排序方法 时间复杂度(平均) 时间复杂度(最坏) 时间复杂度(最好) 空间复杂度 稳定性 冒泡排序 O(n²) O(n²) O(n) O(1) 稳定 选择排序 O(n²) O(n…
题目一:Combinations Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For example, If n = 4 and k = 2, a solution is: [ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4], ] 分析: 题意给我们一个数字n, 和一个数字k,让我们求出从 1~~n中取出k个数所能得到的组合数…
题目一:Interleaving String Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example, Given: s1 = "aabcc", s2 = "dbbca", When s3 = "aadbbcbcac", return true. When s3 = "aadbbbaccc", retu…
题目一:Valid Number Validate if a given string is numeric. Some examples: "0" => true " 0.1 " => true "abc" => false "1 a" => false "2e10" => true Note: It is intended for the problem statement…
今天讲讲arm汇编中除法的底层实现.汇编代码本身比较长了,如需参考请直接拉到文末. 下面我直接把arm的除法算法的汇编代码转译成C语言的代码贴出来,并进行解析. 因为篇幅有限,所以在此只解析无符号整型的除法运算,关于无符号除法和有符号除法的区别请参考上一篇推送. 代码较长如下,电脑端看效果更佳,如无耐心请直接拉下去看讲解即可: #include<stdio.h> unsigned int count_leading_zeros(unsigned int num) { unsigned int…
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in the array. Here are few examples. [1,3,5,6], 5 → 2 [1,3,5,6], 2…
564. 寻找最近的回文数 给定一个整数 n ,你需要找到与它最近的回文数(不包括自身). "最近的"定义为两个整数差的绝对值最小. 示例 1: 输入: "123" 输出: "121" 注意: n 是由字符串表示的正整数,其长度不超过18. 如果有多个结果,返回最小的那个. PS: 可以证明以下结论: 如果n 的前半部分是整数N,那么它的解一定是 以下三者之一: N-1 和 N-1的回文组成的数字. N 和 N的回文组成的数字 N+1 和 N+1…
终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance 44.10% Meidum 475 Heaters  30.20% Easy 474 Ones and Zeroes  34.90% Meidum 473 Matchsticks to Square  31.80% Medium 472 Concatenated Words 29.20% Hard…
Find the length of the longest substring T of a given string (consists of lowercase letters only) such that every character in T appears no less than k times. Example 1: Input: s = "aaabb", k = 3 Output: 3 The longest substring is "aaa"…
题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For example: Given the below binary tree and sum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ / \ 7 2 5 1 return [ [5,4,11,2],…
题目链接:Recover Binary Search Tree | LeetCode OJ Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. Note: A solution using O(n) space is pretty straight forward. Could you devise a constan…
题目链接:Validate Binary Search Tree | LeetCode OJ Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key. The right…
最近刷LeetCode比较频繁,就购买了官方的参考电子书 (CleanCodeHandbook),里面有题目的解析和范例源代码,可以省去非常多寻找免费经验分享内容和整理这些资料的时间.惊喜的是,里面的所有源代码都是用java语言写的. 接下来的一段时间里,我会将里面的大部分内容翻译成中文,再加上一些小y自己的解法和扩展内容,以博客的形式发在博客园.我想,这会是一件非常有趣的事情. 以下是翻译的前言部分,第1.4题以及其解析部分. 前言: 嗨,各位刷LeetCode的小伙伴们. 就像你们看到这本书…
Sept. 13, 2015 Spent more than a few hours to work on the leetcode problem, and my favorite blogs about this problems: 1. http://siddontang.gitbooks.io/leetcode-solution/content/tree/construct_binary_tree.html 2.http://blog.csdn.net/linhuanmars/artic…
The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Now your job is to find the total Hamming distance between all pairs of the given numbers. Example: Input: 4, 14, 2 Output: 6 Explanat…
Winter is coming! Your first job during the contest is to design a standard heater with fixed warm radius to warm all the houses. Now, you are given positions of houses and heaters on a horizontal line, find out minimum radius of heaters so that all…
In the computer world, use restricted resource you have to generate maximum benefit is what we always want to pursue. For now, suppose you are a dominator of m 0s and n 1s respectively. On the other hand, there is an array with strings consisting of…
Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match girl has, please find out a way you can make one square by using up all those matchsticks. You should not break any stick, but you can link them up, a…
Given a list of words (without duplicates), please write a program that returns all concatenated words in the given list of words. A concatenated word is defined as a string that is comprised entirely of at least two shorter words in the given array.…
Given a non-empty string, encode the string such that its encoded length is the shortest. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note: k will be a positive integ…
Given a list of points that form a polygon when joined sequentially, find if this polygon is convex (Convex polygon definition). Note: There are at least 3 and at most 10,000 points. Coordinates are in the range -10,000 to 10,000. You may assume the…
In this problem, your job to write a function to check whether a input string is a valid IPv4 address or IPv6 address or neither. IPv4 addresses are canonically represented in dot-decimal notation, which consists of four decimal numbers, each ranging…