摘要:原题链接:https://leetcode-cn.com/problems/minimum-path-sum/ class Solution { // 动态规划的问题 // dp[i][j] 值表示 i,j 位置到 最右下角的最小数字和 public int minPathSum(int[][] g
阅读全文
摘要:原题链接:https://leetcode-cn.com/problems/maximum-subarray/ class Solution { // 动态规划 public int maxSubArray(int[] nums) { // 记录当前为位置的前一个位置已经得到的最大值 int pre
阅读全文
摘要:原题链接:https://leetcode-cn.com/problems/merge-two-sorted-lists/ /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode
阅读全文
摘要:原题链接:https://leetcode-cn.com/problems/longest-palindromic-substring/ class Solution { // 思路:【动态规划】 // 状态转移方程是 p[i,j] = p[i+1,j-1] && p[i] = p[j] // p[
阅读全文
摘要:题目链接:https://leetcode-cn.com/problems/binary-tree-inorder-traversal/ /** * Definition for a binary tree node. * public class TreeNode { * int val; * T
阅读全文
摘要:原题链接:https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/ class Solution { public int lengthOfLongestSubstring(String s) {
阅读全文
摘要:原题链接:https://leetcode-cn.com/problems/3sum/ class Solution { public List<List<Integer>> threeSum(int[] nums) { // 首先数组进行排序【排序的目的是为了找出来的值不会重复】 // 然后利用双
阅读全文
摘要:题目链接:https://leetcode-cn.com/problems/merge-sorted-array/ class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) { // 思路: // 双指针的方
阅读全文
摘要:题目链接:https://leetcode-cn.com/problems/kth-largest-element-in-an-array/ 1 先快速排序,再取第 K个 class Solution { public int findKthLargest(int[] nums, int k) {
阅读全文
摘要:具体题目请访问题目链接:https://leetcode-cn.com/problems/two-sum/ 思路: 1 暴力,两层循环直接干上去,这样干上去简单好做,但是可能就今天面试就到这里吧,等通知。 2 利用hash表存储,取代调一层循环 key存储数组具体的值,value存储数组的下标,判断
阅读全文
摘要:在歌曲列表中,第 i 首歌曲的持续时间为 time[i] 秒。 返回其总持续时间(以秒为单位)可被 60 整除的歌曲对的数量。形式上,我们希望索引的数字 i 和 j 满足 i < j 且有 (time[i] + time[j]) % 60 == 0。 输入:[30,20,150,100,40]输出:
阅读全文