上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 33 下一页
摘要: 效率不是很好的样子 回溯 用时一小时15分钟 public List<Integer> grayCode(int n) { List<Integer> list = new ArrayList<>(); if(n == 0){ list.add(0); return list; } //当n>1时 阅读全文
posted @ 2020-07-10 17:28 欣姐姐 阅读(180) 评论(0) 推荐(0) 编辑
摘要: 用布尔数组标记是否被访问过,来排查 public boolean isValidSudoku(char[][] board) { //用boolean数组进行标记,是否访问过。 //依次对行列块的数字进行遍历 boolean[] used = new boolean[9]; for(int i = 阅读全文
posted @ 2020-07-10 10:33 欣姐姐 阅读(126) 评论(0) 推荐(0) 编辑
摘要: public String getPermutation(int n, int k) { //itemlist 为原始顺序数列 List<Integer> itemList = new ArrayList<>(); if(n==1){ return "1"; } //阶乘数据 List<Intege 阅读全文
posted @ 2020-07-10 09:51 欣姐姐 阅读(125) 评论(0) 推荐(0) 编辑
摘要: 用哈希表 public int longestConsecutive(int[] nums) { //未排序的数组,先进行排序再进行遍历???光排序就是O(n2)的时间复杂度了吧。 //还有啥办法 //加入哈希map,比较有没有与当前数字连续的键,如果有就进行添加,按顺序。但是这样的话,并不能一下子 阅读全文
posted @ 2020-07-09 11:08 欣姐姐 阅读(112) 评论(0) 推荐(0) 编辑
摘要: 自己想复杂了,虽然意识到了是什么问题,但是处理的过程复杂化了 public boolean search(int[] nums, int target) { int first = 0,last = nums.length; while(first != last){ int mid = first 阅读全文
posted @ 2020-07-08 17:12 欣姐姐 阅读(138) 评论(0) 推荐(0) 编辑
摘要: 完成,还算顺利 public List<List<String>> groupAnagrams(String[] strs) { //将第一个字符串放进一个数组,之后与前面的组的第一个字符串做比较, // 当出现新的字符的时候,就添加一个新的数组进去, // 依次类推,直到遍历结束,返回结果 //字 阅读全文
posted @ 2020-07-08 10:51 欣姐姐 阅读(203) 评论(0) 推荐(0) 编辑
摘要: 应该是用各种排序算法都行的吧 但是效果并不是很好,是可以优化的吧。 public void sortColors(int[] nums) { int n = nums.length; for(int i = 0;i<n;i++){ for(int j =i;j<n;j++){ if(nums[i]> 阅读全文
posted @ 2020-07-06 09:23 欣姐姐 阅读(134) 评论(0) 推荐(0) 编辑
摘要: 自己哼哧哼哧做了好久,两个多小时,终于完成了。。。 public boolean isMatch(String s, String p) { //对p进行预处理 int j = 0; while (j+1<p.length()){ if(p.charAt(j) == '*' && p.charAt( 阅读全文
posted @ 2020-07-05 17:34 欣姐姐 阅读(162) 评论(0) 推荐(0) 编辑
摘要: 还可以; public void merge(int[] nums1, int m, int[] nums2, int n) { if(m == 0){ if (n >= 0) System.arraycopy(nums2, 0, nums1, 0, n); return; } int k = nu 阅读全文
posted @ 2020-07-03 11:31 欣姐姐 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 虽然做出来了,但是好像效果并不是很好。。 public Node connect(Node root) { if(root == null){ return null; } //构建一个队列 Queue<Node> queue = new ArrayDeque<>(); queue.add(root 阅读全文
posted @ 2020-07-03 10:20 欣姐姐 阅读(197) 评论(0) 推荐(0) 编辑
上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 33 下一页