![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode
文章平均质量分 69
风小西
看球,踢球,码代码。
展开
-
LeetCode - Best Time to Buy and Sell Stock IV
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 at most k transactionsO(N^3)算法,dp[i][k]原创 2015-07-23 23:19:49 · 319 阅读 · 0 评论 -
LeetCode - Reverse Linked List
Reverse Linked List Total Accepted: 27232 Total Submissions: 85395My SubmissionsQuestion Solution Reverse a singly linked list.非递归: ListNode* reverse原创 2015-07-16 13:27:39 · 274 阅读 · 0 评论 -
LeetCode - Palindrome Linked List
Palindrome Linked List Total Accepted: 4904 Total Submissions: 20945My SubmissionsQuestion Solution Given a singly linked list, determine if it is a palindrome.Follow up:Coul原创 2015-07-16 13:51:15 · 399 阅读 · 0 评论 -
LeetCode - Largest Number (sort的cmp的写法)
Largest Number Total Accepted: 23153 Total Submissions: 146500My SubmissionsQuestion Solution Given a list of non negative integers, arrange them such that they form the largest原创 2015-07-15 14:03:49 · 468 阅读 · 0 评论 -
LeetCode - Dungeon Game
Dungeon Game Total Accepted: 11922 Total Submissions: 66851My SubmissionsQuestion Solution The demons had captured the princess (P) and imprisoned her in the bottom-right corner原创 2015-07-15 13:32:20 · 302 阅读 · 0 评论 -
LeetCode - Binary Search Tree Iterator
Binary Search Tree Iterator Total Accepted: 20470 Total Submissions: 69577My SubmissionsQuestion Solution Implement an iterator over a binary search tree (BST). Your iterator wil原创 2015-07-14 13:41:56 · 286 阅读 · 0 评论 -
LeetCode - Majority Element
Majority Element Total Accepted: 47480 Total Submissions: 134338My SubmissionsQuestion Solution Given an array of size n, find the majority element. The majority element is the e原创 2015-07-13 12:54:46 · 453 阅读 · 0 评论 -
LeetCode - Excel Sheet Column
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 -> AB 首先算出多少位,再原创 2015-07-10 00:21:05 · 610 阅读 · 0 评论 -
LeetCode - Word Ladder II 题解
Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end, such that:Only one letter can be changed at a timeEach intermediate word must exi原创 2015-01-25 13:57:50 · 447 阅读 · 0 评论 -
LeetCode - Majority Element II
Majority Element II Total Accepted: 4935 Total Submissions: 23021My SubmissionsQuestion Solution Given an integer array of size n, find all elements that appear more than ⌊ n/3原创 2015-07-17 14:40:32 · 287 阅读 · 0 评论 -
LeetCode - Basic Calculator & Basic Calculator II
Implement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and em原创 2015-07-17 16:45:17 · 333 阅读 · 0 评论 -
LeetCode - Read N Characters Given Read4 II - Call multiple times
The API: int read4(char *buf) reads 4 characters at a time from a file.The return value is the actual number of characters read. For example, it returns 3 if there is only 3 characters left in the原创 2015-08-11 13:50:52 · 477 阅读 · 0 评论 -
LeetCode - Different Ways to Add Parentheses
Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are+, - and *.Example 1I原创 2015-08-03 17:58:20 · 396 阅读 · 0 评论 -
LeetCode - Shortest Palindrome (KMP)
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation.For exam原创 2015-08-03 16:18:23 · 370 阅读 · 0 评论 -
LeetCode - The Skyline Problem
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose you are given the locations and height of all the buildings as原创 2015-07-22 22:33:05 · 569 阅读 · 0 评论 -
LeetCode - Word Search II
Given a 2D board and a list of words from the dictionary, find all words in the board.Each word must be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those hor原创 2015-08-03 14:50:13 · 298 阅读 · 0 评论 -
LeetCode - Maximal Square
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0原创 2015-07-21 21:22:40 · 291 阅读 · 0 评论 -
LeetCode - Count Complete Tree Nodes
Given a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely filled,原创 2015-07-21 13:44:52 · 317 阅读 · 0 评论 -
LeetCode - Implement Trie (Prefix Tree)
Implement a trie with insert, search, and startsWith methods.Note:You may assume that all inputs are consist of lowercase letters a-z.一开始用了unorered_map,有点慢,换了数组后快了点class TrieNode {p原创 2015-08-01 09:42:31 · 337 阅读 · 0 评论 -
LeetCode - Sliding Window Maximum
Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window原创 2015-07-20 11:10:11 · 565 阅读 · 0 评论 -
LeetCode - Word Ladder 题解(各种最短路算法)
Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a timeEach intermediate word m原创 2015-01-24 10:01:35 · 761 阅读 · 0 评论 -
LeetCode - Best Time to Buy and Sell Stock III 题解
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 at most two transactions.Note:You ma原创 2015-01-23 13:41:34 · 326 阅读 · 0 评论 -
LeetCode - Binary Tree Maximum Path Sum 题解
Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Return 6.原创 2015-01-23 14:12:26 · 300 阅读 · 0 评论 -
LeetCode - Min Stack 题解
class MinStack {public: stack Stack; stack Min; void push(int x) { Stack.push(x); if(Min.empty() || x <= Min.top()) Min.push(x); } void pop() {原创 2014-11-22 22:32:55 · 358 阅读 · 0 评论 -
LeetCode - Anagrams 题解
Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.分析:对我这种英语不好的人来讲,理解题意比做题更加困难(捂脸)。原题是要求把一系列字符串中由相同字母组成的字符串打印出来(顺序可以不同)。于是可以对每原创 2014-11-27 15:14:15 · 315 阅读 · 0 评论 -
LeetCode - Regular Experssion Matching 题解
class Solution {public: bool isMatch(const char *s, const char *p) { if(*p == '\0' ) return (*s == '\0'); if(*(p+1) == '*'){ do{ if(isMatch(原创 2014-11-20 20:56:48 · 300 阅读 · 0 评论 -
LeetCode - Distinct Subsequences 题解
题目:Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (c原创 2014-11-15 19:00:59 · 386 阅读 · 0 评论 -
LeetCode - sqrt 题解
Implement int sqrt(int x).Compute and return the square root of x.分析:牛顿迭代法求平方根。原创 2014-11-16 10:24:26 · 310 阅读 · 0 评论 -
LeetCode - Text Justification 题解
Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You should pack your words in a greedy approach; that i原创 2014-11-16 10:58:56 · 360 阅读 · 0 评论 -
LeetCode - String to Integer (atoi) 题解
class Solution {public: int atoi(const char *str) { bool minusFlag = false; char *s = const_cast(str); while(*s != '\0' && isspace(*s)) s++; if(*s=='\0原创 2014-11-14 16:33:43 · 295 阅读 · 0 评论 -
LeetCode - Copy List with Random Pointer 题解
class Solution { public: RandomListNode *copyRandomList(RandomListNode *head) { if(!head) return NULL; RandomListNode *p = head;原创 2014-11-14 11:45:40 · 302 阅读 · 0 评论 -
LeetCode - Minimum Window Substring 题解
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window is "BAN原创 2014-11-30 14:59:00 · 485 阅读 · 0 评论 -
LeetCode - Permutation Sequnce 题解
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 (ie, for n = 3):"123""132""213""231""3原创 2014-11-30 21:14:57 · 322 阅读 · 0 评论 -
LeetCode - Maximum Gap 题解
Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 if the array contains less than 2 elements原创 2015-01-27 12:56:06 · 348 阅读 · 0 评论 -
LeetCode - 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 width o原创 2015-01-20 21:38:23 · 366 阅读 · 0 评论 -
LeetCode - 3Sum 题解
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c原创 2014-11-22 20:10:59 · 424 阅读 · 0 评论 -
LeetCode - Maximal Rectangle 题解
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.思路:用A[i][j]表示从i,j向上有多少个连续的1,之后可以转换成Largest Rectangle in Histogram原创 2015-01-20 22:14:14 · 326 阅读 · 0 评论 -
LeetCode - Interleaving String 题解
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", ret原创 2014-12-06 13:31:01 · 341 阅读 · 0 评论 -
LeetCode - Edit Distance 题解
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:原创 2014-12-05 21:23:55 · 310 阅读 · 0 评论 -
LeetCode - Palindrome Partitioning II 题解
Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab",Retu原创 2015-01-26 21:34:54 · 245 阅读 · 0 评论