上一页 1 ··· 4 5 6 7 8 9 下一页
摘要: 220. Contains Duplicate III //这里需要两个指针i和j,刚开始i和j都指向0,然后i开始向右走遍历数组,如果i和j之差大于k,且m中有nums[j],则删除并j加一。这样保证了m中所有的数的下标之差都不大于k,然后我们用map数据结构的lower_bound()函数来找一 阅读全文
posted @ 2017-01-19 11:17 会咬人的兔子 阅读(230) 评论(0) 推荐(0) 编辑
摘要: 215. Kth Largest Element in an Array 4 C++ Solutions using Partition, Max-Heap, priority_queue and multiset respectively Well, this problem has a naiv 阅读全文
posted @ 2017-01-19 08:12 会咬人的兔子 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 214. Shortest Palindrome 这道题让我们求最短的回文串,LeetCode中关于回文串的其他的题目有 Palindrome Number 验证回文数字,Validate Palindrome 验证回文字符串, Palindrome Partitioning 拆分回文串,Palin 阅读全文
posted @ 2017-01-18 09:02 会咬人的兔子 阅读(163) 评论(0) 推荐(0) 编辑
摘要: 208. Implement Trie (Prefix Tree) 字母的字典树每个节点要定义一个大小为26的子节点指针数组,然后用一个标志符用来记录到当前位置为止是否为一个词,初始化的时候讲26个子节点都赋为空。那么insert操作只需要对于要插入的字符串的每一个字符算出其的位置,然后找是否存在这 阅读全文
posted @ 2017-01-13 08:07 会咬人的兔子 阅读(224) 评论(0) 推荐(0) 编辑
摘要: 207. Course Schedule 有向图的环检测 bool canFinish(int numCourses, vector<pair<int, int>>& prerequisites) { ///先来看BFS的解法,我们定义二维数组graph来表示这个有向图,一位数组in来表示每个顶点的 阅读全文
posted @ 2017-01-13 07:58 会咬人的兔子 阅读(475) 评论(0) 推荐(0) 编辑
摘要: 179. Largest Number sort(num.begin(), num.end(), [](int a, int b){ return to_string(a)+to_string(b) > to_string(b)+to_string(a); } ); 218. The Skyline 阅读全文
posted @ 2017-01-10 12:17 会咬人的兔子 阅读(242) 评论(0) 推荐(0) 编辑
摘要: 桶排序(Bucket sort)或所谓的箱排序,是一个排序算法,工作的原理是将数组分到有限数量的桶里。每个桶再个别排序(有可能再使用别的排序算法或是以递归方式继续使用桶排序进行排序)。桶排序是鸽巢排序的一种归纳结果。当要被排序的数组内的数值是均匀分配的时候,桶排序使用线性时间(Θ(n))。但桶排序并 阅读全文
posted @ 2016-12-29 09:43 会咬人的兔子 阅读(725) 评论(0) 推荐(0) 编辑
摘要: 158. Read N Characters Given Read4 II - Call multiple times 题目: The API: int read4(char *buf) reads 4 characters at a time from a file. The return val 阅读全文
posted @ 2016-12-28 12:28 会咬人的兔子 阅读(123) 评论(0) 推荐(0) 编辑
摘要: 149. Max Points on a Line unordered_map<float, int> hash 记录的是斜率对应的点数 unordered_map<float, int>::iterator it = hash.begin(); it != hash.end(); it++ 斜率k 阅读全文
posted @ 2016-12-28 04:22 会咬人的兔子 阅读(101) 评论(0) 推荐(0) 编辑
摘要: 138. Copy List with Random Pointer //不从head走 前面加一个dummy node 从dummy走先连head 只需记录当前节点 //这样就不需要考虑是先new node还是先找联系 //扫两遍 先建立节点和next 利用map<node*, node*>old 阅读全文
posted @ 2016-12-21 07:06 会咬人的兔子 阅读(101) 评论(0) 推荐(0) 编辑
上一页 1 ··· 4 5 6 7 8 9 下一页