自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(84)
  • 收藏
  • 关注

原创 函数传参:值传递、地址传递、引用传递

函数传参//值传递void swap01(int a, int b){ int temp = a; a = b; b = temp;}//地址传递void swap02(int *a, int *b){ int temp = *a; *a = *b; *b = temp;}//引用传递void swap03(int &a, int &b){ int temp = a; a = b; b = temp;}int main(){ int a = 1; i

2022-01-06 00:11:55 433

原创 77. 组合

77. 组合典型dfs+剪枝class Solution { //结果表 List<List<Integer>> res = new ArrayList<List<Integer>>(); //子集 List<Integer> tmp = new ArrayList<Integer>(); public List<List<Integer>> combine(int n, i

2021-12-28 23:35:58 129

原创 57. 插入区间

57. 插入区间— 没搞懂属于什么问题类型class Solution { public int[][] insert(int[][] intervals, int[] newInterval) { int left = newInterval[0]; int right = newInterval[1]; boolean placed = false; List<int[]> ansList = new ArrayLi

2021-12-16 23:52:09 78

原创 跳跃游戏 II

45. 跳跃游戏 IIclass Solution { public int jump(int[] nums) { int len = nums.length; int start = 0; int end = 0; int maxIndex = 0; int count = 0; //当end边界超出数组长度时跳出 while(end < len - 1){

2021-12-15 22:37:25 3406

原创 字符串 全排列

剑指 Offer 38. 字符串的排列class Solution { //存储结果 List<String> rec = new ArrayList<String>(); //判断当前元素是否被访问过 boolean[] vis; public String[] permutation(String s) { int n = s.length(); vis = new boolean[n]; char[

2021-12-14 23:41:21 187

原创 279. 完全平方数 ---动态规划

279. 完全平方数class Solution { int res = Integer.MAX_VALUE; public int numSquares(int n) { if(n == 1) return 1; int[] dp = new int[n + 1]; //默认装状态为最差情况,当前数拆分为n个1 Arrays.fill(dp, n); for(int i = 1; i &lt

2021-12-14 00:04:43 218

原创 Java 动态规划 III

剑指 Offer 46. 把数字翻译成字符串class Solution { public int translateNum(int num) { String[] res = Integer.toString(num).split(""); int len = res.length; if(len == 0) return 0; int[] dp = new int[len + 1]; dp[0]

2021-12-10 00:08:21 154

原创 java 动态规划例题 II

1、连续子数组最大和2、礼物的最大值

2021-12-06 23:55:49 289

原创 java 动态规划例题

动态规划1、剑指 Offer 10- I. 斐波那契数列class Solution { public int fib(int n) { if(n == 0) return 0; int[] df = new int[n + 1]; df[0] = 0; df[1] = 1; for(int i = 2; i < n + 1; i++){ df[i] = (df[i - 1] + df[

2021-11-30 23:49:39 415

原创 26. 树的子结构

剑指 Offer 26. 树的子结构class Solution { public boolean isSubStructure(TreeNode A, TreeNode B) { return (A != null && B != null) && (dfs(A, B) || isSubStructure(A.left, B) || isSubStructure(A.right, B)); } public boolean dfs(

2021-11-30 23:48:08 121

原创 26. 树的子结构

剑指 Offer 26. 树的子结构class Solution { public boolean isSubStructure(TreeNode A, TreeNode B) { return (A != null && B != null) && (dfs(A, B) || isSubStructure(A.left, B) || isSubStructure(A.right, B)); } public boolean dfs(

2021-11-24 00:11:30 35

原创 从上到下打印二叉树 III

剑指 Offer 32 - III. 从上到下打印二叉树 IIIclass Solution { public List<List<Integer>> levelOrder(TreeNode root) { List<List<Integer>> res = new ArrayList<List<Integer>>(); Queue<TreeNode> myQueue = new L

2021-11-23 00:54:37 188 1

原创 深度优先与广度优先 java

深度优先与广度优先 //广度优先遍历 public void BroadFirstSearch(TreeNode nodeHead) { if(nodeHead==null) { return; } Queue<TreeNode> myQueue=new LinkedList<>(); myQueue.add(nodeHead); while(!myQueue.is

2021-11-22 23:46:13 422

原创 HashMap存储频数

使用哈希表存储频数,并返回第一个仅出现一次的字母class Solution { public char firstUniqChar(String s) { Map<Character, Integer> frequency = new HashMap<Character, Integer>(); for (int i = 0; i < s.length(); ++i) { char ch = s.charAt(

2021-11-19 00:34:29 122

原创 二维数组中的查找 hashset方法

二维数组中的查找 hashset方法class Solution { public boolean findNumberIn2DArray(int[][] matrix, int target) { int row = matrix.length; if(matrix.length == 0){ return false; } int colum = matrix[0].length; Hash

2021-11-18 23:40:34 500

原创 字符串操作

字符串操作例 s = “abcdefg”截取String str1 = s.substring(0,2)//outputabString str2 = s.substring(2)//outputcdefg拼接s2+s1//outputcdefgab替换s.repalce("c", "%20");//outputab%20defg

2021-11-16 23:27:37 52

原创 复杂链表的复制

35 复杂链表的复制class Solution { Map<Node, Node> mapOfNode = new HashMap<Node, Node>(); public Node copyRandomList(Node head) { if(head == null) return null; while(!mapOfNode.containsKey(head)){ Node headNew = new

2021-11-16 00:17:00 362

原创 MIN函数栈

MIN函数栈class MinStack { Stack<Integer> stk1; Stack<Integer> stk2; /** initialize your data structure here. */ public MinStack() { stk1 = new Stack<Integer>(); stk2 = new Stack<Integer>(); }

2021-11-12 00:17:12 196

原创 双栈实现队列

双栈实现队列class CQueue { Stack<Integer> stk1 = new Stack<Integer>(); Stack<Integer> stk2 = new Stack<Integer>(); public CQueue() { } public void appendTail(int value) { stk1.push(value); }

2021-11-11 23:51:57 66

原创 260260260

260垃圾解法,也不是不能用class Solution { public int[] singleNumber(int[] nums) { int len = nums.length; LinkedList<Integer> numList = new LinkedList<Integer>(); int[] res = new int[2]; int counter = 0; for(in

2021-11-05 00:06:08 62

原创 919191

91class Solution { public int numDecodings(String s) { int n = s.length(); int[] f = new int[n + 1]; f[0] = 1; for(int i = 1; i <= n; i++){ if(s.charAt(i - 1) != '0'){ f[i] += f[i - 1];

2021-11-04 00:26:34 323

原创 402402402

402class Solution { public String removeKdigits(String num, int k) { Deque<Character> deque = new LinkedList<Character>(); int len = num.length(); for(int i = 0; i < len; i++){ char digit = num.charAt

2021-11-03 00:37:10 57

原创 210210210

210210与207类似,拓扑排序//DFSclass Solution { // 存储有向图 List<List<Integer>> edges; // 标记每个节点的状态:0=未搜索,1=搜索中,2=已完成 int[] visited; // 用数组来模拟栈,下标 n-1 为栈底,0 为栈顶 int[] result; // 判断有向图中是否有环 boolean valid = true; // 栈下标

2021-11-01 23:37:59 82

原创 208208208

208208208 字典树class Trie { private Trie[] children; private boolean isEnd; public Trie() { children = new Trie[26]; isEnd = false; } public void insert(String word) { Trie node = this; for(int i = 0

2021-10-27 00:19:20 58

原创 747474

747474class Solution { boolean res = false; public boolean searchMatrix(int[][] matrix, int target) { int y = matrix.length; int x = matrix[0].length; int yTmp = 0; if(target < matrix[0][0] || target > matrix

2021-10-25 23:56:47 434

原创 207207207

207/*拓扑排序,没整明白*/class Solution { List<List<Integer>> edges; int[] visited; boolean valid = true; public boolean canFinish(int numCourses, int[][] prerequisites) { edges = new ArrayList<List<Integer>>();

2021-10-22 00:30:55 55

原创 134134134

134class Solution { int res = 0; int begin; boolean flag = false; public int canCompleteCircuit(int[] gas, int[] cost) { for(int startIndex = 0; startIndex < gas.length; startIndex++){ begin = startIndex;

2021-10-21 00:04:40 62

原创 123912391239

1239class Solution { StringBuilder stringbuilder = new StringBuilder(); int res = 0; public int maxLength(List<String> arr) { dfs(arr, 0); return res; } public void dfs(List<String> arr, int start){

2021-10-19 00:34:19 46

原创 560560560

560class Solution { int res = 0; public int subarraySum(int[] nums, int k) { int index = 0; int len = nums.length; for(; index < len; index++){ int tmp = 0; for(int flow = index;flow < len; flo

2021-10-14 00:14:26 58

原创 189189189

189class Solution { public void rotate(int[] nums, int k) { int len = nums.length; if(len < k) k = k%len; int[] res = new int[len]; System.arraycopy(nums, len - k, res, 0, k); System.arraycopy(nums, 0, res, k

2021-10-12 23:37:51 80

原创 165165165

165class Solution { int res = 0; int flag = 1; String[] versionlong; String[] versionshort; public int compareVersion(String version1, String version2) { String[] version1_sep = version1.split("\\."); String[] version2_

2021-10-12 00:11:07 48

原创 443443443

443class Solution { public int compress(char[] chars) { int len = chars.length; int left = 0, write = 0; for(int i = 0; i < len; i++){ if((i == len - 1) || (chars[i] != chars[i + 1])){ chars[write

2021-09-29 00:28:12 50

原创 153153153

153class Solution { public int findMin(int[] nums) { int len = nums.length; if(len == 1) return nums[0]; int i = 0; while(i < len - 1){ if(nums[i + 1] < nums[i]){ return nums[i + 1];

2021-09-26 23:06:16 76

原创 277277277

277public class Solution extends Relation { public int findCelebrity(int n) { int idx = -1; int[] whoKnowHe = new int[n]; int[] HeKnowWho = new int[n]; int[][] relationMap = new int[n][n]; for(int i = 0; i <

2021-09-23 23:32:03 55

原创 445445445

445class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { Deque<Integer> stack1 = new LinkedList<Integer>(); Deque<Integer> stack2 = new LinkedList<Integer>(); while (l1 != null) {

2021-09-23 00:27:27 77

原创 838383

83 删除排序链表中重复元素class Solution { public ListNode deleteDuplicates(ListNode head) { if(head == null) return head; ListNode dumpNode= head; while(dumpNode.next != null){ if(dumpNode.val == dumpNode.next.val){

2021-09-15 23:35:38 70

原创 797979

79class Solution { boolean res = false; char[] resString = new char[15]; boolean[][] visit; public boolean exist(char[][] board, String word) { char[] w = word.toCharArray(); int len = w.length; int x = board.length

2021-09-14 23:32:00 120

原创 116116116

116class Solution { Queue<Node> res = new LinkedList<Node>(); public Node connect(Node root) { if(root == null){ return root; } //层序遍历操作所有节点的next指向 res.offer(root); root.next = null;

2021-09-14 00:04:49 48

原创 253253253

253class Solution { public int minMeetingRooms(int[][] intervals) { //对二维矩阵按照每组第一个元素进行排序 Arrays.sort(intervals,(i,j)->i[0]-j[0]); int numOfMeeting = intervals.length; //路子非常野,由于结果矩阵只用第一列,所以此处仅记录行数就行 int[][] numOfRo

2021-09-10 00:24:25 51

原创 144814481448

1448class Solution { int numsOfGoodNodes = 0; int lastNodeVal; public int goodNodes(TreeNode root) { lastNodeVal = root.val; dfs(root, lastNodeVal); return numsOfGoodNodes; } public void dfs(TreeNode root, int l

2021-09-08 22:54:19 58

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除