![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
HELLO_蓝猫
这个作者很懒,什么都没留下…
展开
-
Leetcode 437. Path Sum III
You are given a binary tree in which each node contains an integer value.Find the number of paths that sum to a given value.The path does not need to start or end at the root or a leaf, but it must go downwards (traveling only from parent nodes to chil原创 2020-06-28 18:31:37 · 229 阅读 · 0 评论 -
Leetcode 405. Convert a Number to Hexadecimal
405.Convert a Number to HexadecimalEasy379102Add to ListShareGiven an integer, write an algorithm to convert it to hexadecimal. For negative integer,two’s complementmethod is used.Note:...原创 2020-04-27 18:28:40 · 238 阅读 · 0 评论 -
Leetcode 257. Binary Tree Paths
257.Binary Tree PathsEasy108579FavoriteShareGiven a binary tree, return all root-to-leaf paths.Note:A leaf is a node with no children.Example:Input: 1 / \2 3 \ 5Output:...原创 2019-10-23 16:08:15 · 144 阅读 · 0 评论 -
Leetcode 226. Invert Binary Tree
homebrew作者都不会的题目Invert a binary tree.Example:Input: 4 / \ 2 7 / \ / \1 3 6 9Output: 4 / \ 7 2 / \ / \9 6 3 1/** * Definition for a binar...原创 2019-10-23 11:19:32 · 131 阅读 · 0 评论 -
Leetcode 143. Reorder List
DescriptionHintsSubmissionsDiscussSolutionPick OneGiven a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You may not modify the values in the list's nodes, only nodes itse...原创 2018-06-26 13:17:02 · 114 阅读 · 0 评论 -
Leetcode 182. Duplicate Emails
Write a SQL query to find all duplicate emails in a table named Person.+----+---------+| Id | Email |+----+---------+| 1 | a@b.com || 2 | c@d.com || 3 | a@b.com |+----+---------+For e...原创 2018-07-27 10:30:09 · 136 阅读 · 0 评论 -
Leetcode 199. Binary Tree Right Side View
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { int...原创 2018-08-28 17:15:13 · 106 阅读 · 0 评论 -
Leetcode 200. Number of Islands
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume...原创 2018-09-03 15:13:49 · 84 阅读 · 0 评论 -
Leetocde 120. Triangle
class Solution {public: int minimumTotal(vector<vector<int>>& triangle) { //从下向上加 vector<int> minans(triangle.back()); for (int layer = triangle.size() - 2; layer ...原创 2018-09-07 12:06:27 · 120 阅读 · 0 评论 -
leetcode 206. Reverse Linked List
# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneclass Solution: def reverseList(self, head): """ ...原创 2018-09-19 11:33:53 · 104 阅读 · 0 评论 -
leetcode 217. Contains Duplicate
class Solution: def containsDuplicate(self, nums): dict={} for x in nums: if x in dict.keys(): return True else: dict[x]=1...原创 2018-09-19 16:49:46 · 94 阅读 · 0 评论 -
Leetcode 207. Course Schedule
解法:把课程想象成一个图,进行拓扑排序,看图有没有环,没怀就true,反之不行。用邻接矩阵存储图,遍历一次课程,用一个队列存储入度为0的节点,把队列中的节点删掉,同时该节点连接的所有节点入度减一,当队列为空的时候,观察最后结果,看所有的点是不是入度全部为0.参考https://blog.csdn.net/wongleetion/article/details/79433101There...原创 2018-09-26 16:15:37 · 119 阅读 · 0 评论 -
Leetcode 189. Rotate Array
Given an array, rotate the array to the right by k steps, where k is non-negative.Example 1:Input: [1,2,3,4,5,6,7] and k = 3Output: [5,6,7,1,2,3,4]Explanation:rotate 1 steps to the right: [7,1...原创 2018-07-22 15:28:48 · 108 阅读 · 0 评论 -
Leetcode 863. All Nodes Distance K in Binary Tree
解法:便利所有除了目标节点分支的节点,标记他们的爸爸和自己是左是右。然后从目标节点向外便利。/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val...原创 2018-07-07 22:03:20 · 632 阅读 · 0 评论 -
Leetcode 139. Word Break 动态规划
解法参考:https://blog.csdn.net/yujin753/article/details/48010677Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-sepa...原创 2018-07-06 13:16:58 · 344 阅读 · 0 评论 -
Leetcode 147. Insertion Sort List
解法:找一个代排序列,一个排好序列,然后一个个比较,插入正确位置,重要一点,没插入完一个元素要更新rear的next。Sort a linked list using insertion sort.A graphical example of insertion sort. The partial sorted list (black) initially contains only the fi...原创 2018-06-26 15:40:13 · 153 阅读 · 0 评论 -
Leetcode 167. 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 su...原创 2018-07-08 15:07:32 · 126 阅读 · 0 评论 -
Leetcode 155. Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the ...原创 2018-06-27 09:50:19 · 141 阅读 · 0 评论 -
Leetcode 160. Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘ c...原创 2018-07-09 11:10:32 · 118 阅读 · 0 评论 -
Leetcode 165. Compare Version Numbers
Compare two version numbers version1 and version2.If version1 > version2 return 1; if version1 < version2 return -1;otherwise return 0.You may assume that the version strings are non-empty an...原创 2018-07-17 14:49:15 · 114 阅读 · 0 评论 -
173. Binary Search Tree Iterator
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class BSTIte...原创 2018-07-11 15:14:21 · 214 阅读 · 0 评论 -
Leetcode 138. Copy List with Random Pointer(深拷贝)
/** * Definition for singly-linked list with a random pointer. * struct RandomListNode { * int label; * RandomListNode *next, *random; * RandomListNode(int x) : label(x), next(NULL), ...原创 2018-07-05 12:48:12 · 121 阅读 · 0 评论 -
Leetcode 151. Reverse Words in a String
public class Solution { public String reverseWords(String s) { String []v=s.split(" "); /* for(String x:v) { System.out.println(x); }*/ String ans=""; for(int i=v.length-...原创 2018-07-05 21:02:14 · 193 阅读 · 0 评论 -
Leetcode 115. Distinct Subsequences
115. Distinct SubsequencesHard54125FavoriteShareGiven a string S and a string T, count the number of distinct subsequences of S which equals T.A subsequence of a string is a new string which i...原创 2018-12-29 16:17:56 · 389 阅读 · 0 评论 -
Leetcode 152. Maximum Product Subarray
152. Maximum Product SubarrayMedium159373FavoriteShareGiven an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product.E...原创 2018-12-31 14:26:50 · 218 阅读 · 0 评论 -
Leetcode 238. Product of Array Except Self
字典树Given an arraynumsofnintegers wheren> 1, return an arrayoutputsuch thatoutput[i]is equal to the product of all the elements ofnumsexceptnums[i].Example:Input: [1,2,3,4]Out...原创 2019-03-01 14:41:17 · 95 阅读 · 0 评论 -
Leetcode 236. Lowest Common Ancestor of a Binary Tree
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */cla...原创 2019-05-17 15:58:31 · 171 阅读 · 0 评论 -
Leetcode 32. Longest Valid Parentheses
Given a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substring.Example 1:Input: "(()"Output: 2Explanation: The longest valid...原创 2019-06-19 16:17:12 · 151 阅读 · 0 评论 -
Leetcode 284. Peeking Iterator
Given an Iterator class interface with methods:next()andhasNext(), design and implement a PeekingIterator that support thepeek()operation -- it essentially peek() at the element that will be retu...原创 2019-06-17 17:21:23 · 166 阅读 · 0 评论 -
leetcode 290. Word Pattern
Given apatternand a stringstr, find ifstrfollows the same pattern.Herefollowmeans a full match, such that there is a bijection between a letter inpatternand anon-emptyword instr.Exampl...原创 2019-06-18 14:13:24 · 117 阅读 · 0 评论 -
Leetcode 289. Game of Life
According to theWikipedia's article: "TheGame of Life, also known simply asLife, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."Given aboardwithmbyn...原创 2019-06-18 15:48:38 · 208 阅读 · 0 评论 -
Leetcode 1114. 按序打印
我们提供了一个类:public class Foo {public void one() { print("one"); }public void two() { print("two"); }public void three() { print("three"); }}三个不同的线程将会共用一个Foo实例。线程 A 将会调用 one() 方法线程 B 将会调...原创 2019-07-31 14:30:53 · 188 阅读 · 0 评论 -
Leetcode 1115. 交替打印FooBar
class FooBar {private: int n; std::mutex mutex_t; std::condition_variable cond; bool isfoo;public: FooBar(int n):isfoo(true){ this->n = n; } void fo...原创 2019-07-31 14:40:25 · 399 阅读 · 0 评论 -
Leetcode 1116. 打印零与奇偶数
控制台没问题,不知道为啥没ac 模版里面基数偶数写反了class ZeroEvenOdd {private: int n; mutex mu; condition_variable cond; bool is0,is1,is2;public: ZeroEvenOdd(int n) { this->n = n; ...原创 2019-07-31 16:41:29 · 378 阅读 · 0 评论 -
Leetcode 216. Combination Sum III
216.Combination Sum IIIMedium56429FavoriteShareFind all possible combinations ofknumbers that add up to a numbern, given that only numbers from 1 to 9 can be used and each combination should...原创 2019-05-13 16:18:08 · 106 阅读 · 0 评论 -
Leetcode 235. Lowest Common Ancestor of a Binary Search Tree
235.Lowest Common Ancestor of a Binary Search TreeEasy100079FavoriteShareGiven a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the...原创 2019-05-17 14:27:00 · 123 阅读 · 0 评论 -
Leetcode 213. House Robber II
class Solution {public: int fun(int start,int end,vector<int>&v) { int ans; int num = end - start + 1; int *dp = new int[num + 1]; dp[0] = 0; dp[1] = v[start]; for (int i = 2;...原创 2019-04-08 13:13:07 · 109 阅读 · 0 评论 -
LRU缓存 Leetocde146. LRU Cache
class Node{public: int key_t; int value_t; Node(int key,int value):key_t(key),value_t(value) { }};class LRUCache {public: list<Node> cache;//缓存 双向链表 方便插入...原创 2019-03-14 21:18:39 · 137 阅读 · 0 评论 -
Leetcode 211. Add and Search Word - Data structure design
Design a data structure that supports the following two operations:void addWord(word)bool search(word)search(word) can search a literal word or a regular expression string containing only lette...原创 2019-03-07 15:28:30 · 137 阅读 · 0 评论 -
Leetcode 208. Implement Trie (Prefix Tree) 字典树
class TriNode{public: bool isword; //char value; map<char,TriNode*> child; TriNode() { isword=false; }};class Trie {private: TriNode *root;public: ...原创 2019-03-19 23:39:45 · 124 阅读 · 0 评论