package question;import java.util.AbstractList;import java.util.LinkedList;import java.util.List;/*** @author Roderland* @since 1.0*/public class Question54 {public List<Integer> spiralOrder(int[][] matrix) {int top=0;int bottom=matrix.length-1;int left=0;int right=matrix[0].length-1;int i=0, j=0;int d=0;List<Integer> res = new LinkedList<>();while (top<=bottom && left<=right) {res.add(matrix[i][j]);if (d==0) {if (j==right) {d=1;top++;i++;} else {j++;}} else if (d==1) {if (i==bottom) {d=2;right--;j--;} else {i++;}} else if (d==2) {if (j==left) {d=3;bottom--;i--;} else {j--;}} else if (d==3) {if (i==top) {d=0;left++;j++;} else {i--;}}}return res;}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。