上一页 1 2 3 4 5 6 7 8 ··· 27 下一页
摘要: 包围区域是一个典型的DFS的题目。大意是一个二维数组中存在字符'X'和'O',将被'X'包围的'O'全部变为'X'。具体做法是从数组的边界上为'O'的起点开始DFS,将DFS过程中遇到的字符标记为'Y'。然后遍历二维数组,将'Y'的变为'O',其余为'X'即可。 题目描述: Given a 2D b 阅读全文
posted @ 2017-06-06 09:56 wxquare 阅读(415) 评论(0) 推荐(0) 编辑
摘要: 这道题是一个比较简单的题目,由于题目中要求O(n),限制使用排序,所有借用hash表unordered_set<int> s来存储数组中元素,保证O(n)的时间复杂度。 题目: Given an unsorted array of integers, find the length of the l 阅读全文
posted @ 2017-06-06 09:38 wxquare 阅读(464) 评论(0) 推荐(0) 编辑
摘要: Leetcode中出现了两道词语阶梯的题目,大意是将一个词语将通过字典里面的词语,最终转换到目标词语,每次只能更改一个字符。两道题分别是求最少的转换次数和寻找最短的转换路径。词语阶梯是典型的BFS的题目,但是寻找转换路径的时候单纯的BFS会出现超时的问题,需要增加优化策略。优化策略是删除字典中BFS 阅读全文
posted @ 2017-06-06 09:22 wxquare 阅读(511) 评论(0) 推荐(0) 编辑
摘要: leetcode中股票问题指的是股票的价格处于波动当中,分别在最多购买一次、买卖任意多次、买卖k次的最大收益。 Say you have an array for which the ithelement is the price of a given stock on day i. If you 阅读全文
posted @ 2017-06-05 11:27 wxquare 阅读(1486) 评论(0) 推荐(0) 编辑
摘要: 字符串经常出现括号的问题,主要就是产生括号对、判断括号对是否有效、最长的括号对子串。 Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For 阅读全文
posted @ 2017-05-27 22:35 wxquare 阅读(426) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 int romanToInt(string s) { 4 unordered_map m; 5 m['I'] = 1; 6 m['V'] = 5; 7 m['X'] = 10; 8 m['L'] = 50; 9 m... 阅读全文
posted @ 2017-05-27 11:50 wxquare 阅读(268) 评论(0) 推荐(0) 编辑
摘要: Given two numbers represented as strings, return multiplication of the numbers as a string. Note: The numbers can be arbitrarily large and are non-neg 阅读全文
posted @ 2017-05-27 11:30 wxquare 阅读(297) 评论(0) 推荐(0) 编辑
摘要: Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified. You shou 阅读全文
posted @ 2017-05-27 11:22 wxquare 阅读(249) 评论(0) 推荐(0) 编辑
摘要: Given an absolute path for a file (Unix-style), simplify it. For example,path ="/home/", =>"/home"path ="/a/./b/../../c/", =>"/c" click to show corner 阅读全文
posted @ 2017-05-27 11:17 wxquare 阅读(261) 评论(0) 推荐(0) 编辑
摘要: Implement wildcard pattern matching with support for'?'and'*'. 阅读全文
posted @ 2017-05-27 11:06 wxquare 阅读(339) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 ··· 27 下一页