自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

原创 【leetcode】393. UTF-8 Validation

题目: 思路: 规律很明显,比较简单。 代码实现: 自己实现的代码,有点繁琐: class Solution { public: int type(int i){ int mask = 128; while (mask & i){ ...

2020-05-31 01:33:28 11 0

原创 【leetcode】392. Is Subsequence

题目: Given a string s and a string t, check if s is subsequence of t. A subsequence of a string is a new string which is formed from the original stri...

2020-05-31 00:55:25 27 0

原创 【leetcode】390. Elimination Game

题目: There is a list of sorted integers from 1 to n. Starting from left to right, remove the first number and every other number afterward until you r...

2020-05-31 00:39:49 24 0

原创 【leetcode】389. Find the Difference

题目: Given two strings s and t which consist of only lowercase letters. String t is generated by random shuffling string s and then add one more lette...

2020-05-31 00:24:29 31 0

原创 【leetcode】388. Longest Absolute File Path

题目: 思路: 将"\n"将整个string分割成strings数组,数组中每一个元素都是一个folder名字或file名字,决定其所在层级的是名字最前面的"\t"的数量,"\t"的数量加1就是其所在的层级。剩下的就是利用stack不...

2020-05-31 00:19:18 30 0

原创 Google 开源项目风格指南——C++ 风格指南

Google 开源项目风格指南——C++ 风格指南

2020-05-30 12:48:35 38 0

原创 【leetcode】387. First Unique Character in a String

题目: Given a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1. 思路: 扫描两遍数组即可。 代码实现: class S...

2020-05-30 00:27:00 24 0

原创 【leetcode】386. Lexicographical Numbers

题目: 思路: 抄不懂。手算一下+脑补一下。 代码实现: class Solution { public: vector<int> lexicalOrder(int n) { vector<int> res(n); int cu...

2020-05-30 00:20:25 15 0

原创 【leetcode】385. Mini Parser

题目: 思路: ‘[’ 新建NestedInteger,’,‘跳过,’]’ 出栈并建立好前后关联。 代码实现: class Solution { public: NestedInteger deserialize(string s) { stack<Nested...

2020-05-29 23:34:37 35 0

原创 【leetcode】384. Shuffle an Array

题目: Shuffle a set of numbers without duplicates. 思路: vector<int> &nums用来保存原数组。 reset函数: 直接返回原数组。 shuffle函数: 当前元素为nums[j],在此之前的元素中随机抽一个元素——...

2020-05-29 18:58:01 21 0

原创 【leetcode】383. Ransom Note

题目: Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the...

2020-05-29 18:22:36 18 0

原创 【leetcode】382. Linked List Random Node

题目: Given a singly linked list, return a random node’s value from the linked list. Each node must have the same probability of being chosen. Follow u...

2020-05-29 17:41:58 26 0

原创 【leetcode】380. Insert Delete GetRandom O(1)

题目: 思路: vector<int> nums保存val,unordered_map<int, int> my_map保存val到数组index之间的映射关系(val是唯一的)。 insert函数: 向数组nums尾部添加新val,同时my_map保存val到inde...

2020-05-29 17:08:32 26 0

原创 【leetcode】378. Kth Smallest Element in a Sorted Matrix

题目: Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix. Note that it ...

2020-05-29 16:27:07 31 0

原创 【leetcode】377. Combination Sum IV

题目: Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer ta...

2020-05-29 12:33:12 16 0

原创 【leetcode】376. Wiggle Subsequence

题目: 思路: 首先求出整个nums的diff数组。然后就只有两种情况——负数开头的diff数组和正数开头的diff数组。然后取其中的最大值即可。 代码实现: class Solution { public: int wiggleMaxLength(vector<int>...

2020-05-29 11:51:44 23 0

原创 【leetcode】375. Guess Number Higher or Lower II

题目: We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to guess which number I picked. Every time you guess...

2020-05-29 02:24:37 17 0

原创 【leetcode】374. Guess Number Higher or Lower

题目: 思路: 二分法。 代码实现: /** * Forward declaration of guess API. * @param num your guess * @return -1 if num is lower than the guess number...

2020-05-28 17:58:29 28 0

原创 【leetcode】373. Find K Pairs with Smallest Sums(未理解)

题目: 思路: 抄作业https://leetcode.com/problems/find-k-pairs-with-smallest-sums/discuss/84607/Clean-16ms-C%2B%2B-O(N)-Space-O(KlogN)-Time-Solution-using-P...

2020-05-28 17:32:10 41 0

原创 【leetcode】372. Super Pow

题目: 思路: 抄作业https://leetcode.com/problems/super-pow/discuss/84472/C%2B%2B-Clean-and-Short-Solution 引用博文https://blog.csdn.net/qq_27437197/article/det...

2020-05-28 15:35:10 23 0

原创 【leetcode】371. Sum of Two Integers

题目: Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. 思路: 博文https://www.cnblogs.com/dyzhao-blog/p/5662...

2020-05-28 12:27:00 19 0

原创 【leetcode】368. Largest Divisible Subset

题目: 思路: 直接引用博文https://www.cnblogs.com/godlei/p/5621990.html的解释: 如果a%b==0,则a=mb,所以如果把数组排序后如果a%b==0,且b%c==0则a%c==0。这就为用动态规划实现提供了可能性。设置一个数组result,res...

2020-05-28 11:52:53 21 0

原创 【leetcode】367. Valid Perfect Square

题目: Given a positive integer num, write a function which returns True if num is a perfect square else False. Follow up: Do not use any built-in libra...

2020-05-28 10:47:18 20 0

原创 【leetcode】365. Water and Jug Problem

题目: 思路: 直接看博文https://www.cnblogs.com/grandyang/p/5628836.html。 代码实现: class Solution { public: int GCD(int a, int b){ while (b){ ...

2020-05-28 01:11:53 17 0

原创 【leetcode】357. Count Numbers with Unique Digits

题目: 思路: 规律如下: f(0)=1 f(1)=10 f(2)=9*9+f(1) f(3)=9*9*8+f(2) f(4)=9*9*8*7+f(3) f(5)=9*9*8*7*6+f(4) f(6)=9*9*8*7*6*5+f(5) f(7)=9*9*8*7*6*5*4+f(6) f(8)...

2020-05-28 00:47:59 12 0

原创 【leetcode】355. Design Twitter

题目: 思路: 数据结构解释如下: Tweet: 推特消息,以list的形式存放。一个Tweet就是一个list node,包含id,time以及next指针。 User: 用户,实体对象。其中包含用户id、存放订阅用户的unordered_set<int> follows以及存放...

2020-05-28 00:10:49 16 0

原创 【leetcode】350. Intersection of Two Arrays II

题目: Given two arrays, write a function to compute their intersection. 思路: 直接看代码。 代码实现: class Solution { public: vector<int> intersect(vec...

2020-05-27 21:57:34 24 0

原创 【leetcode】349. Intersection of Two Arrays

题目: Given two arrays, write a function to compute their intersection. 思路: 利用unordered_map<int, bool> my_map保存nums1所有元素,然后遍历nums2。如果某个元素已经遍历过了,...

2020-05-27 19:38:36 28 0

原创 【leetcode】347. Top K Frequent Elements

题目: Given a non-empty array of integers, return the k most frequent elements. 思路: 抄作业https://leetcode.com/problems/top-k-frequent-elements/discuss/8...

2020-05-27 19:29:41 51 0

原创 【leetcode】345. Reverse Vowels of a String

题目: Write a function that takes a string as input and reverse only the vowels of a string. 思路: 很简单,直接看代码。 代码实现: class Solution { public: bool i...

2020-05-27 18:16:04 21 0

原创 【leetcode】343. Integer Break

题目: Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximu...

2020-05-27 17:45:24 15 0

原创 【leetcode】342. Power of Four

题目: Given an integer (signed 32 bits), write a function to check whether it is a power of 4. 思路: (num&(num-1))==0保证整个二进制中只有一个1;(num-1) % 3 == 0保...

2020-05-27 17:04:48 18 0

原创 【leetcode】341. Flatten Nested List Iterator

题目: Given a nested list of integers, implement an iterator to flatten it. Each element is either an integer, or a list – whose elements may also be i...

2020-05-27 16:44:29 22 0

原创 【leetcode】338. Counting Bits

题目: Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation ...

2020-05-27 15:57:28 29 0

原创 【leetcode】337. House Robber III

题目: The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the “root.” Besides the root, eac...

2020-05-27 13:18:59 29 0

原创 【leetcode】334. Increasing Triplet Subsequence

题目: 思路: 抄作业https://www.cnblogs.com/warmland/p/5735208.html。 用x和y保存序列中所有nums[i]<nums[j]中nums[j]最小的那一对。两个变量的解释如下: x:此值尽量压低。 y:此值也尽量压低。其意义是:如果此值为IN...

2020-05-27 12:18:22 32 0

原创 【leetcode】332. Reconstruct Itinerary

题目: 思路: 有向图的深度优先搜索。tickets里实际上保存的是图的有向边。我用unordered_map保存每个from节点(出发地)到其所有邻接to节点(目的地,用一个链表将所有邻接to节点按照字符串从小到大的顺序串起来)的映射关系。每次深度优先遍历邻接点时,都临时将节点从对应链表中删...

2020-05-22 02:57:04 39 0

原创 【leetcode】331. Verify Preorder Serialization of a Binary Tree

题目: 思路: 思路1:引用博文https://blog.csdn.net/fuxuemingzhu/article/details/79537797的解释: 用一个栈,从字符串的左侧向右依次进栈,如果满足栈的后三位是数字,#,#的模式时,说明可以构成合法的叶子节点,把这个叶子节点换成#号,...

2020-05-22 00:13:11 34 0

原创 【leetcode】328. Odd Even Linked List

题目: Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and no...

2020-05-21 23:00:50 50 0

原创 【leetcode】326. Power of Three

题目: Given an integer, write a function to determine if it is a power of three. 思路: 引用博文https://blog.csdn.net/ebowtang/article/details/50485622的解释: ...

2020-05-21 22:49:03 37 0

提示
确定要删除当前文章?
取消 删除