网站首页 站内搜索

搜索结果

查询Tags标签: nums,共有 1882条记录
  • LeetCode 旋转数组算法题解 All In One

    LeetCode 旋转数组算法题解 All In One 189. Rotate Array /**Do not return anything, modify nums in-place instead.*/ // solution 1:暴力破解:❌ Time Limit Exceeded // function rotate(nums: number[], k: number): void { // if(k === 0) { // // return…

    2022/8/12 14:23:08 人评论 次浏览
  • Java学习 (17) Java数组篇(01)数组定义&数组声明和创建

    数组的定义数组是相同类型数据的有序集合. 数组描述的是相同类型的若干个数据,按照一定的先后次序排列组合而成。 其中,每一个数据称作一个数组元素,每个数组元素可以通过一个下标来访问它们.数组的声明和创建首先必须声明数组变量,才能在程序中使用数组Java语言使用new操…

    2022/8/12 1:28:03 人评论 次浏览
  • 1.两数之和

    1. 两数之和 给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它们的数组下标。 你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。 你可以按任意顺序返回答案。示例 1:…

    2022/8/9 23:22:46 人评论 次浏览
  • # 华为机试:HJ77火车进站 与 HJ50四则运算

    华为机试 记录两个与栈相关的算法题,折腾了一下午需要注意dfs前后对称的操作 利用栈结构去处理存在明显先后顺序的问题,比如四则运算等HJ77 火车进站 栈+dfs回溯 #include<bits/stdc++.h> using namespace std; int N; vector<vector<int>> res; vect…

    2022/8/8 23:25:47 人评论 次浏览
  • 力扣-300-最长递增子序列

    直达链接 想到了连续子数组的最大和 自己想 我本来想倒着推,有点像mari和shiny,但是不对 class Solution { public:int lengthOfLIS(vector<int>& nums) {int length = nums.size();if (length < 2) return 1;vector<int> dp(length);dp[length - 1]…

    2022/8/7 23:28:31 人评论 次浏览
  • LeetCode 239 Sliding Window Maximum 单调队列 [Hard]

    You are given an array of integers nums, there is a sliding window of size \(k\) which is moving from the very left of the array to the very right. You can only see the \(k\) numbers in the window. Each time the sliding window moves right by one posit…

    2022/8/3 6:52:48 人评论 次浏览
  • #Leetcode 912 Sort an Array 快排 改进

    改进版快排,pivot 不再是左边第一个元素,而是正中间元素(或者随机)。 有一个比较坑的地方就是,在每一趟双指针完成所有交换后,需要判断 pivot 需不需要被交换。 比如 test case 1 2 4 3,第一趟开始时 pivot 是 2, 先动右边的指针 j, 找到第一个比 2 小的数也就…

    2022/8/3 6:23:52 人评论 次浏览
  • Java二分查找:给定一个?n?个元素有序的(升序)整型数组?nums 和一个目标值?target ?,写一个函数搜索?nums?中的 target,如果目标值存在返回下标,否则返回 -1

    给定一个 n 个元素有序的(升序)整型数组 nums 和一个目标值 target ,写一个函数搜索 nums 中的 target,如果目标值存在返回下标,否则返回 -1。 示例 1: 输入: nums = [-1,0,3,5,9,12], target = 9 输出: 4 解释: 9 出现在 nums 中并且下标为 4利用二分查找思想 clas…

    2022/8/3 1:23:39 人评论 次浏览
  • PAT (Advanced Level) Practice 1008 Elevator 分数 20 Python 解法

    题目 The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 …

    2022/8/2 1:24:09 人评论 次浏览
  • LeetCode 713 Subarray Product Less Than K 滑动窗口

    Given an array of integers nums and an integer k, return the number of contiguous subarrays where the product of all the elements in the subarray is strictly less than k. Solution 滑动窗口的思想。不断增大右端点 \(r\), 当乘积 \(pd\ge k\) 的时候,缩小左…

    2022/8/1 23:24:13 人评论 次浏览
  • LeetCode 238 Product of Array Except Self 前缀积&后缀积

    Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i]. The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer. You must write an algorit…

    2022/7/30 23:24:17 人评论 次浏览
  • LeetCode/二分法综合

    1. 寻找两个正序数组的中位数 2. 两数相除 3. 快速幂 4. 搜索旋转排序数组 5. 数组中的逆序对 6. 在排序数组中查找元素的第一个和最后一个位置 class Solution { public:vector<int> searchRange(vector<int>& nums, int target) {return {find(nums,tar…

    2022/7/30 23:24:15 人评论 次浏览
  • 五大算法之二分搜索

    概述二分搜索是常见的搜索算法,能够将有序数组搜索的线性复杂度降低到对数级别。搜索过程每次取搜索区间内的中间元素,如果等于目标元素则直接返回结果;如果大于或小于目标元素,则将搜索区间缩短到对应的一半元素范围,继续搜索,直至搜索区间为空。当然二分搜索不限于…

    2022/7/28 1:52:56 人评论 次浏览
  • Leetcode的简单算法题:53. 最大子数组和

    链接:https://leetcode.cn/problems/maximum-subarray/ 之前题解的博客:https://tsuish.gitee.io/p/7a78 注:之后把这篇博客整理到hexo 我的代码 int max(int a,int b){return a>b?a:b; } int maxSubArray(int* nums, int numsSize){int dp[100001],res = nums[0];…

    2022/7/27 14:22:43 人评论 次浏览
  • Leetcode的中等算法题:198. 打家劫舍

    链接:https://leetcode.cn/problems/house-robber/ 方法1 学会了动态规划思路后,我独立想出来的一个方法,缺点是代码不够优雅(dp和nums的序号有错位)。 我的代码 int max(int a,int b){return a>b?a:b; } int rob(int* nums, int numsSize){// dp预留出来2个位置…

    2022/7/27 14:22:43 人评论 次浏览
扫一扫关注最新编程教程