- 博客(16)
- 收藏
- 关注
原创 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
原创 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
原创 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 949
原创 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
原创 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
原创 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
原创 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
原创 数组和字符串
数组的声明:int a[maxn]maxn必须是常数,不能是变量a[n++]:首先赋值a[n]=x, 然后执行n=n+1; a[++n]:先n=n+1, 然后用加一之后的n赋值a[n]=x; 数组最好定义在main函数外面,只有放在外面的时候,数组才可以开得很大,放在main函数里面时,数组稍大就会异常退出数组不能进行赋值操作,int a[maxn], b[maxn], 要
2017-04-05 18:39:43 389
原创 循环结构程序设计
FOR对于for循环,建议尽量缩短变量的定义范围,例如在初始化部分定义循环变量。for(int i=0;i<10;i++)aabb(7744)输出所有形如aabb的4位完全平方数;#include<stdio.h>#include<math.h>int main(){ for(int a=1;a<=9;a++) { for(int b=1;b<=9;b++)
2017-03-29 22:40:01 462
原创 程序设计入门
圆柱体的表面积#include<stdio.h>#include<math.h>int main(){ const double pi=acos(-1.0); double r,h,s1,s2,s; scanf("%lf%lf",&r,&h); s1=pi*r*r; s2=2*r*pi*h; s=2.0*s1+s2; printf("ar
2017-03-28 23:23:15 290
原创 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
原创 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 349
原创 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
原创 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 453
原创 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 345
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人