leetcode
文章平均质量分 51
头发太多而被寺庙拒收
总要让自己强大起来,才能保护身边的人
展开
-
腾讯50题刷题-python版
文章目录1. 简单题2. 中等题2.1 leetcode2-两数相加2.2 leetcode5-最长回文子串2.3 leetcode8-字符串转换整数2.4 leetcode11-盛最多水的容器2.5 leetcode15-三数之和2.6 leetcode16-最接近的三数之和2.7 leetcode33-搜索旋转排序数组2.8 leetcode43-字符串相乘2.9 leetcode46-全排列...原创 2020-03-04 13:12:06 · 2148 阅读 · 0 评论 -
leetcode刷题之链表专题
文章目录1.链表的操作1.1 删除链表的倒数第N个节点1.2 合并两个有序链表1.3 合并K个排序链表1.4 两两交换链表中的节点1.5 K个一组翻转链表1.6 旋转链表1.7 删除排序链表中的重复元素II1.8 删除排序链表中的重复元素1.9 分隔链表1.10 反转链表II1.11 重排链表1.12 对链表进行插入排序1.13 排序链表1.链表的操作1.1 删除链表的倒数第N个节点def...原创 2020-02-09 17:04:36 · 391 阅读 · 0 评论 -
leetcode34
题目:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target is not found in...原创 2019-02-20 22:16:44 · 446 阅读 · 0 评论 -
leetcode31
题目:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possib...原创 2019-02-20 18:37:51 · 158 阅读 · 0 评论 -
leetcode30
题目:You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once an...原创 2019-02-20 18:29:32 · 415 阅读 · 0 评论 -
leetcode57
题目:Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times. Ex...原创 2019-02-25 22:33:56 · 274 阅读 · 0 评论 -
leetcode56
题目:Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].解法一:这道和之前那道 Insert Interval 很类似,这次题目要求我们合并区间,之前那题...原创 2019-02-25 22:30:50 · 424 阅读 · 1 评论 -
leetcode55
题目:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if ...原创 2019-02-25 22:27:37 · 406 阅读 · 0 评论 -
leetcode54
题目:Given a matrix of m x n elements (m rows, ncolumns), return all elements of the matrix in spiral order.Example 1:Input:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]Output: [1,2,3,6,9,8,7,4,5]...原创 2019-02-25 22:19:57 · 295 阅读 · 0 评论 -
leetcode53
题目:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,1] ha...原创 2019-02-25 22:17:45 · 364 阅读 · 0 评论 -
leetcode52
题目:Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.解法:这道题是之前那道 N-Queens N皇后问题 的延伸,说是延伸其实我觉得两者顺序应该颠倒一样,上一道题比这道题还要稍稍复杂一些,两...原创 2019-02-25 22:12:31 · 177 阅读 · 0 评论 -
leetcode51
题目:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.Ea...原创 2019-02-25 22:11:13 · 238 阅读 · 0 评论 -
leetcode50
题目:Implement pow(x, n), which calculates x raised to the power n(xn).Example 1:Input: 2.00000, 10Output: 1024.00000Example 2:Input: 2.10000, 3Output: 9.26100Example 3:Input: 2.00000, -2Out...原创 2019-02-25 18:08:31 · 553 阅读 · 0 评论 -
leetcode49
题目:Given an array of strings, group anagrams together.Example:Input: ["eat", "tea", "tan", "ate", "nat", "bat"],Output:[ ["ate","eat","tea"], ["nat"原创 2019-02-25 18:00:04 · 460 阅读 · 0 评论 -
leetcode48
题目:You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You have to rotate the image in-place, which means you have to modify the input 2D matrix ...原创 2019-02-25 17:50:02 · 250 阅读 · 0 评论 -
leetcode29
题目:Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator.Return the quotient after dividing dividend by divisor.The integer division...原创 2019-02-20 08:59:59 · 94 阅读 · 0 评论 -
leetcode28
题目:Implement strStr().Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Example 1:Input: haystack = "hello", needle = "ll"Output: 2Exam...原创 2019-02-19 21:08:47 · 89 阅读 · 0 评论 -
leetcode32
题目:Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()", whi...原创 2019-02-20 22:00:10 · 82 阅读 · 0 评论 -
leetcode33
题目:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array return it...原创 2019-02-20 22:07:44 · 68 阅读 · 0 评论 -
腾讯50题刷题五&leetcode78
文章目录题目解法一思路代码解法二:思路:代码:题目Given a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate sub...原创 2019-08-11 21:24:26 · 157 阅读 · 0 评论 -
腾讯50题刷题七&leetcode231
文章目录题目解法一思路代码解法二思路题目Given an integer, write a function to determine if it is a power of two.Example 1:Input: 1Output: trueExample 2:Input: 16Output: trueExample 3:Input: 218Output: false解法...原创 2019-08-14 10:13:17 · 118 阅读 · 0 评论 -
leetcode63
题目:A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the...原创 2019-04-20 15:42:04 · 71 阅读 · 0 评论 -
leetcode62
题目:A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the...原创 2019-03-05 23:11:50 · 96 阅读 · 0 评论 -
leetcode61
题目:Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.解法一:链...原创 2019-03-05 23:07:06 · 69 阅读 · 0 评论 -
leetcode60
题目:The set [1,2,3,...,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order, we get the following sequence for n = 3:"123""132""213""231""312"...原创 2019-03-05 23:01:56 · 272 阅读 · 0 评论 -
leetcode58
题目:Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.Example:Input: 3Output:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ]]解法一:这道题是要按螺旋的顺序来填数,...原创 2019-03-05 22:59:33 · 135 阅读 · 0 评论 -
leetcode58
题目:Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is def...原创 2019-03-05 22:55:17 · 253 阅读 · 0 评论 -
leetcode40
题目:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combinat...原创 2019-02-21 08:43:58 · 107 阅读 · 0 评论 -
leetcode39
题目:Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.The same rep...原创 2019-02-21 08:39:56 · 98 阅读 · 0 评论 -
leetcode38
题目:The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as "one 2...原创 2019-02-21 08:33:17 · 192 阅读 · 0 评论 -
leetcode37
题目:write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character ‘.’.You may assume that there will be only one unique solution.A sudoku puzzle…...原创 2019-02-21 08:29:41 · 342 阅读 · 0 评论 -
leetcode36
题目:Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character ‘.’.A partially filled sudok...原创 2019-02-21 08:26:12 · 100 阅读 · 0 评论 -
leetcode35
题目: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...原创 2019-02-20 22:23:43 · 342 阅读 · 0 评论 -
leetcode27
题目:Given an array nums and a value val, remove all instances of that value in-place and return the new length.Do not allocate extra space for another array, you must do this by modifying the input ...原创 2019-02-19 21:02:22 · 209 阅读 · 0 评论 -
leetcode26
题目:Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this by modi...原创 2019-02-19 20:58:21 · 604 阅读 · 0 评论 -
leetcode7
class Solution {public: int reverse(int x) { long long res = 0; while(x) { res = res*10 + x%10; x /= 10; } return (res<INT_MIN||res>I...原创 2018-10-16 22:16:31 · 82 阅读 · 0 评论 -
leetcode20
解题思路:用一个栈保存未匹配的左括号,然后遍历字符串,判断当前字符是左括号还是右括号。如果当前字符是左括号,那么将其入栈;如果当前字符是右括号且栈非空,那么判断是否与栈顶的左括号相匹配,如果匹配则弹出栈顶元素,不匹配则返回false。最后判断栈是否为空。class Solution {public: bool isValid(string s) { stack<...原创 2018-10-16 22:15:09 · 175 阅读 · 0 评论 -
leetcode18
class Solution {public: vector<vector<int>> fourSum(vector<int>& nums, int target) { vector<vector<int> > res; int n = nums.size();...原创 2018-10-16 22:12:48 · 121 阅读 · 0 评论 -
leetcode17
class Solution {public: vector<string> letterCombinations(string digits) { vector<string> res; if(digits.length() == 0) return res...原创 2018-10-16 22:11:51 · 122 阅读 · 0 评论 -
leetcode16
class Solution {public: int threeSumClosest(vector<int>& nums, int target) { long res = INT_MAX; sort(nums.begin(), nums.end()); for(...原创 2018-10-16 22:04:29 · 97 阅读 · 0 评论