![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Algorithms
文章平均质量分 63
LadyFeline
这个作者很懒,什么都没留下…
展开
-
Reverse Linked List
Reverse a singly linked list. 解析: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class原创 2015-05-06 13:43:10 · 353 阅读 · 0 评论 -
【Leetcode长征系列】Single Number II
原题: Given an array of integers, every element appears three times except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it withou原创 2014-08-15 11:47:09 · 626 阅读 · 0 评论 -
【Leetcode长征系列】Construct Binary Tree from Inorder and Postorder Traversal
原题: Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. 思路:和上一题一样,后续我们可以通过最后一个值得到根的值,同样可以通过定位根的值得到左右子树的原创 2014-08-21 15:03:07 · 589 阅读 · 0 评论 -
【Leetcode长征系列】Insertion Sort List
原题: Sort a linked list using insertion sort. 知识把原创 2014-08-01 14:18:08 · 545 阅读 · 0 评论 -
【Leetcode长征系列】Reverse Integer
原题: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 zhedao原创 2014-07-14 15:58:48 · 660 阅读 · 0 评论 -
【Leetcode长征系列】Maxmium depth of binary tree
原题: 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.原创 2014-07-14 13:52:34 · 502 阅读 · 0 评论 -
【Leetcode长征系列】Same tree
原题: Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value.原创 2014-07-14 14:15:28 · 499 阅读 · 0 评论 -
【Leetcode长征系列】Single Number
为这个问题纠结了好久表示自己太菜了。 这个问题主要应该是二进制思想的英语原创 2014-07-14 13:02:14 · 578 阅读 · 0 评论 -
【Leetcode长征系列】Palindrome Number
原型: Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of conver原创 2014-07-31 12:02:20 · 821 阅读 · 5 评论 -
【Leetcode长征系列】Binary Tree Preorder Traversal
原题: Given a binary tree, return the preorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,2,3]. Note: Recursive solutio原创 2014-07-15 16:51:35 · 440 阅读 · 0 评论 -
【Leetcode长征系列】 Divide Two Integers
原题: Divide two integers without using multiplication, division and mod operator. 思路: 记录除数与被除数的符号跑原创 2014-07-30 14:32:01 · 653 阅读 · 1 评论 -
【Leetcode长征系列】Validate Binary Search Tree
原题: Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's k原创 2014-08-06 13:19:34 · 673 阅读 · 0 评论 -
【Leetcode长征系列】Linked List Cycle
原题: Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space?原创 2014-07-15 14:50:44 · 420 阅读 · 0 评论 -
【Leetcode长征系列】Valid Parentheses
原题: 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 the s原创 2014-07-30 15:24:23 · 629 阅读 · 0 评论 -
【Leetcode长征系列】Minimum Depth of Binary Tree
原题: 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. 思路: 深度优先原创 2014-07-30 14:48:01 · 634 阅读 · 0 评论 -
【Leetcode长征系列】Sum Root to Leaf Numbers
原题: Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123. Find the to原创 2014-07-30 13:54:24 · 519 阅读 · 0 评论 -
【Leetcode长征系列】Plus One
原题: Given a non-negative number represented as an array of digits, plus one to the number. The digits are stored such that the most significant digit is at the head of the list. 思路:原创 2014-07-29 15:44:35 · 646 阅读 · 0 评论 -
【Leetcode长征系列】Path Sum II
原题: Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For example: Given the below binary tree and sum = 22, 5 / \原创 2014-08-04 12:00:32 · 526 阅读 · 0 评论 -
【Leetcode长征系列】Construct Binary Tree from Preorder and Inorder Traversal
原题: Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. 思路:通过先序我们可以找到根节点,再到中序序列中去找到根节点,根节点的左边便为左子树,右边为右子原创 2014-08-21 14:54:06 · 751 阅读 · 0 评论 -
【Leetcode长征系列】Length of Last Word
原题: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If the last word does not exist, return 0. Note: A word原创 2014-08-08 10:56:19 · 601 阅读 · 0 评论 -
【Leetcode长征系列】Letter Combinations of a Phone Number
原题: 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原创 2014-08-21 17:14:35 · 809 阅读 · 0 评论 -
Rotate Array
Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4]. class Solution { public: void rotate(int n原创 2015-05-01 13:16:40 · 335 阅读 · 0 评论 -
【Leetcode长征系列】Merge k Sorted Lists
原题: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 思路:两条两条地合并。时间复杂度为O(n),n为所有链表节点和。 代码: /** * Definition for singly-linked list. * struct List原创 2014-08-14 16:49:15 · 987 阅读 · 2 评论 -
【Leetcode长征系列】Pow(x, n)
原题: Implement pow(x, n). 思路:递归计算pow。 class Solution { public: double pow(double x, int n) { long long int mid = n/2; int d = n%2; if(n==0) return 1; if(n==1) return原创 2014-08-14 13:53:10 · 778 阅读 · 0 评论 -
【Leetcode长征系列】Sqrt(x)
原题: Implement int sqrt(int x). Compute and return the square root of x. ==============================以下为引用==================================== 牛顿迭代法 为了方便理解,就先以本题为例: 计算x2 = n的解,令f(原创 2014-08-14 14:58:58 · 996 阅读 · 0 评论 -
【Leetcode长征系列】Convert Sorted List to Binary Search Tree
原题: Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 思路:和处理数组的思想类似,用递归。 代码:原创 2014-08-12 11:23:35 · 602 阅读 · 4 评论 -
【Leetcode长征系列】Longest Common Prefix
原题: Write a function to find the longest common prefix string amongst an array of strings. 思路:pre赋给第一个strs值原创 2014-08-11 16:52:09 · 707 阅读 · 0 评论 -
【Leetcode长征系列】Convert Sorted Array to Binary Search Tree
原题: Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 【复习时间】:平衡二叉树(Balanced Binary Tree)具有以下性质:它是一棵空树或它的左右两个子树的高度差的绝对值不超过1,并且左右两个子树都是一棵平衡二叉树。常用算原创 2014-08-11 10:15:11 · 544 阅读 · 0 评论 -
【Leetcode长征系列】Best Time to Buy and Sell Stock
原题: 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 the s原创 2014-08-10 17:51:55 · 735 阅读 · 0 评论 -
【Leetcode长征系列】Evaluate Reverse Polish Notation
原题: Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another expression. Some examples: ["2", "1",原创 2014-08-10 20:45:13 · 509 阅读 · 0 评论 -
【Leetcode长征系列】Symmetric Tree
原题: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the fo原创 2014-08-10 11:09:45 · 502 阅读 · 0 评论 -
【Leetcode长征系列】Unique Binary Search Trees II
原题: Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For example, Given n = 3, your program should return all 5 unique BST's shown below. 1原创 2014-08-10 16:07:30 · 524 阅读 · 0 评论 -
【Leetcode长征系列】Populating Next Right Pointers in Each Node II
原题: Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tree could be any binary tree? Would your previous solution still work? Note: You may only use consta原创 2014-07-18 15:08:57 · 497 阅读 · 0 评论 -
【Leetcode长征系列】Add Binary
原题: Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100".原创 2014-08-10 19:45:45 · 980 阅读 · 0 评论 -
【Leetcode长征系列】Best Time to Buy and Sell Stock II
原题 : 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 (原创 2014-07-14 16:08:24 · 518 阅读 · 0 评论 -
【Leetcode长征系列】Reverse Words in a String
原题: Given an input string, reverse the string word by word. For example, Given s = "the sky is blue", return "blue is sky the". Clarification: What constitutes a word? A sequence of non-s原创 2014-08-10 16:34:51 · 479 阅读 · 0 评论 -
【Leetcode长征系列】Valid Sudoku
原题: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character '.'. A partially f原创 2014-08-03 17:11:19 · 466 阅读 · 0 评论 -
【Leetcode长征系列】Flatten Binary Tree to Linked List
原题: Given a binary tree, flatten it to a linked list in-place. For example, Given 1 / \ 2 5 / \ \ 3 4 6 The flattened tree should look like: 1原创 2014-08-03 15:37:13 · 470 阅读 · 0 评论 -
【Leetcode长征系列】Binary Tree Level Order Traversal II
原题: 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原创 2014-07-22 16:40:24 · 660 阅读 · 0 评论 -
【Leetcode长征系列】Binary Tree Level Order Traversal
原题: 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原创 2014-07-22 14:50:55 · 606 阅读 · 0 评论