随笔分类 -  LeetCode

摘要:https://leetcode.com/problems/split-linked-list-in-parts/ k>=length, 每个部分有且仅有一个,剩下k-length个部分都是空 k<length,每个部分至少有length/k个,那么剩下的length%k个就要给每个部分匀一个 最终 阅读全文
posted @ 2018-12-21 12:45 三人木君 阅读(202) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/rotate-list/ 观察到:倒数第k%length个节点就是新头节点,新头节点的前一个点就是新尾节点 corner case:当k % length = 0的时候,rotate之后还是和原链表一样,故无需变换 阅读全文
posted @ 2018-12-21 11:58 三人木君 阅读(148) 评论(0) 推荐(0)
摘要:Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the or 阅读全文
posted @ 2018-03-19 12:05 三人木君 阅读(145) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/find-all-duplicates-in-an-array/ 一列数,1 ≤ a[i] ≤ n (n = size of array),有的出现一次有的出现两次,输出出现两次的数。 Example: 这就是engineering和sci 阅读全文
posted @ 2016-12-29 14:54 三人木君 阅读(118) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/island-perimeter/ 在一个N×N的矩阵中,N<100,1代表岛,0代表海,岛内没有海,求岛的周长 由正方形组成的不规则图形的周长和正方形个数有什么关系? 这个就是这题的核心 发散一下平移的思想,多一个右邻居,多两条边,多一个 阅读全文
posted @ 2016-12-27 14:53 三人木君 阅读(181) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/reverse-string/ Python语法糖爆炸时间 阅读全文
posted @ 2016-12-26 14:21 三人木君 阅读(113) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/fizz-buzz/ 没什么好说的,上一个小学生解法 主要看下大神解法学习一个 如果不被3或5整除,取非的括号部分出0,or部分出数 如果是被15整除,又因为有or不会出数而出字符串 简直妙 阅读全文
posted @ 2016-12-26 14:16 三人木君 阅读(175) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/counting-bits/ 给定一个非负数n,输出[0,n]区间内所有数的二进制形式中含1的个数 Example: For num = 5 you should return [0,1,1,2,1,2]. 注意fellow up部分,题目 阅读全文
posted @ 2016-12-26 13:52 三人木君 阅读(265) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/ 给出一列数,1 ≤ a[i] ≤ n,n是数组大小,有些数出现两次,有些数出现一次,找出在[1,n]中但是不在数列中的数。 不用额外的空间,时间复杂度O(n 阅读全文
posted @ 2016-12-25 23:48 三人木君 阅读(281) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/battleships-in-a-board/ 给定一个N×N的棋盘,有任意数量的1×N或N×1大小的“船”,注意船船之间是不相邻的,要求统计有多少船 Example: In the above board there are 2 batt 阅读全文
posted @ 2016-12-24 11:06 三人木君 阅读(250) 评论(0) 推荐(0)
摘要:还是觉得自己在算法这块太弱鸡了 不多废话开刷吧,LeetCode与算法导论相辅相成双管齐下,期望能填上算法这个坑 解法没意外都是用Python2.7 由于LeetCode有提供Top Solution,看到有不错的也会写下自己的见解 2016.12 ps.发现leetcode上不少题目还是收费的,看 阅读全文
posted @ 2016-12-23 22:54 三人木君 阅读(751) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/hamming-distance/ 将两个二进制数比较,输出不同位数的个数 这个解法其实很low的,首先用了bin()函数,作用是将异或结果二进制化为字符串,然后利用字符串函数count统计1出现的次数并输出 优秀解法评析(Java): 由 阅读全文
posted @ 2016-12-23 22:47 三人木君 阅读(2086) 评论(0) 推荐(0)