
C++
Scarlettliuu
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
LeetCode13-Roman to Integer
在别处看到了有用STL中的map实现的,并且在LeetCode中运行通过: Runtime Memory 40ms 10.8MB 具体代码如下: class Solution { public: int romanToInt(string s) { int...原创 2019-03-26 16:31:42 · 151 阅读 · 0 评论 -
LeetCode14-Longest Common Prefix
方法一 由两层循环嵌套:一个是遍历第一个字符串中的所有字符;另一个是遍历整个字符串向量,即一个一个比较,这种方法的空间复杂度小,但耗时较长 Runtime Memory 12ms 8.6MB 具体代码如下: class Solution { public: string longestCommonPrefix(vector<string>& strs...原创 2019-03-27 19:46:27 · 146 阅读 · 0 评论 -
LeetCode20-Valid Parentheses
方法一 Runtime Memory 8ms 8.9MB class Solution { public: bool isValid(string s) { stack<string> judge; if(s.substr(0,1)==")"||s.substr(0,1)=="]"||s.substr(0,1)=="}") ...原创 2019-03-28 16:35:33 · 156 阅读 · 0 评论 -
LeetCode21-Merge Two Sorted Lists
方法一 首先新建一个头结点为header的空链表; 比较l1和l2的每个数据域中的数值大小,将header指向数值较小的结点; 若有一个链表已经归并完,直接将另一个链表链接在新生成的链表后即可。 这种方法的效率如下: Runtime Memory 8ms 8.9MB 具体实现代码如下: /** * Definition for singly-linked list. * s...原创 2019-03-28 21:37:56 · 153 阅读 · 0 评论