【LeetCode-897-递增顺序搜索树】教程文章相关的互联网学习教程文章

LeetCode2021.3.17-各位相加【代码】

递归的简单应用,之后补上好点的代码。 # 给定一个非负整数 num,反复将各个位上的数字相加,直到结果为一位数。 # 示例: # 输入: 38 # 输出: 2 # 解释: 各位相加的过程为:3 + 8 = 11, 1 + 1 = 2。 由于2 是一位数,所以返回 2。 class Solution(object):def addDigits(self, num):""":type num: int:rtype: int"""count = sum([int(x) for x in list(str(num))])if count >= 10:return Solution.addDigits(self, count)else:retu...

leetcode 29. 两数相除【代码】【图】

给定两个整数,被除数 dividend 和除数 divisor。将两数相除,要求不使用乘法、除法和 mod 运算符。 返回被除数 dividend 除以除数 divisor 得到的商。 整数除法的结果应当截去(truncate)其小数部分,例如:truncate(8.345) = 8 以及 truncate(-2.7335) = -2 示例 1: 输入: dividend = 10, divisor = 3输出: 3解释: 10/3 = truncate(3.33333..) = truncate(3) = 3示例 2: 输入: dividend = 7, divisor = -3输出: -2解释: 7/-3 ...

Leetcode刷题记录(二)2021.3.29 堆

