当前位置:网站首页>8.31 Tencent interview
8.31 Tencent interview
2022-07-07 23:28:00 【codepig16】
8.31 Tencent interview
Two arithmetic questions
Enter a set of numbers , Output the second largest number . Avoid using the sorting function that comes with the language
requirement : Use one-time traversal to realize
Thought analysis
Find the first k Big element , We need to learn to maintain a small top stack to achieve , If the element is larger than the top of the heap, put it in the heap , Here is the second element, which is relatively simple .
Code implementation
public int getSecond(int[] nums) {
//a Is the maximum value. b Is the second largest value
int a = Integer.MIN_VALUE, b = Integer.MIN_VALUE;
for (int i = 0; i < nums.length; i++) {
if (nums[i] > a) {
b = a; a = nums[i];}
else if (nums[i] > b) b = nums[i];
}
return b;
}
Enter two integers n and m, From the sequence 1,2,3…….n Take a few numbers at random , Make the sum equal to m , Ask for a list of all possible combinations , Arrange from small to large
Thought analysis
List<List<Integer>> res = new ArrayList<>();
List<Integer> list = new ArrayList<>();
// From index To n Middle sum is m Result
public void dfs(int index, int m, int n) {
if (m == 0) {
res.add(new ArrayList<>(list));
} else {
for (int i = index; i <= m && i <= n; i++) {
list.add(i);
dfs(i + 1, m - i, n);
list.remove(list.size() - 1);
}
}
}
The type of the second question can be changed into , Get the number of conditions from the array , Similar topics are
边栏推荐
- Caip2021 preliminary VP
- 树后台数据存储(採用webmethod)[通俗易懂]
- sql 数据库执行问题
- Puce à tension stabilisée LDO - schéma de bloc interne et paramètres de sélection du modèle
- 建筑建材行业SRM供应商云协同管理平台解决方案,实现业务应用可扩展可配置
- 2022注册测绘师备考开始 还在不知所措?手把手教你怎么考?
- B_QuRT_User_Guide(38)
- Matlab-SEIR传染病模型预测
- Three questions TDM
- Solve the problem of duplicate request resource paths /o2o/shopadmin/o2o/shopadmin/getproductbyid
猜你喜欢
B_ QuRT_ User_ Guide(37)
B_ QuRT_ User_ Guide(36)
包装行业智能供应链S2B2B商城解决方案:开辟电商消费新生态
云原生正在吞噬一切,开发者该如何应对?
Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting
Mysql索引优化实战一
The efficient s2b2c e-commerce system helps electronic material enterprises improve their adaptability in this way
海内外技术人们“看”音视频技术的未来
Home appliance industry channel business collaboration system solution: help home appliance enterprises quickly realize the Internet of channels
Live-Server使用
随机推荐
POJ2392 SpaceElevator [DP]
How to generate unique file names
云原生数据仓库AnalyticDB MySQL版用户手册
New potential energy of industrial integration, Xiamen station of city chain technology digital summit successfully held
Spark 离线开发框架设计与实现
Dynamic agent explanation (July 16, 2020)
PCI-Express接口的PCB布线规则
UE4_UE5结合罗技手柄(F710)使用记录
The efficient s2b2c e-commerce system helps electronic material enterprises improve their adaptability in this way
电子设备行业智能供应链协同平台解决方案:解决低效, 赋能产业数字化升级
三问TDM
Archlinux install MySQL
高效的S2B2C电商系统,是这样帮助电子材料企业提升应变能力的
Unity3d learning notes 4 - create mesh advanced interface
Two kinds of curves in embedded audio development
Solve the problem of duplicate request resource paths /o2o/shopadmin/o2o/shopadmin/getproductbyid
2021ICPC上海 H.Life is a Game Kruskal重构树
Unity3D学习笔记6——GPU实例化(1)
PHP uses Alibaba cloud storage
Have all the fresh students of 2022 found jobs? Is it OK to be we media?