随笔分类 -  leetCode

64. 最小路径和
摘要:原题链接:https://leetcode-cn.com/problems/minimum-path-sum/ class Solution { // 动态规划的问题 // dp[i][j] 值表示 i,j 位置到 最右下角的最小数字和 public int minPathSum(int[][] g 阅读全文

posted @ 2020-12-26 14:52 靠自己的骨头长肉 阅读(120) 评论(0) 推荐(0)

53. 最大子序和
摘要:原题链接:https://leetcode-cn.com/problems/maximum-subarray/ class Solution { // 动态规划 public int maxSubArray(int[] nums) { // 记录当前为位置的前一个位置已经得到的最大值 int pre 阅读全文

posted @ 2020-12-25 13:38 靠自己的骨头长肉 阅读(73) 评论(0) 推荐(0)

21. 合并两个有序链表
摘要:原题链接:https://leetcode-cn.com/problems/merge-two-sorted-lists/ /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode 阅读全文

posted @ 2020-12-24 10:36 靠自己的骨头长肉 阅读(89) 评论(0) 推荐(0)

5. 最长回文子串
摘要:原题链接:https://leetcode-cn.com/problems/longest-palindromic-substring/ class Solution { // 思路:【动态规划】 // 状态转移方程是 p[i,j] = p[i+1,j-1] && p[i] = p[j] // p[ 阅读全文

posted @ 2020-12-20 19:48 靠自己的骨头长肉 阅读(105) 评论(0) 推荐(0)

94. 二叉树的中序遍历
摘要:题目链接:https://leetcode-cn.com/problems/binary-tree-inorder-traversal/ /** * Definition for a binary tree node. * public class TreeNode { * int val; * T 阅读全文

posted @ 2020-12-20 14:34 靠自己的骨头长肉 阅读(158) 评论(0) 推荐(0)

3. 无重复字符的最长子串
摘要:原题链接:https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/ class Solution { public int lengthOfLongestSubstring(String s) { 阅读全文

posted @ 2020-12-20 13:48 靠自己的骨头长肉 阅读(98) 评论(0) 推荐(0)

15. 三数之和
摘要:原题链接:https://leetcode-cn.com/problems/3sum/ class Solution { public List<List<Integer>> threeSum(int[] nums) { // 首先数组进行排序【排序的目的是为了找出来的值不会重复】 // 然后利用双 阅读全文

posted @ 2020-12-16 23:42 靠自己的骨头长肉 阅读(127) 评论(0) 推荐(0)

88. 合并两个有序数组
摘要:题目链接:https://leetcode-cn.com/problems/merge-sorted-array/ class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) { // 思路: // 双指针的方 阅读全文

posted @ 2020-12-15 16:43 靠自己的骨头长肉 阅读(125) 评论(0) 推荐(0)

215. 数组中的第K个最大元素
摘要:题目链接:https://leetcode-cn.com/problems/kth-largest-element-in-an-array/ 1 先快速排序,再取第 K个 class Solution { public int findKthLargest(int[] nums, int k) { 阅读全文

posted @ 2020-12-14 22:37 靠自己的骨头长肉 阅读(84) 评论(0) 推荐(0)

两数之和
摘要:具体题目请访问题目链接:https://leetcode-cn.com/problems/two-sum/ 思路: 1 暴力,两层循环直接干上去,这样干上去简单好做,但是可能就今天面试就到这里吧,等通知。 2 利用hash表存储,取代调一层循环 key存储数组具体的值,value存储数组的下标,判断 阅读全文

posted @ 2020-12-12 11:17 靠自己的骨头长肉 阅读(96) 评论(0) 推荐(0)

总持续时间可被 60 整除的歌曲
摘要:在歌曲列表中,第 i 首歌曲的持续时间为 time[i] 秒。 返回其总持续时间(以秒为单位)可被 60 整除的歌曲对的数量。形式上,我们希望索引的数字 i 和 j 满足 i < j 且有 (time[i] + time[j]) % 60 == 0。 输入:[30,20,150,100,40]输出: 阅读全文

posted @ 2020-05-18 22:22 靠自己的骨头长肉 阅读(200) 评论(0) 推荐(0)