GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — JavaInterview/java/src/LeetCode/CounterClockwise.java at master · damaohongtu/JavaInterview

Expand file tree

/

CounterClockwise.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
44 lines (41 loc) · 1.27 KB
/

CounterClockwise.java

Copy path

File metadata and controls

44 lines (41 loc) · 1.27 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package LeetCode;
import java.util.ArrayList;
import java.util.List;
public class CounterClockwise {
public void printMatrixClockWise(int[][]nums){
int start=0;
int w=nums[0].length;
int h=nums.length;
while (w>2*start && h>2*start){
printMatrixInCircle(nums,start);
start++;
}
}
public void printMatrixInCircle(int[][] nums,int start){
int endX=nums[0].length-start-1;
int endY=nums.length-start-1;
for(int i=start;i<=endX;i++){
System.out.println(nums[start][i]);
}
if(start<endY){
for(int i=start+1;i<=endY;i++){
System.out.println(nums[i][endX]);
}
}
if(start<endX && start<endY){
for(int i=endX-1;i>=start;i--){
System.out.println(nums[endY][i]);
}
}
if(start<endX && start<endY-1){
for(int i=endY-1;i>start;i--){
System.out.println(nums[i][start]);
}
}
}
public static void main(String[] args){
CounterClockwise counterClockwise=new CounterClockwise();
int[][]nums={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};
counterClockwise.printMatrixClockWise(nums);
}
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.