
算法
泉山绿树
这个人很懒 什么也没写
展开
-
[Leetcode]Binary Tree Zigzag Level Order Traversal
Binary Tree Zigzag Level Order Traversal My Submissions Question Total Accepted: 47731 Total Submissions: 176275 Difficulty: Medium Given a binary tree, return the zigzag level order traversal of its原创 2015-11-27 13:25:56 · 437 阅读 · 0 评论 -
[Leetcode]Reverse Words in a String
Reverse Words in a String My Submissions Question Total Accepted: 84277 Total Submissions: 546781 Difficulty: Medium Given an input string, reverse the string word by word.For example, Given s = “th原创 2015-12-13 14:37:35 · 393 阅读 · 0 评论 -
[Leetcode]Perfect Squares(DP and Math Solution)
**Perfect Squares My Submissions Question Total Accepted: 16355 Total Submissions: 55778 Difficulty: Medium Given a positive integer n, find the least number of perfect square numbers (for example, 1原创 2015-11-21 10:34:16 · 452 阅读 · 0 评论 -
[Leetcode]Search for a Range
Search for a Range My Submissions Question Total Accepted: 64904 Total Submissions: 232560 Difficulty: Medium Given a sorted array of integers, find the starting and ending position of a given target原创 2015-11-25 21:46:53 · 271 阅读 · 0 评论 -
[Leetcode]Range Sum Query 2D - Immutable
Range Sum Query 2D - Immutable Total Accepted: 4160 Total Submissions: 20469 Difficulty: MediumGiven a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left cor原创 2015-12-11 20:58:41 · 369 阅读 · 0 评论 -
[Leetcode]Binary Tree Right Side View(TAT)
Binary Tree Right Side View My Submissions Question Total Accepted: 26870 Total Submissions: 87779 Difficulty: Medium Given a binary tree, imagine yourself standing on the right side of it, return th原创 2015-11-19 18:59:47 · 299 阅读 · 0 评论 -
[Leetcode]Search a 2D Matrix II
Search a 2D Matrix II My Submissions Question Total Accepted: 19946 Total Submissions: 64757 Difficulty: Medium Write an efficient algorithm that searches for a value in an m x n matrix. This matrix原创 2015-11-19 14:36:08 · 278 阅读 · 0 评论 -
[leetcode]Convert Sorted Array to Binary Search Tree
Convert Sorted Array to Binary Search Tree My Submissions Question Total Accepted: 57734 Total Submissions: 165322 Difficulty: Medium Given an array where elements are sorted in ascending order, conv原创 2015-11-02 23:09:27 · 267 阅读 · 0 评论 -
[leetcode]Product of Array Except Self
Product of Array Except Self My Submissions Question Total Accepted: 21825 Total Submissions: 57345 Difficulty: Medium Given an array of n integers where n > 1, nums, return an array output such that原创 2015-11-02 22:16:27 · 294 阅读 · 0 评论 -
[Leetcode]Course Schedule II
Course Schedule II My Submissions Question Total Accepted: 16442 Total Submissions: 80267 Difficulty: Medium There are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may原创 2015-12-11 17:20:22 · 372 阅读 · 0 评论 -
[Leetcode]Construct Binary Tree from Inorder and Postorder Traversal
Construct Binary Tree from Inorder and Postorder Traversal My Submissions Question Total Accepted: 44071 Total Submissions: 159513 Difficulty: Medium Given inorder and postorder traversal of a tree,原创 2015-11-23 20:49:18 · 317 阅读 · 0 评论 -
[Leetcode]Word Search
Word Search Total Accepted: 58219 Total Submissions: 270800 Difficulty: MediumGiven a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially原创 2015-12-10 16:14:11 · 309 阅读 · 0 评论 -
[Leetcode]Rotate List
Rotate List Total Accepted: 55147 Total Submissions: 249704 Difficulty: MediumGiven a list, rotate the list to the right by k places, where k is non-negative.For example: Given 1->2->3->4->5->NULL an原创 2015-12-08 19:19:32 · 349 阅读 · 0 评论 -
[Leetcode]3Sum Closest
3Sum Closest My Submissions Question Total Accepted: 58639 Total Submissions: 212334 Difficulty: Medium Given an array S of n integers, find three integers in S such that the sum is closest to a give原创 2015-11-26 12:14:42 · 291 阅读 · 0 评论 -
[Leetcode]Rectangle Area
Rectangle Area Total Accepted: 24959 Total Submissions: 89043 Difficulty: EasyFind the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corne原创 2015-12-14 20:16:18 · 309 阅读 · 0 评论 -
[Leetcode]Evaluate Reverse Polish Notation
Evaluate Reverse Polish Notation Total Accepted: 55506 Total Submissions: 249113 Difficulty: MediumEvaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *原创 2015-12-06 16:46:55 · 273 阅读 · 0 评论 -
[Leetcode]Longest Palindromic Substring
Longest Palindromic Substring Total Accepted: 82394 Total Submissions: 381112 Difficulty: MediumGiven a string S, find the longest palindromic substring in S. You may assume that the maximum length of原创 2015-12-10 15:16:56 · 299 阅读 · 0 评论 -
[Leetcode]Decode Ways
Decode Ways Total Accepted: 55623 Total Submissions: 331926 Difficulty: MediumA message containing letters from A-Z is being encoded to numbers using the following mapping:‘A’ -> 1 ‘B’ -> 2 … ‘Z’ -原创 2015-12-12 22:21:15 · 342 阅读 · 0 评论 -
[Leetcode]Bulls and Cows
Bulls and Cows Total Accepted: 10932 Total Submissions: 42057 Difficulty: EasyYou are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess w原创 2015-12-14 20:55:36 · 329 阅读 · 0 评论 -
[Leetcode]Range Sum Query
Range Sum Query - Immutable Total Accepted: 9791 Total Submissions: 40927 Difficulty: EasyGiven an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:G原创 2015-12-14 21:04:22 · 329 阅读 · 0 评论 -
[Leetcode]House Robber
House Robber Total Accepted: 45703 Total Submissions: 142461 Difficulty: EasyYou are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the原创 2015-12-18 19:51:35 · 393 阅读 · 0 评论 -
[Leetcode]Bulb Switcher
Bulb Switcher Total Accepted: 970 Total Submissions: 2597 Difficulty: MediumThere are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the thi原创 2015-12-20 21:04:49 · 1397 阅读 · 0 评论 -
[Leetcode]Sqrt(x)
Sqrt(x) Total Accepted: 74812 Total Submissions: 310770 Difficulty: MediumImplement int sqrt(int x).Compute and return the square root of x.Subscribe to see which companies asked this question题目很简单,弄清原创 2015-12-02 19:31:22 · 389 阅读 · 0 评论 -
[Leetcode]House Robber II
House Robber II Total Accepted: 18212 Total Submissions: 63419 Difficulty: MediumNote: This is an extension of House Robber.After robbing those houses on that street, the thief has found himself a new原创 2015-12-18 20:43:17 · 486 阅读 · 0 评论 -
[Leetcode]Remove Duplicates from Sorted List II
Remove Duplicates from Sorted List II Total Accepted: 58686 Total Submissions: 228299 Difficulty: MediumGiven a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct原创 2015-11-30 21:44:26 · 353 阅读 · 0 评论 -
[Leetcode]Populating Next Right Pointers in Each Node
Populating Next Right Pointers in Each Node My Submissions Question Total Accepted: 72104 Total Submissions: 198545 Difficulty: Medium Given a binary treestruct TreeLinkNode { TreeLinkNode *left;原创 2015-12-15 10:25:20 · 302 阅读 · 0 评论 -
[Leetcode]Search in Rotated Sorted Array
Search in Rotated Sorted Array My Submissions Question Total Accepted: 78974 Total Submissions: 271221 Difficulty: Hard Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.原创 2015-11-17 13:53:52 · 303 阅读 · 0 评论 -
[Leetcode]Combination Sum III
LeetCode OJ LeetCode Premium Subscription Problems Pick One! Courses Discuss Book WooStam Combination Sum III My Submissions Question Total Accepted: 17981 Total Submissions: 56703 Difficult原创 2015-11-16 21:45:29 · 423 阅读 · 0 评论 -
[leetcode]Palindrome Linked List
细节实现题,在纸上画了一会才AC/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public:原创 2015-10-20 11:37:07 · 326 阅读 · 0 评论 -
求字符串的全部组合(字符串中无重复字符)
中午吃东西时候看到这道题有个奇妙的解法挺好玩,求字符串“abcd”的全部组合。 输入:“abcd” 输出:”a”,”b”,”c”,”d”,”ab”,”ac”,”ad”,”bc”,”bd”,”cd”,”abc”,”abd”,”acd”,”bcd”,”abcd”。当然不要求顺序也完全相同。以往的想法是通过深度优先搜索,用递归实现,思路比较常见。但是中午大神给出的这种想法是生成(2^n) - 1个数字原创 2015-10-19 17:14:42 · 1143 阅读 · 0 评论 -
LeetCode:Symmetric 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原创 2015-09-30 12:26:40 · 414 阅读 · 0 评论 -
[leetcode]Move zeros 慢方法和快方法
慢方法class Solution {public: void moveZeroes(vector<int>& nums) { for(int i = 0;i != nums.size();++i){ if(nums[i] == 0){ for(int j = i + 1;j != nums.size();++j){原创 2015-09-20 14:08:55 · 1708 阅读 · 0 评论 -
期望时间为线性时间的选择算法(C++)
#include <iostream>using namespace std;void exchange(int& x, int& y){ int tem = x; x = y; y = tem;} int par(int a[],int b,int e){ int x = a[b]; int j = b + 1; int i = b; f原创 2015-09-01 19:31:20 · 1632 阅读 · 0 评论 -
Leetcode:String to Integer(atoi)
这道应该是最经典的一道题了吧class Solution {public: int myAtoi(string str) { int n = str.size(); long long num = 0; int sig = 1; int i = 0; while(str[i] == ' ' && i < n)原创 2015-09-28 19:38:57 · 357 阅读 · 0 评论 -
Leetcode: Balanced Binary Tree
class Solution {public: bool isBalanced(TreeNode* root) { if(root == nullptr) return true; stack<TreeNode*> sT; TreeNode* t = root; while(!sT.empty() || t){原创 2015-09-28 20:38:14 · 291 阅读 · 0 评论 -
求N位格雷码(递归版and循环版and位运算版)
#include <iostream>#include <vector>using namespace std;vector<string> func(size_t n){ vector<string> res{}; if(n == 0) return res; if(n == 1){ res = {"0","1"}; return res原创 2015-09-06 20:55:11 · 1048 阅读 · 6 评论 -
算法导论计数排序实现(C++)
#include <iostream>using namespace std;#define len 5 void countSorting(int A[],int B[],int k ){ int C[k + 1] = {0}; for(size_t i = 0;i != len;++i) ++C[A[i]]; for(size_t i = 1 ;i !=原创 2015-08-31 22:47:20 · 384 阅读 · 0 评论 -
算法导论快排实现(C++)
算法导论的快排算法,#include <iostream>using namespace std;int a[] = {9};void exchange(int& x, int& y){ int tem = x; x = y; y = tem;}int par(int a[],int b,int e){ int x = a[b]; int j = b +原创 2015-08-30 22:27:36 · 361 阅读 · 0 评论 -
非递归深度优先遍历算法
当然是伪码,自己在纸上模拟了一遍是没错的。如果发现什么错误欢迎指正。N_DFS(gragh g, int i){ int j; seqstack s; INITSTACK(s); while(!EMPTY(s)){ if(visited[i] == 0){ visited[i] = 1; printf(g原创 2015-05-25 23:15:38 · 2746 阅读 · 0 评论 -
一道笔试题:假设在n进制下,下面的等式成立,n的值是(),567*456=150216.<转载>
假设在n进制下,下面的等式成立,n的值是(),567*456=150216.完全是考数学的题目:http://topic.youkuaiyun.com/u/20100319/14/ffd0920a-b256-48d8-8d86-da36a3bfab8d.html做不出来也就算了,实际上,IT公司好多这样子的题目(腾讯除外),难怪考出来,成绩很差都可以进面试。这道题是google和淘宝的笔试题目,没事看看,确实很转载 2015-06-19 00:49:47 · 643 阅读 · 0 评论