
Algorithm
阳光岛主
阳光、快乐、创新
展开
-
Python 和 PHP 对腾讯云签名 hmac_sha256 算法实现
开宗明义,米扑科技在使用腾讯云的API接口签名中,按照官方示例开发PHP、Python的接口,经常会提示签名错误123456789{ "Response": { "Error": { "Code": "InvalidParameter.SignatureFailure", "Message": "The provided credentials could not be.原创 2018-05-08 22:45:18 · 11155 阅读 · 1 评论 -
link 链表反转
链表反转,示例如下:偶数个:a->b->c->d->e->fe->f->c->d->a->b奇数个:a->b->c->d->e->f->gg->e->f->c->d->a->b#include #include #include /************** start of stack *************/#define STACK_SIZE 1024char st原创 2014-07-26 22:02:36 · 4198 阅读 · 0 评论 -
【leetcode】Construct Binary Tree from Inorder and Postorder Traversal
Question: Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.Anwser 1 : /** * Definition for binary tree * st原创 2013-05-04 00:20:24 · 5236 阅读 · 0 评论 -
【leetcode】Construct Binary Tree from Preorder and Inorder Traversal
Question: Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.Anwser 1 : /** * Definition for binary tree * s原创 2013-05-03 23:26:32 · 5928 阅读 · 1 评论 -
【leetcode】Binary Tree Inorder Traversal
Question : Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Recursive solution is trivia原创 2013-05-03 22:36:35 · 4074 阅读 · 0 评论 -
【leetcode】Flatten Binary Tree to Linked List
Question : Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1 \原创 2013-05-02 00:00:46 · 5122 阅读 · 0 评论 -
【leetcode】Binary Tree Level Order Traversal II
Question : Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree {3,9,20,#,#,15原创 2013-05-01 23:21:41 · 5507 阅读 · 1 评论 -
【leetcode】Balanced Binary Tree
Question : Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node neve原创 2013-05-01 22:54:40 · 3794 阅读 · 0 评论 -
【leetcode】Minimum Depth of Binary Tree
Question : Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.Anwser 1 : /** * Definition原创 2013-05-01 22:15:33 · 3607 阅读 · 0 评论 -
【leetcode】Generate Parentheses
Question : Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "原创 2013-05-01 21:40:50 · 4531 阅读 · 1 评论 -
【leetcode】Longest Valid Parentheses
Question:Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()",原创 2013-05-01 20:55:25 · 4154 阅读 · 1 评论 -
【leetcode】Valid Parentheses
Question : Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are al原创 2013-05-01 20:07:17 · 4568 阅读 · 1 评论 -
【leetcode】Binary Tree Maximum Path Sum
Question : Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Return 6.Anwser 1 :原创 2013-05-01 19:19:11 · 3573 阅读 · 0 评论 -
【leetcode】Letter Combinations of a Phone Number
Question : Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit s原创 2013-05-01 18:20:16 · 4758 阅读 · 0 评论 -
【leetcode】Longest Consecutive Sequence
Question : Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is [1,原创 2013-05-01 17:25:39 · 3636 阅读 · 1 评论 -
【leetcode】Valid Number
Question : Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueNote: It is intended for the problem statement to be ambiguous. You s原创 2013-04-21 23:50:28 · 4857 阅读 · 1 评论 -
【leetcode】Word Ladder II
Question : Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end, such that:Only one letter can be changed at a timeEach intermediate word m原创 2013-04-21 23:04:41 · 4974 阅读 · 0 评论 -
【leetcode】Word Ladder
Question :Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a timeEach intermediate原创 2013-04-21 21:57:11 · 3186 阅读 · 0 评论 -
【leetcode】Best Time to Buy and Sell Stock III
Question : Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note:You may原创 2013-04-21 21:18:20 · 2903 阅读 · 0 评论 -
【leetcode】Best Time to Buy and Sell Stock II
Quesion : Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie,原创 2013-04-21 20:46:33 · 2854 阅读 · 0 评论 -
【leetcode】Best Time to Buy and Sell Stock
Question : Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of t原创 2013-04-21 19:39:02 · 3422 阅读 · 0 评论 -
【leetcode】Integer to Roman
Question : Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.Anwser 1 : class Solution {public: string intToRoman(int num) { //原创 2013-04-21 18:41:14 · 3752 阅读 · 0 评论 -
【leetcode】Roman to Integer
Question :Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.Anwser 1 : class Solution {public: int toNum(char c) { sw原创 2013-04-21 10:40:29 · 3336 阅读 · 0 评论 -
【leetcode】Reverse Integer
Question : Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321Have you thought about this?Here are some good questions to ask before coding. Bonus points for you原创 2013-04-21 08:46:56 · 3762 阅读 · 0 评论 -
【leetcode】Divide Two Integers
Question : Divide two integers without using multiplication, division and mod operator.Anwser 1 : class Solution {public: int divide(int dividend, int divisor) { // Start typing your原创 2013-04-20 10:21:37 · 4491 阅读 · 0 评论 -
【leetcode】Binary Tree Zigzag Level Order Traversal
Question :Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given bin原创 2013-04-20 09:31:19 · 2679 阅读 · 0 评论 -
【leetcode】Zigzag Conversion
Question : The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P原创 2013-04-20 00:58:32 · 3050 阅读 · 0 评论 -
【leetcode】String to Integer (atoi)
Question :Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible in原创 2013-04-19 23:30:13 · 7147 阅读 · 2 评论 -
【leetcode】Binary Tree Level Order Traversal
Question :Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20原创 2013-04-19 22:42:40 · 2839 阅读 · 0 评论 -
【leetcode】Maximum Depth of Binary Tree
Question :Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Anwser 1 : DFS/** * Definition原创 2013-04-19 21:36:02 · 6716 阅读 · 0 评论 -
【leetcode】Surrounded Regions
Question :Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region .For example,X X X XX O O XX X原创 2013-04-14 15:54:45 · 4120 阅读 · 3 评论 -
【leetcode】Palindrome Partitioning II
Question : Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab",Retur原创 2013-04-14 14:47:08 · 3128 阅读 · 0 评论 -
【leetcode】Palindrome Partitioning
Question:Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa","b"]原创 2013-04-14 13:48:52 · 2793 阅读 · 0 评论 -
【leetcode】Palindrome Number
Question:Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the integer to string, n原创 2013-04-14 12:14:06 · 6461 阅读 · 2 评论 -
【leetcode】Valid Palindrome
Question:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a原创 2013-04-14 11:31:01 · 3436 阅读 · 0 评论 -
【leetcode】Implement strStr()
Question:Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.Anwser 1: O(n*m)class Solution {public: char *strStr(char *原创 2013-04-14 10:53:37 · 2852 阅读 · 0 评论 -
【leetcode】Rotate List
Question:Given 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 and k = 2,return 4->5->1->2->3->NULL.Anwser 1: merge a circle /** * Defi原创 2013-04-14 09:51:20 · 2513 阅读 · 1 评论 -
【leetcode】Triangle
Question:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4],原创 2013-04-14 01:10:18 · 2499 阅读 · 1 评论 -
【leetcode】Pascal's Triangle II
Question:Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?Anwser 1: class S原创 2013-04-14 00:20:16 · 2639 阅读 · 0 评论 -
【leetcode】Pascal's Triangle
Question: Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]Anwser 1: class So原创 2013-04-13 23:31:58 · 2603 阅读 · 0 评论