
算法分析与设计
seven_-
这个作者很懒,什么都没留下…
展开
-
Divide and Conquer -- Leetcode problem241:Different Ways to Add Parentheses
描述: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-13 10:30:42 · 256 阅读 · 0 评论 -
Breadth-first Search -- Leetcode problem102. 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,null,null,15,7], 3 / \ 9 20 /原创 2017-10-11 14:27:29 · 258 阅读 · 0 评论 -
Breadth-first Search -- Leetcode problem107. 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,null,null,15原创 2017-10-11 14:50:13 · 222 阅读 · 0 评论 -
Linked List -- Leetcode problem 2. Add Two Numbers
描述:You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return原创 2017-10-20 15:33:42 · 180 阅读 · 0 评论 -
Dynamic Programing -- Leetcode problem 647. Palindromic Substrings
描述: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 even they consist原创 2017-10-30 14:26:17 · 223 阅读 · 0 评论 -
Dynamic Programing -- Leetcode problem 338. Counting Bits
描述:Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array.Example: For num = 5 yo原创 2017-10-25 13:23:40 · 204 阅读 · 0 评论 -
Depth-first Search -- Leetcode problem394. Decode String
描述: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. Note that k is gu原创 2017-10-25 14:00:52 · 182 阅读 · 0 评论 -
Dynamic Programing -- Leetcode problem 62. Unique Paths
描述:A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the b原创 2017-11-02 14:49:20 · 274 阅读 · 0 评论 -
Dynamic Programing -- Leetcode problem 63. Unique Paths II
描述:Follow up for “Unique Paths”:Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the grid.原创 2017-11-02 15:31:50 · 197 阅读 · 0 评论 -
Dynamic Programing -- Leetcode problem 343. Integer Break
描述:Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.For example, given n = 2, retu原创 2017-12-12 15:28:18 · 163 阅读 · 0 评论 -
Dynamic Programing -- Leetcode problem 712. Minimum ASCII Delete Sum for Two Strings
描述:Given two strings s1, s2, find the lowest ASCII sum of deleted characters to make two strings equal.Example 1: Input: s1 = “sea”, s2 = “eat” Output: 231 Explanation: Deleting “s” from “sea”原创 2017-12-12 16:24:26 · 225 阅读 · 0 评论 -
算法概论第八章习题
题目:8.3 STINGY SAT is the following problem: given a set of clauses (each a disjunction of literals) and an integer k, find a satisfying assignment in which at most k variables are true, if such an assi原创 2018-01-02 17:21:44 · 256 阅读 · 0 评论 -
Dynamic Programing -- Leetcode problem 746. Min Cost Climbing Stairs
描述: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 reach the top of原创 2018-01-13 10:44:10 · 246 阅读 · 0 评论 -
Dynamic Programing -- Leetcode problem 70. Climbing Stairs
描述:You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n will be a positive原创 2018-01-13 10:49:23 · 199 阅读 · 0 评论 -
Breadth-first Search -- Leetcode problem515. Find Largest Value in Each Tree Row
描述: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]分析:这道题要求找到每层树中最大的元素,并输出。思路一:用bfs对整棵数进行搜索原创 2017-10-11 14:03:22 · 152 阅读 · 0 评论 -
Hash Table -- Leetcode problem676. Implement Magic Dictionary
描述:Implement a magic directory with buildDict, and search methods.For the method buildDict, you’ll be given a list of non-repetitive words to build a dictionary.For the method search, you’ll be given原创 2017-09-22 15:31:39 · 341 阅读 · 0 评论 -
Array -- Leetcode problem1. Two Sum
描述:Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the same原创 2017-09-22 13:17:28 · 200 阅读 · 0 评论 -
Depth-first Search -- Leetcode problem104. Maximum 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.树的结构: /** Definition for a binar原创 2017-09-23 14:37:32 · 226 阅读 · 0 评论 -
Hash Table -- Leetcode problem500: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. Example 1: Input: [“Hello”, “Alaska”, “Dad”, “Peace原创 2017-09-15 14:51:51 · 209 阅读 · 0 评论 -
Depth-first Search -- Leetcode problem100. 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.分析:判断两棵树是否相等,水原创 2017-09-24 09:45:19 · 225 阅读 · 0 评论 -
Depth-first Search -- Leetcode problem112. Path Sum
描述:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example: Given the below binary tree and sum原创 2017-09-24 10:46:13 · 254 阅读 · 0 评论 -
Depth-first Search -- Leetcode problem113. 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 / \ 4 8原创 2017-09-24 16:37:59 · 214 阅读 · 0 评论 -
Divide and Conquer -- Leetcode problem169: Majority Element
描述: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 the majority element alw原创 2017-09-08 13:43:23 · 526 阅读 · 0 评论 -
Divide and Conquer -- Leetcode problem215: Kth Largest Element in an Array
描述:Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.Example, Given [3,2,1,5,6,4] and k = 2, return 5. Note原创 2017-09-17 10:25:50 · 410 阅读 · 0 评论 -
Divide and Conquer -- Leetcode problem53. Maximum Subarray
描述:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4], the contiguous subarray [4,-1,2,1] has原创 2017-09-20 13:19:07 · 503 阅读 · 0 评论 -
Hash Table -- Leetcode problem454. 4Sum II
描述:Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero.To make problem a bit easier, all A, B, C, D have same leng原创 2017-09-21 14:00:19 · 182 阅读 · 0 评论 -
Hash Table -- Leetcode problem349. Intersection of Two Arrays
描述:Given two arrays, write a function to compute their intersection.Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].Note: Each element in the result must be unique. The result can b原创 2017-09-21 19:12:57 · 154 阅读 · 0 评论 -
Hash Table -- Leetcode problem350. Intersection of Two Arrays II
描述:Given two arrays, write a function to compute their intersection.Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2].Note: Each element in the result should appear as many times as原创 2017-09-21 19:22:09 · 178 阅读 · 0 评论 -
Breadth-first Search -- Leetcode problem690. Employee Importance
描述:You are given a data structure of employee information, which includes the employee’s unique id, his importance value and his direct subordinates’ id.For example, employee 1 is the leader of employ原创 2017-10-09 14:33:16 · 210 阅读 · 0 评论 -
Breadth-first Search -- Leetcode problem513. Find Bottom Left Tree Value
描述:Given a binary tree, find the leftmost value in the last row of the tree. Example 1: Input: 2 / \ 1 3Output: 1原创 2017-10-09 15:27:55 · 154 阅读 · 0 评论 -
Divide and Conquer -- Leetcode problem240. Search a 2D Matrix II
描述:Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to right. Integers i原创 2017-09-18 13:37:35 · 652 阅读 · 0 评论