LeetCode
文章平均质量分 58
PRISMATIC2017
Dance Dance Dance to the Distortion~
展开
-
LeetCode :【Easy】461. Hamming Distance
LeetCode :【Easy】461. Hamming DistanceThe Hamming distance between two integers is the number of positions at which the corresponding bits are different.Given two integers x and y, calculate the Ha原创 2017-03-03 14:37:39 · 343 阅读 · 0 评论 -
309. Best Time to Buy and Sell Stock with Cooldown
It took me more than 2 hours trying to solve it by myself. Failed. My mind was completely in mess. I was frustrated dealing this problem, and finally went to the discuss section and found it can be ...原创 2018-06-29 12:53:42 · 200 阅读 · 0 评论 -
Greedy--406
406 Queue Reconstruction by HeightI find it difficult for me to come up with a general idea about this problem, in another words, my solution can only pass some of the tests. How to get down to th...原创 2018-06-24 07:55:17 · 936 阅读 · 0 评论 -
Separate a string word by word -- istringstream AND getline
Problem: 151. Reverse Words in a String The straightforward solution is simply recording each word into a string vector, then empty the original string s, iterate the string vector reversely to gener...原创 2018-06-22 11:03:38 · 195 阅读 · 0 评论 -
637. Average of Levels in Binary Tree
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class原创 2017-08-14 15:47:20 · 232 阅读 · 0 评论 -
503. Next Greater Element II
class Solution {public: vector<int> nextGreaterElements(vector<int>& nums) { int n = nums.size(); vector<int> result(n, -1); stack<int> s; for (int i = 0; i < n; i+原创 2017-07-30 22:21:50 · 257 阅读 · 0 评论 -
611. Valid Triangle Number
Given an array consists of non-negative integers, your task is to count the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle.Example 1: In原创 2017-07-20 22:04:16 · 288 阅读 · 0 评论 -
LeetCode :【Easy】344. Reverse String
Write a function that takes a string as input and returns the string reversed.Example: Given s = “hello”, return “olleh”.原创 2017-03-14 10:58:10 · 253 阅读 · 0 评论 -
LeetCode :【Easy】412. Fizz Buzz
Write a program that outputs the string representation of numbers from 1 to n.But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”.原创 2017-03-13 15:51:16 · 348 阅读 · 0 评论 -
LeetCode :【Easy】500. Keyboard Row
Given a List of words, return the words that can be typed using letters of alphabet on only one row’s of American keyboard like the image below.原创 2017-03-12 16:10:13 · 348 阅读 · 0 评论 -
LeetCode :【Easy】476. Number Complement
Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.Note: The given integer is guaranteed to fit within the range of a 32-b原创 2017-03-10 16:32:41 · 452 阅读 · 0 评论 -
300. Longest Increasing Subsequence
When going through the discuss section, I found several different solutions for this problem, one using the standard DP (O(N^2)), one using binary search (O(NlogN)), The last one is tricky using lower...原创 2018-06-29 04:19:18 · 160 阅读 · 0 评论