ramihoo

756

Pikachuu
M4ex

ramihoo
9天前
class Solution {

}

//虚拟链头
ListNode left = new ListNode(-1);
ListNode mid = new ListNode(-1);
ListNode right = new ListNode(-1);

//链尾
ListNode ltail = left, mtail = mid, rtail = right;
//取一个val值。将小于val的放left链表，等于val放mid链表，大于val放right链表
for(ListNode p = head; p != null; p = p.next) {
if(p.val < val) ltail = ltail.next = p;
else if(p.val == val) mtail = mtail.next = p;
else rtail = rtail.next = p;
}
ltail.next = mtail.next = rtail.next = null;

//递归排左右两边，由于中间是一样的，无需再排序
//将新的链头加到链尾
left.next = quickSortList(left.next);
right.next = quickSortList(right.next);

//拼接链表
getTail(left).next = mid.next;
getTail(left).next = right.next;

//记录答案链表
ListNode p = left.next;

//清理链表
left = null;
mid = null;
right =null;
return p;
}
}


ramihoo
10天前
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int m = scanner.nextInt();
int[][] res = new int[n][m];
int[] dx={0,1,0,-1},dy = {1,0,-1,0};
for (int x = 0, y = 0, d = 0, k = 1; k <= n * m; k++) {
res[x][y] = k;
int _x = x + dx[d];
int _y = y + dy[d];
if (_x < 0 || _x >= n || _y < 0 || _y >= m || res[_x][_y] != 0) {
d = (d + 1) % 4;
_x = x + dx[d];
_y = y + dy[d];
}
x = _x;
y = _y;
}

for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
System.out.print(res[i][j] + " ");
}
System.out.println("");
}

}
}



ramihoo
20天前

ramihoo
20天前

ramihoo
20天前

ramihoo
20天前

ramihoo
20天前

ramihoo
21天前

ramihoo
28天前

ramihoo
28天前