不准访问
积分 746
大米 颗
鳄梨 个
水井 尺
蓝莓 颗
萝卜 根
小米 粒
学分 个
注册时间 2023-7-18
最后登录 1970-1-1
注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
本帖最后由 庞克莱门汀 于 2023-9-20 17:30 编辑
RT,TL没有提出空白行的问题,只是我自己写代码的时候,为了增加可读性,一段逻辑结束后加入 空白行,增加段落感。
就比如Leetcode一道题,207. Course Schedule , 这个是我的solution
增加空白一行意味着新逻辑的开始。class Solution {
public boolean canFinish(int n, int[][] edges) {
Map<Integer, Set<Integer>> graph = new HashMap<>();
for (int i = 0; i < n; i++) graph.putIfAbsent(i, new HashSet<>());
int[] indegree = new int[n];
for (int[] edge : edges) {
int v = edge[0];
int u = edge[1];
indegree[v]++;
graph.get(u).add(v);. .и
}
Set<Integer> visited = new HashSet<>();. 1point3acres.com
int cnt = 0;
Deque<Integer> queue = new ArrayDeque<>();.--
for (int i = 0; i < n; i++) {
if (indegree[i] == 0) {.1point3acres
visited.add(i);. ----
queue.offer(i);
}. 1point 3 acres
}
.1point3acres
while (!queue.isEmpty()) {. Χ
int u = queue.poll();
for (int v : graph.get(u)) {
if (visited.contains(v)) continue;. 1point3acres
indegree[v]--;
if (indegree[v] == 0) {
queue.offer(v);
visited.add(v);
}. 1point3acres
}
}
. From 1point 3acres bbs
return visited.size() == n;
}
} 复制代码 工作中写到的代码也有这个意思。
. 1point3acres.com
另外除了大段逻辑的划分,有一些小的频繁的代码, 也想划分, 比如区分前public void test() {
Cell idCell = row.createCell(ID_IDX);
idCell.setCellStyle(Style.FAILURE);
Cell nameCell = row.create(NAME_IDX);.
nameCell.setCellStyle(Style.SUCCESS);. 1point 3 acres
Cell ageCell = row.createCell(AGE_IDX);
ageCell.setCellStyle(Style.FAILURE);
} 复制代码 区分后:public void test() {
Cell idCell = row.createCell(ID_IDX);
idCell.setCellStyle(Style.FAILURE);
Cell nameCell = row.create(NAME_IDX);
nameCell.setCellStyle(Style.SUCCESS);
Cell ageCell = row.createCell(AGE_IDX);
ageCell.setCellStyle(Style.FAILURE);
}
.1point3acres 复制代码 PR中reviewer没有提出空白行的问题。
但是去年实习的时候,我的mentor,从🐶家出身,每次PR我的代码,都专门会让我把空白行代码删除掉。他的实力也很强。
今天,我也问了身边SDE好朋友,感觉这个问题没有最终答案,但是我们都比较偏向大段逻辑划分可以加空白。 .
-baidu 1point3acres
这个问题是不是仁者见仁,智者见智,opinion-based?
感谢各位指导!
上一篇:
终于收到了亚麻拒信 下一篇:
求问前端工作如何选择: Lacework, Doordash, Docusign, Intuit, Atlassian