当前位置:网站首页>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
边栏推荐
- 成年人只有一份主业是要付出代价的,被人事劝退后,我哭了一整晚
- USB (XV) 2022-04-14
- 系统设计概述
- 力扣解法汇总648-单词替换
- 2022 届的应届生都找到工作了吗?做自媒体可以吗?
- HDU 4747 Mex「建议收藏」
- Archlinux install MySQL
- 三问TDM
- 谷歌浏览器怎么登录及开启同步功能
- Digital procurement management system for fresh food industry: help fresh food enterprises solve procurement problems and implement online procurement throughout the process
猜你喜欢

2022 Season 6 perfect children's model Shaanxi finals came to a successful conclusion

leetcode-520. Detect capital letters -js

Inftnews | web5 vs Web3: the future is a process, not a destination

2022注册测绘师备考开始 还在不知所措?手把手教你怎么考?

B_QuRT_User_Guide(36)

Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting

Add data analysis tools in Excel

PCB wiring rules of PCI Express interface
![[compilation principle] lexical analysis design and Implementation](/img/8c/a3a50e6b029c49caf0d791f7d4513a.png)
[compilation principle] lexical analysis design and Implementation

B / Qurt Utilisateur Guide (36)
随机推荐
PCI-Express接口的PCB布线规则
As a new force, chenglian premium products was initially injected, and the shares of relevant listed companies rose 150% in response
How can we make money by making video clips from our media?
LDO穩壓芯片-內部框圖及選型參數
家用电器行业渠道商协同系统解决方案:助力家电企业快速实现渠道互联网化
深入理解Mysql锁与事务隔离级别
New potential energy of industrial integration, Xiamen station of city chain technology digital summit successfully held
海内外技术人们“看”音视频技术的未来
Archlinux install MySQL
Freelink open source call center design idea
Matlab-SEIR传染病模型预测
谷歌浏览器怎么登录及开启同步功能
城联优品作为新力量初注入,相关上市公司股价应声上涨150%
USB (十七)2022-04-15
Adults have only one main job, but they have to pay a price. I was persuaded to step back by personnel, and I cried all night
Coreseek:第二步建索引及測试
Talk about the design and implementation logic of payment process
USB(十四)2022-04-12
STL标准模板库(Standard Template Library)一周学习总结
USB (XIV) 2022-04-12