自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(19)
  • 收藏
  • 关注

原创 LeetCode——133.Clone Graph && 621.Task Scheduler

本周两道题,一道是图的题,一道是贪心的题。Clone Graph1.问题描述克隆一个无向图,已知节点的形式,是一个结构体,有一个label和一个邻接表,表示所有邻居节点。节点的label值是唯一的,图可能是有环,甚至是自环。2.思路题目思路很简单,但是做起来就发现还是要注意很多细节。首先这个题目可使用BFS或者DFS形式来实现,BFS的话就是对于一个点,

2017-06-25 15:52:32 267

原创 算法概论:第八章NP-完全问题——课后题8.16

在写题目之前,想先总结一下这一章的基本内容。这一章主要讲的是NP, NPC问题。关于NP问题P问题,是它能够找到一个在多项式时间内解决的算法;而NP问题不是非P问题,而是可以在多项式时间里验证一个解的问题。NP问题:所有搜索问题都称为NP问题。搜索问题的特征性定义是,任意可能解的正确性都能被快速检验,也就是说,存在以问题实例I(用于确定待求解问题的数据)和可能解S为输入的高效检验算

2017-06-20 11:36:11 1160

原创 Leetcode——134. Gas Station && 435. Non-overlapping Intervals

Gas Station1. 问题描述有N个加油站围成一个圈,第i个加油站的油量是gas[i],一辆车有一个无限量的油箱,每次从第i个加油站开到第i+1个加油站需要消耗cost[i]的油量。车一开始没有油,判断这辆车能否从某一个加油站出发,环绕一圈回到起始点,若不能,则返回-1.数据输入:gas数组和cost数组2.思路车在起点加油后,油量要足够它开到下一个加油站,即gas[

2017-06-19 09:36:36 493

原创 Leetcode——92. Reverse Linked List II && 25. Reverse Nodes in k-Group

Reverse Linked List II 1.题目描述:给定一个链表以及起止点m和n,反转从m开始到n的链表,其他保持不变。2.思路:   首先描述反转链表的思路。反转链表,可以利用栈来实现。从链表头开始遍历节点,将节点压入栈中直到链表尾,接着定义一个新的链表头,将节点从栈中顶出,重新链接到新链表上。这里需要特别注意的地方是,栈中的节点是由next的,指向的是正向的下一个节点;

2017-06-12 13:37:54 296

原创 Leetcode——139 Word Break && 140 Word BreakII

Word Break1.问题描述给出一个字符串数组作为字典dict与一个目标字符串,在数组中查找字符串能否拼接成目标字符串。举个例子,s = "leetcode", dict = ["leet", "code"],那么s可以由字典中的leet和code组成;再举一个例子,s = "cars", dict = ["car", "ca","rs"],那么s可以由字典中的ca和rs组成。

2017-06-05 18:10:06 802

原创 Leetcode——84.Largest Rectangle in Histogram && 85.Maximal Rectangle

一、直方图中的最大矩形(Largest Rectangle in Histogram)1.问题描述Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the

2017-05-28 10:09:35 249

原创 Leetcode——32. Longest Valid Parentheses

一、题目描述Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring

2017-05-21 23:24:38 319

原创 Leetcode——44Wildcard Matching && 10 Regular Expression Matchi

本周做的两道题有点类似,一道是通配符匹配问题,一道是正则表达式匹配问题。难度有点大,前者没有用DP或者递归,后者用了DP来实现。通配符匹配问题描述实现一个通配符模式匹配,其中通配符包括‘?’和 ‘ * ’‘?’可以匹配任意单一字符;‘ * ’可以匹配任意的字符串(包括空串)函数isMatch(string s, string p)用于判断字符串s是否能匹配带有通配符的字

2017-05-14 16:49:56 280

原创 Leetcode——174. Dungeon Game

本周做了一个动态规划的题目:Dungeon Game题目描述The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Ou

2017-05-07 19:06:54 257

原创 Leetcode05——Longest Palindromic Substring && 115 Distinct Subsequences

本周继续练习动态规划的相关题目。记录两道印象深刻的题,分别是05最长回文子串和115不同的子序列。Longest Palindromic Substring最长回文子串Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s

2017-04-28 16:54:01 239

原创 Leetcode——72 Edit Distance && 97Interleaving String

本周写了几道动态规划的题目,选取了两道与字符串相关的题目来写。一道是讲过的Edit Distance(编辑距离),另一道是交错字符串。这两个题目都是经典的字符串相关的动态规划题目。一.Edit DistanceGiven two words word1 and word2, find the minimum number of steps required to convert

2017-04-23 17:17:01 317

原创 Leetcde——121 Best Time to Buy and Sell Stock && 123 Best Time to Buy and Sell Stock

本周学习的算法是动态规划dynamic programming(DP),在写题目之前,我想先比较下贪心算法,分治算法和DP算法。贪心算法Greedy:按照局部最优的标准递增地建立解决方法;分治算法Divide and Conquer:将一个问题分成一个个独立的子问题,解决每个子问题,并将子问题的解决方案组合成原问题的解决方案;动态规划DP:将一个问题分解成一组重叠的子问题,建立起更

2017-04-15 18:34:49 258

原创 Leetcode——321.Create Maximum Number

本周的题目是产生最大的数字,题目描述如下:Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum number of length k  from digits of the two. The relative order of the digits

2017-04-08 17:32:33 248

原创 Leetcode——45Jump GameII

本周做的是一道关于贪心思想的题目,在实现过程中主要用到的算法是BFS~一、题目描述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

2017-04-02 21:14:35 289

原创 Leetcode——310 Minimum Height Trees && 332 Reconstruct Itinerary

本周记录两道图论的题目,第一道是关于BFS的题目,310, Minimum Height Trees ;第二道是关于DFS的题目,332,Reconstruct Itinerary。一、Minimum Height Trees 1. 题目描述For a undirected graph with tree characteristics, we can choose any nod

2017-03-25 22:05:12 261

原创 Leetcode——337House RobberIII

本周记录了一道与DFS相关的题目。DFS,深度优先搜索,基本思想是搜到底,然后 退一步重新搜,关键是将DFS应用到实际问题里面。如果将DFS用于搜索树,那么,对于一个节点,若它的左子树不为空且没有访问过,则对左子节点进行DFS;若它的右子树不为空且没有访问过,则对其右子节点进行DFS。当然,一道题不可能这么简单让你遍历所有节点,肯定是有一些操作需要去加入。下面是Leetcode上的一道题目

2017-03-18 17:20:41 217

原创 Leetcode——04Median of Two Sorted Arrays

Leetcode,Median of Two Sorted Arrays

2017-03-12 18:05:15 201

原创 Leetcode-43.Multiply Strings

本次做的是大数相乘的题目。1. 题目Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2.Note:The length of both num1 and num2 is Both num1

2017-03-04 14:11:19 213

原创 LeetCode——15.3Sum

首次使用LeetCode学习算法设计,希望通过本次学习可以提高自己对各种算法的了解。本次选择的题目是15.3Sum,属于medium难度。该题目的描述是"Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triple

2017-02-25 18:08:05 237

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除