Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea
LeetCode
out/production
random
src
.DS_Store
README.md
javaSolution.iml

README.md

Purpose

In order to solving the interesting alogrithm problems which meeting at the interviews frequently by me and some interesting LeetCode problems.


1.solved with python named as Leetcode? + details

2.solved with java named as src/Solution? + details

3.others solved named as random


EggTopFloor

Tencent - Machine learning Engineer

HuffmanEncoding

Didichuxing - Statistical Analyst

SortAlgorithm

Almost everytime such as Alibaba、JD、Didichuxing...

GapCount

Hp(Hewlett-Packard) - Model Engineer

Leetcode 137 Single Number II.py

这题有数学解法和位解法两种,都很值得看一下

Coming from : https://leetcode.com/problems/single-number-ii/description/

Leetcode 240. Search a 2D Matrix II.py

这题其实可以从右上角开始查找,会更快

Coming from :https://leetcode.com/problems/search-a-2d-matrix-ii/

LeetCode 56. Merge Intervals.py

Coming from :https://leetcode.com/problems/merge-intervals/

LeetCode 78 Subsets

这题利用了python的语言机制,很有意思

Coming from :https://leetcode.com/problems/subsets/#/description

无序数组排序(时间复杂度为O(n))

问题:给你n个无序的int整型数组arr,并且这些整数的取值范围都在0-20之间,要你在 O(n) 的时间复杂度中把这 n 个数按照从小到大的顺序打印出来。

LeetCode 1 two-sum

Coming from :https://leetcode-cn.com/problems/two-sum/

LeetCode 19 remove-nth-node-from-end-of-list

链表很经典的一道题

Coming from :https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/

LeetCode 211 add-and-search-word-data-structure-design

Tire树很经典的一道题

Coming from :https://leetcode-cn.com/problems/add-and-search-word-data-structure-design/

LeetCode 824 goat-latin

Coming from:https://leetcode-cn.com/problems/goat-latin/

LeetCode 190 reverse-bits

Coming from:https://leetcode-cn.com/problems/reverse-bits/

LeetCode 120 triangle

Coming from:https://leetcode-cn.com/problems/triangle/

LeetCode 303 range-sum-query-immutable

Coming from:https://leetcode-cn.com/problems/range-sum-query-immutable/

LeetCode 198 house-robber

dp算法很经典的一道题

Coming from:https://leetcode-cn.com/problems/house-robber/

LeetCode 791 custom-sort-string

Coming from:https://leetcode-cn.com/problems/custom-sort-string/

LeetCode 64 minimum-path-sum

非常基础简单的动态规划问题,适合理解动态规范的想法

Coming from:https://leetcode-cn.com/problems/minimum-path-sum/

LeetCode 171. Excel Sheet Column Number

Coming from:https://leetcode-cn.com/problems/excel-sheet-column-number/

LeetCode 560. Subarray Sum Equals K

Coming from:https://leetcode-cn.com/problems/subarray-sum-equals-k/

LeetCode 810. Chalkboard XOR Game

逻辑鬼才的题目

Coming from:https://leetcode-cn.com/problems/chalkboard-xor-game/

LeetCode 1024. Video Stitching

贪心算法概念的比较好理解的一道题

Coming from:https://leetcode-cn.com/problems/video-stitching/

LeetCode 349. Intersection of Two Arrays

Coming from:https://leetcode-cn.com/problems/intersection-of-two-arrays/

LeetCode 1054. Distant Barcodes

Coming from:https://leetcode-cn.com/problems/distant-barcodes/

LeetCode 1051. Height Checker

Coming from:https://leetcode-cn.com/problems/height-checker/

LeetCode 771. Jewels and Stones

Coming from:https://leetcode-cn.com/problems/jewels-and-stones/

LeetCode 263. Ugly Number

Coming from:https://leetcode-cn.com/problems/ugly-number/

LeetCode 292. Nim Game

规律题,数学归纳

Coming from:https://leetcode-cn.com/problems/nim-game/

LeetCode 203. Remove Linked List Elements

协助理解链表里面的head = head, head.next = head.next.next

Coming from:https://leetcode-cn.com/problems/remove-linked-list-elements/

LeetCode 860. Lemonade Change

Coming from:https://leetcode-cn.com/problems/lemonade-change/

LeetCode 59. Spiral Matrix II

旋转矩阵题型,用了余数判断位置,比较亮点

Coming from:https://leetcode-cn.com/problems/spiral-matrix-ii/

LeetCode 386. Lexicographical Numbers

字典排序,用了python特性,也同时整理基础概念,值得去看

Coming from:https://leetcode-cn.com/problems/lexicographical-numbers/

最大公共字符串长度

