- 博客(6)
- 收藏
- 关注
原创 486. Predict the Winner
今天遇到一道很有趣的DP题,参考了MIT教授的思路。很显然,这道题current situation depends on another (the next) step’s result,适合用dynamic programming解决,但找出dp公式并不简单。因为我们有两个gamer,想知道第一个出手的gamer A能不能赢,则希望A每次出手都是在通向获得maximum score的道路上的最优选择;同时必须要假设第二个出手的gamer B肯定也是遵循同样的策略,希望每次出手都能在最终最大化地打击到
2020-07-22 08:25:28
167
原创 Binary search总结
Binary search问题三种基本工具1.从数组中找出等于目标值的数,不存在,返回-1public static int findOneTarget(int[] nums, int target) { int left = 0; int right = nums.length - 1; while (left <= right) { int mid = left + (right - left) / 2; if (nums[mid] == tar
2020-06-13 08:19:52
291
原创 300. Longest Increasing Subsequence
代码:class Solution { public int lengthOfLIS(int[] nums) { int[]tails=new int[nums.length]; int size=0; for(int n:nums){ int pos=binarySearchLarger(tails,n,size); if(pos==-1){ pos=size;
2020-06-13 06:37:41
132
原创 222. Count Complete Tree Nodes
代码:public int countNodes(TreeNode root) { int h=height(root); int count=0; while(root!=null){ if(height(root.right)==h-1){ count+=1<<h; root=root.right; }else{
2020-06-12 07:43:44
149
原创 446. Arithmetic Slices II - Subsequence
446是413. Arithmetic Slices问题同思路的DP多维扩展版。代码与说明先给出413代码:public int numberOfArithmeticSlices(int[] A) { int res=0; int dp=0; if(A.length<3)return res; int diff=A[1]-A[0]; // 默认搜索时动态地维护一个差值,不满足该差值时重启计算 for(int i=2;
2020-06-09 07:08:27
118
原创 Kendall tau distance坐标转换理解
数组a[],b[]转换过程分析想求a[]与b[]之间的Kendall tau distance,表面上是将a[]作为标准,期望在inversion函数中运算b[],求b[]以a[]为参照时的distance。但显然这样比较困难。那么如果想在普通标准下通过运算b[],求得a[]与b[]之间的Kendall tau distance,即使用以普通标准做为参照的newb[],则需要:a[]从普通标准上做了哪些变换,就要在b[]上逆向转换回去,得到newb[]。普通标准中0->0, 1->1,…,i
2020-06-04 06:11:29
376
1
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人