摘要: 不使用乘法、除法、求余数,计算两个数字相除。 使用加法和减法运算。 Java实现代码如下: 上述代码用实际的例子进行解释,假设a=10,b=3,主要介绍10~19行的循环体的逻辑。 外部循环1:判断 3 <= 10满足 内部循环1.1:3 + 3 <= 10满足,count = 2,sum = 6 阅读全文
posted @ 2018-10-21 21:03 Sempron2800+ 阅读(130) 评论(0) 推荐(0) 编辑
摘要: public class Solution { public String fractionToDecimal(int numerator, int denominator) { HashMap maps = new HashMap();//store divid number List number = new ArrayList(); ... 阅读全文
posted @ 2018-10-21 21:02 Sempron2800+ 阅读(120) 评论(0) 推荐(0) 编辑
摘要: C++实现,使用BFS: 补充一个python的实现,使用DFS: 阅读全文
posted @ 2018-10-21 21:00 Sempron2800+ 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 补充一个python的实现: 参考:https://leetcode.com/problems/decode-ways/discuss/30529/Readable-Python-DP-Solution 本题关键在于第11行到15行之间的逻辑,更新dp[i]的规则。 dp[i]表示,前i个字符(从1 阅读全文
posted @ 2018-10-21 20:57 Sempron2800+ 阅读(166) 评论(0) 推荐(0) 编辑
摘要: 数据结构:HashSet<String> wordSet 实用hash存储第三个参数单词字典,加速查找 HashMap<String, Integer> map 存储已经访问过的节点,相当于visited LinkedList<Object> q 主循环判断的Stack 算法流程:q中添加源单词,同 阅读全文
posted @ 2018-10-21 20:55 Sempron2800+ 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 先给出一个作弊的程序,注意第2,3行。 不得其法,越做越蒙。 再给一个简短的程序: 阅读全文
posted @ 2018-10-21 20:47 Sempron2800+ 阅读(134) 评论(0) 推荐(0) 编辑
摘要: /** * Definition for singly-linked list with a random pointer. * struct RandomListNode { * int label; * RandomListNode *next, *random; * RandomListNode(int x) : label(x), next(NULL),... 阅读全文
posted @ 2018-10-21 20:40 Sempron2800+ 阅读(116) 评论(0) 推荐(0) 编辑
摘要: 补充一个python的版本: 阅读全文
posted @ 2018-10-21 20:37 Sempron2800+ 阅读(123) 评论(0) 推荐(0) 编辑
摘要: 补充一个使用dfs思想的python实现代码: 阅读全文
posted @ 2018-10-21 20:34 Sempron2800+ 阅读(129) 评论(0) 推荐(0) 编辑
摘要: 补充一个python的实现: 阅读全文
posted @ 2018-10-21 20:32 Sempron2800+ 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 补充一个python的实现: 题目确保,如果存在解,是唯一的解,因此程序只需要找出可以完成全程的第一个起点就行。 因为全程的加油数量和耗油数量都是固定的,因此从哪个点计算全程的总的消耗都是一样的。不需要先找到起点,然后再进行计算。 因此可以在一次循环中,完成两种计算:1判断是否可以走完全程(tota 阅读全文
posted @ 2018-10-21 20:20 Sempron2800+ 阅读(150) 评论(0) 推荐(0) 编辑
摘要: 补充一个python的实现,使用深度优先遍历,进行拓扑排序: 阅读全文
posted @ 2018-10-21 20:14 Sempron2800+ 阅读(122) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: int reachNumber(int target) { // 理解这题的意思 这题就好做了 // 分析 首先考虑一种比较极端的情况 即一直向正方向移动n步 ,刚好达到target // 那么target的值就等于前n步的和 ,也就是1+2+.....+n = n*(n+1)/2 ... 阅读全文
posted @ 2018-10-21 20:08 Sempron2800+ 阅读(113) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: int networkDelayTime(vector>& times, int N, int K) { vector > graph(N + 1, vector(N + 1, 60001)); vector cost(N + 1); vector visited(N + 1, false)... 阅读全文
posted @ 2018-10-21 20:04 Sempron2800+ 阅读(112) 评论(0) 推荐(0) 编辑
摘要: public class Solution { public string ShortestCompletingWord(string licensePlate, string[] words) { var list = words.OrderBy(x => x.Length); var pattern = ... 阅读全文
posted @ 2018-10-21 18:56 Sempron2800+ 阅读(103) 评论(0) 推荐(0) 编辑
摘要: public class Solution { public bool IsLongPressedName(string name, string typed) { var list1 = new List>(); var list2 = new List>(); int name_... 阅读全文
posted @ 2018-10-21 17:36 Sempron2800+ 阅读(107) 评论(0) 推荐(0) 编辑