
数据结构与算法
文章平均质量分 77
忧伤的肚腩
华中科技大学计算机专业在读
展开
-
Leetcode解题
3.Longest Substring Without Repeating Characters [题目连接]https://leetcode.com/problems/longest-substring-without-repeating-characters/hints/ - 解题思路 - 代码块高亮 - 图片链接和图片上传 - LaTex数学公式 - UML序列图和流程...原创 2018-07-09 21:48:28 · 335 阅读 · 0 评论 -
Ugly Number II
丑数的定义: 因素分解后因子只包含2,3,5(由这三个数的组成,不一定要三个都用上,也可以使用多个相同的情况)的数 比如 10= 2*5, 给定一个数,找到第n个丑数比如输入10,找到第10个丑数, Input: n = 10 Output: 12 Explanation: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the ...原创 2018-09-07 15:09:41 · 107 阅读 · 0 评论 -
Leetcode:264. Ugly Number II
描述Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. Example:Input: n = 10 Output: 12 Explanation: 1, 2, 3, 4, 5, 6, 8, ...原创 2018-09-08 16:03:18 · 145 阅读 · 0 评论 -
Leetcode 121. Best Time to Buy and Sell Stock
题目描述一个一维数组代表着股票的价值,可以执行两个操作,一个是买操作,一个是卖操作,如何能让利润最大化, 说白了就是如何让差价最大话,在卖股票之前必须进行股票的购买操作,每个操作只最多只能执行一次。 Example 1:Input: [7,1,5,3,6,4] Output: 5 Explanation: Buy on day 2 (price = 1) and sell on d...原创 2018-08-24 14:52:38 · 109 阅读 · 0 评论 -
Leetcode 122:买卖股票二
题目描述https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/description/与第一次的题目相比,可以多次买卖等情况,只要求出最大利润即可, 可以将一次买卖分为过个过程即可; [1,2,3,4,5] 比如正常情况下是第一天买进,第五天卖出,但这个过程可以分解为多次买进卖出 在第一天买进,第二天卖出,获得利...原创 2018-08-31 14:57:59 · 165 阅读 · 0 评论 -
213. House Robber II
题目描述每个房子有一定的钱条件 不能偷相邻房子的钱条件 第一个房子和最后一个房子相邻,围成一个圆形,也就是不能同时偷第一个房子和最后一个房子的钱解题思路如果抢劫第一家,则不可以抢最后一家;否则,可以抢最后一家。因此,这个问题就转化成为了两趟动规,可以复用 “House Robber” 的代码。对第一个房子到倒数第二个房子进行动态规划, 对第二个房子到最后一个房子进行动...原创 2018-08-22 11:00:06 · 179 阅读 · 0 评论 -
Leetcode 33. Search in Rotated Sorted Array
题目描述将有序数组打乱,然后从中查找一个数据的下标 Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).You are given a targ...原创 2018-07-31 20:41:08 · 140 阅读 · 0 评论 -
LeetCode 63. Unique Paths II
题目描述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 ...原创 2018-07-15 17:07:07 · 128 阅读 · 0 评论 -
LeetCode 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 t...原创 2018-07-15 13:26:48 · 90 阅读 · 0 评论 -
找出数组中重复数字
描述查找数组中的重复元素情况,时间复杂度为o(n), 空间复杂度为o(1), 数组的大小为n, 数组元素值大小为0到n-1, 比如 n=4,[2,3,,1,2,-3]思路一采用记录的思路访问 ,如果array[i]代表一个位置,如果array[array[i]]>=0代表是第一次访问,让起取负,做一个标志,如果array[array[i]]<0 代表array[i] 这...原创 2018-07-20 14:52:14 · 413 阅读 · 0 评论 -
Leetcode 460. LFU Cache
题目链接题目描述Design and implement a data structure for Least Frequently Used (LFU) cache. It should support the following operations: get and put. get(key) - Get the value (will always be positive) ...原创 2018-07-14 21:06:18 · 320 阅读 · 0 评论 -
leetcode 322. Coin Change硬币交换问题
题目详细描述You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amou...原创 2018-07-11 23:03:26 · 650 阅读 · 0 评论 -
leetcode解题300.最长递增序列长度
题目连接解题思路一维动态规划,两次循环dp[i] = max{dp[j]+1} if(nums[j]import java.util.Arrays;public class LongestIncreasingSubsequence { public int solution(int [] nums) { int n = nums.length; ...原创 2018-07-10 23:32:04 · 154 阅读 · 0 评论 -
LeetCode91. Decode Ways
描述A message containing letters from A-Z is being encoded to numbers using the following mapping:‘A’ -> 1‘B’ -> 2…‘Z’ -> 26Given a non-empty string containing only digits, determine the ...原创 2018-09-21 15:38:05 · 126 阅读 · 0 评论