
C/C++
文章平均质量分 67
Maria21
这个作者很懒,什么都没留下…
展开
-
%i 使用
格式串 %d %i转载 2022-07-23 13:23:37 · 964 阅读 · 1 评论 -
Enable multithreading to use std::thread: Operation not permitted
Enable multithreading to use std::thread: Operation not permitted原创 2022-07-11 08:00:39 · 599 阅读 · 0 评论 -
去除变最大/小 单调栈
402. 移掉 K 位数字(中等)我们从一个简单的问题入手,识别一下这种题的基本形式和套路,为之后的三道题打基础。题目描述给定一个以字符串表示的非负整数 num,移除这个数中的 k 位数字,使得剩下的数字最小。注意:num 的长度小于 10002 且 ≥ k。num 不会包含任何前导零。示例 1 :输入: num = "1432219", k = 3输出: "1219"解释: 移除掉三个数字 4, 3, 和 2 形成一个新的最小的数字 1219。示例 2 :输..原创 2020-09-03 22:16:14 · 312 阅读 · 0 评论 -
leetcode problem 167. Two Sum II - Input array is sorted
Given an array of integers that is alreadysorted 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 index1 must b.原创 2020-08-20 22:16:45 · 149 阅读 · 0 评论 -
leetcode problem 129. Sum Root to Leaf Numbers
Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which represents the number123.Find the total sum of all root-to-leaf numbers.Note:A leaf is a no...原创 2020-08-18 12:11:38 · 160 阅读 · 0 评论 -
leetcode problem 300 Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence.Example:Input: [10,9,2,5,3,7,101,18]Output: 4 Explanation: The longest increasing subsequence is [2,3,7,101], therefore the length is 4. Note:There may be mo原创 2020-08-15 14:47:08 · 351 阅读 · 0 评论 -
leetcode problem 125. Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.Note:For the purpose of this problem, we define empty string as valid palindrome.Example 1:Input: "A man, a plan, a canal: Panama"Output: .原创 2020-08-14 22:25:55 · 201 阅读 · 0 评论 -
leetcode problem 437. Path Sum III
You are given a binary tree in which each node contains an integer value.Find the number of paths that sum to a given value.The path does not need to start or end at the root or a leaf, but it must go downwards (traveling only from parent nodes to chil原创 2020-08-14 21:57:15 · 182 阅读 · 0 评论 -
leetcode problem 687 Longest Univalue Path
Given a binary tree, find the length of the longest path where each node in the path has the same value. This path may or may not pass through the root.The length of path between two nodes is represented by the number of edges between them.Example 1:原创 2020-08-14 20:42:43 · 167 阅读 · 0 评论 -
leetcode problem 122 Best Time to Buy and Sell Stock II
Say you have an arraypricesfor which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times)...原创 2020-08-13 22:21:51 · 249 阅读 · 1 评论 -
leetcode problem 121 Best Time to Buy and Sell Stock
Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit.Note t...原创 2020-08-13 21:54:04 · 151 阅读 · 0 评论 -
leetcode 1518 Water Bottles
GivennumBottlesfull water bottles, you can exchangenumExchangeempty water bottles for one full water bottle.The operation of drinking a full water bottle turns it into an empty bottle.Return themaximumnumber of water bottles you candrink.Ex...原创 2020-08-12 22:25:55 · 354 阅读 · 0 评论 -
leetcode problem Fraction to Recurring Decimal
Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeating, enclose the repeating part in parentheses.If multiple answers are possible, just return any of them.原创 2020-08-12 17:50:08 · 173 阅读 · 0 评论 -
leetcode problem 165 Compare Version Numbers
Compare two version numbersversion1andversion2.Ifversion1>version2return1;ifversion1<version2return-1;otherwise return0.You may assume that the version strings are non-empty and contain only digits and the.character.The.charac...原创 2020-08-12 11:48:40 · 171 阅读 · 0 评论 -
leetcode problem 162 Find Peak Element
题目:A peak element is an element that is greater than its neighbors.Given an input arraynums, wherenums[i] ≠ nums[i+1], find a peak element and return its index.The array may contain multiple peaks, in that case return the index to any one of the pe..原创 2020-08-12 01:01:49 · 145 阅读 · 0 评论 -
leetcode problem 160 Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:begin to intersect at node c1.Example 1:Input: intersectVal = 8, listA = [4,1,8,4,5], listB = [5,6,1,8,4,5原创 2020-08-12 00:52:25 · 157 阅读 · 0 评论 -
leetcode problem 154 Find Minimum in Rotated Sorted Array II
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7]might become [4,5,6,7,0,1,2]).Find the minimum element.The array may contain duplicates.Example 1:Input: [1,3,5]Output: 1...原创 2020-08-12 00:06:37 · 201 阅读 · 0 评论 -
leetcode problem 153 Find Minimum in Rotated Sorted Array
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7]might become [4,5,6,7,0,1,2]).Find the minimum element.You may assume no duplicate exists in the array.Example 1:Input: [3,4,5...原创 2020-08-11 23:13:47 · 198 阅读 · 0 评论 -
leetcode problem 152 Maximum Product Subarray
Given an integer arraynums, find the contiguous subarray within an array (containing at least one number) which has the largest product.Example 1:Input: [2,3,-2,4]Output: 6Explanation:[2,3] has the largest product 6.Example 2:Input: [-2,0,-1..原创 2020-08-11 22:38:52 · 156 阅读 · 0 评论 -
leetcode problem 151 Reverse Words in a String
Given an input string, reverse the string word by word.Example 1:Input: "the sky is blue"Output:"blue is sky the"Example 2:Input: " hello world! "Output:"world! hello"Explanation: Your reversed string should not contain leading or trailin...原创 2020-08-11 22:16:45 · 169 阅读 · 0 评论 -
leetcode problem 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 the top element. getMin() -- Retrieve the minimum ele原创 2020-08-11 21:56:56 · 153 阅读 · 0 评论 -
leetcode 1513 Number of Substrings With Only 1s
Given a binary strings(a string consisting only of '0' and '1's).Return the number of substrings with all characters 1's.Since the answermay be too large,return it modulo10^9 + 7.Example 1:Input: s = "0110111"Output: 9Explanation: There ...原创 2020-08-11 02:16:38 · 175 阅读 · 0 评论 -
leetcode 1512 Number of Good Pairs
Given an array of integersnums.A pair(i,j)is calledgoodifnums[i]==nums[j]andi<j.Return the number ofgoodpairs.Example 1:Input: nums = [1,2,3,1,1,3]Output: 4Explanation: There are 4 good pairs (0,3), (0,4), (3,4), (2,5) 0-inde...原创 2020-08-11 01:54:01 · 247 阅读 · 0 评论 -
leetcode1510 Stone Game IV
Alice and Bob take turns playing a game, with Alice starting first.Initially, there arenstones in a pile. On each player's turn, that player makes amoveconsisting of removinganynon-zerosquare numberof stones in the pile.Also, if a player canno...原创 2020-08-11 01:12:13 · 237 阅读 · 0 评论 -
leetcode1509 Minimum Difference Between Largest and Smallest Value in Three Moves
题目:Given an arraynums, you are allowed to choose one element ofnumsand change it by anyvalue in one move.Return the minimum difference between the largest and smallest value ofnumsafter perfoming at most 3 moves.Example 1:Input: nums = [5...原创 2020-08-11 00:29:45 · 249 阅读 · 0 评论 -
leetcode1508 Range Sum of Sorted Subarray Sums
题目:Given the arraynumsconsisting ofnpositive integers. You computed the sum of all non-empty continous subarrays fromthe array and then sort them in non-decreasing order, creating a new array ofn * (n + 1) / 2numbers.Return the sum of the number...原创 2020-08-10 23:57:55 · 229 阅读 · 0 评论 -
leetcode1507 Reformat Date
题目:Given adatestring in the formDay Month Year, where:Dayis in the set{"1st", "2nd", "3rd", "4th", ..., "30th", "31st"}. Monthis in the set{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}. Yearis in the ran......原创 2020-08-10 17:33:03 · 355 阅读 · 1 评论 -
leetcode1529 Bulb Switcher IV
题目:There is a room withnbulbs, numbered from0ton-1,arranged in a row from left to right. Initially all the bulbs areturned off.Your task is to obtain the configuration represented bytargetwheretarget[i]is '1' if the i-th bulb is turned on an...原创 2020-08-09 12:08:34 · 179 阅读 · 0 评论 -
leetcode1528 Shuffle String
题目:Given a stringsand an integer arrayindicesof thesame length.The stringswill be shuffled such that the character at theithposition moves toindices[i]in the shuffled string.Returnthe shuffled string.Example 1:Input: s = "codeleet...原创 2020-08-09 11:51:19 · 173 阅读 · 0 评论 -
leetcode_130 Binary Tree Postorder Traversal
题目:Given a binary tree, return thepostordertraversal of its nodes' values.Example:Input:[1,null,2,3] 1 \ 2 / 3Output:[3,2,1]Follow up:Recursive solution is trivial, could you do it iteratively?解法一:递归法/** * Definiti...原创 2020-08-09 00:57:54 · 154 阅读 · 0 评论 -
leetcode_129 Triangle
题目:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,5,7], [4,1,8,3]]The minimum path sum from top t原创 2020-08-09 00:20:43 · 142 阅读 · 0 评论 -
leetcode_128 Pascal‘s Triangle II
Given a non-negativeindexkwherek≤33, return thekthindex row of the Pascal's triangle.Note that the row index starts from0.Example:Input: 3Output: [1,3,3,1]Follow up:Could you optimize your algorithm to use onlyO(k) extra space?方法...原创 2020-08-08 17:52:48 · 176 阅读 · 0 评论 -
leetcode_127 Pascal‘s Triangle
Given a non-negative integernumRows, generate the firstnumRowsof Pascal's triangle.Example:Input: 5Output:[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]代码如下:class Solution {public: vector<vector<int>> gener...原创 2020-08-08 17:25:57 · 154 阅读 · 0 评论 -
leetcode_126 Populating Next Right Pointers in Each Node II
题目:Given a binary treestruct Node { int val; Node *left; Node *right; Node *next;}Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set toNULL.Initially, all next poin.原创 2020-08-08 16:51:18 · 134 阅读 · 0 评论 -
leetcode_125 Populating Next Right Pointers in Each Node
题目:You are given aperfect binary treewhereall leaves are on the same level, and every parent has two children. The binary tree has the following definition:struct Node { int val; Node *left; Node *right; Node *next;}Populate each next p...原创 2020-08-08 16:33:30 · 145 阅读 · 0 评论 -
leetcode_124 Distinct Subsequences
Given a stringSand a stringT, count the number of distinct subsequences ofSwhich equalsT.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the rela...原创 2020-08-08 16:14:37 · 151 阅读 · 0 评论 -
leetcode_122 Binary Tree Preorder Traversal
题目:Given a binary tree, return thepreordertraversal 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?方法一:递归代码如下:/** * Def...原创 2020-08-08 00:00:22 · 202 阅读 · 0 评论 -
leetcode_123 Flatten Binary Tree to Linked List
题目:把二叉树转换为链表Given a binary tree, flatten it to a linked list in-place.For example, given the following tree: 1 / \ 2 5 / \ \3 4 6The flattened tree should look like:1 \ 2 \ 3 \ 4 \ 5原创 2020-08-07 23:45:48 · 142 阅读 · 0 评论 -
leetcode-121 Path Sum II
题目:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.Note:A leaf is a node with no children.Example:Given the below binary tree andsum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ ..原创 2020-08-07 18:32:50 · 136 阅读 · 0 评论 -
leetcode_120 Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.Note:A leaf is a node with no children.Example:Given the below binary tree andsum = 22, 5 ..原创 2020-08-07 18:13:09 · 148 阅读 · 0 评论