leetcode
文章平均质量分 60
玉界尺
这个作者很懒,什么都没留下…
展开
-
LeetCode 847. Shortest Path Visiting All Nodes
这周lc比赛最后一题比较复杂拿出来说下An undirected, connected graph of N nodes (labeled 0, 1, 2, ..., N-1) is given as graph.graph.length = N, and j != i is in the list graph[i] exactly once, if and only if nodes i...原创 2018-06-06 16:14:21 · 1121 阅读 · 0 评论 -
weekly contest 56 第一题 1-bit and 2-bit Characters
题目We have two special characters. The first character can be represented by one bit 0. The second character can be represented by two bits (10 or 11).Now given a string represented by several bits. Ret原创 2017-10-31 09:29:51 · 175 阅读 · 0 评论 -
动态规划hard--639. Decode Ways II
题目A message containing letters from A-Z is being encoded to numbers using the following mapping way:'A' -> 1'B' -> 2...'Z' -> 26Beyond that, now the encoded string can also contain the character '*原创 2017-10-18 16:37:40 · 226 阅读 · 0 评论 -
动态规划中级教程91. Decode Ways
先看题目A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total number原创 2017-10-18 16:16:49 · 173 阅读 · 0 评论 -
447. Number of Boomerangs
Approach #1 (Brute Force) [Time Limit Exceeded]AlgorithmCheck all the points that satisfied distance( points i , points j ) == distance( points i , points k )c++class Solution {public: int distan原创 2017-09-13 08:51:05 · 239 阅读 · 0 评论 -
423. Reconstruct Original Digits from English
Approach #1 Simple Solution with Hash Table[Accept]AlgorithmFirst we can find the characters ‘z’ of “zero” is unique and ‘w’ of “two” is unique as well the ‘u’ of “four” and ‘x’ of “six”.So we can easi原创 2017-09-13 08:50:08 · 159 阅读 · 0 评论 -
334. Increasing Triplet Subsequence
Approach # 1 Brute Force [ Time Limit Exceeded ]AlgorithmFor each num of array (index from 1 to n - 1 ), we check whether index i meets such conditions1 If it exist a index j (index from 0 to i -原创 2017-09-13 08:49:10 · 139 阅读 · 0 评论 -
23.Merge k sorted lists
Approach #1 Brute Force [Accepted]AlgorithmThis is a simple solution , we merge each two lists from 0 to k ( lists size ) . We can refer to 21. Merge Two Sorted Lists c++class Solution {public: L原创 2017-09-13 08:47:58 · 175 阅读 · 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 · 145 阅读 · 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 · 193 阅读 · 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 · 245 阅读 · 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 · 346 阅读 · 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 · 648 阅读 · 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 · 198 阅读 · 0 评论 -
weekly contest 56 第二题 443. String Compression
题目String Compression My SubmissionsBack to Contest User Accepted: 1210 User Tried: 1446 Total Accepted: 1223 Total Submissions: 3403 Difficulty: Easy Given an array of characters, compress it in原创 2017-10-31 09:36:16 · 499 阅读 · 0 评论 -
LeetCode Weekly Contest 56 第三题
题目Maximum Length of Repeated Subarray My SubmissionsBack to Contest User Accepted: 778 User Tried: 1121 Total Accepted: 744 Total Submissions: 1920 Difficulty: Medium Given two integer arrays A原创 2017-10-31 09:41:50 · 172 阅读 · 0 评论 -
LeetCode Weekly Contest 56 Find K-th Smallest Pair Distance
题目Given an integer array, return the k-th smallest distance among all the pairs. The distance of a pair (A, B) is defined as the absolute difference between A and B.Example 1: Input: nums = [1,3,1]原创 2017-10-31 09:54:05 · 273 阅读 · 0 评论 -
多叉树(二叉树)的递归与非递归的后序遍历
之前说过前序遍历 这次我就教教大家如何用前序遍历的方法搞定后序遍历之前写过的结构体不再重复书写了void dfs( TreeNode *root ){ if( root == NULL ) return ; dfs( root->left ); dfs(root->right ); cout root->valendl ;}原创 2018-01-25 21:08:55 · 1527 阅读 · 0 评论 -
多叉树(包括二叉)如何用栈和递归两种方法前序遍历
算法学习所学习的永远不是代码而是思想首先说二叉树的前序遍历 定义二叉树的结构体(类)calss TreeNode{public: int val ; TreeNode *left ; TreeNode *right ; TreeNode ( int _val) { val = _val ; left == NULL原创 2018-01-24 13:11:56 · 582 阅读 · 0 评论 -
二叉树的递归非递归实现的中序遍历
和前序遍历类似这次我们不引入多叉树的概念(因为你不能判断你在哪个中间不像二叉树,所以不引入多叉树的的中序遍历)首先定义树的结构struct TreeNode { int val ; TreeNode *left; TreeNode *right ; TreeNode( int _val ){ val = _val; left原创 2018-01-24 19:30:18 · 430 阅读 · 0 评论 -
图论(二) - 并查集相关题目和代码
题目There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a direct friend of C, then原创 2017-12-29 14:03:00 · 175 阅读 · 0 评论 -
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 · 219 阅读 · 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 · 426 阅读 · 0 评论 -
leetcode weekly contest 61 ( 740. Delete and Earn )
Given an array nums of integers, you can perform operations on the array.In each operation, you pick any nums[i] and delete it to earn nums[i] points. After, you must delete every element equal to nums原创 2017-12-05 14:26:37 · 737 阅读 · 0 评论 -
leetcode weekly contest 61(739. Daily Temperatures)
Given a list of daily temperatures, produce a list that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for which this i原创 2017-12-05 14:15:15 · 892 阅读 · 0 评论 -
leetcode weekly contest 61 ( 738. Monotone Increasing Digits )
Given a non-negative integer N, find the largest number that is less than or equal to N with monotone increasing digits.(Recall that an integer has monotone increasing digits if and only if each pair o原创 2017-12-05 14:06:00 · 378 阅读 · 0 评论 -
weekly contest 55 第三题 Subarray Product Less Than K
题目Your are given an array of positive integers nums.Count and print the number of (contiguous) subarrays where the product of all the elements in the subarray is less than k.Example 1:Input: nums = [1原创 2017-10-23 15:39:36 · 595 阅读 · 0 评论 -
weekly contest 55 第二题Minimum ASCII Delete Sum for Two Strings
题目Given two strings s1, s2, find the lowest ASCII sum of deleted characters to make two strings equal.Example 1:Input: s1 = "sea", s2 = "eat"Output: 231Explanation: Deleting "s" from "sea" adds the原创 2017-10-23 15:17:19 · 130 阅读 · 0 评论 -
weekly contest 55 Best Time to Buy and Sell Stock with Transaction Fee
题目Your are given an array of integers prices, for which the i-th element is the price of a given stock on day i; and a non-negative integer fee representing a transaction fee.You may complete as many t原创 2017-10-23 14:21:20 · 1159 阅读 · 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 · 175 阅读 · 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 · 219 阅读 · 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 · 467 阅读 · 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 · 277 阅读 · 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 · 191 阅读 · 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 · 157 阅读 · 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 · 171 阅读 · 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 · 190 阅读 · 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 · 194 阅读 · 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 · 501 阅读 · 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 · 278 阅读 · 0 评论