![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode刷题笔记
wang碗碗
这个作者很懒,什么都没留下…
展开
-
leetcode---C++实现---524. Longest Word in Dictionary through Deleting(通过删除字母匹配到字典里最长单词)
题目level:mediumGiven a string and a string dictionary, find the longest string in the dictionary that can be formed by deleting some characters of the given string. If there are more than one possible results, return the longest word with the smallest lex原创 2020-05-24 22:19:30 · 225 阅读 · 0 评论 -
leetcode---C++实现---141. Linked List Cycle(环形链表)
题目level:easyGiven a linked list, determine if it has a cycle in it.To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where tail connects to. If pos is -1, then there is no c原创 2020-05-24 21:50:39 · 217 阅读 · 0 评论 -
leetcode---C++实现---88. Merge Sorted Array(合并两个有序数组)
题目level:easyGiven two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:The number of elements initialized in nums1 and nums2 are m and n respectively.You may assume that nums1 has enough space (size that is great原创 2020-05-24 21:30:59 · 245 阅读 · 0 评论 -
leetcode---C++实现---680. Valid Palindrome II(验证回文字符串 II)
题目level: easyGiven a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome.Example 1:Input: “aba”Output: TrueExample 2:Input: “abca”Output: TrueExplanation: You could delete the character ‘c’.Not原创 2020-05-24 21:05:36 · 210 阅读 · 0 评论 -
leetcode---C++实现---345. Reverse Vowels of a String(反转字符串中的元音字母)
题目level: easyWrite a function that takes a string as input and reverse only the vowels of a string.Example 1:Input: “hello”Output: “holle”Example 2:Input: “leetcode”Output: “leotcede”Note:The vowels does not include the letter “y”.来源:力扣(Leet原创 2020-05-24 20:34:46 · 177 阅读 · 0 评论 -
leetcode---C++实现---633. Sum of Square Numbers(平方数之和)
题目level: easyGiven a non-negative integer c, your task is to decide whether there’re two integers a and b such that a2 + b2 = c.Example 1:Input: 5Output: TrueExplanation: 1 * 1 + 2 * 2 = 5Example 2:Input: 3Output: False来源:力扣(LeetCode)链接:https://原创 2020-05-24 16:56:51 · 634 阅读 · 0 评论 -
leetcode---C++实现---167. Two Sum II - Input array is sorted(两数之和 II - 输入有序数组)
题目level:easyGiven an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, where原创 2020-05-24 16:29:04 · 122 阅读 · 0 评论 -
leetcode---C++实现---11. Container With Most Water(盛最多水的容器)
题目Given n non-negative integers a1, a2, …, an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, s原创 2020-05-17 17:49:57 · 190 阅读 · 0 评论 -
leetcode---C++实现---26. Remove Duplicates from Sorted Array(删除排序数组中的重复项)
题目Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.Ex原创 2020-05-17 17:37:40 · 148 阅读 · 0 评论 -
leetcode---C++实现---98. Validate Binary Search Tree(验证二叉搜索树)
题目解题思路二叉搜索树的特性为:(节点为二叉搜索树上的任一节点)节点的左子树所有节点均比当前节点值小;节点的右子树所有节点均比当前节点值大。方法1:根据上述特性,可以采用递归方法实现,向下递归时,传递左右子树的取值范围;方法2:另一种递归方式是:判断节点的左子树是否为有效的二叉搜索树,再判断当前节点的数值是否比左儿子大,再判断节点的右子树是否为有效的二叉搜索树,判断右儿子的值是否比当前节点数值大;方法3:利用二叉树中序遍历结果为从小到大依次排列的特性。算法实现方法1:/**原创 2020-05-17 17:22:32 · 142 阅读 · 0 评论 -
leetcode---C++实现---104. Maximum Depth of Binary Tree(二叉树的最大深度)
题目Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Note: A leaf is a node with no children.Example:Given binary tree [3,9,20,null,null,15,7],原创 2020-05-17 17:00:57 · 105 阅读 · 0 评论 -
leetcode---C++实现---589. N-ary Tree Preorder Traversal(N叉树的前序遍历)
题目Given an n-ary tree, return the preorder traversal of its nodes’ values.Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).Follow up:Recursive solution is原创 2020-05-17 16:54:17 · 144 阅读 · 0 评论 -
leetcode---C++实现---144. Binary Tree Preorder Traversal(二叉树的前序遍历)
题目Given a binary tree, return the preorder traversal of its nodes’ values.Example:Input: [1,null,2,3]1\2/3Output: [1,2,3]Follow up: Recursive solution is trivial, could you do it iteratively?来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/bi原创 2020-05-17 16:34:29 · 126 阅读 · 0 评论 -
leetcode---C++实现---面试题59 - I. 滑动窗口的最大值
题目给定一个数组 nums 和滑动窗口的大小 k,请找出所有滑动窗口里的最大值。示例:输入: nums = [1,3,-1,-3,5,3,6,7], 和 k = 3输出: [3,3,5,5,6,7]解释:滑动窗口的位置最大值[1 3 -1] -3 5 3 6 731 [3 -1 -3] 5 3 6 731 3 [-1 -3 ...原创 2020-05-17 16:15:27 · 239 阅读 · 0 评论 -
leetcode---C++实现---1047. Remove All Adjacent Duplicates In String(删除字符串中所有相邻重复项)
题目Given a string S of lowercase letters, a duplicate removal consists of choosing two adjacent and equal letters, and removing them.We repeatedly make duplicate removals on S until we no longer can....原创 2020-05-06 00:33:24 · 194 阅读 · 0 评论 -
leetcode---C++实现---1021. Remove Outermost Parentheses(删除最外层的括号)
题目A valid parentheses string is either empty (""), “(” + A + “)”, or A + B, where A and B are valid parentheses strings, and + represents string concatenation. For example, “”, “()”, “(())()”, and “...原创 2020-05-05 23:36:37 · 183 阅读 · 1 评论 -
leetcode---C++实现---844. Backspace String Compare(比较含退格的字符串)
题目Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character.Note that after backspacing an empty text, the text will continue emp...原创 2020-05-05 22:02:44 · 215 阅读 · 0 评论 -
leetcode---C++实现---682. Baseball Game(棒球比赛)
题目You’re now a baseball game point recorder.Given a list of strings, each string can be one of the 4 following types:Integer (one round’s score): Directly represents the number of points you get i...原创 2020-05-05 17:09:11 · 405 阅读 · 0 评论 -
leetcode---C++实现---496. Next Greater Element I(下一个更大元素I)
题目You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1’s elements in the corresponding places of nums2...原创 2020-05-05 12:57:08 · 197 阅读 · 0 评论 -
leetcode---C++实现---232. Implement Queue using Stacks(用栈实现队列)
题目Implement the following operations of a queue using stacks.push(x) – Push element x to the back of queue.pop() – Removes the element from in front of queue.peek() – Get the front element.empty...原创 2020-05-05 11:06:24 · 182 阅读 · 0 评论 -
leetcode---C++实现---225. Implement Stack using Queues(用队列实现栈)
题目Implement the following operations of a stack using queues.push(x) – Push element x onto stack.pop() – Removes the element on top of the stack.top() – Get the top element.empty() – Return whet...原创 2020-05-04 23:11:13 · 107 阅读 · 0 评论 -
leetcode---C++实现---155. Min Stack(最小栈)
题目Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) – Push element x onto stack.pop() – Removes the element on top of the stack.top() – Get...原创 2020-05-04 20:28:04 · 485 阅读 · 0 评论 -
leetcode---C++实现---20. Valid Parentheses(有效的括号)
题目Given a string containing just the characters ‘(’, ‘)’, ‘{’, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type of...原创 2020-05-03 21:31:30 · 110 阅读 · 0 评论