Leetcode刷题记录(二)2021.3.29 堆 Java中PriorityQueue的用法 PriorityQueue<Integer> pq = new PriorityQueue<>(new Comparator<Integer>(){ public int compare(Integer a,Integer b){ return a-b;//a是刚插入该优先队列的数值,如果return的数小于0,则上升,return的数大于0则下降 //当a-b<0时,a上升,由此可知该优先队列是最小堆}}); Map<Integer,Integer> map = new HashMap();map.put(key,value);map.get(key);map....

Leetcode 202: Happy Number【代码】

问题描述: Write an algorithm to determine if a number n is happy. A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits. Repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are...

leetcode--database

ps:limit 1,1 第一个1是表示第二行,第二个1表示从第二行开始往后输出几行。limit 1,1表示只输出第二行。 leetcode--database标签:本文系统来源:http://www.cnblogs.com/lorryrui/p/5671411.html

LeetCode 456. 132 模式【代码】

原题 LeetCode 456. 132 模式 代码1 枚举“3” c++ class Solution { public:bool find132pattern(vector<int>& nums) {bool flag=0;int min=1000000000;for(int i=0;i<nums.size()-1;i++){for(int j=i+1;j<nums.size();j++){if(nums[j]>min && nums[j]<nums[i]) flag=1;}if(nums[i]<min) min=nums[i];}return flag;} };

LeetCode笔记:Biweekly Contest 49 比赛记录【代码】

LeetCode笔记:Biweekly Contest 49 0. 赛后总结1. 题目一 1. 解题思路2. 代码实现 2. 题目二 1. 解题思路2. 代码实现 3. 题目三 1. 解题思路2. 代码实现 4. 题目四 1. 解题思路2. 代码实现3. 算法优化 0. 赛后总结 表示人果然来是老了,中午和同学聚餐,跑去吃日料自助,兴致所至畅饮3大杯梅酒,然后直接就给跪了,当时没啥反应,吃完回来之后发现头晕脑涨,一觉睡到晚上快8点,回去之后还是晕乎乎的,饭都不怎么吃得下,硬塞了...

Leetcode 472~478题【代码】

第四百七十二题: class Solution { public:unordered_set<string> hash;bool check(string& word) {int n = word.size();vector<int> f(n + 1, INT_MIN);f[0] = 0;for (int i = 0; i <= n; i ++ ) {if (f[i] < 0) continue;for (int j = n - i; j; j -- ) {if (hash.count(word.substr(i, j))) {f[i + j] = max(f[i + j], f[i] + 1);if (f[n] > 1) return true;}}}return false;}vector<string> findAllConcatenatedWordsInADict(...

leetcode每日一题 2021/4/3 1143. 最长公共子序列【代码】【图】

题目: 给定两个字符串 text1 和 text2,返回这两个字符串的最长 公共子序列 的长度。如果不存在 公共子序列 ,返回 0 。 一个字符串的 子序列 是指这样一个新的字符串:它是由原字符串在不改变字符的相对顺序的情况下删除某些字符(也可以不删除任何字符)后组成的新字符串。 例如,“ace” 是 “abcde” 的子序列,但 “aec” 不是 “abcde” 的子序列。 两个字符串的 公共子序列 是这两个字符串所共同拥有的子序列。 示例 1: 输...

[每日一题] leetcode 403. 青蛙过河【代码】

因为数据太大,但数据量少,因此可以用map先建立映射关系 再用二维set,其中set[i]表示第i个石块所能跳的距离数组 二维vector会超时,set去重就可以了 然后遍历每个石块,并求出其所能到达石块 所能跳的距离 最后判断第n - 1个石块是否有能跳的步数即可class Solution { public:set<int> V[2020];map<int, int> M;bool canCross(vector<int>& stones) {int n = stones.size();int cnt = 0;for(int i = 0; i < n; i++)M[stones[i]] ...

LeetCode 力扣题解(1)两数之和【代码】

LeetCode 力扣题解(1)两数之和 LeetCode 力扣题解(1)两数之和,实现语音 Python。 一、题目:两数之和 给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 的那 两个 整数,并返回它们的数组下标。 你可以假设每种输入只会对应一个答案。但是,数组中同一个元素不能使用两遍。 你可以按任意顺序返回答案。 示例 1: 输入:nums = [2,7,11,15], target = 9 输出:[0,1] 解释:因为 nums[0] + nums...

leetcode-315. 计算右侧小于当前元素的个数(树状数组)【代码】

给定一个整数数组 nums,按要求返回一个新数组 counts。数组 counts 有该性质: counts[i] 的值是 nums[i] 右侧小于 nums[i] 的元素的数量。 示例: 输入:nums = [5,2,6,1] 输出:[2,1,1,0] 解释: 5 的右侧有 2 个更小的元素 (2 和 1) 2 的右侧仅有 1 个更小的元素 (1) 6 的右侧有 1 个更小的元素 (1) 1 的右侧有 0 个更小的元素提示: 0 <= nums.length <= 10^5 -10^4 <= nums[i] <= 10^4 题解 树状数组求逆序数 class Solutio...

leetcode-62-不同路径【代码】

1. 题目介绍 https://leetcode-cn.com/problems/unique-paths/ 2. 解题代码public int UniquePaths(int m, int n) {int[,] f=new int[m,n];int i,j;for (i = 0; i < m; i++){for (j = 0; j < n; j++){if (i == 0 || j == 0){f[i,j]=1;}else{f[i,j]=f[i-1,j]+f[i,j-1];}}}return f[m-1,n-1];}

leetcode66---数组加一【代码】

leetcode66—数组加一:关键字:数组,字符串转换 题目: 给定一个由 整数 组成的 非空 数组所表示的非负整数,在该数的基础上加一。 最高位数字存放在数组的首位, 数组中每个元素只存储单个数字。 你可以假设除了整数 0 之外,这个整数不会以零开头。 示例 1: 输入:digits = [1,2,3] 输出:[1,2,4] 解释:输入数组表示数字 123。 示例 2: 输入:digits = [4,3,2,1] 输出:[4,3,2,2] 解释:输入数组表示数字 4321。 示例 3: 输...

[LeetCode] 1838. Frequency of the Most Frequent Element【代码】

The frequency of an element is the number of times it occurs in an array. You are given an integer array nums and an integer k. In one operation, you can choose an index of nums and increment the element at that index by 1. Return the maximum possible frequency of an element after performing at most k operations. Example 1: Input: nums = [1,2,4], k = 5 Output: 3 Explanation: Increment the first el...