-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
115 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
> ## Voiceover: | ||
> | ||
> ***见者有缘,缘来好运。欢迎大家来到我的博客【CS_GUIDER】: | ||
> [https://wlei224.gitee.io](https://wlei224.gitee.io/) (建议访问这个,速度极快) | ||
> [https://wl2o2o.github.io](https://wl2o2o.github.io/) (建议收藏至浏览器书签)*** | ||
> | ||
> 我的开源博客涵盖了**八股文**、**Java基础**、**JVM**、**MySQL**、**Linux**、**框架技术**、**算法**以及其他领域的文章,博客域名长期有效!!!如果本站对您来说有用,请收藏本文链接奥。万分感谢。请放心,开源博客,没有任何套路。 | ||
> | ||
> 个人博客建站教程长期不定时连载,囊括我基于 Hexo | fluid 主题的搭建版本记录以及搭建踩坑记录,还有基于原 fluid 主题增加的小功能,如果感兴趣,欢迎大家在页脚评论区咨询。 | ||
> | ||
> ![博客文章](https://cs-wlei224.obs.cn-south-1.myhuaweicloud.com/blog-imgs/202311210931702.png) | ||
#### 美团直接5道编程题,但是整体难度偏中等,汉得还有选择题可以蒙一下🤣,但是编程题直接来了两个二叉树,没刷过呀T_T,反正我是想直接交卷了··· ··· | ||
|
||
![alt text](https://cs-wlei224.obs.cn-south-1.myhuaweicloud.com/blog-imgs/202403091838374.png) | ||
|
||
|
||
|
||
#### 第一道“母夜叉”: | ||
|
||
![alt text](https://cs-wlei224.obs.cn-south-1.myhuaweicloud.com/blog-imgs/202403091838299.png) | ||
|
||
#### 第二道“母夜叉”: | ||
|
||
![alt text](https://cs-wlei224.obs.cn-south-1.myhuaweicloud.com/blog-imgs/202403091839037.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
> ## Voiceover: | ||
> | ||
> ***见者有缘,缘来好运。欢迎大家来到我的博客【CS_GUIDER】: | ||
> [https://wlei224.gitee.io](https://wlei224.gitee.io/) (建议访问这个,速度极快) | ||
> [https://wl2o2o.github.io](https://wl2o2o.github.io/) (建议收藏至浏览器书签)*** | ||
> | ||
> 我的开源博客涵盖了**八股文**、**Java基础**、**JVM**、**MySQL**、**Linux**、**框架技术**、**算法**以及其他领域的文章,博客域名长期有效!!!如果本站对您来说有用,请收藏本文链接奥。万分感谢。请放心,开源博客,没有任何套路。 | ||
> | ||
> 个人博客建站教程长期不定时连载,囊括我基于 Hexo | fluid 主题的搭建版本记录以及搭建踩坑记录,还有基于原 fluid 主题增加的小功能,如果感兴趣,欢迎大家在页脚评论区咨询。 | ||
> | ||
> ![博客文章](https://cs-wlei224.obs.cn-south-1.myhuaweicloud.com/blog-imgs/202311210931702.png) | ||
如图所示: | ||
![笔试中的某一题](https://cs-wlei224.obs.cn-south-1.myhuaweicloud.com/blog-imgs/202403091401792.png) | ||
|
||
我的题解: | ||
|
||
```java | ||
package leetcode; | ||
import java.util.ArrayList; | ||
import java.util.Scanner; | ||
|
||
// 注意类名必须为 Main, 不要有任何 package xxx 信息 | ||
public class Main1 { | ||
public static void main(String[] args) { | ||
Scanner in = new Scanner(System.in); | ||
long cnt = 0; | ||
long cnt0 = 0; | ||
ArrayList<Integer> list = new ArrayList<>(); | ||
// 注意 hasNext 和 hasNextLine 的区别 | ||
while (in.hasNextInt()) { // 注意 while 处理多个 case | ||
int n = in.nextInt(); | ||
int q = in.nextInt(); | ||
for (int i = 0; i < n; i++) { | ||
list.add(in.nextInt()); | ||
cnt += list.get(i); | ||
if (list.get(i) == 0) cnt0++; | ||
// System.out.print(list.get(i)); | ||
} | ||
for (int i = 0; i < q; i++) { | ||
long l = in.nextLong(); | ||
long r = in.nextLong(); | ||
System.out.println((cnt + l*cnt0) + " " + (cnt + r*cnt0)); | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
|
||
春招的第一个笔试,属实有点紧张了,没有想起来用前缀和数组,而是使用了最简单的且浪费效率遍历查询,最终虽然AC了90% ,但是还是超时了,造成没有全AC的原因之一可能还与没有处理[L,R]边界有关! | ||
|
||
下面是来自AI的建议: | ||
> 造成这段代码超时的原因在于: | ||
> 重复计算:在处理每个查询时,代码都会遍历整个数组来重新计算总和cnt和0的个数cnt0。对于多个查询,这种做法会> 导致大量的重复计算。 | ||
> 无效操作:对每个查询范围内的元素并未进行任何针对性的计算,而是直接使用全局累计的cnt和cnt0进行求解。这种方> 式无法正确处理区间内包含0的情况,因为在计算结果时未剔除区间内的0的影响。 | ||
> 为了优化这个问题,应当在读取输入数组之后,预先计算出所有非零元素的累加和(可以采用前缀和的方法),同时记录> 每个位置之前连续非零元素的累加和。这样,在处理查询时,可以直接根据前缀和计算出给定区间的非零元素之和,从而> 避免重复计算并提高效率。 |