ICode9

精准搜索请尝试: 精确搜索
  • LeetCode 128 Longest Consecutive Sequence2022-09-17 04:30:19

    Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence. You must write an algorithm that runs in \(O(n)\) time. Solution 既然不能排序,那就用 \(set\) 将元素全部存进去。从所有可能序列中的最小开始遍历,逐次递增,然后

  • 每天都努力的课堂随笔Day082022-09-16 16:31:23

    Recursion Method A call method B, it is easy to grasp! Recursion: Method A call method A, that is method A call itself. Using recursion could solve some complex matters, it usually swap a big and complex problem to a small scale problem, recursion

  • 搜索插入位置2022-09-16 01:31:50

    搜索插入位置 一、题目描述 给定一个有序数组。需要插入一个元素。返回插入索引。 请必须使用时间复杂度为 O(log n) 的算法。 实例 输入: nums = [1,3,5,6], target = 5 输出: 2 输入: nums = [1,3,5,6], target = 2 输出: 1 输入: nums = [1,3,5,6], target = 7 输出: 4 二、

  • leetcode 78. 子集 js 实现2022-09-14 01:30:09

    给你一个整数数组 nums ,数组中的元素 互不相同 。返回该数组所有可能的子集(幂集)。 解集 不能 包含重复的子集。你可以按 任意顺序 返回解集。 示例 1: 输入:nums = [1,2,3]输出:[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]示例 2: 输入:nums = [0]输出:[[],[0]]  提示: 1 <= nums.leng

  • 977. 有序数组的平方2022-09-13 23:32:34

    理解 比较数组两端的元素,一定能比较出一个最大的数字 代码 class Solution { public int[] sortedSquares(int[] nums) { int left=0, right = nums.length - 1; int[] resultArr = new int[nums.length]; int resIdx = nums.le

  • 线段树优化最长上升子序列问题2022-09-13 16:30:28

    最长上升子序列 给定一个长度为 $N$ 的数列,求数值严格单调递增的子序列的长度最长是多少。 输入格式 第一行包含整数 $N$。 第二行包含 $N$ 个整数,表示完整序列。 输出格式 输出一个整数,表示最大长度。 数据范围 $1 \leq N \leq 1000$,${−10}^{9} \leq \text{数列中的数} \leq {10

  • LeetCode力扣(数组01:存在重复元素)2022-09-13 12:32:03

    LeetCode力扣(数组01:存在重复元素) 题目: 给你一个整数数组 nums 。如果任一值在数组中出现 至少两次 ,返回 true ;如果数组中每个元素互不相同,返回 false 。 示例: 示例 1: 输入:nums = [1,2,3,1] 输出:true 示例 2: 输入:nums = [1,2,3,4] 输出:false 示例 3: 输入:nums = [1,1,1,3,3,4,3,2,4,

  • LeetCode 416. 分割等和子集2022-09-13 11:01:49

    01背包 const int N = 20010; class Solution { public: int dp[N]; bool canPartition(vector<int>& nums) { int sum = 0; for (int i = 0; i < nums.size(); i ++) sum += nums[i]; if (sum % 2 != 0) return false;

  • 查找除 Self 之外的数组的乘积2022-09-13 01:31:44

    查找除 Self 之外的数组的乘积 Photo by 克里斯托弗·高尔 on 不飞溅 给定一个 整数 大批 数字 , 返回 数组 回答 这样 答案[我] 等于所有元素的乘积 数字 除了 数字[i] . 任何前缀或后缀的乘积 数字 是 保证 适应一个 32 位 整数。 您必须编写一个运行在 上) 时间和不使用除

  • [LeetCode] 1608. Special Array With X Elements Greater Than or Equal X2022-09-13 00:02:56

    You are given an array nums of non-negative integers. nums is considered special if there exists a number x such that there are exactly x numbers in nums that are greater than or equal to x. Notice that x does not have to be an element in n

  • 152. 乘积最大子数组2022-09-12 23:03:42

    152. 乘积最大子数组 给你一个整数数组 nums ,请你找出数组中乘积最大的非空连续子数组(该子数组中至少包含一个数字),并返回该子数组所对应的乘积。 测试用例的答案是一个 32-位 整数。 子数组 是数组的连续子序列。   示例 1: 输入: nums = [2,3,-2,4] 输出: 6 解释: 子数组

  • 数组的遍历2022-09-12 14:03:39

    很多天没有上力扣刷题了,感觉都生疏很多,今天重新开始,按照https://leetcode.cn/circle/article/48kq9d/帖子刷题加油/*485、最大连续1的个数*//*思路:遍历,判断,比较*//*通过*/public int findMaxConsecutiveOnes(int[] nums) { int max = 0, tmp = 0; for (int num : nums) {

  • LeetCode 6206. 最长递增子序列 II2022-09-12 11:31:01

    本题思路是遍历一遍当前数组的元素,假设当前元素为i,f[i]是以元素i结尾的最长的递增子序列长度,那么f[i] = 1 + max(f[i-k], f[i-k+1],...,f[i-1])。核心问题就是如何在遍历每个元素时求出max(f[i-k], f[i-k+1],...,f[i-1]),如果使用普通的遍历,那么时间复杂度为\(O(n^2)\),会超时,因此可

  • NC79 丑数2022-09-12 11:30:30

    NC79 丑数 描述 把只包含质因子2、3和5的数称作丑数(Ugly Number)。例如6、8都是丑数,但14不是,因为它包含质因子7。 习惯上我们把1当做是第一个丑数。求按从小到大的顺序的第 n个丑数。 数据范围:0≤n≤2000 要求:空间复杂度 O(n), 时间复杂度 O(n) 示例1 输入: 7 返

  • 未知(有问题):不重复的全排列2022-09-11 22:32:11

    给定一个可包含重复数字的序列 nums ,按序列内字典升序返回所有不重复的全排列。 其中序列内字典升序指的是, 序列内从左到右的非降序排列,例如 nums=[1,2,3], 则因为[1,2,3] < [1,3,2], [3,1,2] < [3,2,1], [1,2,3]要先于[1,3,2]输出,[3,1,2]要先于[3,2,1]输出 输入例子1: [3,3,4]

  • 算法养成计划--day52022-09-11 20:30:23

    20220911 第二题直接看答案,很巧妙的方法,充分的利用异或的性质来写循环。mark一下 第一题 nums[::2], nums[1::2] = nums[:n], nums[n:] 第二题 nums = [5,1,6] candidates = [0] for x in nums: candidates += [x^y for y in candidates] sum(candidates)

  • 198. 打家劫舍2022-09-11 01:01:31

    198. 打家劫舍 你是一个专业的小偷,计划偷窃沿街的房屋。每间房内都藏有一定的现金,影响你偷窃的唯一制约因素就是相邻的房屋装有相互连通的防盗系统,如果两间相邻的房屋在同一晚上被小偷闯入,系统会自动报警。 给定一个代表每个房屋存放金额的非负整数数组,计算你 不触动警报装置的

  • hashmap 17262022-09-11 01:00:58

    1726. Tuple with Same Product Medium 47322Add to ListShare Given an array nums of distinct positive integers, return the number of tuples (a, b, c, d) such that a * b = c * d where a, b, c, and d are elements of nums, and a != b != c != d

  • 算法总结2022-09-10 22:32:14

    1.值和下标之差都在给定的范围内 给你一个整数数组 nums 和两个整数 k 和 t 。请你判断是否存在 两个不同下标 i 和 j,使得 abs(nums[i] - nums[j]) <= t ,同时又满足 abs(i - j) <= k 。如果存在则返回 true,不存在返回 false。 package com.chenghaixiang.jianzhi2.day19; impor

  • LeetCode 15题. 三数之和2022-09-10 19:30:09

    难度挺大..降重细节多 看到个老哥的评价,醍醐灌顶: 说白了就是降维处理, 由三维降到二维, 针对任意索引i的\(nums[i]\) 求\([i+1,size )\)范围内不重复的$$twoSum target = - nums[i];$$后面还有一个四数之和, 一样的问题, 先降到三维, 再降到二维, 随想录 https://gitee.com/p

  • Leetcode 128. 最长连续序列2022-09-10 16:32:05

    地址 https://leetcode.cn/problems/longest-consecutive-sequence/ 给定一个未排序的整数数组 nums ,找出数字连续的最长序列(不要求序列元素在原数组中连续)的长度。 请你设计并实现时间复杂度为 O(n) 的算法解决此问题。 示例 1: 输入:nums = [100,4,200,1,3,2] 输出:4 解释:最长

  • 使用最佳实践编写干净的 javascript。2022-09-10 10:00:08

    使用最佳实践编写干净的 javascript。 什么是干净的代码? 干净的代码是一种以读者为中心的开发风格,可以生成易于编写、阅读和维护的软件。当应用程序按预期运行时,您可能会认为您的工作已完成。认识到您的代码不仅适用于计算机消费,而且适用于现实生活中的人类!关键是使代码更具可读

  • leetcode27-移除元素2022-09-09 19:02:22

          https://leetcode.cn/problems/remove-element/ 首先是自己想的铸币解法。先进行排序,那么目标数字就连续聚在一起。等快指针移动到最后一个目标值得下一个元素就开始进行赋值操作。然后快指针和慢指针不断同步地右移进行赋值操作,直到快指针移动到最后一个元素,两个指针都

  • 移动零2022-09-09 11:34:35

    题目: 一.交换 void swap(int* a, int* b) { int temp = *a; *a = *b; *b = temp; } void moveZeroes(int* nums,int numsSize) { if (numsSize == 1&&numsSize==0&&nums==null) return; for (int i = 0; i < numsSize; i++) {

  • LeetCode题目答案及理解汇总(持续更新)2022-09-08 17:32:40

    面试算法题 dfs相关 全排列 #include<bits/stdc++.h> using namespace std; const int N = 10; //用一个path数组来存储每次到底层的路径 int path[N]; //用一个布尔数组来存储每次已经遍历的点,默认是false bool st[N]; int n; //u表示当前的层数 void dfs(int u) {

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有