
Leetcode
wotu__
这个作者很懒,什么都没留下…
展开
-
LeetCode-365-水壶问题 (不定次方程的整数解)
365. Water and Jug ProblemDescriptionYou are given two jugs with capacities x and y litres. There is an infinite amount of water supply available. You need to determine whether it is possible to m...原创 2019-12-09 11:52:57 · 348 阅读 · 0 评论 -
260. Single Number III (位运算)
LeetCode-260.Single Number IIIDescriptionGiven an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that a...原创 2019-11-22 13:43:24 · 302 阅读 · 0 评论 -
LeetCode.208 实现 Trie (字典树的实现)
LeetCode.208实现一个字典树 TrieTrie: 百度百科结点类型的定义在我的实现中, 用了两种不太一样的结点类型.Node1视频教程地址: Trie Data Structure (EXPLAINED)(演示不断插入每个字符之后树的变化)两个成员变量:map, 用于接受一个字符, 并得到对应的下一个孩子结点isLeaf, 指定当前是否到达叶子结点除此之...原创 2019-11-14 13:03:54 · 276 阅读 · 0 评论 -
LeetCode.207 LeetCode.210 (有向无环图拓扑排序的实现)
210. Course Schedule II207. Course ScheduleDescriptionThere are a total of n courses you have to take, labeled from 0 to n-1.Some courses may have prerequisites, for example to take course 0 you h...原创 2019-11-14 12:18:36 · 680 阅读 · 0 评论 -
200. Number of Islands (并查集)
200. Number of IslandsDescriptionGiven a 2d grid map of '1's (land) and '0's (water), count thenumber of islands. An island is surrounded by water and is formedby connecting adjacent lands horizon...原创 2019-11-12 13:44:52 · 270 阅读 · 0 评论 -
187. Repeated DNA Sequences (位运算)
LeetCode-187.Repeated DNA SequencesDescriptionAll DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to i...原创 2019-11-11 21:51:35 · 207 阅读 · 0 评论 -
166. Fraction to Recurring Decimal (map + math)
166. Fraction to Recurring DecimalDescription给定一个分子, 一个分母.返回计算得到的结果.如果小数部分有重复的, 则将重复部分用 () 括起来.ExampleInput: numerator = 1, denominator = 2Output: "0.5"Input: numerator = 2, denominator = 1...原创 2019-11-09 13:08:44 · 161 阅读 · 0 评论 -
LeetCode-165. Compare Version Numbers(版本比较)
165. Compare Version NumbersDescription比较两个字符串类型表示的版本 version1, version2.如果 version1 > version2 return 1;如果 version1 < version2 return -1;如果 version1 == version2 return 0;ExampleInput: v...原创 2019-11-09 12:51:24 · 327 阅读 · 0 评论 -
146. LRU Cache (双向链表+哈希表实现 LRU Cache)
146. LRU Cache题目大意: 设计并实现一个 LRU Cache.实现对应的函数 get(key), put(key, value).Follow up: 所有操作 O(1) 时间复杂度.实现 LRU Cache 的关键数据结构: 双向链表 + 哈希表.以下实现中, 定义了双向链表结点类 Node. 以及 unordered_map<int, *Node> 类型的 ...原创 2019-11-07 16:06:28 · 419 阅读 · 0 评论 -
LeetCode- 137.Single Number II (位运算)
LeetCode-137链接: 137. Single Number IISolution1:不合题意的解法.循环遍历每个数的每一位(32 bit).将所有数的某一位 (第 i 位) 加起来, 得到的总和为 sum.sum % 3 得到这个单独数的第 i 位.通过位运算将这个第 i 位移到正确位置, 遍历完所有位得到最终结果.Code:class Solution { ...原创 2019-11-02 11:33:26 · 324 阅读 · 0 评论 -
LeetCode-130 与 并查集
LeetCode-130Solution1:遍历边界点, 如果该值为 ‘O’, 则在该处进行递归继续扩展. 并将走过的路程上的点赋值为 ‘*’.遍历整个二维空间, 将所有为 ‘*’ 的赋值为 ‘O’, 其他均为 ‘X’.Code:class Solution {public: void solve(vector<vector<char>>& ...原创 2019-10-31 17:52:51 · 474 阅读 · 1 评论 -
LeetCode-114
题目链接:LeetCode-114. Flatten Binary Tree to Linked ListSolution1递归处理, 对于每个结点, 每次处理返回其右子树的最右结点:处理该结点的左子树, 返回结点 left.处理该结点的右子树, 返回结点 right.根据 left, right 将左子树连接到该结点与右子树的中间.根据 left, right 是否为空, 返回 ...原创 2019-10-27 12:56:53 · 252 阅读 · 0 评论 -
LeetCode-102 树的层次遍历
#####LeetCode-102Solution1:直接使用队列, 每次处理一层.class Solution { // 层次遍历, 使用队列. 93.41%.public: vector<vector<int>> levelOrder(TreeNode* root) { vector<vector<int>>...原创 2019-10-25 17:22:23 · 228 阅读 · 0 评论 -
Leetcode-60 Permutation Sequence
Leetcode-60链接: 60.Permutation SequenceDescription:The set [1,2,3,...,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order, we get the following s...原创 2019-10-12 11:06:02 · 198 阅读 · 0 评论 -
Leetcode-46 Leetcode-47
题目链接Leetcode-46Description给定一组无重复整数, 返回所有可能的排列.Example:Input: [1,2,3]Output:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]解法一:class Solution {public: vector<vec...原创 2019-10-07 13:11:55 · 188 阅读 · 0 评论 -
Leetcode-395. 至少有 k 个重复字符的最长子串
Leetcode-395.至少有K个重复字符的最长子串链接:Leetcode-139算法思想 : 分治法, 递归使用一个数组来存储字符串中每个字符的个数, 遍历找出其中个数小于 k 的字符,根据这些字符对字符串进行分隔,递归求解分隔以后的更小的子问题。// 递归,分治// 使用数组计数class Solution { public int re = 0; public int...原创 2019-05-28 15:41:00 · 660 阅读 · 0 评论