leetcode
文章平均质量分 71
leetcode的题目讲解
玉界尺
这个作者很懒,什么都没留下…
展开
-
LeetCode Two Sum
鄙人 刘天昊 csdn新用户 用博客来记录自己的学习过程也希望和网络上志同道合的朋友做一些交流leetcode篇因为研究生本科都不是cs出生,所以自学数据结构,所有的leetcode都是c语言实现Given an array of integers, return indices of the two numbers such that they add up to原创 2017-05-11 09:37:24 · 239 阅读 · 0 评论 -
LeetCode Add Two Numbers
鄙人 刘天昊 csdn新用户 用博客来记录自己的学习过程也希望和网络上志同道合的朋友做一些交流leetcode篇因为研究生本科都不是cs出生,所以自学数据结构,所有的leetcode都是C语言实现You are given two non-empty linked lists representing two non-negative i原创 2017-05-11 10:04:35 · 174 阅读 · 0 评论 -
LeetCode Longest Substring Without Repeating Characters
鄙人 刘天昊 csdn新用户 用博客来记录自己的学习过程也希望和网络上志同道合的朋友做一些交流leetcode篇因为研究生本科都不是cs出生,所以自学数据结构,所有的leetcode都是C语言实现Given a string, find the length of the longest substring without repeating cha原创 2017-05-11 12:18:35 · 180 阅读 · 0 评论 -
LeetCode Median of Two Sorted Arrays
鄙人 刘天昊 csdn新用户 用博客来记录自己的学习过程也希望和网络上志同道合的朋友做一些交流leetcode篇因为研究生本科都不是cs出生,所以自学数据结构,所有的leetcode都是C语言实现There are two sorted arrays nums1 and nums2 of size m and n respectively原创 2017-05-11 12:44:36 · 183 阅读 · 0 评论 -
LeetCode ZigZag Conversion
鄙人 刘天昊 csdn新用户 用博客来记录自己的学习过程也希望和网络上志同道合的朋友做一些交流leetcode篇因为研究生本科都不是cs出生,所以自学数据结构,所有的leetcode都是C语言实现The string "PAYPALISHIRING" is written in a zigzag pattern on a given number原创 2017-05-12 13:08:02 · 202 阅读 · 0 评论 -
LeetCode Climbing Stairs
鄙人 刘天昊 csdn新用户 用博客来记录自己的学习过程也希望和网络上志同道合的朋友做一些交流leetcode篇因为研究生本科都不是cs出生,所以自学数据结构,所有的leetcode都是C语言实现今天换换胃口,来说一说一道自己觉得很funny的题目You are climbing a stair case. It takes n steps原创 2017-05-12 13:43:05 · 205 阅读 · 0 评论 -
LeetCode Implement strStr()(朴素的字符串匹配,RK算法,KMP算法)
这次来个大整合,因为正好处理到经典的字符串匹配问题那么也是用c语言实现,现在开始吧Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.简单的问题描述,字符串needle是否尾h原创 2017-05-12 21:51:28 · 516 阅读 · 0 评论 -
LeetCode Distribute Candies
啦啦啦,我是刘天昊,那么今天来分享一道简单的题目,主要想和大家谈谈如何去加速自己的代码先看题目Given an integer array with even length, where different numbers in this array represent different kinds of candies. Each number means one candy原创 2017-05-15 17:35:55 · 326 阅读 · 0 评论 -
LeetCode Reverse Integer
大家好,我是刘天昊,这次的题目是比较简单的整数逆序先看题目Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321题目还有些提示Have you thought about this?Here are some good questi原创 2017-05-16 19:21:28 · 209 阅读 · 0 评论 -
LeetCode Pow(x,n)(分治法)
大家好,我是刘天昊,今天来说说这题吧,之前有写过这题,那么先看题目Implement pow(x, n).实现x的n次方的计算那么先来个正常人的思路,x*x*x......*x也就是n个x相乘,so,O(n),naive 挺好线性的实现了这个,你会发现你提交不上去,这个时候就要思考了啊我们要找个比O(n)还要小的时间复杂度ok先不考虑n的奇数 和偶数问题x的原创 2017-05-18 19:06:50 · 451 阅读 · 0 评论 -
LeetCode JumpGame and JumpGame II
大家好,今天给大家带来的是一个贪心算法的题目先来看下题目描述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原创 2017-05-19 11:38:03 · 211 阅读 · 0 评论 -
LeetCode Kth Largest Element in an Array
大家好,我是刘天昊,今天给大家带来的是《算法导论》里的一种算法在LeetCode中的体现同样是c语言给大家实现,废话不多说先看题目Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth dis原创 2017-05-22 14:32:48 · 232 阅读 · 0 评论 -
LeetCode 这次写点不一样的(快排序,随机快排序,归并排序)
2那么还是我刘天昊这次想和大家分享的是快排序和随机快排序的速度上的差异那么算法导论里的老师(MIT的一个教授)说过随机快排序在大量的数据的情况下会比快排序好接近三倍我觉得这句话是没问题的却是快了很多(三倍觉得略夸张)那么leetcode好在哪里就是不用我们自己做测试集好我们来说说一个我们说过的问题那么可以看我之前的博客里的这篇Distribute Candies这题虽然原创 2017-05-22 15:45:52 · 649 阅读 · 0 评论 -
LeetCode Binary Tree Level Order Traversal
大家好,我是刘天昊,这次带来的是树的题目发现自己树的题目po上来的不多(实际上还没能融汇贯通- 。 -)先来一个简答的树的层次遍历吧Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).Fo原创 2017-05-22 18:41:49 · 218 阅读 · 0 评论 -
LeetCode Merge Two Sorted Lists and Sort List
大家好,我是刘天昊,这次给大家带来的是链表的问题先说说 Merge Two Sorted 没记错的话这是第二次写关于链表的博客,这次抛砖引玉是为了和大家谈谈合并排序Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the原创 2017-05-25 15:32:19 · 251 阅读 · 0 评论 -
LeetCode 1.Minimum Path Sum 2.Unique Paths I and II
大家好,我是刘天昊,快到端午节了,今天说两道动态规划的题目(话说动规真的挺难的)当然这三题是一样的解体思路先看Unique Paths 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 m原创 2017-05-26 16:40:02 · 320 阅读 · 0 评论 -
LeetCode Merge k Sorted Lists(分治法)
hello world 我是刘天昊,今天给大家带来的是链表的合并,用到了之前说的合并排序的思想先看题目Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.我们先看看合并两个链表的操作struct ListNode *merge(struct原创 2017-05-28 16:06:17 · 260 阅读 · 0 评论 -
LeetCode Clone Graph
大家好,我是刘天昊,那么这次的题目厉害了因为之前我的blog也没有关于图结构的操作,这次特地找了leetcode总不多的图结构的操作题先看题目Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected原创 2017-05-31 12:56:09 · 295 阅读 · 0 评论 -
LeetCode 位运算操作集锦(一)
大家好,我是刘天昊,这次给大家带来的是leetcode中位运算的操作集锦那么一次放出三题,并且我会总结其中的位运算的操作那么直接开始(推荐直接在leetcode上找题目,先做做看再看我的blog,要有自己思考的过程)36. Valid SudokuDetermine if a Sudoku is valid, according to: Sudoku Puzzles -原创 2017-06-01 16:31:00 · 964 阅读 · 0 评论 -
LeetCode Trie树(前缀树)
大家好,我是刘天昊,这次带来的数据结构-前缀树那么先看题目,同样c语言带来的trie树very funnyImplement a trie with insert, search, and startsWith methods.Note:You may assume that all inputs are consist of lowercase letters原创 2017-06-05 20:43:23 · 511 阅读 · 0 评论 -
LeetCode Min Stack
大家好这几次都是带来的设计题,这题是设计一个栈,那么同样也是c语言带来的先看题目Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Remov原创 2017-06-05 21:20:01 · 379 阅读 · 0 评论 -
Permutations(主要谈谈如何做全排列,组合等回溯的使用)
Given a collection of distinct numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]原创 2017-06-26 15:17:34 · 719 阅读 · 0 评论 -
Letter Combinations of a Phone Number(回溯,dfs)
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit st原创 2017-06-29 17:09:04 · 606 阅读 · 0 评论 -
Word Search (如何在二维的题目中深搜,回溯)
先看题目Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or原创 2017-07-04 16:29:38 · 310 阅读 · 0 评论 -
Largest Rectangle in Histogram(分治法)
看题目先Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where原创 2017-07-04 16:34:09 · 284 阅读 · 0 评论 -
Maximum Subarray(分治法)
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原创 2017-07-04 19:02:17 · 584 阅读 · 0 评论 -
动态规划入门级教学(leetcode)53.Maximum Subarray
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原创 2017-07-25 20:17:02 · 217 阅读 · 0 评论 -
动态规划入门级教学(leetcode)121.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 (ie, buy one and sell one share of the stock),原创 2017-07-25 21:07:24 · 498 阅读 · 0 评论 -
动态规划入门级教程(leetcode) 198.House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house原创 2017-07-26 09:40:12 · 234 阅读 · 0 评论 -
动态规划中级教程(leetcode)152.Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous subarray [2,3] has the largest原创 2017-07-26 09:52:21 · 203 阅读 · 0 评论 -
动态规划中级教程300.Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence.For example,Given [10, 9, 2, 5, 3, 7, 101, 18],The longest increasing subsequence is [2, 3, 7, 101], theref原创 2017-07-26 12:32:33 · 214 阅读 · 0 评论 -
动态规划中级教程。 650. 2 Keys Keyboard
Initially on a notepad only one character 'A' is present. You can perform two operations on this notepad for each step: Copy All: You can copy all the characters present on the notepad (partial原创 2017-08-03 09:03:24 · 355 阅读 · 0 评论 -
动态规划中级教程 646. Maximum Length of Pair Chain
You are given n pairs of numbers. In every pair, the first number is always smaller than the second number.Now, we define a pair (c, d) can follow another pair (a, b) if and only if b . Chain原创 2017-08-03 10:10:26 · 293 阅读 · 0 评论 -
动态规划中级教程 651. 4 Keys Keyboard
651. 4 Keys KeyboardMy SubmissionsBack to ContestUser Accepted:262User Tried:454Total Accepted:265Total Submissions:928Difficulty:MediumImagine you have a s原创 2017-08-04 09:26:44 · 662 阅读 · 0 评论 -
动态规划中级教程 322. Coin Change
You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money原创 2017-08-04 12:13:31 · 392 阅读 · 0 评论 -
动态规划中级教程 343. Integer Break
Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.For example, given n = 2, ret原创 2017-08-04 12:30:14 · 279 阅读 · 0 评论 -
动态规划中级教程 377. Combination Sum IV
Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.Example:nums = [1, 2, 3]target = 4The pos原创 2017-08-04 16:21:17 · 215 阅读 · 0 评论 -
动态规划中级教程 279. Perfect Squares
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.For example, given n = 12, return 3 because 12 = 4 + 4 + 4; given n =原创 2017-08-07 16:07:53 · 252 阅读 · 0 评论 -
动态规划中级教程 96. Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \原创 2017-08-08 09:05:36 · 219 阅读 · 0 评论 -
239.Sliding windows maximum
Approach #1 Segment Tree [ Accepted ]AlgorithmIt is a RMQ question so we think about the segment tree.We query the Sliding window in O(LogN)O(LogN).c++class Solution {public: int n; vector<in原创 2017-09-13 08:45:57 · 176 阅读 · 0 评论