摘要: 186. Reverse Words in a String II 先反转整个字符串,再反转每个单词(调整顺序也可以) 反转单词的时候:当 j 指到最后一个字符的时候,或者 j 的下一个指向空格,则反转该单词。 class Solution { public void reverseWords(ch 阅读全文
posted @ 2019-12-06 15:49 阿飞哦 阅读(106) 评论(0) 推荐(0) 编辑
摘要: 277. Find the Celebrity knows(i, j): By comparing a pair(i, j), we are able to discard one of them 1. True: i 必定不是Celebrity, 因为Celebrity不认识任何人 2. Fals 阅读全文
posted @ 2019-12-04 17:15 阿飞哦 阅读(94) 评论(0) 推荐(0) 编辑
摘要: 337. House Robber III 每个结点有两个结果: 1. result[ 0 ], 不偷, 需要加上子节点的最大值,left[ 0 ] , left[ 1 ] 的最大值 + right[ 0 ], right[ 1 ] 2. result[ 1 ], 偷, 加上子节点不偷的值, lef 阅读全文
posted @ 2019-12-03 16:33 阿飞哦 阅读(111) 评论(0) 推荐(0) 编辑
摘要: 258. Add Digits class Solution { public int addDigits(int num) { if(num == 0) return 0; if(num % 9 == 0){ return 9; }else{ return num % 9; } } } 43. M 阅读全文
posted @ 2019-12-02 15:51 阿飞哦 阅读(129) 评论(0) 推荐(0) 编辑
摘要: 179. Largest Number 冒泡排序,每一轮都把最小的数字选出放在最后。 class Solution { public String largestNumber(int[] nums) { for(int i = 0; i < nums.length; i++){ for(int j 阅读全文
posted @ 2019-12-01 17:21 阿飞哦 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 274. H-Index 这道题让我们求H指数,这个质数是用来衡量研究人员的学术水平的质数,定义为一个人的学术文章有n篇分别被引用了n次,那么H指数就是n. 用桶排序,按引用数从后往前计算论文数量,当论文数 >= 当前引用下标时。满足至少有N篇论文分别被引用了n次。 class Solution { 阅读全文
posted @ 2019-11-30 15:00 阿飞哦 阅读(80) 评论(0) 推荐(0) 编辑
摘要: 212. Word Search II class TrieNode{ char val; TrieNode[] children; String word; public TrieNode(char x){ children = new TrieNode[26]; word = null; } } 阅读全文
posted @ 2019-11-29 14:48 阿飞哦 阅读(99) 评论(0) 推荐(0) 编辑
摘要: 133. Clone Graph 我们也可以使用 BFS 来遍历图,使用队列 queue 进行辅助,还是需要一个 HashMap 来建立原图结点和克隆结点之间的映射。先克隆当前结点,然后建立映射,并加入 queue 中,进行 while 循环。在循环中,取出队首结点,遍历其所有 neighbor 结 阅读全文
posted @ 2019-11-28 15:57 阿飞哦 阅读(130) 评论(0) 推荐(0) 编辑
摘要: 380. Insert Delete GetRandom O(1) class RandomizedSet { ArrayList<Integer> nums; HashMap<Integer, Integer> locs; Random rand = new Random(); /** Initi 阅读全文
posted @ 2019-11-27 14:37 阿飞哦 阅读(96) 评论(0) 推荐(0) 编辑
摘要: 150. Evaluate Reverse Polish Notation class Solution { public int evalRPN(String[] tokens) { Stack<Integer> stack = new Stack<Integer>(); for(int i = 阅读全文
posted @ 2019-11-26 22:54 阿飞哦 阅读(82) 评论(0) 推荐(0) 编辑