- 博客(10)
- 收藏
- 关注
原创 【leetcode】78. 子集
用动态规划:/** * @Auther: Mason * @Date: 2020/09/20/8:13 * @Description: *//*给定一组不含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集)。说明:解集不能包含重复的子集。用动态规划的方法进行解题。 */class Solution { public static void main(String[] args) { Solution s = new Solution(); .
2020-09-20 08:55:32 123
原创 Callable Future FutureTask
Callable接口只有一个call方法Future接口有get等方法FutureTask类实现了RunnableFuture接口RunnableFuture接口继承了Runnable和Future总之:Runnable可以想象成一个没有参数和返回值的异步方法,Callable与Runnable类似,但是有返回值。 public static void main(String[] args) throws InterruptedException, ExecutionException {
2020-09-19 14:53:26 126
原创 【leetcode】两数之和;三数之和;四数之和
两数之和可以排序,然后双指针;也可以用hashmap,记录数字和序号。遍历。三数之和升序排列,然后用三指针。第一个指针遍历。第二个指针遍历。第三个指针从后往前走。四数之和升序排列,用四指针。其实就是四层遍历。/** * @Auther: Mason * @Date: 2020/09/15/7:56 * @Description: */class Solution { public static void main(String[] args) { Soluti
2020-09-15 08:44:11 120
原创 【leetcode】77. 组合
我用的方法是 搜索回溯的方法。/** * @Auther: Mason * @Date: 2020/09/08/8:12 * @Description: */class Solution { public static void main(String[] args) { Solution s = new Solution(); List<List<Integer>> list = s.combine(4, 2); .
2020-09-08 09:02:44 171
原创 将Integer List 转换为int数组、将Integer Set转换为int数组
https://blog.csdn.net/gloriaied/article/details/103970729
2020-09-07 08:09:20 1584
原创 printStackTrace 方法【打印方法栈轨迹】
public class Demo01 { public void method() { int[] arr = new int[2]; try { int a = arr[5]; } catch (Exception e) { e.printStackTrace(); } } public void method2() { method(); }
2020-09-06 14:45:28 2241
原创 finally 遮蔽返回值 甚至吞掉异常
public class Demo01 { public int method(){ int[] arr = new int[2]; try{ int a = arr[5]; }finally { return 999; } } public static void main(String[] args) { Demo01 d = new Demo01()
2020-09-06 11:12:41 176
原创 List<Integer> 转为 int[]
// List<Integer> 转 int[]int[] intArray2 = listInteger1.stream() //先把List<Integer>转成Stream<Integer> .mapToInt(Integer::valueOf) //把Stream<Integer>转成IntStream .toArray();
2020-09-04 08:37:53 596
原创 【LeetCode】486. 预测赢家
自己没有做出来,看了官方的解答,我用dp[i][j]表示,作为先手,数组的起止坐标为i和j,自己获得的积分和对手获取积分差值的最大值。有状态转移方程:dp[i][j] = max{nums[i]-dp[i+1][j], nums[j]-dp[i][j-1]},用动态规划的方式来解决这道题目。/** * @Auther: Mason * @Date: 2020/09/01/8:15 * @Description: */// [1,5,233,7] 并不是拿最大的就好。比如我先拿1,你不管拿哪.
2020-09-01 19:44:04 298
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人