ICode9

精准搜索请尝试: 精确搜索
  • leetcode.剑指 Offer 46. 把数字翻译成字符串2022-07-16 18:00:20

      给定一个数字,我们按照如下规则把它翻译为字符串:0 翻译成 “a” ,1 翻译成 “b”,……,11 翻译成 “l”,……,25 翻译成 “z”。一个数字可能有多个翻译。请编程实现一个函数,用来计算一个数字有多少种不同的翻译方法。   示例 1: 输入: 12258输出: 5解释: 12258有5种不同的翻译,分别

  • Leetcode刷题笔记(双指针)2022-07-16 14:37:02

    1.何为双指针 双指针主要用来遍历数组,两个指针指向不同的元素,从而协同完成任务。我们也可以类比这个概念,推广到多个数组的多个指针。 若两个指针指向同一数组,遍历方向相同且不会相交,可以称之为滑动窗口(两个指针包围的区域为当前的窗口),经常用于区间搜索。 若两个指针指向同一数

  • Leetcode栈&队列2022-07-16 14:02:06

    Leetcode栈&队列 232.用栈实现队列 题干: 思路: 栈是FILO,队列是FIFO,所以如果要用栈实现队列,目的就是要栈实现一个FIFO的特性。 具体实现方法可以理解为,准备两个栈,一个栈用作输入栈,入数据就存数据,一个栈用作输出栈,出数据就入数据再弹数据。 代码: class MyQueue { /** *

  • leetcode.code.18. 四数之和2022-07-16 11:32:58

    给你一个由 n 个整数组成的数组 nums ,和一个目标值 target 。请你找出并返回满足下述全部条件且不重复的四元组 [nums[a], nums[b], nums[c], nums[d]] (若两个四元组元素一一对应,则认为两个四元组重复): 0 <= a, b, c, d < na、b、c 和 d 互不相同nums[a] + nums[b] + nums[c] +

  • LeetCode Gas Station 数学2022-07-14 22:05:19

    There are n gas stations along a circular route, where the amount of gas at the \(i\)th station is gas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from the \(i\)th station to its next \((i + 1)\)th station. Yo

  • [Leetcode Weekly Contest]3002022-07-14 21:36:47

    链接:LeetCode [Leetcode]2325. 解密消息 给你字符串 key 和 message ,分别表示一个加密密钥和一段加密消息。解密 message 的步骤如下: 使用 key 中 26 个英文小写字母第一次出现的顺序作为替换表中的字母 顺序 。 将替换表与普通英文字母表对齐,形成对照表。 按照对照表 替换 messa

  • leetcode 经典题2022-07-14 15:03:10

    #include <iostream> #include <vector> #include <stack> #include <string> #include <algorithm> #include <climits> #include <unordered_map> #include <unordered_set> #include <queue> using namespace std;

  • LeetCode/前缀和后缀搜索(字典树)2022-07-14 01:31:48

    设计一个包含一些单词的特殊词典,并能够通过前缀和后缀来检索单词 1. 暴力哈希 实现存储所有可能前后缀组合对应最大下标 class WordFilter { private: unordered_map<string, int> dict;//记录所有前后缀组合对应最大下标 public: WordFilter(vector<string>& words) {

  • 7.13 LeetCode刷题记录(简单x1,中等x1)2022-07-13 18:00:17

    7.13 LeetCode刷题记录(简单x1,中等x1) 1、两数之和(简单) 题目 给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它们的数组下标。 你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。 你可

  • leetcode 135. 分发糖果(困难)2022-07-13 13:01:30

    一、题目大意 标签: 贪心 https://leetcode.cn/problems/candy n 个孩子站成一排。给你一个整数数组 ratings 表示每个孩子的评分。 你需要按照以下要求,给这些孩子分发糖果: 每个孩子至少分配到 1 个糖果。 相邻两个孩子评分更高的孩子会获得更多的糖果。 请你给每个孩子分发糖果,计

  • LeetCode剑指 Offer 60. n个骰子的点数2022-07-12 16:36:00

    LeetCode剑指 Offer 60. n个骰子的点数 dp记录状态数量,数学解法会是更快的解法 class Solution: def dicesProbability(self, n: int) -> List[float]: m, p, l, tot = 6, [1, 2, 3, 4, 5, 6], n * 6, 1. dp = [[0 for i in range(l + 1)] for j in range(n)

  • leetcode.面试题 02.08. 环路检测2022-07-12 10:34:47

    给定一个链表,如果它是有环链表,实现一个算法返回环路的开头节点。若环不存在,请返回 null。 如果链表中有某个节点,可以通过连续跟踪 next 指针再次到达,则链表中存在环。 为了表示给定链表中的环,我们使用整数 pos 来表示链表尾连接到链表中的位置(索引从 0 开始)。 如果 pos 是 -1,则在

  • leetcode-dp-1222022-07-12 10:03:12

    /** * <p>给你一个整数数组 <code>prices</code> ,其中&nbsp;<code>prices[i]</code> 表示某支股票第 <code>i</code> 天的价格。</p> * * <p>在每一天,你可以决定是否购买和/或出售股票。你在任何时候&nbsp;<strong>最多</strong>&nbsp;只能持有

  • leetcode 23 merge K soted lists2022-07-12 02:31:23

        返回成一个排好序的list   K  个,第一个NODE,开始比较; 每个LIST 第一个NODE ,作为比较开始,这样如此; prioty quee,最小数poll出来,等到其变成空,就得到   public LsitNode mergeKList(ListNode[] lists){ if(lists==null||lists.length==0) return null;// corner case Queue<L

  • LeetCode 3Sum 双指针2022-07-11 03:31:06

    Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0. Notice that the solution set must not contain duplicate triplets. Solution 我们需要输出方案,不在乎下标,

  • LeetCode Two Sum Map映射2022-07-10 02:31:15

    Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer

  • leetcode-1422. 分割字符串的最大得分2022-07-09 15:01:56

    1422. 分割字符串的最大得分 刷题代码汇总:https://www.cnblogs.com/geaming/p/16428234.html 题目 思路 首先统计出整个字符串中的所有0的个数,采用for循环从左到右依次计算不同分割方式的得分情况。 \[num_{right1} = len - n - 1 - (num_0-num_{left0}) \]右侧字符串1个数=右侧

  • LeetCode/最长斐波那契子序列的长度2022-07-09 02:32:43

    给定一个严格递增的正整数数组形成序列 arr ,找到 arr 中最长的斐波那契式的子序列的长度。如果一个不存在,返回0 1. 暴力法 先用哈希表记录,再二重循环遍历转移,会存在重复遍历 class Solution { public: int lenLongestFibSubseq(vector<int>& arr) { unordered_set<int

  • LeetCode No1217. 玩筹码2022-07-09 00:05:39

    题目 有 n 个筹码。第 i 个筹码的位置是 position[i] 。 我们需要把所有筹码移到同一个位置。在一步中,我们可以将第 i 个筹码的位置从 position[i] 改变为: position[i] + 2 或 position[i] - 2 ,此时 cost = 0 position[i] + 1 或 position[i] - 1 ,此时 cost = 1 返

  • 7.8 leetcode刷题记录(简单x2)2022-07-08 18:32:45

    7.8 leetcode刷题记录(简单x2) 1.字符串中的第一个唯一字符 给定一个字符串 s ,找到 它的第一个不重复的字符,并返回它的索引 。如果不存在,则返回 -1 。 示例 1: 输入: s = "leetcode" 输出: 0 示例 2: 输入: s = "loveleetcode" 输出: 2 示例 3: 输入: s = "aabb" 输出: -1 解答 way

  • leetcode-最小的k个数-golang版-堆排序-性能及高2022-07-07 17:12:00

    package main import ( "fmt" ) /* 输入整数数组 arr ,找出其中最小的 k 个数。例如,输入4、5、1、6、2、7、3、8这8个数字,则最小的4个数字是1、2、3、4。 示例1: 输入:arr = [3,2,1], k = 2 输出:[1,2] 或者 [2,1] */ func main() { fmt.Println(getLeastNumbers([]int{2, 3, 1,

  • Leetcode 208 实现前缀树2022-07-07 12:33:01

    一、题目   Trie树(前缀树)是一种树形数据结构(多叉树),它可用于高效地存储和检索字符串数据集中的键。这一数据结构有相当多的应用情景,例如自动补完和拼写检查。   请你实现 Trie 类: Trie() 初始化前缀树对象。 void insert(String word) 向前缀树中插入字符串 word 。 boolean s

  • LeetCode No67. 二进制求和2022-07-06 22:03:39

    题目 给你两个二进制字符串,返回它们的和(用二进制表示)。 输入为 非空 字符串且只包含数字 1 和 0。 示例 1: 输入: a = "11", b = "1" 输出: "100" 示例 2: 输入: a = "1010", b = "1011" 输出: "10101" 提示: 每个字符串仅由字符 '0' 或 '1' 组成。 1 <= a

  • 四数之和2022-07-06 18:04:09

       https://leetcode.cn/problems/4sum-ii/solution/si-shu-xiang-jia-ii-by-leetcode-solution/       时间复杂度和空间复杂度都是O(n2) func fourSumCount(a, b, c, d []int) (ans int) { mp:=make(map[int]int,0) for i:=0;i<len(a);i++{ for j:=0;j<

  • leetcode 11. 盛最多水的容器2022-07-06 18:02:35

    题目描述 给定一个长度为 n 的整数数组 height 。有 n 条垂线,第 i 条线的两个端点是 (i, 0) 和 (i, height[i]) 。找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水。返回容器可以储存的最大水量。 说明:你不能倾斜容器。 链接:https://leetcode.cn/proble

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

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

ICode9版权所有