LeetCode
chenguiyuan1234
这个作者很懒,什么都没留下…
展开
-
LeetCode 96. Unique Binary Search Trees
96. Unique Binary Search Trees题目给定一个整数 n,求以 1 ... n 为节点组成的二叉搜索树有多少种?示例:输入: 3输出: 5解释:给定 n = 3, 一共有 5 种不同结构的二叉搜索树: 1 3 3 2 1 \ / / / \ \ 3 ...原创 2019-03-16 22:15:57 · 100 阅读 · 0 评论 -
Leetcode215. 数组中的第K个最大元素
执行用时 : 76 ms内存消耗 : 12.1 MBclass Solution(object): def findKthLargest(self, nums, k): """ :type nums: List[int] :type k: int :rtype: int """ nums =...原创 2019-05-07 10:13:54 · 148 阅读 · 0 评论 -
169.众数
class Solution(object): def majorityElement(self, nums): """ :type nums: List[int] :rtype: int """ ret, cnt = 0, 0 for num in nums: if c...原创 2019-05-06 22:34:02 · 167 阅读 · 0 评论 -
Leetcode第133周赛1030. 距离顺序排列矩阵单元格
题目内容给出 R 行 C 列的矩阵,其中的单元格的整数坐标为 (r, c),满足 0 <= r < R 且 0 <= c < C。另外,我们在该矩阵中给出了一个坐标为 (r0, c0) 的单元格。返回矩阵中的所有单元格的坐标,并按到 (r0, c0) 的距离从最小到最大的顺序排,其中,两单元格(r1, c1) 和 (r2, c2) 之间的距离是曼哈顿距离,|r1 ...原创 2019-04-24 10:59:36 · 178 阅读 · 0 评论 -
Leetcode第133周赛1031. 两个非重叠子数组的最大和
题目内容给出非负整数数组 A ,返回两个非重叠(连续)子数组中元素的最大和,子数组的长度分别为 L 和 M。(这里需要澄清的是,长为 L 的子数组可以出现在长为 M 的子数组之前或之后。)从形式上看,返回最大的 V,而 V = (A[i] + A[i+1] + ... + A[i+L-1]) + (A[j] + A[j+1] + ... + A[j+M-1]) 并满足下列条件之一: ...原创 2019-04-24 10:53:01 · 359 阅读 · 0 评论 -
LeetCode1035. 不相交的线
class Solution(object):def maxUncrossedLines(self, A, B):“”":type A: List[int]:type B: List[int]:rtype: int“”"# lenA, lenB = len(A), len(B)# dp = [[0 for i in range(lenB + 1)] for j in range(l...原创 2019-05-03 22:59:30 · 869 阅读 · 0 评论 -
Leetcode42.接雨水
class Solution {public:int trap(vector& heights) {vector left, right;int length = heights.size();// left[0]=heights[0];// right[length-1]=heights[length-1];int water=0;for(int i=1; i<le...原创 2019-04-19 14:11:06 · 129 阅读 · 0 评论 -
LeetCode-weekly-contest-134. Moving Stones Until Consecutive
题目内容原题链接:https://leetcode-cn.com/contest/weekly-contest-134/problems/moving-stones-until-consecutive/题目内容三枚石子放置在数轴上,位置分别为 a,b,c。每一回合,我们假设这三枚石子当前分别位于位置 x, y, z 且 x < y < z。从位置 x 或者是位置 z 拿起一...原创 2019-05-02 22:41:42 · 128 阅读 · 0 评论 -
Leetcode27.Remove Element
27.Remove Element题目原题链接:https://leetcode.com/problems/remove-element/题目内容: Given an array nums and a value val, remove all instances of that value in-place and return the new length. ...原创 2019-04-17 14:11:06 · 112 阅读 · 0 评论 -
Leetcode第133周赛1029. 两地调度
1029. 两地调度题目内容用户通过次数 299用户尝试次数 494通过次数 305提交次数 985题目难度 Easy公司计划面试 2N 人。第 i 人飞往 A 市的费用为 costs[i][0],飞往 B 市的费用为 costs[i][1]。返回将每个人都飞到某座城市的最低费用,要求每个城市都有 N 人抵达。 示例:输入:[[10,20],[30,200],[400...原创 2019-04-21 21:58:09 · 279 阅读 · 0 评论 -
Leetcode015. 3sum
class Solution {public: vector<vector<int>> threeSum(vector<int>& nums) { vector<vector<int>> ret; sort(nums.begin(), nums.end()); for(in...原创 2019-04-16 21:03:53 · 114 阅读 · 0 评论 -
LeetCode2. Add Two Numbers
题目介绍原题链接:https://leetcode-cn.com/problems/add-two-numbersYou are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nod...原创 2019-04-12 21:57:24 · 123 阅读 · 0 评论 -
剑指offer_跳台阶
题目描述一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法(先后次序不同算不同的结果)。原题链接:https://www.nowcoder.com/practice/8c82a5b80378478f9484d87d1c5f12a4?tpId=13&tqId=11161&tPage=1&rp=1&ru=/ta/coding-i...原创 2019-04-02 11:04:19 · 104 阅读 · 0 评论 -
111. Minimum Depth of Binary Tree
题目描述Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path fromthe root node down to the nearest leaf node.Note: A leaf is a node with no chi...原创 2019-04-03 21:50:04 · 94 阅读 · 0 评论 -
LeetCode104. Maximum Depth of Binary Tree
题目原题链接https://leetcode.com/problems/maximum-depth-of-binary-tree/Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node do...原创 2019-03-22 21:36:41 · 112 阅读 · 0 评论 -
Leetcode 102. Binary Tree Level Order Traversal
题目描述题目链接:https://leetcode-cn.com/problems/binary-tree-level-order-traversal/给定一个二叉树,返回其按层次遍历的节点值。 (即逐层地,从左到右访问所有节点)。例如:给定二叉树: [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7返回其层次遍历结果...原创 2019-03-22 21:33:41 · 125 阅读 · 0 评论 -
LeetCode 101.对称二叉树
class Solution {public:bool isMirror(TreeNode* p, TreeNode* q){if(!p && !q)return true;else if(p && !q || !p && q)return false;else if(p->val == q->val){return i...原创 2019-03-18 12:56:03 · 101 阅读 · 0 评论 -
LeetCode 100. Same Tree
LeetCode 100. Same Tree题目描述原题链接:https://leetcode.com/problems/same-tree/description/Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered ...原创 2019-03-17 14:36:00 · 95 阅读 · 0 评论 -
剑指offer-用两个栈实现队列以及用两个队列实现一个栈
两个栈实现队列class Solution: def __init__(self): self.stack1 = [] self.stack2 = [] def push(self, node): self.stack1.append(node) def pop(self): if self.stack2:...原创 2019-10-10 22:08:00 · 137 阅读 · 0 评论