转行狗, 很快要春招了, 1 个月的时间 准备的侧重点?

2017-01-30 23:12:09 +08:00
 q397064399

一直都是自学,时间跨度比较长,学的也很杂, Java 后端 ,做过练手的小 case

基本上该知道的都知道 该入门的都入了一遍 ( Java SQL Spring 反射 事务 前端 xx 之类)

前段时间报了九章的算法班,打算加强下 刷题的能力

(自学过一段时间的 算法 x 数据结构 都限于了解, 一编程就懵逼 思路全断,这也是后来报班的缘故, 说实话 收获还是有的,开阔了一些解题的思路,以及解题的思维)

(我个人觉得解决这些算法问题,在实际工作中应用不大, 但是 这些算法的思路 以及 数据结构 又培养了我分析解决问题的思维模式)

http://www.lintcode.com/zh-cn/problem/number-of-islands/

像以前这道题,我 看到是半天拿不出半点思路的,

但是我昨天 只用了 2 分钟 想出 队列结合 hash 表的方式 就 AC 了,复杂度虽然下不来,终归还是 AC 了


以上是问题背景

问题:

作为一个转行狗,没有经验,求职 Java 实习生, 只剩下一个月的时间,

方案一:用功复习下 《Think in Java》 《Spring in Action《 java 多线程》 等等这些经典应用书籍,顺带写个小 case 出来

方案二:继续刷 OJ 把精力放在面试算法题上?

站在老司机的视角,各位提点建议?

顺带有春招新手 方便留个邮箱 我会投递简历 jonwinters1992@gmail.com

5084 次点击
所在节点    程序员
26 条回复
johnj
2017-01-31 00:11:34 +08:00
还是要结合要找的工种来决定努力方向
要是 web 方向,可能算法面的不多,主要还是关心你 Java 基础怎么样,实践能力怎么样,多久能上手出活

一家之言,仅供参考
scnace
2017-01-31 01:57:50 +08:00
mark 下…
tscat
2017-01-31 02:02:25 +08:00
看你面试公司的级别了, bat 之类的准备算法吧。其他不入流 IT 公司就做一两个项目。使用框架的那种
ryd994
2017-01-31 05:35:58 +08:00
同等春招,找实习中
看到题拔不出来了,你说用队列和 hash 我不太懂

我想到的是着色
从左上开始遍历,找到 1 的话检查左侧和上侧,如果有已着色的,就把当前涂上同样颜色,如果没有,就分配新颜色
然后考虑 corner case 就是如果是十字形的会存在问题。 dirty patch :如果左侧上侧都有色而且颜色不同,对左侧元素重新着色,检查左边的延伸。
ryd994
2017-01-31 05:50:32 +08:00
刚刚突然想到,这不就是个图么?求连通性而已,有更简单的
数 1 的个数
遍历每一个元素,如果和其他 1 贴,就减 1
复杂度和上面的差不多,一回事
zhy0216
2017-01-31 06:00:30 +08:00
九章还有个强化班 楼主也可以试试~~
Allianzcortex
2017-01-31 07:12:03 +08:00
这道题是刘汝佳算法里的题目,求油田的联通性。 dfs 。
q397064399
2017-01-31 07:36:18 +08:00
r#4 @Allianzcortex #7
@ryd994 #4

