上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 17 下一页
摘要: 用一个变量存放当前所能到达的最远的下标位置 class Solution { public boolean canJump(int[] nums) { int farestIndex = 0;// 记录当前最远能到达的下标 for (int i = 0; i <= farestIndex && i 阅读全文
posted @ 2024-02-05 16:08 破忒头头 阅读(10) 评论(0) 推荐(0)
摘要: 动态规划,五种状态,关键是找出状态转移式 class Solution { public int maxProfit(int[] prices) { int buy1 = -prices[0]; int sell1 = 0; int buy2 = -prices[0]; int sell2 = 0; 阅读全文
posted @ 2024-02-05 15:33 破忒头头 阅读(10) 评论(0) 推荐(0)
摘要: 将所有的递增段的增加值叠加起来 class Solution { public int maxProfit(int[] prices) { if (prices.length <= 1){ return 0; } int pre = 0; int p = 1; int maxPro = 0; int 阅读全文
posted @ 2024-02-03 14:32 破忒头头 阅读(14) 评论(0) 推荐(0)
摘要: 从右往左遍历 class Solution { public int maxProfit(int[] prices) { Map<Integer, Integer> priceMap = new HashMap<Integer, Integer>(); Integer leftMaxNum = nu 阅读全文
posted @ 2024-01-27 20:45 破忒头头 阅读(21) 评论(0) 推荐(0)
摘要: class Solution { public void rotate(int[] nums, int k) { if (k > nums.length){ k = k % nums.length; } reverse(nums, nums.length - k, nums.length-1); r 阅读全文
posted @ 2024-01-27 18:04 破忒头头 阅读(19) 评论(0) 推荐(0)
摘要: 快排 class Solution { public int majorityElement(int[] nums) { QuickSort(nums, 0, nums.length - 1); return nums[nums.length / 2]; } int partition(int[] 阅读全文
posted @ 2024-01-27 10:16 破忒头头 阅读(14) 评论(0) 推荐(0)
摘要: 向前移动元素需要k的值,所以移动需要放在最后面。 class Solution { public int removeDuplicates(int[] nums) { if (nums.length < 1) return 0; int curNum = nums[0]; int k = 0; in 阅读全文
posted @ 2024-01-26 16:52 破忒头头 阅读(11) 评论(0) 推荐(0)
摘要: 解 快慢指针 class Solution { public int removeDuplicates(int[] nums) { int pre = nums[0]; int place = 1; for (int i = 1; i < nums.length; i++){ if (nums[i] 阅读全文
posted @ 2024-01-08 21:21 破忒头头 阅读(10) 评论(0) 推荐(0)
摘要: 解 快慢指针 class Solution { public int removeElement(int[] nums, int val) { //快慢指针 int place = 0; //实际插入位置 for (int i = 0; i < nums.length; i++){ if ( num 阅读全文
posted @ 2024-01-08 21:12 破忒头头 阅读(12) 评论(0) 推荐(0)
摘要: 解 class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) { int[] nums3 = new int[m]; int p = 0; //指向nums3 int q = 0; //指向nums3 int 阅读全文
posted @ 2024-01-08 20:52 破忒头头 阅读(16) 评论(0) 推荐(0)
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 17 下一页