Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 694d675

Browse filesBrowse files
committed
增加腾讯模拟笔试题目
1 parent 9a9bfdc commit 694d675
Copy full SHA for 694d675

6 files changed

+195-3Lines changed: 195 additions & 3 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎README.md‎

Copy file name to clipboardExpand all lines: README.md
+6-1Lines changed: 6 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@
8686
- [303.区域和检索 - 数组不可变](src/leetcode/all/solution301_350/Solution303.java)
8787
- [304.二维区域和检索 - 矩阵不可变](src/leetcode/all/solution301_350/Solution304.java)
8888

89+
**351-400**
90+
91+
- [354.俄罗斯套娃信封问题](src/leetcode/all/solution351_400/Solution354.java)
92+
8993
**431-500**
9094

9195
- [442.数组中重复的数据](src/leetcode/all/solution431_500/Solution442.java)
@@ -108,4 +112,5 @@
108112

109113
### 笔试真题
110114

111-
- [阿里2019秋招编程测试-客户端开发岗位](src/ali2019/MaxWorkinghourGap.java)
115+
- [阿里2019秋招编程测试-客户端开发岗位](src/ali2019/MaxWorkinghourGap.java)
116+
- [腾讯2019笔试模拟题-客户端开发岗位](src/tencent/Main1.java)
Collapse file

‎src/ali2019/MaxWorkinghourGap.java‎

Copy file name to clipboardExpand all lines: src/ali2019/MaxWorkinghourGap.java
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
/**
66
* 阿里2018秋招客户端开发工程师编程测试
77
*
8-
* 这次的题目确实相当简单,题目是关于工时预估的,
8+
* 题目是关于工时预估的,
99
* 我这里将题目简化一下:
1010
*
1111
* 给定一个数组,如果数组只有一个元素,返回0
1212
* 对数组排序,然后计算相邻的差的最大值
1313
*
14+
* 要求时间复杂度为O(n),空间复杂度也有限制(具体多少记不清了)
15+
*
1416
* @author 刘壮飞
1517
* https://github.com/zfman.
1618
* https://blog.csdn.net/lzhuangfei.
Collapse file
+75Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package leetcode.all.solution351_400;
2+
3+
import utils.ArrayUtils;
4+
5+
import java.util.Arrays;
6+
7+
/**
8+
* 354. 俄罗斯套娃信封问题
9+
*
10+
* 给定一些标记了宽度和高度的信封,宽度和高度以整数对形式 (w, h) 出现。当另一个信封的宽度和高度都比这个信封大的时候,这个信封就可以放进另一个信封里,如同俄罗斯套娃一样。
11+
*
12+
* 请计算最多能有多少个信封能组成一组“俄罗斯套娃”信封(即可以把一个信封放到另一个信封里面)。
13+
*
14+
* 说明:
15+
* 不允许旋转信封。
16+
*
17+
* 示例:
18+
*
19+
* 输入: envelopes = [[5,4],[6,4],[6,7],[2,3]]
20+
* 输出: 3
21+
* 解释: 最多信封的个数为 3, 组合为: [2,3] => [5,4] => [6,7]。
22+
*
23+
* @author 刘壮飞
24+
* https://github.com/zfman.
25+
* https://blog.csdn.net/lzhuangfei.
26+
*/
27+
public class Solution354 {
28+
29+
/**
30+
* 先对宽度递增排序,然后对高度计算“最长递增子序列的长度”
31+
* @param envelopes
32+
* @return
33+
*/
34+
public int maxEnvelopes(int[][] envelopes) {
35+
if (envelopes.length == 0) return 0;
36+
int[] dp = new int[envelopes.length];
37+
Arrays.fill(dp, 1);
38+
sort(envelopes);
39+
int max = 1;
40+
for (int i = 1; i < envelopes.length; i++) {
41+
for (int j = 0; j < i; j++) {
42+
if (envelopes[i][0]>envelopes[j][0]&&envelopes[i][1] > envelopes[j][1]) {
43+
dp[i] = Math.max(dp[i], dp[j] + 1);
44+
}
45+
}
46+
if (dp[i] > max) max = dp[i];
47+
}
48+
return max;
49+
}
50+
51+
public void sort(int[][] envelopes) {
52+
for (int i = 0; i < envelopes.length - 1; i++) {
53+
for (int j = i + 1; j < envelopes.length; j++) {
54+
if (envelopes[i][0] > envelopes[j][0]) {
55+
int[] tmp = envelopes[i];
56+
envelopes[i] = envelopes[j];
57+
envelopes[j] = tmp;
58+
}
59+
}
60+
}
61+
}
62+
63+
public static void main(String[] args) {
64+
int[][] envelopes = {
65+
{5,4},{6,4},{6,7},{2,3}
66+
};
67+
// 2,4 5,4 6,4 6,7
68+
// 1 1 1 1
69+
70+
int r = new Solution354().maxEnvelopes(envelopes);
71+
System.out.println(r);
72+
}
73+
74+
75+
}
Collapse file
+62Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package leetcode.all.solution51_100;
2+
3+
import utils.ArrayUtils;
4+
5+
/**
6+
* 91. 解码方法
7+
*
8+
* 一条包含字母 A-Z 的消息通过以下方式进行了编码:
9+
*
10+
* 'A' -> 1
11+
* 'B' -> 2
12+
* ...
13+
* 'Z' -> 26
14+
* 给定一个只包含数字的非空字符串,请计算解码方法的总数。
15+
*
16+
* 示例 1:
17+
*
18+
* 输入: "12"
19+
* 输出: 2
20+
* 解释: 它可以解码为 "AB"(1 2)或者 "L"(12)。
21+
* 示例 2:
22+
*
23+
* 输入: "226"
24+
* 输出: 3
25+
* 解释: 它可以解码为 "BZ" (2 26), "VF" (22 6), 或者 "BBF" (2 2 6) 。
26+
*
27+
* @author 刘壮飞
28+
* https://github.com/zfman.
29+
* https://blog.csdn.net/lzhuangfei.
30+
*/
31+
public class Solution91 {
32+
33+
/**
34+
* 1.长度小于1,返回0
35+
* 2.dp的长度比字符串长度多一个,第一位默认为1
36+
* 3.对s中的每个字符:
37+
* ch为'0',该位置为0,否则,为上一个值
38+
* 如果可以和上个元素组合为符合的数字,
39+
* 那么该位置等于该位置的值+上上个位置的值
40+
*
41+
* @param s
42+
* @return
43+
*/
44+
public int numDecodings(String s) {
45+
if(s==null||s.length()<1) return 0;
46+
int[] dp=new int[s.length()+1];
47+
dp[0]=1;
48+
for(int i=1;i<=s.length();i++){
49+
dp[i]=s.charAt(i-1)=='0'?0:dp[i-1];
50+
if(i>1&&(s.charAt(i-2)=='1'||(s.charAt(i-2)=='2'&&s.charAt(i-1)<='6'))){
51+
dp[i]+=dp[i-2];
52+
}
53+
}
54+
return dp[s.length()];
55+
}
56+
57+
public static void main(String[] args){
58+
String s="110";
59+
int r=new Solution91().numDecodings(s);
60+
System.out.println(r);
61+
}
62+
}
Collapse file

