- 博客(3)
- 收藏
- 关注
原创 LeetCode 797 所有可能的路径
练习dfs的一道很好的题目 class Solution { List<List<Integer>> res=new ArrayList<>(); public List<List<Integer>> allPathsSourceTarget(int[][] graph) { int n= graph.length; boolean[] st=new boolean[n];//是否已访问过
2021-11-24 10:33:22
292
原创 Leetcode 34
思路:先通过二分查找找到元素,再从该位置向左、向右找到边界并输出。 若数组的每个元素都为目标值,则时间复杂度会上升到O(n)。 解答成功: 执行耗时:0 ms,击败了100.00% 的Java用户 内存消耗:40.9 MB,击败了99.77% 的Java用户 (不知道为啥这样可以近似双百) class Solution { public int[] searchRange(int[] nums, int target) { int l...
2021-11-13 09:52:22
854
原创 数组模拟单链表Java实现
思路:head为头节点,数组e[]储存每个节点的值,ne[]储存每个节点指向的下一节点的索引(位置),idx为当前数组储存到了哪个位置。 其次实现了插入、删除的功能。 public class LinkNode{ final int N=100010; int head; int[] e=new int[N];//储存每个节点的元素值 int[] ne=new int[N];//储存每个节点的下一节点的索引 int idx;//储...
2021-11-06 18:56:36
221
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人