Skip to content

Commit 95b5fbd

Browse files
committed
feat: leetcode_weekly_267
1 parent 06c4aaf commit 95b5fbd

4 files changed

+82
-0
lines changed

contest/leetcode_week_267/[editing]leetcode_2076_Process_Restricted_Friend_Requests.java

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public int timeRequiredToBuy(int[] tickets, int k) {
3+
int size = tickets.length, ret = 0;
4+
5+
while (tickets[k] > 0) {
6+
for (int i = 0; i < size; i++) {
7+
if (tickets[i] > 0) {
8+
tickets[i]--;
9+
ret++;
10+
if (tickets[k] == 0) {
11+
return ret;
12+
}
13+
}
14+
}
15+
}
16+
17+
return ret;
18+
}
19+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
class Solution {
2+
public ListNode reverseEvenLengthGroups(ListNode head) {
3+
int groupSize = 1;
4+
List<List<ListNode>> record = new ArrayList<>();
5+
ListNode headCopy = head;
6+
while (headCopy != null) {
7+
List<ListNode> tempList = new ArrayList<>();
8+
for (int i = 0; i < groupSize && headCopy != null; i++) {
9+
tempList.add(headCopy);
10+
headCopy = headCopy.next;
11+
}
12+
record.add(tempList);
13+
groupSize++;
14+
}
15+
// for (List<ListNode> listNodes : record) {
16+
// for (ListNode listNode : listNodes) {
17+
// System.out.print(listNode.val + " ");
18+
// }
19+
// System.out.println();
20+
// }
21+
22+
ListNode retPrev = new ListNode(-1), ret = retPrev;
23+
for (List<ListNode> listNodes : record) {
24+
if (listNodes.size() % 2 == 0) {
25+
Collections.reverse(listNodes);
26+
27+
// for (ListNode listNode : listNodes) {
28+
// System.out.print("reverse:" + listNode.val + " ");
29+
// }
30+
// System.out.println();
31+
}
32+
for (ListNode listNode : listNodes) {
33+
ret.next = listNode;
34+
// System.out.print("single val: " + listNode.val + " ");
35+
ret = ret.next;
36+
}
37+
}
38+
ret.next = null;
39+
40+
return retPrev.next;
41+
}
42+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public String decodeCiphertext(String encodedText, int rows) {
3+
int size = encodedText.length(), cols = size / rows, posX = 0, posY = 0, pos = 0;
4+
if (rows == 1 || size <= 1) {
5+
return encodedText;
6+
}
7+
StringBuilder ret = new StringBuilder();
8+
while (posY < cols) {
9+
int index = posX * cols + posY;
10+
ret.append(encodedText.charAt(index));
11+
posX++;
12+
posY++;
13+
if (posX >= rows) {
14+
posX = 0;
15+
posY = posY - rows + 1;
16+
}
17+
pos++;
18+
}
19+
return ret.toString().replaceAll("\\s+$","");
20+
}
21+
}

0 commit comments

Comments
 (0)