- 博客(132)
- 收藏
- 关注
原创 记:使用spring boot jpa,用JpaRepository的getOne()方法会爆null的原因
有一次开发中,使用了JpaRepository的getOne()来取数据,但明明数据库有,却一直爆null的错,一直没找到真实原因,最后发现是pom以来的问题https://githubmemory.com/repo/vladmihalcea/hibernate-types/issues/227当使用如下依赖时<dependency> <groupId>com.vladmihalcea</groupId> <artifactId>
2022-01-25 20:53:29 1711
原创 记一次spring boot启动爆Caused by: java.net.UnknownHostException: 127.0.0.1
时不时地启动spring boot会报以下错org.postgresql.util.PSQLException: 尝试连线已失败。Caused by: java.net.UnknownHostException: 127.0.0.1Caused by: org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection但是本地起psql是可以正常访问的,查了很久,原因竟然是连了vpn,所以时
2022-01-18 12:02:08 1403
原创 洛谷搜索题单(BFS/DFS)13道题总结
洛谷搜索题单(BFS/DFS)13道题总结P1219 八皇后经典深搜问题,本题的难点在于如何判断斜线上是否已有棋子,可使用数学中斜率和截距来判断是否是在同一条直线上。P2392 kkksc03考前临时抱佛脚深搜问题,但本题又是01背包问题,把作业分别放进左脑和右脑,最后去左脑和右脑的最大值就是该课的最终结果,一开始想得太复杂了,想把左脑和右脑一起处理。因此应该将搜索简单化,编写代码时尽量简化状态背包容量相当于t/2,最好的结果当然是t/2,意味着左脑和右脑之间没有时间差,即求时间差尽量小,单脑时间
2021-07-25 23:43:07 1569
原创 Leetcode dynamic programming Top interview Question 15道题总结
本文是对leetcode中dynamic programing标签下的top interview question进行总结leetcode 62. Unique Pathsdp[i][j] = dp[i-1][j] + dp[i][j-1]dp[i][j]代表走到(i,j)坐标的所有路径数Leetcode 121. Best Time to Buy and Sell Stockdp[i] = min(dp[i-1], nums[i])dp[i]代表i之前的最小价格数,记录的并不是直接结果,而是序
2020-07-06 11:22:30 161
原创 Leetcode sort Top interview Question 6道题总结
本文针对Leetcode下sort标签的6道Top interview Question进行总结Leetcode 75. sort colors使用快排算法思想,以1作为pivot,然后不断交换0和1Leetcode 148. Sort List对链表进行排序,使用归并排序能够达到O(nlogn)Leetcode 315. Count of Smaller Numbers After Self本题即为求逆序数对,求逆序相关的问题,归并排序是标准思路,归并排序的过程中,可以顺便把逆序数求出来,因为
2020-07-06 10:23:01 169
原创 Leetcode 91. Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping:‘A’ -> 1‘B’ -> 2…‘Z’ -> 26Given a non-empty string containing only digits, determine the total number of ways to decode it.Example 1:Input: “12”O
2020-07-05 22:39:58 104
原创 Leetcode 5. Longest Palindromic Substring
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example 1:Input: “babad”Output: “bab”Note: “aba” is also a valid answer.Example 2:Input: “cbbd”Output: “bb”method dp字符串回文dp,思维方式在Lee
2020-07-05 22:34:41 139
原创 Leetcode 322. Coin Change
You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, retur
2020-07-05 22:27:29 93
原创 Leetcode 140. Word Break II
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences.Note:The same word in the dictionary may be
2020-07-05 22:08:29 82
原创 Leetcode 198. House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatical
2020-07-05 13:31:21 72
原创 Leetcode 70. Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Example 1:Input: 2Output: 2Explanation: There are two ways to climb to the top.1 step
2020-07-05 10:53:15 97
原创 Leetcode 121. Best Time to Buy and Sell Stock
Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit.Note tha
2020-07-05 10:40:27 75
原创 Leetcode 139. Word Break
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.Note:The same word in the dictionary may be reused multiple times i
2020-06-29 19:38:05 88
原创 Leetcode 215. Kth Largest Element in an Array
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.Example 1:Input: [3,2,1,5,6,4] and k = 2Output: 5Example 2:Input: [3,2,3,1,2,4,5,5,6] and k = 4Output: 4meth
2020-06-29 17:28:06 86
原创 Leetcode 179. Largest Number
Given a list of non negative integers, arrange them such that they form the largest number.Example 1:Input: [10,2]Output: “210”Example 2:Input: [3,30,34,5,9]Output: “9534330”Note: The result may be very large, so you need to return a string instead
2020-06-29 17:25:16 112
原创 Leetcode 324. Wiggle Sort II
Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]…Example 1:Input: nums = [1, 5, 1, 1, 6, 4]Output: One possible answer is [1, 4, 1, 5, 1, 6].Example 2:Input: nums = [1, 3, 2, 2, 3, 1]Output: One possib
2020-06-29 17:21:30 96
原创 Leetcode 315. Count of Smaller Numbers After Self
You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smaller elements to the right of nums[i].Example:Input: [5,2,6,1]Output: [2,1,1,0]Explanation:To the righ
2020-06-29 16:42:46 110
原创 Leetcode 148. Sort List
Sort a linked list in O(n log n) time using constant space complexity.Example 1:Input: 4->2->1->3Output: 1->2->3->4Example 2:Input: -1->5->3->4->0Output: -1->0->3->4->5method 1 归并排序先使用快慢指针,将链表一分为二,然后使用归并排序。
2020-06-29 15:58:57 105
原创 Leetcode 69. Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x, where x is guaranteed to be a non-negative integer.Since the return type is an integer, the decimal digits are truncated and only the integer part of the result is returned.Example 1:In
2020-06-29 12:03:57 92
原创 Leetcode 300.longest-increasing-subsequence
method 1 dp使用动态规划,dp[i]代表以第i个数结尾时的最大长度//dp[i]表示以num[i]结尾的序列的最大长度int lengthOfLIS(vector<int>& nums) { if (nums.size() == 0) return 0; vector<int> dp(nums.size(), 1); for (int i = 1; i < nums.size(); i++) { for (int j = 0; j <
2020-06-29 11:47:41 103
原创 Leetcode 240. Search a 2D Matrix II
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to right.Integers in each column are sorted in ascending from top to bottom.Exampl
2020-06-29 11:34:50 79
原创 Leetcode 454. 4Sum II
Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero.To make problem a bit easier, all A, B, C, D have same length of N where 0 ≤ N ≤ 500. All integers are in the range o
2020-06-29 11:01:58 59
原创 Leetcode 378. Kth Smallest Element in a Sorted Matrix
Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.Note that it is the kth smallest element in the sorted order, not the kth distinct element.Example:matrix = [[ 1, 5, 9]
2020-06-29 10:46:52 106
原创 Leetcode 212. Word Search II
Given a 2D board and a list of words from the dictionary, find all words in the board.Each word must be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizo...
2020-02-15 12:37:41 95
原创 Leetcode 208. Implement Trie (Prefix Tree)
Implement a trie with insert, search, and startsWith methods.Example:Trie trie = new Trie();trie.insert(“apple”);trie.search(“apple”); // returns truetrie.search(“app”); // returns falsetr...
2020-02-15 12:32:21 94
原创 Leetcode backtracking Top interview Question 7道题总结
本篇文章是对leetcode tree和Top Interview Questions标签下7道backtracking类型题目的总结Leetcode 46. Permuation求一个数组的排列,不断加入新的元素递归,递归结束后删去,并在新一轮循环中同一个位置加入新的元素Leetcode 22. Generate Parentheses求(和)的排列,思路同上,只是要满足左括号和右括号的...
2020-02-14 11:38:02 206
原创 Leetcode 140. Word Break II
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible ...
2020-02-14 11:17:40 87
原创 Leetcode 131. Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.Example:Input: “aab”Output:[[“aa”,“b”],[“a”,“a”,“b”]]...
2020-02-14 11:06:02 74
原创 Leetcode 17. Letter Combinations of a Phone Number
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is give...
2020-02-14 10:56:07 82
原创 Leetcode 22. Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[“((()))”,“(()())”,“(())()”,“()(())”,“()()()”...
2020-02-14 10:36:16 60
原创 Leetcode 46/47/31/60 Permutations 专题
Leetcode 46 PermutationsGiven a collection of distinct integers, return all possible permutations.Example:Input: [1,2,3]Output:[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]求给定数组的所有排列,...
2020-02-14 10:30:58 114
原创 Leetcode 279. Perfect Squares
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, …) which sum to n.Example 1:Input: n = 12Output: 3Explanation: 12 = 4 + 4 + 4.Example 2:Inp...
2020-02-09 20:16:50 115
原创 Leetcode 127. Word Ladder
Given two words (beginWord and endWord), and a dictionary’s word list, find the length of shortest transformation sequence from beginWord to endWord, such that:Only one letter can be changed at a tim...
2020-02-09 20:16:21 123
原创 Leetcode 130. Surrounded Regions
Given a 2D board containing ‘X’ and ‘O’ (the letter O), capture all regions surrounded by ‘X’.A region is captured by flipping all 'O’s into 'X’s in that surrounded region.Explanation:Surrounded r...
2020-02-09 18:58:22 178
原创 Leetcode 207/210. Course Schedule I/II
There are a total of n courses you have to take, labeled from 0 to n-1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair:...
2020-02-09 18:36:09 145
原创 Leetcode 329. Longest Increasing Path in a Matrix
Given an integer matrix, find the length of the longest increasing path.From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally or move outside of...
2020-02-09 18:18:14 105
原创 Leetcode 200. Number of Islands
Given a 2d grid map of '1’s (land) and '0’s (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume...
2020-02-09 17:47:52 232
原创 Leetcode tree Top Interview Questions 12道题总结
本篇文章是对leetcode tree和Top Interview Questions标签下12道array类型题目的总结Leetcode 104. Maximum Depth of Binary Tree此题需要求一颗二叉树的最大深度,可归结于树的遍历问题解:使用DFS,添加一个depth参数,每递归一层,depth++,并且每次求最大值Leetcode 230. Kth Smalles...
2020-02-03 21:30:52 114
原创 Leetcode 98. Validate Binary Search Tree
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node’s key.The rig...
2020-02-03 20:51:03 97
原创 116/117. Populating Next Right Pointers in Each Node I/II
先看116Given a binary treestruct Node {int val;Node *left;Node *right;Node *next;}Populate each next pointer to point to its next right node. If there is no next right node, the next pointer sho...
2020-02-02 20:27:10 166
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人