算法概论作业
邓sh
这个作者很懒,什么都没留下…
展开
-
53. 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] h原创 2017-09-19 22:08:43 · 207 阅读 · 0 评论 -
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” adds t原创 2017-12-09 19:59:31 · 87 阅读 · 0 评论 -
718. Maximum Length of Repeated Subarray
题目Given two integer arrays A and B, return the maximum length of an subarray that appears in both arrays.Example 1: Input: A: [1,2,3,2,1] B: [3,2,1,4,7] Output: 3 Explanation: The repeated subar原创 2017-12-04 00:48:07 · 95 阅读 · 0 评论 -
714. Best Time to Buy and Sell Stock with Transaction Fee
题目Your are given an array of integers prices, for which the i-th element is the price of a given stock on day i; and a non-negative integer fee representing a transaction fee.You may complete as many t原创 2017-12-04 01:24:35 · 106 阅读 · 0 评论 -
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 t原创 2017-12-24 10:20:28 · 154 阅读 · 0 评论 -
740. Delete and Earn
题目 Given an array nums of integers, you can perform operations on the array. In each operation, you pick any nums[i] and delete it to earn nums[i] points. After, you must delete every element equal ...原创 2017-12-24 10:59:00 · 121 阅读 · 0 评论 -
19. Remove Nth Node From End of List
题目Given a linked list, remove the nth node from the end of list and return its head.For example,Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, the linked list原创 2017-12-24 11:22:27 · 127 阅读 · 0 评论 -
486. Predict the Winner
题目Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on. Each time a player picks原创 2017-12-24 12:25:14 · 132 阅读 · 0 评论 -
494. Target Sum
题目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 symbol.Find out how many原创 2017-12-24 13:08:28 · 112 阅读 · 0 评论 -
121. 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 stock), de原创 2017-11-29 23:06:12 · 106 阅读 · 0 评论 -
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 o原创 2017-11-29 22:33:16 · 95 阅读 · 0 评论 -
100. 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-26 18:12:59 · 112 阅读 · 0 评论 -
257. Binary Tree Paths
问题描述Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree:1 / \ 2 3 \ 5 All root-to-leaf paths are:思路分析稍后再写代码/** * Definition for a binary tree原创 2017-09-26 17:41:05 · 106 阅读 · 0 评论 -
169. Majority Element 分治解法
169. 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 an原创 2017-09-12 20:06:54 · 959 阅读 · 0 评论 -
4. Median of Two Sorted Arrays
题目There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Example 1: nums1 = [1, 3] n原创 2017-10-07 15:42:24 · 181 阅读 · 0 评论 -
207. Course Schedule
题目There are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pai原创 2017-10-30 22:34:06 · 150 阅读 · 0 评论 -
684. Redundant Connection
题目内容In this problem, a tree is an undirected graph that is connected and has no cycles.The given input is a graph that started as a tree with N nodes (with distinct values 1, 2, …, N), with one additio原创 2017-10-14 14:22:28 · 123 阅读 · 0 评论 -
455. Assign Cookies
题目Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a co原创 2017-11-18 16:37:25 · 121 阅读 · 0 评论 -
406. Queue Reconstruction by Height
题目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 in front of this原创 2017-11-18 19:52:12 · 112 阅读 · 0 评论 -
作业8.3
可知STINGY SAT 的解是可以在多项式时间内验证的,所以它属于 NP。而且,可以通过将 k 设为所有变量的总个数,将 SAT 归约到 STINGY SAT,最终可知 STINGY SAT 为 NP 完全问题原创 2017-12-29 13:08:07 · 132 阅读 · 0 评论