Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For example,Given [3,2,1,5,6,4] and k = 2, return 5. 思路: 堆.讲解:二叉堆 class Solution { public: //新插入i结点 其父节点为(i…
[LeetCode]764. Largest Plus Sign 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/largest-plus-sign/description/ 题目描述: In a 2D grid from (0, 0) to (N-1, N-1), every cell contains a 1, except thos…
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For example,Given [3,2,1,5,6,4] and k = 2, return 5. [一句话思路]:快速选择:先利用pivot进行两侧的排序,再选一侧递归查找. [一刷]: Kth函数中要调用一…
题目: Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements. 思路: 1.计算左子树元素个数leftSize. 2. leftSize+1 = K,则根节点即为第K个元素 leftSize >=k, 则第K个元素在左子树…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序 日期 题目地址:https://leetcode.com/problems/largest-perimeter-triangle/ 题目描述 Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero area, f…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/largest-divisible-subset/description/ 题目描述: Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in thi…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 三重循环 组合函数 日期 题目地址:https://leetcode.com/problems/largest-triangle-area/description/ 题目描述 You have a list of points in the plane. Return the area of the largest triangle that can…
题意: 在一个无序的数组中第k大的数是多少? 思路: 按照快排的思路,如果每次分成两段后,设为L和R.如果R>=k ,则答案在右边集合,否则在左边集合. 这里用了3位取中法.注意快排别给写死循环了. class Solution { public: int findKthLargest(vector<int>& nums, int k) { ; ,nums.size()-,k); } int DFS(vector<int>& nums,int s,int e,…
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7 return its…
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example,Given 1->2->3->3->4->4->5, return 1->2->5.Given 1->1->1->2->3, return 2->3.…