c++
bald
在读研究生,只是做一些微小的记录。
展开
-
leetcode problem 287. Find the Duplicate Number 20190416
DescriptionGiven an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicat...原创 2019-04-15 14:00:21 · 131 阅读 · 0 评论 -
leetcode problem 62. Unique Paths [20190417]
DescriptionA robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to r...原创 2019-04-15 14:11:40 · 136 阅读 · 0 评论 -
leetcode problem 312. Burst Balloons 20190718
DescriptionGiven n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloons. If the you burst balloon i you will...原创 2019-07-19 14:30:58 · 156 阅读 · 0 评论 -
leetcode problem 399. Evaluate Division
20190719DescriptionEquations are given in the format A / B = k, where A and B are variables represented as strings, and k is a real number (floating point number). Given some queries, return the a...原创 2019-07-19 22:02:41 · 169 阅读 · 0 评论 -
leetcode problem 84. Largest Rectangle in Histogram
DescriptionGiven n non-negative integers representing the histogram’s bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where widt...原创 2019-08-01 11:03:09 · 139 阅读 · 0 评论 -
c++ 读入一串数,未知长度,遇到回车停止
int n; vector<int> arr; while (cin >> n){ arr.push_back(n); if (cin.get() == '\n') break; }原创 2019-09-09 21:12:58 · 625 阅读 · 0 评论 -
cpp 超常用tips! -- 每天一个写bug小技巧
c++ map 相当于python 中的dict, 一个关键词对应一个值(multimap可以对应多个值)map默认是排好序的,如果有需要用到排序的对,那么可以创建map来维护数据结构。那么如果要取根据关键词(key)排序的元素的最后一位应该怎么做呢:取最后一位元素参考auto iter = my_map.crbegin();...原创 2019-09-11 12:23:17 · 1036 阅读 · 0 评论 -
leetcode problem 96. Unique Binary Search Trees
DescriptionGiven n, how many structurally unique BST’s (binary search trees) that store values 1 … n?Example:Input: 3Output: 5Explanation:Given n = 3, there are a total of 5 unique BST's: 1 ...原创 2019-04-14 23:17:10 · 108 阅读 · 0 评论 -
leetcode problem 538. Convert BST to Greater Tree
DescriptionGiven a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in ...原创 2019-04-14 14:20:10 · 135 阅读 · 0 评论 -
leetcode problem 46. Permutations
DescriptionGiven a collection of distinct integers, return all possible permutations.Example:Input: [1,2,3]Output:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]Solution递归...原创 2019-04-13 15:57:38 · 134 阅读 · 0 评论 -
leetcode problem 647. Palindromic Substrings
DescriptionGiven a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes or end indexes are counted as different substrings even th...原创 2019-03-30 00:04:18 · 131 阅读 · 0 评论 -
leetcode problem 70. Climbing Stairs
DescriptionYou are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n will be ...原创 2019-04-10 12:16:30 · 119 阅读 · 0 评论 -
leetcode problem 206. Reverse Linked List
DescriptionReverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULLFollow up:A linked list can be reversed either iteratively or r...原创 2019-04-01 01:12:21 · 122 阅读 · 0 评论 -
leetcode problem 394. Decode String
DescriptionGiven an encoded string, return it’s decoded string.The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note th...原创 2019-04-10 15:48:12 · 135 阅读 · 0 评论 -
leetcode problem 21. Merge Two Sorted Lists
DescriptionMerge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Example:Input: 1->2->4, 1->3->4O...原创 2019-04-10 16:19:02 · 165 阅读 · 0 评论 -
leetcode problem 64. Minimum Path Sum
DescriptionGiven a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or...原创 2019-04-11 11:11:29 · 168 阅读 · 0 评论 -
leetcode problem 309. Best Time to Buy and Sell Stock with Cooldown
DescriptionSay you have an array for which the iii-th element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like...原创 2019-04-02 13:24:24 · 160 阅读 · 0 评论 -
leetcode problem 22. Generate Parentheses
DescriptionGiven n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "(()())", "(())()", ...原创 2019-04-02 14:40:23 · 158 阅读 · 0 评论 -
leetcode problem 169. Majority Element
DescriptionGiven an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority e...原创 2019-04-02 16:55:54 · 148 阅读 · 0 评论 -
leetcode problem 406. Queue Reconstruction by Height
problemSuppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person and k is the number of people in front ...原创 2019-03-29 12:33:51 · 195 阅读 · 0 评论 -
leetcode problem Path Sum (series)
Path Sum 1Given 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....原创 2019-04-12 14:55:36 · 270 阅读 · 0 评论 -
leetcode problem 121. Best Time to Buy and Sell Stock
DescriptionSay you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of ...原创 2019-04-03 16:15:19 · 117 阅读 · 0 评论