上一页 1 ··· 11 12 13 14 15
摘要: 方法一: 动态规划 (O(n)) class Solution { public int lengthOfLIS(int[] nums) { int n = nums.length; if(n < 2) return n; int[] dp = new int[n+1]; // dp[i] : 以第 阅读全文
posted @ 2020-07-08 11:50 Sexyomaru 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 两种复杂度O(n)的方法 方法一:快速选择 class Solution { public int findKthLargest(int[] nums, int k) { int lo = 0, hi = nums.length - 1; // 当前partition 函数的区间边界 int tar 阅读全文
posted @ 2020-07-08 11:44 Sexyomaru 阅读(126) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 给定一个正数数组arr,arr的累加和代表金条的总长度,arr的每个数代表金条要分成的长度。规定长度为K的金条只需分成两块,费用为K个铜板。返回把金条分出arr中的每个数字的最小代价。 public static int split(int[] arr) { if(arr.length 阅读全文
posted @ 2020-07-07 21:40 Sexyomaru 阅读(353) 评论(0) 推荐(0) 编辑
摘要: 题目描述 给定两个整数W和K,W代表你拥有的初始资金,K代表你最多可以做K个项目。再给定两个长度为N的正数数组costs[]和profits[],代表一共有N个项目,costs[i]和profits[i]分别表示第i号项目的启动资金与做完后的利润(注意是利润,如果一个项目的启动资金为10,利润为4, 阅读全文
posted @ 2020-07-07 21:17 Sexyomaru 阅读(481) 评论(0) 推荐(0) 编辑
摘要: (一)请分别简单说一说进程和线程以及它们的区别。 进程是对运行时程序的封装,是系统进行资源调度和分配的的基本单位,实现了操作系统的并发; 线程是进程的子任务,是CPU调度和分派的基本单位,用于保证程序的 实时性,实现进程内部的并发; 一个程序至少有一个进程,一个进程至少有一个线程,线程依赖于进程而存 阅读全文
posted @ 2020-07-07 17:27 Sexyomaru 阅读(298) 评论(0) 推荐(0) 编辑
摘要: class TreeAncestor { int[][] dp; //预处理数组 dp[i][j] 表示i的第2^j个祖先 // 倍增思想 public TreeAncestor(int n, int[] parent) { dp = new int[n][(int)(Math.log(n) / M 阅读全文
posted @ 2020-07-07 16:43 Sexyomaru 阅读(159) 评论(0) 推荐(0) 编辑
摘要: 方法一:滑动窗口 class Solution { public List<Integer> partitionLabels(String s) { List<Integer> res = new ArrayList<>(); int[] arr = new int[128]; for(char c 阅读全文
posted @ 2020-07-07 16:35 Sexyomaru 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 不含负数,可能含有相同数值的山峰数组(环形) 山峰A和山峰B能互相看见的条件是: 1、AB是不同的山且相邻 2、AB是不同的山,且A到B的两个方向上至少有一个方向上没有比A高的山峰 分析:本题有两种情况 第一种是山峰都是不同高度的,这样的话本题就可以有O(1)的解,山峰如果是不同高度,那么当山峰数量 阅读全文
posted @ 2020-07-07 15:28 Sexyomaru 阅读(184) 评论(0) 推荐(0) 编辑
上一页 1 ··· 11 12 13 14 15