码迷,mamicode.com
首页 >  
搜索关键字:leetcode 19    ( 34993个结果
leetcode刷题总结501-550
501. 二叉搜索树中的众数 描述: 思路:中序遍历。 503. 下一个更大元素 II 描述: 思路:单调栈。 506. 相对名次 描述: 思路:先拍戏。再替换。 508. 出现次数最多的子树元素和 描述: 思路:后序遍历。否则叶子节点就遍历了很多次。通过hash存《和,次数》 513. 找树左下角 ...
分类:其他好文   时间:2020-07-13 13:31:19    阅读次数:83
LeetCode 1503. 所有蚂蚁掉下来前的最后一刻
脑筋急转弯 每只蚂蚁都一样,相遇之后,相当于两人互换身份,继续朝原来的方向前进。因此,找出距离朝向端点最远的蚂蚁需要走多久,就是答案。 class Solution { public int getLastMoment(int n, int[] left, int[] right) { int re ...
分类:其他好文   时间:2020-07-13 13:24:49    阅读次数:54
leetcode——134.加油站
自己完成了,但是效果好像并不怎么样 public int canCompleteCircuit(int[] gas, int[] cost) { int len = gas.length; if(len == 1){ return gas[0] >= cost[0]?0:-1; } int sum1 ...
分类:其他好文   时间:2020-07-13 12:03:19    阅读次数:57
【LeetCode-数组】旋转数组
题目描述 给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数。 示例: 输入: [1,2,3,4,5,6,7] 和 k = 3 输出: [5,6,7,1,2,3,4] 解释: 向右旋转 1 步: [7,1,2,3,4,5,6] 向右旋转 2 步: [6,7,1,2,3,4,5] 向 ...
分类:编程语言   时间:2020-07-13 12:00:44    阅读次数:177
LeetCode第 30 场双周赛题解
5177. 转变日期格式 思路:按照空格划分出年月日,年已经是数字形式,不需要做处理。月是英文单词的缩写,需要对应到相应的数字。 对于日,只需要把结尾的英文序数词去掉,只留下数字即可。 这里要注意月和日可能是个位数,这种情况下要在前面补一个0. class Solution { string mon ...
分类:其他好文   时间:2020-07-13 11:58:07    阅读次数:75
【刷题-LeetCode】190 Reverse Bits
Reverse Bits Reverse bits of a given 32 bits unsigned integer. Example 1: Input: 00000010100101000001111010011100 Output: 0011100101111000001010010100 ...
分类:其他好文   时间:2020-07-13 11:35:53    阅读次数:58
Leetcode刷题日记(2020.7.13)程序员面试经典:消失的两个数字
题目描述如下: 分析如下: 此题目乍一看挺难的没有思路,其实很简单,他要找消失的两个数字,那么也及时其实原数组应该是在现有输入数组的基础上加上两个数字,此时range()函数就可以上场了,但是很多人说,你这样会有重复哎,咋办呢,直接使用set()去重复即可。 代码如下: 1 #!/usr/bin/e ...
分类:其他好文   时间:2020-07-13 11:31:50    阅读次数:69
leetcode每日一题(2020-07-13):350. 两个数组的交集 II
题目描述: 给定两个数组,编写一个函数来计算它们的交集。 今日学习: 1.啊!美好的简单题! 题解: 1.暴力法,开始居然忘了indexOf 2.暴力法,利用indexOf一次循环 3.排序法,双指针移动 4.hash法,列出较短数组元素的出现次数,遍历较长数组去比较 /** * @param {n ...
分类:编程语言   时间:2020-07-13 11:23:35    阅读次数:75
[LeetCode] 1512. Number of Good Pairs
Given an array of integers nums. A pair (i,j) is called good if nums[i] == nums[j] and i < j. Return the number of good pairs. Example 1: Input: nums ...
分类:其他好文   时间:2020-07-13 09:57:03    阅读次数:63
[LeetCode] 1513. Number of Substrings With Only 1s
Given a binary string s (a string consisting only of '0' and '1's). Return the number of substrings with all characters 1's. Since the answer may be t ...
分类:其他好文   时间:2020-07-13 09:45:45    阅读次数:61
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!