![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 71
夏洛的网
这个作者很懒,什么都没留下…
展开
-
【动态规划】常见动态规划题目总结
此博客是为总结动态规划常见题目题目1:word break1.1 题目描述:Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For exa...原创 2018-08-10 17:01:52 · 4413 阅读 · 0 评论 -
【leetcode】680. Valid Palindrome II(Python & C++)
680. Valid Palindrome II题目链接680.1 题目描述:Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome.Example 1:Input: “aba” Output: TrueExample 2:Input:原创 2017-09-19 20:51:14 · 1520 阅读 · 3 评论 -
【leetcode】160. Intersection of Two Linked Lists(Python & C++)
160. Intersection of Two Linked Lists题目链接160.1 题目描述:Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists: A:原创 2017-09-11 21:33:23 · 754 阅读 · 0 评论 -
【leetcode】234. Palindrome Linked List(Python & C++)
234. Palindrome Linked List题目链接234.1 题目描述:Given a singly linked list, determine if it is a palindrome.Follow up: Could you do it in O(n) time and O(1) space?234.2 解题思路:思路一:判断链表是否回文,找一个vector把链表里的值都一次原创 2017-09-02 20:15:34 · 1773 阅读 · 5 评论 -
【leetcode】479. Largest Palindrome Product(Python & C++)
479. Largest Palindrome Product题目链接479.1 题目描述:Find the largest palindrome made from the product of two n-digit numbers.Since the result could be very large, you should return the largest palindrome mod原创 2017-09-27 19:59:48 · 1053 阅读 · 0 评论 -
【leetcode】7. Reverse Integer(Python & C++)
7. Reverse Integer题目链接7.1 题目描述:Reverse digits of an integer.Example1: x = 123, return 321 Example2: x = -123, return -321Note: The input is assumed to be a 32-bit signed integer. Your function should原创 2017-09-27 18:33:45 · 1327 阅读 · 0 评论 -
【leetcode】290. Word Pattern(Python & C++)
290. Word Pattern题目链接290.1 题目描述:Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a n原创 2017-09-01 21:12:13 · 635 阅读 · 0 评论 -
【leetcode】189. Rotate Array(Python & C++)
189. Rotate Array题目链接189.1 题目描述:Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].189.2 解题思路:首先,本题中如果k比数组的原创 2017-09-26 09:29:38 · 439 阅读 · 0 评论 -
【二叉树】常用处理与leetcode相关题目总结
前言:这学期刷leetcode时碰到了不少二叉树的题目,以前一看到二叉树就头疼,于是乎也算做了很多这方面的题了,是时候整理一波了。本篇博客主要是围绕leetcode上关于树的题目展开的,其中也穿插一些二叉树的基本知识,如前序、中序、后序遍历的递归非递归遍历,广度优先搜索和深度优先搜索,层次遍历,结合栈和队列的应用等。语言方面用Python和C++两种语言各实现了一遍。以下,正文。100.Same T原创 2017-07-24 17:04:44 · 579 阅读 · 0 评论 -
【leetcode】111. Minimum Depth of Binary Tree(Python & C++)
111. Minimum Depth of Binary Tree题目链接111.1 题目描述:Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf原创 2017-08-31 22:13:41 · 382 阅读 · 0 评论 -
【leetcode】20. Valid Parentheses(Python & C++)
20. Valid Parentheses题目链接20.1 题目描述:Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.The brackets must close in the correct order, “(原创 2017-08-31 20:09:19 · 897 阅读 · 0 评论 -
【leetcode】665. Non-decreasing Array(Python & C++)
665. Non-decreasing Array题目链接665.1 题目描述:Given an array with n integers, your task is to check if it could become non-decreasing by modifying at most 1 element.We define an array is non-decreasing if ar原创 2017-09-28 21:35:45 · 1817 阅读 · 0 评论 -
【leetcode】400. Nth Digit(Python & C++)
400. Nth Digit题目链接400.1 题目描述:Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, …Note: n is positive and will fit within the range of a 32-bit signed integer (n < 2原创 2017-09-12 21:37:49 · 1636 阅读 · 0 评论 -
【leetcode】532. K-diff Pairs in an Array(Python & C++)
532. K-diff Pairs in an Array题目链接532.1 题目描述:Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. Here a k-diff pair is defined as an integer pai原创 2017-09-20 20:36:21 · 1351 阅读 · 0 评论 -
【leetcode】28. Implement strStr()(Python & C++)(KMP算法)
28. Implement strStr()题目链接28.1 题目描述:Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.28.2 解题思路:字符串匹配,一般都是普通解法和KMP算法。KMP算法看起来比较原创 2017-09-19 09:42:10 · 1528 阅读 · 0 评论 -
【leetcode】537. Complex Number Multiplication(Python & C++)
537. Complex Number Multiplication题目链接537.1 题目描述:Given two strings representing two complex numbers.You need to return a string representing their multiplication. Note i2 = -1 according to the definiti原创 2017-10-17 10:30:29 · 677 阅读 · 0 评论 -
【leetcode】419. Battleships in a Board(C++ & Python)
419. Battleships in a Board题目链接419.1 题目描述:Given an 2D board, count how many battleships are in it. The battleships are represented with ‘X’s, empty slots are represented with ‘.’s. You may assume the f原创 2017-10-24 22:38:36 · 486 阅读 · 0 评论 -
【leetcode】338. Counting Bits(C++ & Python)
338. Counting Bits题目链接338.1 题目描述:Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an a原创 2017-10-24 20:36:45 · 537 阅读 · 0 评论 -
【leetcode】513. Find Bottom Left Tree Value(Python & C++)
513. Find Bottom Left Tree Value题目链接513.1 题目描述:Given a binary tree, find the leftmost value in the last row of the tree.Example 1: Input: 2 / \ 1 3Output: 1Example 2: Input: 1 / \原创 2017-10-31 11:01:09 · 482 阅读 · 0 评论 -
【leetcode】442. Find All Duplicates in an Array(Python & C++)
442. Find All Duplicates in an Array题目链接442.1 题目描述:Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements that appear twic原创 2017-10-31 09:21:32 · 906 阅读 · 1 评论 -
【leetcode】654. Maximum Binary Tree(Python & C++)
654. Maximum Binary Tree题目链接654.1 题目描述:Given an integer array with no duplicates. A maximum tree building on this array is defined as follow:The root is the maximum number in the array. 1、The left sub原创 2017-10-12 20:48:11 · 1091 阅读 · 0 评论 -
【leetcode】204. Count Primes(Python & C++)
204. Count Primes题目链接204.1 题目描述:Description:Count the number of prime numbers less than a non-negative number, n.204.2 解题思路:思路一:分两步:第一步判断一个数是否是质数,第二步求出小于n的质数有多少。(结果超时)判断是否是质数:以i循环n,起始位置是2,结束位置是n的平方根。如原创 2017-09-21 21:22:03 · 509 阅读 · 0 评论 -
【leetcode】414. Third Maximum Number(Python & C++)
414. Third Maximum Number题目链接414.1 题目描述:Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be原创 2017-09-21 20:10:14 · 621 阅读 · 0 评论 -
【leetcode】69. Sqrt(x)(Python & C++)
69. Sqrt(x)[题目链接]https://leetcode.com/problems/sqrtx/description/)69.1 题目描述:Implement int sqrt(int x).Compute and return the square root of x.69.2 解题思路:思路一:直接从1到x/2之间遍历,判断是否是平方根的条件是,i*i小于等于x并且(i+1)*(i原创 2017-09-20 22:02:31 · 703 阅读 · 0 评论 -
【leetcode】438. Find All Anagrams in a String(Python & C++)
438. Find All Anagrams in a String[题目链接]https://leetcode.com/problems/find-all-anagrams-in-a-string/description/)438.1 题目描述:Given a string s and a non-empty string p, find all the start indices of p’s原创 2017-08-30 20:31:54 · 1340 阅读 · 0 评论 -
【leetcode】5. Longest Palindromic Substring(Python & C++)
5. Longest Palindromic Substring题目链接5.1 题目描述:Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example:Input: “babad”Output: “bab”Note:原创 2017-08-24 17:18:48 · 1419 阅读 · 0 评论 -
【leetcode】278. First Bad Version(Python & C++)
278. First Bad Version题目链接278.1 题目描述:You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since ea原创 2017-09-24 21:28:12 · 435 阅读 · 0 评论 -
【leetcode】219. Contains Duplicate II(Python & C++)
219. Contains Duplicate II题目链接219.1 题目描述:Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute d原创 2017-09-04 22:38:41 · 564 阅读 · 0 评论 -
【leetcode】203. Remove Linked List Elements(Python & C++)
203. Remove Linked List Elements题目链接203.1 题目描述:Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 –> 2 –> 6 –> 3 –> 4 –> 5 –> 6, val = 6 Return: 1 –> 2 –> 3 –> 4 –>原创 2017-09-04 21:08:02 · 487 阅读 · 0 评论 -
【leetcode】67. Add Binary(Python & C++)
67. Add Binary题目链接67.1 题目描述:Given two binary strings, return their sum (also a binary string).For example,a = “11” b = “1” Return “100”.67.2 解题思路:思路一:二进制相加的情况比较少,只有1、1和1、0和0、0,然后再加上是否进位就可以,所以可以直接列出所原创 2017-09-04 20:18:41 · 1064 阅读 · 3 评论 -
【leetcode】205. Isomorphic Strings(Python & C++)
205. Isomorphic Strings题目链接205.1 题目描述:Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a charact原创 2017-08-25 21:27:15 · 965 阅读 · 0 评论 -
【leetcode】112. Path Sum(Python & C++)
112. Path Sum题目链接112.1 题目描述:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the bel原创 2017-08-25 20:10:42 · 656 阅读 · 0 评论 -
【leetcode】38. Count and Say(Python & C++)
38. Count and Say题目链接38.1 题目描述:The count-and-say sequence is the sequence of integers with the first five terms as following:1112112111112211 is read off as “one 1” or 11. 11 is read off as “two原创 2017-08-24 19:40:28 · 560 阅读 · 0 评论 -
【leetcode】4. Median of Two Sorted Arrays(Python & C++)
4. Median of Two Sorted Arrays题目链接3.1 题目描述:There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O原创 2017-08-24 11:39:11 · 899 阅读 · 0 评论 -
【算法题】求二叉树所有节点的左右子树的绝对值差的和
题目描述:leetcode 563. Binary Tree Tilt: Given a binary tree, return the tilt of the whole tree.The tilt of a tree node is defined as the absolute difference between the sum of all left subtree node value原创 2017-06-05 20:12:35 · 1629 阅读 · 0 评论 -
【算法题】不使用加减乘除符号计算两数之和a+b
【算法题】不使用加减乘除符号计算两数之和a+b参考博客1:http://blog.csdn.net/morewindows/article/details/8710737参考博客2:http://blog.csdn.net/morewindows/article/details/73545711、a+b—–假设在十进制的情况下,5+7的进位是1,不进位和是2,最后的结果是1*10+2=12,所以在二原创 2017-05-02 20:34:35 · 904 阅读 · 0 评论 -
【算法题】非负整数的各位相加,直至变成个位数
参考博客:参考博客1——题目描述: leetcode 258: Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1原创 2017-05-05 22:08:18 · 1285 阅读 · 0 评论 -
【leetcode】88. Merge Sorted Array(Python & C++)
88. Merge Sorted Array题目链接88.1 题目描述:Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note: You may assume that nums1 has enough space (size that is greater o原创 2017-09-05 21:39:01 · 1812 阅读 · 0 评论 -
【leetcode】2. Add Two Numbers(Python & C++)
1原创 2017-08-24 09:36:08 · 1886 阅读 · 0 评论 -
【leetcode】1. Two Sum(Python & C++)
1. Two Sum题目链接题目描述:Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may n原创 2017-07-24 17:08:03 · 522 阅读 · 0 评论