LeetCode
ZayneHuang
这个作者很懒,什么都没留下…
展开
-
LeetCode 771. Jewels and Stones
题目链接:https://leetcode.com/problems/jewels-and-stones/description/题目解析:利用字符的ACSII离散化一下,确定有没有出现即可。代码如下:0ms Acceptedclass Solution {public: int numJewelsInStones(string J, string S) { ...原创 2018-07-24 21:31:27 · 90 阅读 · 0 评论 -
LeetCode 797. All Paths From Source to Target
题目链接:https://leetcode.com/problems/all-paths-from-source-to-target/description/Given a directed, acyclic graph of N nodes. Find all possible paths from node 0 to node N-1, and return them in any o...原创 2018-07-26 11:35:53 · 136 阅读 · 0 评论 -
LeetCode 728. Self Dividing Numbers
题目链接:https://leetcode.com/problems/self-dividing-numbers/description/A self-dividing number is a number that is divisible by every digit it contains.For example, 128 is a self-dividing number bec...原创 2018-07-26 11:46:01 · 116 阅读 · 0 评论 -
LeetCode 561. Array Partition I
题目链接:https://leetcode.com/problems/array-partition-i/description/Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) w...原创 2018-07-26 12:14:35 · 132 阅读 · 0 评论 -
LeetCode 872. Leaf-Similar Trees
题目链接:https://leetcode.com/problems/leaf-similar-trees/description/Consider all the leaves of a binary tree. From left to right order, the values of those leaves form a leaf value sequence.For ...原创 2018-07-26 12:25:54 · 237 阅读 · 0 评论 -
LeetCode 763. Partition Labels
题目链接:https://leetcode.com/problems/partition-labels/description/A string S of lowercase letters is given. We want to partition this string into as many parts as possible so that each letter appears...原创 2018-07-26 12:56:57 · 148 阅读 · 0 评论 -
LeetCode 537. Complex Number Multiplication
题目链接:https://leetcode.com/problems/complex-number-multiplication/description/Given two strings representing two complex numbers.You need to return a string representing their multiplication. Note...原创 2018-07-26 13:55:19 · 110 阅读 · 0 评论 -
LeetCode 58. Length of Last Word
题目链接:https://leetcode.com/problems/length-of-last-word/description/Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the stri...原创 2018-07-26 20:50:57 · 113 阅读 · 0 评论 -
LeetCode 814. Binary Tree Pruning
题目链接:https://leetcode.com/problems/binary-tree-pruning/description/We are given the head node root of a binary tree, where additionally every node's value is either a 0 or a 1.Return the same tre...原创 2018-07-25 14:18:43 · 132 阅读 · 0 评论 -
LeetCode 861. Score After Flipping Matrix
题目链接:https://leetcode.com/problems/score-after-flipping-matrix/description/We have a two dimensional matrix A where each value is 0 or 1.A move consists of choosing any row or column, and togglin...原创 2018-07-25 14:03:41 · 153 阅读 · 0 评论 -
LeetCode 654. Maximum Binary Tree(O(n)方法!)
题目链接:https://leetcode.com/problems/maximum-binary-tree/description/题目解析:应该很容易想到的是递归做法,分别在左右两侧分治法即可,需要每次都遍历一次子数组,肯定比较慢emmmmm看到Discuss里面C++ O(N) solution帖子中有的方法,非常精妙!感谢@mrsuyi~主要的思路是用一个vector维护一个递...原创 2018-07-25 10:02:35 · 193 阅读 · 0 评论 -
LeetCode 807. Max Increase to Keep City Skyline
题目链接:https://leetcode.com/problems/max-increase-to-keep-city-skyline/description/题目解析:的做法,找到Column和Row中的最大值,然后sum加上当前位置横纵数值的min与当前高度之差即可。有个小优化是,在循环里面同时找出横纵的最大值,可以减少数组读取。代码如下:0ms Acceptedclass...原创 2018-07-24 21:38:14 · 97 阅读 · 0 评论 -
LeetCode 709. To Lower Case
题目链接:https://leetcode.com/problems/to-lower-case/description/题目解析:没什么特别的,善用STL。代码如下:0ms Acceptedclass Solution {public: string toLowerCase(string str) { transform(str.begin(), str....原创 2018-07-24 21:40:38 · 111 阅读 · 0 评论 -
LeetCode 804. Unique Morse Code Words
题目链接:https://leetcode.com/problems/unique-morse-code-words/description/题目解析:字符串去重用set即可。代码如下:0ms Acceptedclass Solution {public: int uniqueMorseRepresentations(vector<string>& wo...原创 2018-07-25 00:38:32 · 63 阅读 · 0 评论 -
LeetCode 461. Hamming Distance
题目链接:https://leetcode.com/problems/hamming-distance/description/方法一题目解析:从%2的情况来计算,换成二进制来计算差异。代码如下:0ms Acceptedclass Solution {public: int hammingDistance(int x, int y) { int dis ...原创 2018-07-25 00:52:00 · 72 阅读 · 0 评论 -
LeetCode 832. Flipping an Image
题目链接:https://leetcode.com/problems/flipping-an-image/description/题目解析:vector的反转可以很方便使用reverse,然后将0 1对调即可。代码如下:8ms Acceptedclass Solution {public: vector<vector<int>> flipAndInv...原创 2018-07-25 00:56:42 · 72 阅读 · 0 评论 -
LeetCode 657. Judge Route Circle
题目链接:https://leetcode.com/problems/judge-route-circle/description/题目解析:只要记下横竖坐标即可,最终如果移动到原点,那么横竖坐标均为0。代码如下:4ms Acceptedclass Solution {public: bool judgeCircle(string moves) { int ...原创 2018-07-25 00:59:00 · 122 阅读 · 0 评论 -
LeetCode 852. Peak Index in a Mountain Array
题目链接:https://leetcode.com/problems/peak-index-in-a-mountain-array/description/题目解析:只要找到非递增点就可以。 代码如下:4ms Accepted beating 100% class Solution {public: int peakIndexInMountainArray(vect...原创 2018-07-25 01:05:30 · 78 阅读 · 0 评论 -
LeetCode 617. Merge Two Binary Trees
题目链接:https://leetcode.com/problems/merge-two-binary-trees/description/题目解析:将T1作为模板,把T2合进来。容易想到的是用递归的方法遍历子树,主要分成三种情况——T1和T2当前节点都存在,那么两者值相加即可,继续分别递归左右子树; T1不存在,T2存在,那么把T1当前空节点赋值为T2当前节点即可,以T2当前节点为根结...原创 2018-07-25 01:11:15 · 78 阅读 · 0 评论 -
LeetCode 824. Goat Latin
题目链接:https://leetcode.com/problems/goat-latin/description/A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and uppercase letters only.We would like to...原创 2018-07-26 21:54:47 · 195 阅读 · 0 评论