随笔分类 - LeetCode_分治
摘要:具体可参考 https://leetcode-cn.com/problems/shu-zu-zhong-de-ni-xu-dui-lcof/solution/bao-li-jie-fa-fen-zhi-si-xiang-shu-zhuang-shu-zu-b/ 代码如下: 1 class Solut
阅读全文
摘要:题目描述: 求一个整数 x 的平方根,返回整数,结果是小数 ,就向下取整。 思路: x的平方根 一定在 [1,x ] 区间内,使用二分查找,在 O(log x) 时间就可找到。 代码如下所示。 1 class Solution { 2 public: 3 //二分法 Time O(log x) 空间
阅读全文
摘要:题目描述: 在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对。 输入一个数组,求出这个数组中的逆序对的总数。 示例 1: 输入: [7,5,6,4] 输出: 5 限制: 0 <= 数组长度 <= 50000 分析: 本题的暴力方法显然容易想到,但是会报超时,难度等级 h
阅读全文
摘要:Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. Example: Inpu
阅读全文

浙公网安备 33010602011771号