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];
}
编写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