‎src/leetcode/common/TreeNode.java‎

Copy file name to clipboardExpand all lines: src/leetcode/common/TreeNode.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class TreeNode {
1010
public TreeNode left;
1111
public TreeNode right;
1212

13-
TreeNode(int x) {
13+
public TreeNode(int x) {
1414
val = x;
1515
}
1616

Collapse file

‎src/tencent/Main1.java‎

Copy file name to clipboard
+48Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package tencent;
2+
3+
import java.util.Arrays;
4+
import java.util.Scanner;
5+
6+
/**
7+
* 腾讯2018秋招模拟笔试
8+
*
9+
* 有一组数字,两个人A和B依次从其中取出一个数字,每次都取出剩余数字中最大的一个,
10+
* A先B后,计算A取出的数字之和-B取出的数字之和
11+
*
12+
* @author 刘壮飞
13+
* https://github.com/zfman.
14+
* https://blog.csdn.net/lzhuangfei.
15+
*/
16+
public class Main1 {
17+
18+
/**
19+
* 先排序,再依次求得A、B各自的分数
20+
*
21+
* @param a
22+
* @return
23+
*/
24+
public static int done(int[] a){
25+
int n=a.length;
26+
if(n==0) return 0;
27+
Arrays.sort(a);
28+
int v1=0,v2=0;
29+
int index=0;
30+
for(int i=n-1;i>=0;i--){
31+
if(index%2==0) v1+=a[i];
32+
else v2+=a[i];
33+
index++;
34+
}
35+
return v1-v2;
36+
}
37+
38+
public static void main(String[] args){
39+
Scanner in = new Scanner(System.in);
40+
int n=in.nextInt();
41+
int[] a=new int[n];
42+
for(int i=0;i<n;i++){
43+
a[i]=in.nextInt();
44+
}
45+
int r=done(a);
46+
System.out.println(r);
47+
}
48+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.