From e43801c2745d047ad1ae1b6475de364c4c985cb9 Mon Sep 17 00:00:00 2001 From: whai Date: Tue, 26 Mar 2024 16:45:52 +0800 Subject: [PATCH] AM src/main/java/cn/whaifree/interview/Meituan/MeiTuan24QiuZhao.java AM src/main/java/cn/whaifree/interview/MiHaYou/Problem310.java AM src/main/java/cn/whaifree/leetCode/Dynamic/AbsoluteBeiBao.java AM src/main/java/cn/whaifree/leetCode/Dynamic/LeetCode474.java M src/main/java/cn/whaifree/leetCode/Dynamic/LeetCode494.java AM src/main/java/cn/whaifree/leetCode/Dynamic/LeetCode518.java M src/main/java/cn/whaifree/test/LambdaClass.java AM src/main/java/cn/whaifree/test/testTry.java ?? hs_err_pid119104.log --- .../interview/Meituan/MeiTuan24QiuZhao.java | 55 +++++++++++++++++++ .../interview/MiHaYou/Problem310.java | 9 +++ .../leetCode/Dynamic/AbsoluteBeiBao.java | 9 +++ .../leetCode/Dynamic/LeetCode474.java | 9 +++ .../leetCode/Dynamic/LeetCode518.java | 9 +++ src/main/java/cn/whaifree/test/testTry.java | 9 +++ 6 files changed, 100 insertions(+) create mode 100644 src/main/java/cn/whaifree/interview/Meituan/MeiTuan24QiuZhao.java create mode 100644 src/main/java/cn/whaifree/interview/MiHaYou/Problem310.java create mode 100644 src/main/java/cn/whaifree/leetCode/Dynamic/AbsoluteBeiBao.java create mode 100644 src/main/java/cn/whaifree/leetCode/Dynamic/LeetCode474.java create mode 100644 src/main/java/cn/whaifree/leetCode/Dynamic/LeetCode518.java create mode 100644 src/main/java/cn/whaifree/test/testTry.java diff --git a/src/main/java/cn/whaifree/interview/Meituan/MeiTuan24QiuZhao.java b/src/main/java/cn/whaifree/interview/Meituan/MeiTuan24QiuZhao.java new file mode 100644 index 0000000..f115fc5 --- /dev/null +++ b/src/main/java/cn/whaifree/interview/Meituan/MeiTuan24QiuZhao.java @@ -0,0 +1,55 @@ +package cn.whaifree.interview.Meituan; + +import org.junit.Test; + +import java.util.Scanner; + +/** + * 【刷题节】美团2024届秋招笔试第二场编程真题 + * ... + * @version 1.0 + * @Author whai文海 + * @Date 2024/3/25 15:04 + * @注释 + */ +public class MeiTuan24QiuZhao { + + @Test + public void test() { + Solution_1 solution_1 = new Solution_1(); + //1, 1 4 5 1 4 + solution_1.getMax(new int[]{1, 1, 4, 5, 1, 4}); + } + + + class Solution_1{ + + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + // 注意 hasNext 和 hasNextLine 的区别 + int n = in.nextInt(); + int[] nums = new int[n]; + for (int i = 0; i < n; i++) { + nums[i] = in.nextInt(); + } + + getMax(nums); + } + + public static void getMax(int[] nums) { + + long sum = 0; + for (int num : nums) { + sum += num; + } + + long max = sum; + for (int i = 0; i < nums.length - 1; i++) { + max = Math.max(max, (sum - nums[i] - nums[i + 1]) + ((long) nums[i] * nums[i + 1])); + } + System.out.println(max); + + } + + } +} diff --git a/src/main/java/cn/whaifree/interview/MiHaYou/Problem310.java b/src/main/java/cn/whaifree/interview/MiHaYou/Problem310.java new file mode 100644 index 0000000..c8fce78 --- /dev/null +++ b/src/main/java/cn/whaifree/interview/MiHaYou/Problem310.java @@ -0,0 +1,9 @@ +package cn.whaifree.interview.MiHaYou;/** + * @Author whai文海 + * @Date 2024/3/25 13:23 + * @version 1.0 + * @注释 + * + */ +public class Problem310 { +} diff --git a/src/main/java/cn/whaifree/leetCode/Dynamic/AbsoluteBeiBao.java b/src/main/java/cn/whaifree/leetCode/Dynamic/AbsoluteBeiBao.java new file mode 100644 index 0000000..b6e635a --- /dev/null +++ b/src/main/java/cn/whaifree/leetCode/Dynamic/AbsoluteBeiBao.java @@ -0,0 +1,9 @@ +package cn.whaifree.leetCode.Dynamic;/** + * @Author whai文海 + * @Date 2024/3/26 13:30 + * @version 1.0 + * @注释 + * + */ +public class AbsoluteBeiBao { +} diff --git a/src/main/java/cn/whaifree/leetCode/Dynamic/LeetCode474.java b/src/main/java/cn/whaifree/leetCode/Dynamic/LeetCode474.java new file mode 100644 index 0000000..b858516 --- /dev/null +++ b/src/main/java/cn/whaifree/leetCode/Dynamic/LeetCode474.java @@ -0,0 +1,9 @@ +package cn.whaifree.leetCode.Dynamic;/** + * @Author whai文海 + * @Date 2024/3/26 11:49 + * @version 1.0 + * @注释 + * + */ +public class LeetCode474 { +} diff --git a/src/main/java/cn/whaifree/leetCode/Dynamic/LeetCode518.java b/src/main/java/cn/whaifree/leetCode/Dynamic/LeetCode518.java new file mode 100644 index 0000000..3043f5f --- /dev/null +++ b/src/main/java/cn/whaifree/leetCode/Dynamic/LeetCode518.java @@ -0,0 +1,9 @@ +package cn.whaifree.leetCode.Dynamic;/** + * @Author whai文海 + * @Date 2024/3/26 15:37 + * @version 1.0 + * @注释 + * + */ +public class LeetCode518 { +} diff --git a/src/main/java/cn/whaifree/test/testTry.java b/src/main/java/cn/whaifree/test/testTry.java new file mode 100644 index 0000000..6350b91 --- /dev/null +++ b/src/main/java/cn/whaifree/test/testTry.java @@ -0,0 +1,9 @@ +package cn.whaifree.test;/** + * @Author whai文海 + * @Date 2024/3/24 22:42 + * @version 1.0 + * @注释 + * + */ +public class testTry { +}