- 博客(150)
- 资源 (7)
- 收藏
- 关注
原创 子数组的最大累加和问题
题目链接public class Solution { /** * max sum of the subarray * @param arr int整型一维数组 the array * @return int整型 */ public int maxsumofSubarray (int[] arr) { // write code here if(arr.length==0) return 0;
2021-06-29 20:15:13
231
原创 树算法复习
1.树的最大深度递归public class Solution { /** * * @param root TreeNode类 * @return int整型 */ public int maxDepth (TreeNode root) { // write code here if(root==null) return 0; return Math.max(maxDepth(root
2021-06-29 19:59:05
231
原创 链表算法复习
1.两个链表生成相加链表注意用到栈结构,不需要单独算出每一个链表代表的数字import java.util.*;/* * public class ListNode { * int val; * ListNode next = null; * } */public class Solution { /** * * @param head1 ListNode类 * @param head2 ListNode类 * @re
2021-06-29 16:06:10
235
原创 学习:泛型
1.什么是泛型集合容器类在设计阶段/声明阶段不能确定这个容器到底实际存的是什么类型的对象,所以在JDK1.5之前只能把元素类型设计为Object,JDK1.5之 后使用泛型来解决。因为这个时候除了元素的类型不确定,其他的部分是确定的,例如关于这个元素如何保存,如何管理等是确定的,因此此时把元素的类型设计成一个参数,这个类型参数叫做泛型。...
2021-06-01 17:26:42
173
原创 牛客网:华为机试Day-1,1-10
1.字符串最后一个单词的长度import java.util.*;public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); String s=sc.nextLine(); String[] arr=s.split(" "); int length=arr[arr.length-1].length()
2021-05-30 17:34:10
164
原创 归并排序——递归、非递归、小和
1,递归 public void mergeSort(int[] arr){ if(arr==null || arr.length<2) return; sort1(arr,0,arr.length-1); } public void sort1(int[] arr,int l,int r){ if(l>=r) return; int mid=l+((r-l)>>1);
2021-03-21 21:19:42
91
原创 异或——交换、奇数次数、最右的1
1.2.设一个变量res异或每一个数3.a&((~a)+1)4.5.求二进制1的个数 public int bit1counts(int n){ int count=0; while(n!=0){ int rightOne=n&((~n)+1); count++; n^=rightOne; }
2021-03-20 23:03:06
158
原创 算法系列——二分法
目录1.有序数组,查找某个值2.有序数组,找满足>=value的最左位置3.有序数组,找满足<=value的最右位置4.局部最小值——二分法不止用法有序数组上1.有序数组,查找某个值2.有序数组,找满足>=value的最左位置 @Test public void test01(){ int[] arr={1,2,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4.
2021-03-20 22:22:00
140
原创 使用Mybatis遇到的错误
使用Mybatis遇到的错误1.在MybatisConfig.xml文件中设置延迟加载2.Mapper.xml的路径下次继续补充1.在MybatisConfig.xml文件中设置延迟加载 <properties resource="jdbc.properties"></properties> <settings> <setting name="lazyLoadingEnabled" value="true"/>
2021-03-11 16:20:29
217
原创 java: 请用java代码实现字符串的反转,如:输入abcde,输出edcba。
public class Main{ public static void main(String[] args) { String a="cdsjcnjanadbcds"; System.out.println(reverse(a)); } public static String reverse(String s){ StringBuilder sb=new StringBuilder(); for (int i.
2021-03-03 16:10:29
1746
1
原创 java根据元素出现的个数进行排序---hashmap、sort
给定一个正整数无序数组,按照出现的次数由少到多排序,如果两数次数相同则按照数由小到大排。例:给定数组:{3,3,3,2,2,4,4,1,8,7,7,7,7,6},排序结果为:[1, 6, 8, 2, 4, 3, 7]解析:1出现一次,6出现一次,8出现一次,按照1<6<8;2出现两次,4出现两次,按照2<4;3出现三次,7出现四次。提示:你可以使用Map,Java8 API来解决。我的解题:现将每个数与其出现的个数保存在hashmap中将hashmap的keySe...
2021-03-03 16:03:33
1534
1
原创 剑指 Offer 03. 数组中重复的数字----hashset / swap
剑指 Offer 03. 数组中重复的数字class Solution { public int findRepeatNumber(int[] nums) { HashSet<Integer> set=new HashSet<>(); int len=nums.length; for(int i=0;i<len;i++){ if(!set.add(nums[i])) return n...
2020-08-25 12:46:39
132
原创 剑指 Offer 34. 二叉树中和为某一值的路径
剑指 Offer 34. 二叉树中和为某一值的路径LinkedList的用法: list.removeLast()注意代码中添加路径时需要new LinkedList(list) 否则结果为空(可能是因为, new LinkedList(path)是深拷贝,要拷贝一个 path并添加~ 不然 res 里面所有的 path 都指向同一个对象)class Solution { LinkedList<List<Integer>> res=new LinkedL
2020-08-19 12:29:18
144
原创 剑指 Offer 55 - I. 二叉树的深度---递归/广度遍历
剑指 Offer 55 - I. 二叉树的深度方法一: 递归class Solution { public int maxDepth(TreeNode root) { if(root==null) return 0; return Math.max(maxDepth(root.left)+1,maxDepth(root.right)+1); }}方法二: 广度遍历(Queue)class Solution { public in
2020-08-18 18:19:40
122
原创 剑指 Offer 33. 二叉搜索树的后序遍历序列---递归
剑指 Offer 33. 二叉搜索树的后序遍历序列后序遍历数组: 左子树--右子树--根节点取根节点, 从从左向右遍历数组段, 以第一个大于根节点的元素的索引(k)分割数组段若右子树存在小于根节点的元素则falseclass Solution { public boolean verifyPostorder(int[] postorder) { if(postorder==null || postorder.length==0) return true;
2020-08-18 18:08:25
163
原创 剑指 Offer 32 - III. 从上到下打印二叉树 III---LinkedList(双向链表)
剑指 Offer 32 - III. 从上到下打印二叉树 IIILinkedListlist. addLastlist.addFirstlist.add--->从后面添加元素class Solution { public List<List<Integer>> levelOrder(TreeNode root) { List<List<Integer>> res=new ArrayList<>..
2020-08-18 17:44:03
105
原创 剑指 Offer 32 - II. 从上到下打印二叉树 II
剑指 Offer 32 - II. 从上到下打印二叉树 IIclass Solution { public List<List<Integer>> levelOrder(TreeNode root) { List<List<Integer>> res=new ArrayList<>(); Queue<TreeNode> q=new LinkedList<>();
2020-08-18 15:50:23
102
原创 剑指 Offer 32 - I. 从上到下打印二叉树---Queue
剑指 Offer 32 - I. 从上到下打印二叉树Queue的用法:https://www.runoob.com/java/data-queue.htmlQueue<String> queue = new LinkedList<String>();//添加元素queue.offer("a");System.out.println("poll="+queue.poll());//返回第一个元素,并在队列中删除System.out.println("eleme.
2020-08-18 15:35:34
133
原创 剑指 Offer 27. 二叉树的镜像--递归/Stack
剑指 Offer 27. 二叉树的镜像方法一: 递归class Solution { public TreeNode mirrorTree(TreeNode root) { if(root!=null){ TreeNode tmp=root.left; root.left=root.right; root.right=tmp; mirrorTree(root.left);
2020-08-18 15:19:28
135
原创 剑指 Offer 26. 树的子结构--递归
剑指 Offer 26. 树的子结构class Solution { public boolean isSubStructure(TreeNode A, TreeNode B) { if(A==null || B==null) return false; if(A.val ==B.val && func(A.right,B.right) && func(A.left,B.left))
2020-08-18 15:06:21
105
原创 剑指 Offer 07. 重建二叉树
剑指 Offer 07. 重建二叉树HashMap的用法:map.put(key,value)map.get(key)/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solutio
2020-08-18 14:50:45
170
原创 剑指 Offer 18. 删除链表的节点---双指针
剑指 Offer 18. 删除链表的节点方法一: 双指针/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */class Solution { public ListNode deleteNode(ListNode head, int val)
2020-08-18 11:15:13
172
原创 剑指 Offer 52. 两个链表的第一个公共节点---指针相遇
剑指 Offer 52. 两个链表的第一个公共节点链表1为A+C.链表2为B+C.当两个指针都走过程度A+B+C时会相遇, 若C=0,相遇时节点为null/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = ..
2020-08-18 10:51:28
138
原创 剑指 Offer 35. 复杂链表的复制---hashmap
35. 复杂链表的复制class Solution { public Node copyRandomList(Node head) { if(head==null) return null; HashMap<Node,Node> map=new HashMap<>(); Node cur=head; while(cur!=null){ map.put(cur,new Node(cur
2020-08-17 21:14:46
134
原创 剑指 Offer 25. 合并两个排序的链表---常规遍历/递归
25. 合并两个排序的链表我的方法:/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */class Solution { public ListNode mergeTwoLists(ListNode l1, ListNode l2) { .
2020-08-17 20:40:11
67
原创 剑指 Offer 22. 链表中倒数第k个节点 --双指针/递归
22. 链表中倒数第k个节点双指针/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */class Solution { public ListNode getKthFromEnd(ListNode head, int k) {
2020-08-17 19:47:08
157
原创 剑指 Offer 06. 从尾到头打印链表
06. 从尾到头打印链表方法一:使用栈, 从头到尾遍历链表, 保存每一个元素/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */class Solution { public int[] reversePrint(ListNode head)
2020-08-17 17:12:01
64
原创 java学习记录---前端 : 士兵行走
士兵图片链接:http://www.aigei.com/view/73716.html<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> *{ margin: 0; padding: 0; } div{ //position: r.
2020-08-04 17:01:51
116
原创 LeetCode刷题记录: 141. 环形链表
141. 环形链表方法一:哈希表/** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Solution { public boolean hasCy
2020-08-03 13:14:02
161
原创 LeetCode刷题记录: hashmap 1. 两数之和 387. 字符串中的第一个唯一字符
1. 两数之和class Solution { public int[] twoSum(int[] nums, int target) { HashMap<Integer,Integer> map=new HashMap<>(); for(int i=0;i<nums.length;i++){ if(map.containsKey(target-nums[i])) return
2020-08-03 12:43:28
198
原创 算法学习: (1)归并 (2)求小和 (3)求逆序对数目
目录1.归并排序2.小和3.降序对1.归并排序public class Merge { public static void mergeSort(int[] arr,int l,int r){ if(l==r) return; int mid=l+((r-l)>>1); mergeSort(arr,l,mid); mergeSort(arr,mid+1,r); merge(arr,
2020-08-01 15:07:30
167
原创 [JAVA学习]:打印日历_Calendar
package cal;import java.util.Calendar;import java.util.GregorianCalendar;import java.util.Scanner;public class Test1 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.print("请输入日期:"); ...
2020-06-19 18:02:29
479
原创 LeetCode 78. 子集 [中等]——动态规划 | 90. 子集 II
78. 子集class Solution {public: vector<vector<int>> subsets(vector<int>& nums) { int n=nums.size(); vector<vector<int>> res; if(n==0) ...
2020-05-07 00:58:34
170
原创 剑指offer 面试题65. 不用加减乘除做加法 [简单]
https://leetcode-cn.com/problems/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof/solution/mian-shi-ti-65-bu-yong-jia-jian-cheng-chu-zuo-ji-7/位运算搞不明白,就记住吧class Solution {public: int add(int a, i...
2020-05-03 00:21:00
144
原创 剑指offer 面试题60. n个骰子的点数 [简单]——动态规划
面试题60. n个骰子的点数class Solution {public: vector<double> twoSum(int n) { vector<vector<int>> dp(n+1,vector<int>(6*n+1,0)); for(int i=1;i<=6;i++) ...
2020-05-02 23:08:07
400
原创 剑指offer 面试题66. 构建乘积数组 [简单]
面试题66. 构建乘积数组class Solution {public: vector<int> constructArr(vector<int>& a) { int n=a.size(); vector<int> b(n,1); int tmp=1; for(int i...
2020-05-02 22:16:01
223
原创 剑指offer 面试题11. 旋转数组的最小数字 [简单]——二分
面试题11. 旋转数组的最小数字class Solution {public: int minArray(vector<int>& numbers) { int n=numbers.size(); int i=0,j=n-1; while(i<j){ int mid=(i+j)/2...
2020-05-02 17:16:57
148
tensorflow-1.9.0-cp36-cp36m-win_amd64.whl
2020-03-16
算法分析作业-钻石金字塔问题
2019-04-06
计算机图形学作业-设计和实现一个图形函数库
2019-04-03
编译原理-语法分析程序。内含代码+exe+测试txt
2018-12-25
算法分析-钻石金字塔问题
2018-06-08
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人