有两个字符串,你只可以进行删除操作,问你最少进行多少次操作可以使两个字符串相等

Coming from:字节跳动面试题

LeetCode 812. Largest Triangle Area

任给三点,三角形面积等于abs(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))/2

Coming from:https://leetcode-cn.com/problems/largest-triangle-area/

LeetCode 917. Reverse Only Letters

Coming from:https://leetcode-cn.com/problems/reverse-only-letters/

LeetCode 334. Increasing Triplet Subsequence

such that arr[i] < arr[j] < arr[k] given 0 ≤ i < j < k ≤ n-1 else return false,其中只要保证固定住最小和最大,不断降低最小值的下限,使得比最小值要大的值可以尽可能的接近最小值,从而更容易找到比接近最小值的值

Coming from:https://leetcode-cn.com/problems/increasing-triplet-subsequence/

LeetCode 870. Advantage Shuffle

这道题的难点在于耗时,贪心算法即可

Coming from:https://leetcode-cn.com/problems/advantage-shuffle/

LeetCode 3. Longest Substring Without Repeating Characters

滑动窗口

Coming from:https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/

LeetCode LeetCode 2. Add Two Numbers

Coming from:https://leetcode-cn.com/problems/add-two-numbers/

src/Solution7 Reverse Integera

Coming from:https://leetcode-cn.com/problems/reverse-integer/

src/Solution9 Palindrome Number

Coming from:https://leetcode-cn.com/problems/palindrome-number/

src/Solution13 Roman to Integer

Coming from:https://leetcode-cn.com/problems/roman-to-integer/

src/Solution14 Longest Common Prefix

Coming from:https://leetcode-cn.com/problems/longest-common-prefix/

src/Solution20 Valid Parentheses

Coming from:https://leetcode-cn.com/problems/valid-parentheses/

src/Solution26 Remove Duplicates from Sorted Array

Coming from:https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/

src/Solution264 Ugly Number II

Coming from:https://leetcode-cn.com/problems/ugly-number-ii/

src/Solution35 Search Insert Position

Coming from:https://leetcode-cn.com/problems/search-insert-position/

src/Solution21 Merge Two Sorted Lists

Coming from:https://leetcode-cn.com/problems/merge-two-sorted-lists/

src/Solution27 Remove Element

Coming from:https://leetcode-cn.com/problems/remove-element/

src/Solution3 3Sum

左右双指针,亮点在于定义了很多提前跳出条件,在相同值跳过的条件判断中用nums[i+1]还是nums[i-1]尤为灵活

Coming from:https://leetcode-cn.com/problems/3sum/

src/Solution16 3Sum Closest

这题和上面一题很类似,只是最好不要在多生产变量了,直接拿num[first]+num[last]+num[i]去和target比,而不要考虑差值是否大于0,很容易绕进去

Coming from:https://leetcode-cn.com/problems/3sum-closest/

src/Solution18 4Sum

Coming from:https://leetcode-cn.com/problems/4sum/

src/Solution24 Swap Nodes in Pairs

递归算法,讲的很详细,递归复习专用

该题递归在函数中间位置,很有意思

Coming from:https://leetcode-cn.com/problems/swap-nodes-in-pairs/

src/Solution17 Letter Combinations of a Phone Number

LeetCode 17 Letter Combinations of a Phone Number

这题用了dp和递归两种方法,dp更好理解也很Pythonic,递归则更加通用

盖题递归位置在循环中,很有意思

Coming from:https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/

src/Solution698 Partition to K Equal Sum Subsets

依旧是递归,区别在递归逻辑在for循环中,相当于并发了n条处理逻辑,有点像树展开

Coming from:https://leetcode-cn.com/problems/partition-to-k-equal-sum-subsets/

LeetCode 779 K-th Symbol in Grammar

src/Solution779 K-th Symbol in Grammar

python用了最简单的递归表示,把结果表示出来再做,比较慢,所以加了@functools.lru_cache(maxsize=128, typed=False)对结果进行缓存

Coming from:https://leetcode-cn.com/problems/k-th-symbol-in-grammar/

src/Solution39 combination-sum

这题和上面这题很像,递归在for循环里面的回溯算法,把所有情况跑一遍

画重点,求解过程中存着result 是List<List<Integer>>的,而tmp_list是list的,需要把tmp_list再裹一层new ArrayList<>(tmp_list)再进行add

Coming from:https://leetcode-cn.com/problems/combination-sum/

src/Solution29 combination-sum

位运算

Coming from:https://leetcode-cn.com/problems/divide-two-integers/

src/Solution206 reverse-linked-list

递归在中间,简单题,对比上面的24题可以对比着看

Coming from:https://leetcode-cn.com/problems/reverse-linked-list/

You can’t perform that action at this time.