我用的也是dp,66.67,后来想了一下用股票数量/股票单价的应该先取,排序依次取就行了,可惜没时间了,也不知道这样写对不对; ``` java public int planStock (int[][] order, int balance) { Arrays.sort(order, Comparator.comparingDouble(o -> -o[1]*1.0 / o[0])); int ans=0; for (int[] ints : order) { if (balance >= ints[1] * ints[0]) { ans += ints[1]; balance-=ints[1] * ints[0]; } } return ans; } ```
点赞 评论

相关推荐

给🐭🐭个面试机会吧:嘿,mvbatis
点赞 评论 收藏
分享
牛客网
牛客企业服务