前言
华为三道题,100+200+300,100及格,大家做对第一题就好了,祝大家全都有心仪的offer,不要慌,不要焦虑。
![fef205573baba7edf0a7a7a93f54493b.png](https://i-blog.csdnimg.cn/blog_migrate/75562c2e71227afa4f639399c0de0f29.jpeg)
一、完美排列
package huawei0909;import java.util.Scanner;/** * Created by IntelliJ IDEA. * * @Author: * @Email: * @Date: 2020/9/9 * @Time: 19:04 * @Version: 1.0 * @Description: Description */public class First { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int K = sc.nextInt(); int[] perArr = new int[K]; int[] perArr1 = new int[K]; for (int i = 0; i < K; i++) perArr[i] = sc.nextInt(); for (int i = 0; i < K; i++) perArr1[i] = sc.nextInt(); int n = sc.nextInt(); int[] arr = new int[n]; int[] arr1 = new int[n]; for (int i = 0; i < n; i++) arr[i] = sc.nextInt(); for (int i = 0; i < n; i++) arr1[i] = sc.nextInt(); sc.close(); /*if (n
二、最长的水沟
package huawei0909;import java.util.Scanner;/** * Created by IntelliJ IDEA. * * @Author: * @Email: * @Date: 2020/9/9 * @Time: 19:36 * @Version: 1.0 * @Description: Description */public class Second { public static int[][] matrix; public static int[][] dp; public static int[][] k = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; public static int n, m, ans; public static void main(String[] args) { Scanner sc = new Scanner(System.in); n = sc.nextInt(); m = sc.nextInt(); matrix = new int[n + 1][m + 1]; dp = new int[n + 1][m + 1]; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) matrix[i][j] = sc.nextInt(); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) ans = Math.max(ans, dfs(i, j)); System.out.println(ans + 1); } public static int dfs(int x, int y) { if (dp[x][y] != 0) return dp[x][y]; for (int i = 0; i <= 3; i++) { int tx = x + k[i][0]; int ty = y + k[i][1]; if (!(tx < 1 || ty < 1 || tx > n || ty > m || matrix[tx][ty] >= matrix[x][y])) dp[x][y] = Math.max(dp[x][y], 1 + dfs(tx, ty)); } return dp[x][y]; }}
三、树最大异或路径
import java.util.HashMap;import java.util.Scanner;public class Main { static int result = 0; public static class TreeNode{ int id; int value; int left_id; int right_id; TreeNode left; TreeNode right; public TreeNode() { } public TreeNode(int id, int value) { this.id = id; this.value = value; } public TreeNode(int id, int value, int left_id, int right_id) { this.id = id; this.value = value; this.left_id = left_id; this.right_id = right_id; } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); HashMap map = new HashMap<>(); for(int i =0;iresult){ result = value; } dfs(node.left,value); dfs(node.right,value); }}
感谢大家看到这里,文章有不足,欢迎大家指出;如果你觉得写得不错,那就给我一个赞吧。
我这边也整理了很多面试的文档笔记。 也还整理了一些最新2020收集的一些大厂的面试真题(都整理成文档,小部分截图)。
![41555b3b947f75b5ec22d4970549e36f.png](https://i-blog.csdnimg.cn/blog_migrate/f4aa68de964febc626c17139593103d7.jpeg)
![6ccd4c1b7727efd24d58f6820dae8a50.png](https://i-blog.csdnimg.cn/blog_migrate/4c60a78b1c9b923eabec692d44ccf30a.jpeg)
上述的面试题答案都整理成文档笔记。有需要的伙伴可以私信回复我:CHZguai,即可免费领取
点关注,不迷路!如果本文对你有帮助的话不要忘记点赞支持哦!