• LeetCode题解之 Implement strStr()

    时间:2022-06-22 10:43:55

    1、题目描述2.题目分析字符串操作,注意边界条件即可。3.代码intstrStr(stringhaystack,stringneedle){intn=needle.size();intres=-;if(needle.size()==)return;for(string::iteratorit=hay...

  • 【LeetCode题解】347_前K个高频元素(Top-K-Frequent-Elements)

    时间:2022-06-07 07:41:49

    更多LeetCode题解笔记可以访问我的github。目录描述解法一:排序算法(不满足时间复杂度要求)Java实现Python实现复杂度分析解法二:最小堆思路Java实现Python实现复杂度分析解法三:桶排序(bucketsort)思路Java实现Python实现复杂度分析描述给定一个非空的整数数...

  • 【LeetCode题解】24_两两交换链表中的节点(Swap-Nodes-in-Pairs)

    时间:2022-06-07 07:41:37

    更多LeetCode题解笔记可以访问我的github。目录描述解法一:迭代思路Java实现Python实现复杂度分析解法二:递归(不满足空间复杂度要求)思路Java实现Python实现复杂度分析描述给定一个链表,两两交换其中相邻的节点,并返回交换后的链表。示例:给定1->2->3->...

  • leetcode 题解: Length of Last Word

    时间:2022-04-12 07:10:32

    leetcode:Givenastring s consistsofupper/lower-casealphabetsandemptyspacecharacters '',returnthelengthoflastwordinthestring.Ifthelastworddoesnotexist,r...

  • 【LeetCode题解】25_k个一组翻转链表(Reverse-Nodes-in-k-Group)

    时间:2022-04-02 07:22:33

    更多LeetCode题解笔记可以访问我的github。目录描述解法一:迭代思路Java实现Python实现复杂度分析解法二:递归(不满足空间复杂度)思路Java实现Python实现复杂度分析描述给出一个链表,每k个节点一组进行翻转,并返回翻转后的链表。k是一个正整数,它的值小于或等于链表的长度。如果...

  • C#版 - Leetcode 65. 有效数字 - 题解

    时间:2022-03-13 10:01:42

    版权声明:本文为博主BravoYeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址http://blog.csdn.net/lzuacm。Leetcode65.有效数字Leetcode65.ValidNumber在线提交:Leetcodehttps://lee...

  • [LeetCode]题解(python):081 - Search in Rotated Sorted Array II

    时间:2022-02-19 08:08:58

    题目来源https://leetcode.com/problems/search-in-rotated-sorted-array-ii/Followupfor"SearchinRotatedSortedArray":Whatif duplicates areallowed?Wouldthisaffe...

  • 【LeetCode题解】231_2的幂(Power-of-Two)

    时间:2022-02-05 11:40:00

    目录描述解法1:判断整数$x$的二进制表示中是否只有一位为1实现方式1:除以2Java实现(非递归)Python实现(非递归)Java实现(递归)Python实现(递归)复杂度分析实现方式2:位运算Java实现Python实现复杂度分析描述给定一个整数,编写一个函数来判断它是否是2的幂次方。示例1:...

  • 《LeetBook》leetcode题解(6): ZigZag Conversion[E]

    时间:2022-01-24 17:15:28

    我现在在做一个叫《leetbook》的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看书的地址:https://hk029.gitbooks.io/leetbook/006.ZigZagConversion[E]题目Thestring“PA...

  • LeetCode题解之Squares of a Sorted Array

    时间:2022-01-22 01:59:10

    1、题目描述2、问题分析使用过两个计数器。3、代码classSolution{public:vector<int>sortedSquares(vector<int>&A){intleft=,right=A.size()-;vector<int>res;wh...

  • LeetCode题解之Binary Tree Pruning

    时间:2022-01-18 01:30:16

    1、题目描述2、问题分析使用递归3、代码TreeNode*pruneTree(TreeNode*root){if(root==NULL)returnNULL;prun(root);returnroot;}voidprun(TreeNode*root){if(root==NULL)return;if(...

  • [LeetCode]题解(python):069-Sqrt(x)

    时间:2022-01-10 22:24:50

    题目来源:https://leetcode.com/problems/sqrtx/题意分析:实现一个整型的开根。题目思路:利用牛顿迭代法可以求解。首先讲数据类型转成浮点数,然后选取初始值为n/2,然后用牛顿迭代,直到迭代结果相差小于1.0,最后将浮点数转回整型。代码(Python):classSol...

  • Leetcode:maximum_depth_of_binary_tree题解

    时间:2022-01-08 13:32:08

    一、    题目给定一个二叉树,求它的最大深度。最大深度是沿从根节点,到叶节点最长的路径。二、    分析(做到这里发现接连几道题都是用递归,可能就是由于自己时挑的简单的做的吧。)找出最深路径,则每经过一个节点要加上1,当遇到空节点时,返回0。在网上看了看有的做法除了麻烦点可是非常不错的方法,比方使...

  • 【LeetCode题解】844_比较含退格的字符串(Backspace-String-Compare)

    时间:2022-01-01 08:06:44

    更多LeetCode题解笔记可以访问我的github。目录描述解法一:字符串比较思路Java实现Python实现复杂度分析解法二:双指针(推荐)思路Java实现Python实现复杂度分析描述给定S和T两个字符串,当它们分别被输入到空白的文本编辑器后,判断二者是否相等,并返回结果。#代表退格字符。示例...

  • 【LeetCode题解】3_无重复字符的最长子串(Longest-Substring-Without-Repeating-Characters)

    时间:2022-01-01 08:06:38

    更多LeetCode题解笔记可以访问我的github。目录描述解法一:暴力枚举法(TimeLimitExceeded)思路Java实现Python实现复杂度分析解法二:滑动窗口(双指针)思路Java实现Python实现复杂度分析解法三:滑动窗口(优化版)思路Java实现Python实现复杂度分析解法...

  • 【LeetCode题解】232_用栈实现队列(Implement-Queue-using-Stacks)

    时间:2022-01-01 08:06:56

    更多LeetCode题解笔记可以访问我的github。目录描述解法一:在一个栈中维持所有元素的出队顺序思路入队(push)出队(pop)查看队首(peek)是否为空(empty)Java实现Python实现解法二:一个栈入,一个栈出思路入队(push)出队(pop)查看队首(peek)是否为空(em...

  • 【LeetCode题解】225_用队列实现栈(Implement-Stack-using-Queues)

    时间:2022-01-01 08:06:32

    更多LeetCode题解笔记可以访问我的github。@目录描述解法一:双队列,入快出慢思路入栈(push)出栈(pop)查看栈顶元素(peek)是否为空(empty)Java实现Python实现解法二:双队列,入慢出快思路入栈(push)出栈(pop)查看栈顶元素(peek)是否为空(empty)...

  • [LeetCode]题解(python):107 Binary Tree Level Order Traversal II

    时间:2021-12-31 07:02:13

    题目来源https://leetcode.com/problems/binary-tree-level-order-traversal-ii/Givenabinarytree,returnthe bottom-uplevelorder traversalofitsnodes'values.(ie,f...

  • [LeetCode]题解(python):047-Permutations II

    时间:2021-12-31 06:27:43

    题目来源https://leetcode.com/problems/permutations-ii/Givenacollectionofnumbersthatmightcontainduplicates,returnallpossibleuniquepermutations.Forexample,[...

  • 【题解】【字符串】【Leetcode】Valid Palindrome

    时间:2021-12-19 15:17:16

    Givenastring,determineifitisapalindrome,consideringonlyalphanumericcharactersandignoringcases.Forexample,"Aman,aplan,acanal:Panama" isapalindrome."rac...