-
找出句子里面最多but not in the word to exclude list
https://leetcode.com/problems/most-common-word/ -
count number of substrings with exactly k distinct characters
一道是用滑动窗口求包含K个distinct字符的子串数目
https://blog.csdn.net/roufoo/article/details/84934364
12个test case, 最后一个test case是当k为0时的输出 -
reOrder log files
-
find subtree with maximum average node
https://yeqiuquan.blogspot.com/2017/03/lintcode-597-subtree-with-maximum.html -
Highest 5
highest five, 背景知识是有一堆productID 和product的reviews, 给每一个productID找出最高的五个review的平均值,用priorityqueue做就可以,注意data type是double
highest five reviews,给一个Map储存的是id和其对应的review score,返回一个Map, key是id,value是相对应的5个最高评分的平均数
https://yeqiuquan.blogspot.com/2017/03/lintcode-613-high-five.html
lintcod 第613题类似,区别是amazon的score是double,lintcode是int,注意下就好 -
find substrings of size k with k-1 distinct characters
input是inputString和num,output是所有长为num且distinct character为num - 1的subString的list
public List<String> subStringWithKDistinct(String s, int k) {
Map<Character, Integer> map = new HashMap<>();
List<String> result = new ArrayList<>();
int n = s.length();
if( n * k == 0) {
return 0;
}
int left = 0, right = 0;
while(right < n) {
map.put(s.charAt(right), right++);
if(map.size() == k) {
if(right - left == k + 1) {
result.add(s.substring(left,right));
}
}
if(map.size() > k) {
int del_idx = Collections.min(map.values());
map.remove(s.charAt(del_idx));
left = del_idx + 1;
}
}
return result;
}
- 有一排数据中心,求最小的cost把所有的数据中心连起来 (MST)
- K closest points to origin.
https://leetcode.com/problems/k-closest-points-to-origin/ - 给一个字符串和一个整数k,问有多少个substring有k个distinct character。仔细读题,题目要求的是重复的substring也可以满足要求
https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters/
https://www.geeksforgeeks.org/count-number-of-substrings-with-exactly-k-distinct-characters/
小土刀
-
Right Rotation
-
Grey code
-
去元音 remove vowel
-
检验括号
-
longest palindromic substring
https://leetcode.com/problems/longest-palindromic-substring/ -
merge two sorted linkedlist
-
reverse second half of linked list
-
Subtree
-
Two Sum
-
Find K Nearest Point
-
Overlap Rectangle
给两个长方形的topLeft和bottomRight坐标, 判断这两个长方形是否重叠
Rectangle Overlap。这题和leetcode 算相交面积的区别:它帮你定义好两个类,一个叫Point,一个叫Rectangle,Rectangle包括左上右下两个Point, Point包括x, y的值, 这种细节并不影响程序,总之一句判断直接通过了全部20多个case. -
window sum
-
GCD Greatest Common Divisor
-
LRU Cache count miss
-
Round Robin
-
Rotate Matrix
-
insert into cycle linked list
-
Loop in linked list
-
Shorted job first
一个处理器要处理一堆request,一次只能处理一条,如果它有几个积压着的requests,它会先执行持续时间短的那个;对于持续时间相等的requests,先执行最早到达处理器的request。问平均每个request要等多久才能被处理。input:requestTimes[],每个request到达处理器的时间; durations[] 每个request要处理的持续时间。 两个数组是一一对应的,并已按requestTimes[] 从小到大排序过 -
Binary search tree minimum sum from root to leaf
-
Day change(cell growth)
https://leetcode.com/problems/prison-cells-after-n-days/
to 9
public int shortestDistance(int[][] maze, int[] start, int[] dest) {
int[][] distance = new int[maze.length][maze[0].length];
for (int[] row: distance)
Arrays.fill(row, Integer.MAX_VALUE);
distance[start[0]][start[1]] = 0;
int[][] dirs={{0, 1} ,{0, -1}, {-1, 0}, {1, 0}};
Queue < int[] > queue = new LinkedList < > ();
queue.add(start);
while (!queue.isEmpty()) {
int[] s = queue.remove();
for (int[] dir: dirs) {
int x = s[0] + dir[0];
int y = s[1] + dir[1];
int count = 0;
while (x >= 0 && y >= 0 && x < maze.length && y < maze[0].length && maze[x][y] == 0) {
x += dir[0];
y += dir[1];
count++;
}
if (distance[s[0]][s[1]] + count < distance[x - dir[0]][y - dir[1]]) {
distance[x - dir[0]][y - dir[1]] = distance[s[0]][s[1]] + count;
queue.add(new int[] {x - dir[0], y - dir[1]});
}
}
}
return distance[dest[0]][dest[1]] == Integer.MAX_VALUE ? -1 : distance[dest[0]][dest[1]];
}
- Minimum Path Sum 窗口内最小
- Four Integer 四个数字 差的绝对值最大
- Arithmetic sequence
https://leetcode.com/problems/arithmetic-slices/ - Tree Amplitude
Given a tree of N nodes, return the amplitude of the tree
就是从 root 到 leaf max - min 的差 - Maximum Minimum Path
给一个int[][]的matirx,对于一条从左上到右下的path pi,pi中的最小值是mi,求所有mi中的最大值。只能往下或右. - Search in 2D matrix
- two close capacity
网友评论