Skip to content

Latest commit

 

History

History
46 lines (37 loc) · 1.38 KB

215.md

File metadata and controls

46 lines (37 loc) · 1.38 KB

✏️Leetcode基础刷题之(215. Kth Largest Element in an Array)

2019-02-27 吴亲库里 库里的深夜食堂


✏️题目描述

在一组无序数组中,找出第K个大的元素,.


✏️题目实例

给定一个数组[3,2,1,5,6,4],k=2,那么第k(k=2)的数就是5,


✏️题目分析

先把无序数组变成有序,然后计算当前数组的元素个数,第k个大的元素,说明他存在数组的位置是数组元素的个数-k


✏️最终实现

function findKthLargest($nums, $k) {
        sort($nums);
        $count=count($nums);
        return $nums[$count-$k];
    }

💾今天的数据库(184. Department Highest Salary)

💾题目描述

编写SQL查询以查找每个部门中薪水最高的员工。


💾最终实现sql

select d.name as Department ,e.Name as Employee ,e.Salary as Salary from Department d,Employee e,
(select DepartmentId,Max(Salary)Salary from Employee GROUP BY DepartmentId) m  where e.DepartmentId = d.Id 
and e.DepartmentId=m.DepartmentId
and e.Salary=m.Salary

联系