![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode刷题
文章平均质量分 87
XINGKONG_04
这个作者很懒,什么都没留下…
展开
-
LeetcodeOJ1 TwoSum
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 not use the sam原创 2017-11-22 10:26:38 · 203 阅读 · 0 评论 -
Leetcode398 Random Pick Index
题目Given an array of integers with possible duplicates, randomly output the index of a given target number. You can assume that the given target number must exist in the array.Note:The array size can b...原创 2018-03-05 00:02:48 · 222 阅读 · 0 评论 -
Leetcode172 Factorial Trailing Zeroes
题目Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.中文大意给定整数n,返回改整数阶乘n!结果的尾随零的个数分析直观的思路是:先求出阶乘结果n!,然原创 2018-03-05 14:50:28 · 177 阅读 · 0 评论 -
Leetcode70 Climbing Stairs
问题描述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?Note: Given n will be a positive...原创 2018-05-10 19:17:58 · 141 阅读 · 0 评论 -
leetcode121 Best Time to Buy and Sell Stock
问题描述Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock...原创 2018-05-11 10:05:21 · 133 阅读 · 0 评论 -
Leetcode122 Best Time to Buy and Sell Stock II
原题目Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy o...原创 2018-05-17 21:01:17 · 164 阅读 · 0 评论 -
Leetcode35 Search Insert Position
原文题目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....原创 2018-05-17 22:59:41 · 161 阅读 · 0 评论 -
Leetcode66 Plus One
原文题目Given a non-empty array of digits representing a non-negative integer, plus one to the integer.The digits are stored such that the most significant digit is at the head of the list, and each eleme...原创 2018-05-18 09:26:39 · 244 阅读 · 0 评论 -
Leetcode119 Pascal's Triangle II
原题目Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle.Note that the row index starts from 0.In Pascal's triangle, each number is the sum of the two numbers di...原创 2018-05-26 16:48:30 · 195 阅读 · 0 评论 -
Leetcode38 Count and Say
原题The count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113. 214. 12115. 1112211 is read off as "one 1" or 11.11 is read off as ...原创 2018-06-03 23:07:33 · 152 阅读 · 0 评论 -
Leetcode 58 Length of Last Word
原题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 defined...原创 2018-06-03 23:41:53 · 192 阅读 · 0 评论 -
Leetcode 67
英文原题Given two binary strings, return their sum (also a binary string).The input strings are both non-empty and contains only characters 1 or 0.Example 1:Input: a = "11", b = "1"Output: "100"Example 2...原创 2018-06-11 21:43:41 · 207 阅读 · 0 评论 -
Leetcode 168 Excel Sheet Column Title
原题Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> ...原创 2018-06-05 08:58:44 · 135 阅读 · 0 评论 -
Leetcode167 Two Sum II - Input array is sorted
原题Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers ...原创 2018-05-29 10:13:00 · 133 阅读 · 0 评论 -
Leetcode283 Move Zeroes
原题Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.Example:Input: [0,1,0,3,12]Output: [1,3,12,0,0]Note:You must do ...原创 2018-05-29 11:21:43 · 146 阅读 · 0 评论 -
Leetcode130 Surrounded Regions
题目Given a 2D board containing 'X' and 'O' (the letter O), capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region.For example,X X X XX O O ...原创 2018-03-03 23:11:33 · 271 阅读 · 0 评论 -
Leetcode628 Maximum Product of Three Numbers
题目Given an integer array, find three numbers whose product is maximum and output the maximum product.Example 1:Input: [1,2,3]Output: 6Example 2:Input: [1,2,3,4]Output: 24Note:The length of the giv...原创 2018-03-02 19:37:27 · 135 阅读 · 0 评论 -
Leetcode260 Single Number III
题目Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:原创 2018-03-02 09:24:20 · 166 阅读 · 0 评论 -
Leetcode 008 String to Integer
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca原创 2017-11-23 14:25:31 · 226 阅读 · 0 评论 -
Leetcode020 Valid Parentheses
Leetcode020 Valid Parentheses问题描述Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the co原创 2017-12-12 16:49:43 · 203 阅读 · 0 评论 -
Leetcode003 Longest Substring Without Repeating Characters
问题:Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer原创 2017-12-06 15:01:19 · 154 阅读 · 0 评论 -
Leetcode007 Reverse Integer
题目要求:Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21原创 2017-12-06 15:37:24 · 177 阅读 · 0 评论 -
Leetcode002 Add Two Numbers
问题:You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and原创 2017-11-27 19:57:28 · 213 阅读 · 0 评论 -
Leetcode009 Palindrome Number
问题Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the integer to stri原创 2017-12-07 11:21:37 · 302 阅读 · 0 评论 -
Leetcode013 Roman to Integer
问题Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.给定一个罗马数字,将其转换为阿拉伯数字,输入的范围为1-399分析1.先补充一下罗马数字的知识:(1)连写的数字重复不超过三次,比方说要表示4,就不原创 2017-12-07 15:51:28 · 249 阅读 · 0 评论 -
Leetcode012 Integer to Roman
问题Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.给定一个阿拉伯整数,将其转换为一个罗马数字,输入的范围为1-3999分析(1)关于罗马数字的问题,查看Leetcode013的内容。(2)问题的解决原创 2017-12-07 18:51:22 · 233 阅读 · 0 评论 -
java之树的遍历
深度优先遍历(Depth First Search,DFS)和广度优先遍历(Breadth First Search)是两种遍历树中元素的方式。深度优先遍历(DFS):对于上述tree来说,DFS的遍历结果为:A B D E C F G如果某个节点有子节点和兄弟节点,那么优先遍历子节点,左子树优先于右子树,直到子树都被深度遍历后,然后再遍历兄弟节点及其子树。由于不会立马遍历原创 2018-01-18 11:10:58 · 706 阅读 · 0 评论 -
Leetcode747 Min Cost Climbing Stairs(爬楼梯的最小代价)
题目:On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed).Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to reach the top of原创 2018-01-19 10:04:45 · 398 阅读 · 0 评论 -
Leetcode724 Find Pivot Index(数组的中间下标)
题目Given an array of integers nums, write a method that returns the "pivot" index of this array.We define the pivot index as the index where the sum of the numbers to the left of the index is equal to原创 2018-01-19 13:35:59 · 400 阅读 · 0 评论 -
Leetcode661 Image Smoother
题目Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother to make the gray scale of each cell becomes the average gray scale (rounding down) of all the 8 sur...原创 2018-02-27 09:58:31 · 283 阅读 · 0 评论 -
Leetcode553 Optimal Division
题目Given a list of positive integers, the adjacent integers will perform the float division. For example, [2,3,4] -> 2 / 3 / 4.However, you can add any number of parenthesis at any position原创 2018-02-28 19:55:37 · 225 阅读 · 0 评论 -
Leetcode643 Maximum Average Subarray I
题目Given an array consisting of n integers, find the contiguous subarray of given length k that has the maximum average value. And you need to output the maximum average value.Example 1:原创 2018-02-28 20:14:40 · 214 阅读 · 0 评论 -
回溯算法原理总结
回溯算法理论总结回溯法是一种类似枚举的搜索尝试过程,既然是枚举,那么就会遍历解空间树中的所有解(或者是“路径”),搜索的过程按照DFS原则,而尝试就意味着,在遍历的过程中,有可能到达某一个结点后,发现不能够满足约束条件,在这次尝试中,这条“路”是不优的,将走不通,即无法找到所求的解,那么就会回退到上一步的状态,重新作出选择。如果即满足约束条件,但是依然没有获得有效的解,那么我们就需要在此基础上...原创 2018-07-19 19:29:09 · 3618 阅读 · 0 评论