```
public class Solution {


int total;
int mapX, mapY;

class Node {

public int x, y;

public Node(int x, int y) {
this.x = x;
this.y = y;
}

@Override
public int hashCode() {
return (x + y) / 20;
}

@Override
public boolean equals(Object obj) {
Node objNode = (Node) obj;
if (objNode.x == this.x && objNode.y == this.y) {
return true;
}
return false;
}
}

Set<Node> nodeSet = new HashSet<Node>();

public int numIslands(boolean[][] grid) {
if (grid.length == 0){
return 0;
}
mapY = grid.length;
mapX = grid[0].length;
// Write your code here
for (int y = 0; y < grid.length; y++) {
for (int x = 0; x < grid[0].length; x++) {
if (grid[y][x] == false) {
continue;
}

Node temp = new Node(x, y);
if (grid[y][x] == true && !nodeSet.contains(temp)) {
nodeSet.add(temp);
buildIsland(temp, grid);
//todo
total++;
}
}
}
return total;
}

private void buildIsland(Node node, boolean[][] grid) {
Node curNode;
Stack<Node> stack = new Stack<Node>();
stack.push(node);
while (!stack.isEmpty()) {
Node temp = stack.pop();
int x = temp.x;
int y = temp.y;

if (isLegalNode(x - 1, y) && grid[y][x-1]) {
curNode = new Node(x - 1, y);
if (nodeSet.add(curNode)) {//第一次出现
stack.push(curNode);
}
}
if (isLegalNode(x + 1, y) && grid[y][x+1]) {
curNode = new Node(x + 1, y);
if (nodeSet.add(curNode)) {
stack.push(curNode);
}
}
if (isLegalNode(x, y - 1) && grid[y-1][x]) {
curNode = new Node(x, y - 1);
if (nodeSet.add(curNode)) {
stack.push(curNode);
}
}
if (isLegalNode(x, y + 1) && grid[y+1][x]) {
curNode = new Node(x, y + 1);
if (nodeSet.add(curNode)) {
stack.push(curNode);
}
}
}

}

private boolean isLegalNode(int x, int y) {
if (x >= 0 && x < mapX && y >= 0 && y < mapY) {
return true;
}
return false;
}

}
```
q397064399
2017-01-31 07:40:03 +08:00
r#6 @zhy0216 #6 找工作 重要啊,都吃不起饭了,再搞强化班的话
arnofeng
2017-01-31 08:30:05 +08:00
人人都转程序员。
zgqq
2017-01-31 09:12:56 +08:00
@ryd994 这题我认为简单遍历就行
Cbdy
2017-01-31 09:20:46 +08:00
现在 Java 流行什么框架?
Allianzcortex
2017-01-31 09:37:55 +08:00
@q397064399 我是 Python 党啊(大雾)。你用 Hash 的目的是为了每个 i,j 的位置生成一个唯一的 ID?我贴一下我之前学的时候写的解法,没有检验参数,但基本就是这样啦。也改成 Java 版了:

```
public class NumberOfIslands {
int count = 2;

public int solve(int[][] island) {

for (int i = 0; i < island.length; i++)
for (int j = 0; j < island[0].length; j++) {
if (island[i][j] == 1) {
dfs(island, i, j);
count += 1;
}
}
for (int i = 0; i < island.length; i++) {
for (int j = 0; j < island[0].length; j++) {
System.out.print(island[i][j] + " ");
}
System.out.println();
}
return count-2;
}

public void dfs(int[][] island, int i, int j) {
if (i < 0 || i >= island.length || j < 0 || j >= island[0].length || island[i][j] == 0)
return;
if (island[i][j] == 1) {
island[i][j] = count;
dfs(island, i + 1, j);
dfs(island, i - 1, j);
dfs(island, i, j - 1);
dfs(island, i, j + 1);
}
}

public static void main(String[] args) {
int[][] island = {
{1, 1, 0, 0, 0},
{0, 1, 0, 0, 1},
{0, 0, 0, 1, 1},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 1},
};
NumberOfIslands s = new NumberOfIslands();
System.out.println(s.solve(island));
}
}

```
Allianzcortex
2017-01-31 09:48:10 +08:00
对了,我最近在写这个: https://github.com/Allianzcortex/bweever :-D 把之前零散的东西聚起来~~
xpol
2017-01-31 10:21:26 +08:00
复习一下概率论。面试官喜欢问这个。
byebyejude
2017-01-31 11:04:20 +08:00
免费劳动力大神 你怎么也开始慌了。。。。
SourceMan
2017-01-31 13:33:15 +08:00
iOS
hxndg
2017-01-31 13:50:10 +08:00
岛屿那个不就是寻找岛屿的头部么?
q397064399
2017-01-31 14:02:29 +08:00
r#16 @byebyejude #16 我可不是什么大神 ,兄台
nbndco
2017-01-31 15:16:11 +08:00
完全取决于你要面什么类型的公司,大体上,从最好的公司排起
纯算法加智力题或者概率题的公司
算法加上基础的公司/算法同时偏重语言细节的公司,会加若干项目经历如果面试官有兴趣的话,也可能只字不提
只问项目和 API 背诵的公司,或者只问面试官知道的不多的莫名其妙的技术细节的公司

看你想去和能去哪一种了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/337457

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX