![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法 Algorithm
我家小狗迷路了
这个作者很懒,什么都没留下…
展开
-
[LeetCode] 241. Different Ways to Add Parentheses
Problem :Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *.原创 2017-09-23 21:50:22 · 148 阅读 · 0 评论 -
[LeetCode] 100. Same Tree
Problem:Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes have the same原创 2017-12-16 11:45:29 · 144 阅读 · 0 评论 -
[LeetCode] Convert Sorted Array to Binary Search Tree
Problem:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which原创 2017-12-16 13:13:54 · 148 阅读 · 0 评论 -
[LeetCode] 557. Reverse Words in a String III
Problem:Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.Example 1:Input: "Let's take L原创 2017-12-25 22:04:53 · 131 阅读 · 0 评论 -
[LeetCode] 136. Single Number
Problem:Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it wit原创 2017-12-25 22:46:03 · 120 阅读 · 0 评论 -
[LeetCode] 728. Self Dividing Numbers
Problem:A self-dividing number is a number that is divisible by every digit it contains.For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0.原创 2017-12-26 11:27:32 · 186 阅读 · 0 评论 -
[证明] NP-完全问题
算法概论(注释版)第八章 Exercise 8.3题目描述:STINGY SAT is the following problem: given a set of clauses(each a disjunction of literals) and aninteger k, find a satisfying assignment in which at most k var原创 2018-01-01 11:09:28 · 1566 阅读 · 0 评论 -
[LeetCode] 337. House Robber III
Problem:The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "root." Besides the root, each house has one and only one parent house原创 2017-12-17 21:55:41 · 155 阅读 · 0 评论 -
[LeetCode] 55. Jump Game
Problem :Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.原创 2017-10-25 19:56:46 · 196 阅读 · 0 评论 -
[LeetCode] 394. Decode String
Problem:Given an encoded string, return it's decoded string.The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times.原创 2018-01-02 12:31:57 · 181 阅读 · 0 评论 -
[LeetCode] 747. Min Cost Climbing Stairs
Problem:On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed).Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to原创 2018-01-03 21:03:40 · 184 阅读 · 0 评论 -
构造回文--最长回文子序列
Description:时间限制:1秒空间限制:32768K给定一个字符串s,你可以从中删除一些字符,使得剩下的串是一个回文串。如何删除才能使得回文串最长呢?输出需要删除的字符个数。输入描述:输入数据有多组,每组包含一个字符串s,且保证:1<=s.length<=1000. 输出描述:对于每组数据,输出一个整数,代表最少需要删除的字符个数。输入例子1:abcdagoogle输出例...原创 2018-03-24 23:02:27 · 174 阅读 · 0 评论 -
[剑指offer] 合并两个有序
Description:输入两个单调递增的链表,输出两个链表合成后的链表,需要合成后的链表满足单调不减规则Solution:/*public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; }}*/public class ...原创 2018-04-07 15:13:04 · 138 阅读 · 0 评论 -
[LeetCode] 5. Longest Palindromic Substring
Description:Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example:Input: "babad"Output: "bab"Note: "aba" is also a valid answer...原创 2018-03-24 23:48:25 · 122 阅读 · 0 评论 -
[剑指offer] 矩阵中的路径
Description:请设计一个函数,用来判断在一个矩阵中是否存在一条包含某字符串所有字符的路径。路径可以从矩阵中的任意一个格子开始,每一步可以在矩阵中向左,向右,向上,向下移动一个格子。如果一条路径经过了矩阵中的某一个格子,则该路径不能再进入该格子。 例如 : a b t g c f c s j ...原创 2018-04-07 22:12:42 · 120 阅读 · 0 评论 -
[剑指offer] 重建二叉树
Description:输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5,3,8,6},则重建二叉树并返回。Solution:/** * Definition for binary tree * public class TreeNode {...原创 2018-03-31 16:53:11 · 125 阅读 · 0 评论 -
[LeetCode] 463. Island Perimeter
Description:You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is...原创 2018-04-11 23:02:10 · 119 阅读 · 0 评论 -
[LeetCode] 811. 子域名访问计数
题目描述:一个网站域名,如"discuss.leetcode.com",包含了多个子域名。作为顶级域名,常用的有"com",下一级则有"leetcode.com",最低的一级为"discuss.leetcode.com"。当我们访问域名"discuss.leetcode.com"时,也同时访问了其父域名"leetcode.com"以及顶级域名 "com"。给定一个带访问原创 2018-04-12 19:36:37 · 1457 阅读 · 0 评论 -
[LeetCode] 515. Find Largest Value in Each Tree Row
Problem:You need to find the largest value in each row of a binary tree.Example:Input: 1 / \ 3 2 / \ \ 5 3 9 Output: [1, 3, 9]解法原创 2017-11-18 14:32:33 · 173 阅读 · 0 评论 -
[LeetCode] 646. Maximum Length of Pair Chain
Problem:You are given n pairs of numbers. In every pair, the first number is always smaller than the second number.Now, we define a pair (c, d) can follow another pair (a, b) if and only原创 2017-11-30 11:50:54 · 140 阅读 · 0 评论 -
[LeetCode] 169. Majority Element
Description :Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and th原创 2017-09-17 10:25:22 · 234 阅读 · 0 评论 -
[LeetCode] 461. Hamming Distance
Problem:The 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 Hamming distance.原创 2017-10-28 09:48:05 · 139 阅读 · 0 评论 -
[LeetCode] 617. Merge Two Binary Trees
Problem :Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need to merge them into原创 2017-11-08 13:27:10 · 138 阅读 · 0 评论 -
[LeetCode] 406. Queue Reconstruction by Height
Problem:Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person and k is the number of people原创 2017-10-26 12:51:35 · 180 阅读 · 0 评论 -
[LeetCode] 654. Maximum Binary Tree
Problem:Given an integer array with no duplicates. A maximum tree building on this array is defined as follow:The root is the maximum number in the array.The left subtree is the maximum tree原创 2017-11-07 19:00:22 · 142 阅读 · 0 评论 -
[LeetCode] 669.Trim a Binary Search Tree
Problem :Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You might need to change the root of the原创 2017-11-08 19:51:52 · 161 阅读 · 0 评论 -
[LeetCode] 690. Employee Importance
Problem :You are given a data structure of employee information, which includes the employee's unique id, his importance value and his directsubordinates' id.For example, employee 1 is the原创 2017-10-07 11:19:44 · 195 阅读 · 0 评论 -
[LeetCode] 258. Add Digits
Description:Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2原创 2017-09-10 11:12:40 · 206 阅读 · 0 评论 -
[LeetCode] 513. Find Bottom Left Tree Value
Problem:Given a binary tree, find the leftmost value in the last row of the tree.Example 1:Input: 2 / \ 1 3Output:1Example 2: Input: 1 / \原创 2017-10-15 23:58:21 · 154 阅读 · 0 评论 -
[LeetCode] 647. Palindromic Substrings
Problem :Given a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes or end indexes are counted as different substrings e原创 2017-11-12 13:34:42 · 183 阅读 · 0 评论 -
[LeetCode] 695. Max Area of Island
Problem:Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of t原创 2017-11-28 19:19:11 · 246 阅读 · 0 评论 -
[LeetCode] 357. Count Numbers with Unique Digits
Problem:Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x n.Example:Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x原创 2017-12-13 00:19:55 · 156 阅读 · 0 评论 -
[LeetCode] 650. 2 Keys Keyboard
Problem:Initially on a notepad only one character 'A' is present. You can perform two operations on this notepad for each step:Copy All: You can copy all the characters present on the notepa原创 2017-12-13 22:34:08 · 201 阅读 · 0 评论 -
[LeetCode] 494. Target Sum
Problem:You are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + and - as its new symbo原创 2017-12-21 20:36:16 · 143 阅读 · 0 评论 -
[LeetCode] 199. Binary Tree Right Side View
Problem:Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example:Given the following binary原创 2017-12-23 13:40:19 · 139 阅读 · 0 评论 -
[LeetCode] 416. Partition Equal Subset Sum
Problem:Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.Note:Eac原创 2017-12-21 19:28:48 · 145 阅读 · 0 评论 -
[LeetCode] 547. Friend Circles
Problem:There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a direct frie原创 2017-12-15 23:38:47 · 195 阅读 · 0 评论 -
[LeetCode] 696. 计数二进制子串
题目描述:给定一个字符串 s,计算具有相同数量0和1的非空(连续)子字符串的数量,并且这些子字符串中的所有0和所有1都是组合在一起的。重复出现的子串要计算它们出现的次数。示例 1 :输入: "00110011"输出: 6解释: 有6个子串具有相同数量的连续1和0:“0011”,“01”,“1100”,“10”,“0011” 和 “01”。请注意,一些重复出现的子串要计算它们出现的次数。...原创 2018-04-13 14:07:25 · 650 阅读 · 0 评论