Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
332 views
in Technique[技术] by (71.8m points)

java - 如何在网格Java中获取相邻案例(How to get adjacent cases in a grid Java)

Ive passed a test yesterday and I did not do great on it.

(我昨天通过了考试,但我做得不好。)

The thing is it a 2d grid, inputs are column number(int), row number(int) and the grid(List>).

(事情是它是2d网格,输入是列号(int),行号(int)和网格(List>)。)

each case can eaither be in a 0 or a 1 state.

(每种情况都可以处于0或1状态。)

The goal is to find the number of adjuscent rows that are in a 0 state (including the case itself) This is my try but its not working:

(目标是找到处于0状态(包括大小写本身)的辅助行数。这是我的尝试,但不起作用:)

 int minimumHours(int rows, int columns, List<List<Integer> > grid)
    {
        int cpt=0;
        List<Integer> keepc = Arrays.asList(columns-2,columns-1,columns);
        List<Integer> keepr = Arrays.asList(rows-2,rows-1,rows);

        for (List<Integer> row : grid.stream()
                .filter(i -> keepr.contains(i))
                .collect(Collectors.toList()) ) {
            for(int column:row.stream()
                    .filter(j -> keepc.contains(j))
                    .collect(Collectors.toList())) {
                cpt=column==0?cpt+1:cpt;
            }
        }
        return cpt;
    }
  ask by pochi translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...