res.add(“R”);
return res;
}
int x = 2000, y = 2000;
char pos = ‘R’;
minx = Math.min(minx, x);
miny = Math.min(miny, y);
maxX = Math.max(maxX, x);
maxY = Math.max(maxY, y);
while (K > 0) {
int prex = x, prey = y;
if (arr[x][y] == 0) {
if (pos == ‘R’) {
x += 1;
pos = ‘D’;
} else if (pos == ‘D’) {
y -= 1;
pos = ‘L’;
} else if (pos == ‘L’) {
x -= 1;
pos = ‘U’;
} else {
y += 1;
pos = ‘R’;
}
} else {
if (pos == ‘R’) {
x -= 1;
pos = ‘U’;
} else if (pos == ‘U’) {
y -= 1;
pos = ‘L’;
} else if (pos == ‘L’) {
x += 1;
pos = ‘D’;
} else {
y += 1;
pos = ‘R’;
}
}
arr[prex][prey] = arr[prex][prey] == 1 ? 0 : 1;
K–;
minx = Math.min(minx, x);
miny = Math.min(miny, y);
maxX = Math.max(maxX, x);
maxY = Math.max(maxY, y);
}
for (int i = minx; i <= maxX; i++) {
StringBuilder sb = new StringBuilder();
for (int j = miny; j <= maxY; j++) {
if (i == x && j == y) {
sb.append(pos);
} else {
if (arr[i][j] == 0) sb.append(“_”);
else sb.append(“X”);
}
}
res.add(sb.toString());
}
return res;
}
Q16.24 数对和
设计一个算法,找出数组中两数之和为指定值的所有整数对。一个数只能属于一个数对。
示例 1:
输入: nums = [5,6,5], target = 11
输出: [[5,6]]
示例 2:
输入: nums = [5,6,5,6], target = 11
输出: [[5,6],[5,6]]
提示:
nums.length <= 100000
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/pairs-with-sum-lcci
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
public List<List> pairSums(int[] nums, int target) {
List<List> res = new ArrayList<>();
Arrays.sort(nums);
int l = 0, r = nums.length-1;
while (l<r){
if(nums[l] + nums[r] == target){
List list = new ArrayList<>();
list.add(nums[l]);
list.add(nums[r]);
res.add(list);
l++; r–;
}else if(nums[l] + nums[r] > target) r–;
else l++;
}
return res;
}
Q16.25 LRU 缓存
设计和构建一个“最近最少使用”缓存,该缓存会删除最近最少使用的项目。缓存应该从键映射到值(允许你插入和检索特定键对应的值),并在初始化时指定最大容量。当缓存被填满时,它应该删除最近最少使用的项目。
它应该支持以下操作: 获取数据 get 和 写入数据 put 。
获取数据 get(key) - 如果密钥 (key) 存在于缓存中,则获取密钥的值(总是正数),否则返回 -1。
写入数据 put(key, value) - 如果密钥不存在,则写入其数据值。当缓存容量达到上限时,它应该在写入新数据之前删除最近最少使用的数据值,从而为新的数据值留出空间。
示例:
LRUCache cache = new LRUCache( 2 /* 缓存容量 */ );
cache.put(1, 1);
cache.put(2, 2);
cache.get(1); // 返回 1
cache.put(3, 3); // 该操作会使得密钥 2 作废
cache.get(2); // 返回 -1 (未找到)
cache.put(4, 4); // 该操作会使得密钥 1 作废
cache.get(1); // 返回 -1 (未找到)
cache.get(3); // 返回 3
cache.get(4); // 返回 4
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/lru-cache-lcci
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
class LRUCache {
Map<Integer, Integer> map;
int capacity;
public LRUCache(int capacity) {
map = new LinkedHashMap<>(capacity);
this.capacity = capacity;
}
public int get(int key) {
if (!map.containsKey(key))
return -1;
int value = map.get(key);
map.remove(key);
map.put(key, value);
return value;
}
public void put(int key, int value) {
if (map.containsKey(key)) {
map.remove(key);
map.put(key, value);
} else {
if (map.size() == capacity)
map.remove(map.keySet().iterator().next());
map.put(key, value);
}
}
}
Q16.26 计算器
给定一个包含正整数、加(+)、减(-)、乘(*)、除(/)的算数表达式(括号除外),计算其结果。
表达式仅包含非负整数,+, - ,*,/ 四种运算符和空格 。 整数除法仅保留整数部分。
示例 1:
输入: “3+2*2”
输出: 7
示例 2:
输入: " 3/2 "
输出: 1
示例 3:
输入: " 3+5 / 2 "
输出: 5
说明:
你可以假设所给定的表达式都是有效的。
请不要使用内置的库函数 eval。
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/calculator-lcci
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
public int calculate(String s) {
Stack stack = new Stack<>();
char opt = ‘+’;
int num = 0;
for (int i = 0; i < s.length(); i++) {
char ch = s.charAt(i);
if (Character.isDigit(ch))
num = num * 10 + (ch - ‘0’);
if ((!Character.isDigit(ch) && ch != ’ ') || i == s.length() - 1) {
if (opt == ‘+’)
stack.push(num);
else if (opt == ‘-’)
stack.push(-num);
else if (opt == ‘*’)
stack.push(stack.pop() * num);
else
stack.push(stack.pop() / num);
num = 0;
opt = ch;
}
}
int res = 0;
while (!stack.isEmpty())
res += stack.pop();
return res;
}
最后
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。
因此我收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门
如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
[外链图片转存中…(img-T41frI5m-1715682504454)]
[外链图片转存中…(img-PuzgDL45-1715682504456)]
[外链图片转存中…(img-OnFhq4dF-1715682504457)]
[外链图片转存中…(img-Ay7NG3FG-1715682504458)]
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门
如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!