Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Created Spiral_Matrix code from leetcode#759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
02-Shivaraj wants to merge1 commit intocodemistic:main
base:main
Choose a base branch
Loading
from02-Shivaraj:main

Conversation

02-Shivaraj
Copy link

No description provided.

int count = 0;
int row = 0;
int col = 0;
boolean right = true;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Too many boolean flags for directions

  • right, left, up, down, and curr lead to bloated logic and repetitive conditionals.
  • This could be replaced by a direction array and an index to keep it clean.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

`public List spiralOrder(int[][] matrix) {
List result = new ArrayList<>();
if (matrix == null || matrix.length == 0) return result;

    int top = 0;    int bottom = matrix.length - 1;    int left = 0;    int right = matrix[0].length - 1;    while (top <= bottom && left <= right) {        // move right        for (int i = left; i <= right; i++) {            result.add(matrix[top][i]);        }        top++;        // move down        for (int i = top; i <= bottom; i++) {            result.add(matrix[i][right]);        }        right--;        // move left        if (top <= bottom) {            for (int i = right; i >= left; i--) {                result.add(matrix[bottom][i]);            }            bottom--;        }        // move up        if (left <= right) {            for (int i = bottom; i >= top; i--) {                result.add(matrix[i][left]);            }            left++;        }    }    return result;}

}`

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@SrishtiSinha2003SrishtiSinha2003SrishtiSinha2003 approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@02-Shivaraj@SrishtiSinha2003

[8]ページ先頭

©2009-2025 Movatter.jp