Skip to content

Commit eb21ee0

Browse files
committed
Roughly commit
1 parent cc4f417 commit eb21ee0

File tree

3 files changed

+95
-2
lines changed

3 files changed

+95
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.fibers.algorithm.datastructure;
2+
3+
import java.util.LinkedList;
4+
import java.util.Queue;
5+
import java.util.Stack;
6+
7+
//TODO: Need fix
8+
public class Calculator {
9+
10+
public static int eval(String s) {
11+
Queue<String> output = shuntingYard(s);
12+
Stack<String> temp = new Stack<>();
13+
int result = 0;
14+
String token = null;
15+
while ((token = output.poll()) != null) {
16+
switch (token) {
17+
case "+":
18+
result += (Integer.valueOf(temp.pop()) + Integer.valueOf(temp.pop()) );
19+
default:
20+
temp.add(token);
21+
22+
}
23+
}
24+
25+
return result;
26+
}
27+
28+
public static Queue<String> shuntingYard(String s) {
29+
Stack<String> operator = new Stack<>();
30+
Queue<String> output = new LinkedList<>();
31+
32+
33+
return output;
34+
}
35+
36+
public String nextToken(char[] c, int index) {
37+
return null;
38+
}
39+
40+
}

src/main/java/com/fibers/algorithm/datastructure/ListNode.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,22 @@ public ListNode(int t) {
99
val = t;
1010
}
1111

12-
public static void main(String[] args){
12+
public static ListNode valueOf(int[] ar) {
13+
if (ar == null || ar.length == 0) {
14+
return null;
15+
}
16+
17+
ListNode head = new ListNode(ar[0]);
18+
ListNode p = head;
19+
for (int i = 1; i<ar.length ;i++) {
20+
ListNode temp = new ListNode(ar[i]);
21+
p.next = temp;
22+
p = p.next;
23+
}
24+
return head;
25+
}
26+
27+
public static void main(String[] args) {
1328
System.out.println("aaaa");
1429
}
1530

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,42 @@
11
package com.fibers.algorithm.leetcode._061;
2+
3+
import com.fibers.algorithm.datastructure.ListNode;
4+
import com.fibers.utils.Utils;
5+
26
public class Solution {
7+
8+
public static void main(String[] args) {
9+
ListNode head = ListNode.valueOf(new int[]{1,2,3,4,5});
10+
11+
Solution s = new Solution();
12+
Utils.printListNode(s.rotateRight(head, 2));
13+
}
14+
15+
public ListNode rotateRight(ListNode head, int k) {
16+
if (head == null || k == 0) {
17+
return head;
18+
}
19+
20+
ListNode p = head;
21+
ListNode tail = null;
22+
int size = 0;
23+
while (p != null) {
24+
size++;
25+
tail = p;
26+
p = p.next;
27+
}
28+
29+
int index = size - k % size;
30+
p = head;
31+
while (--index > 0) {
32+
p = p.next;
33+
}
34+
35+
tail.next = head;
36+
head = p.next;
37+
p.next = null;
38+
39+
return head;
40+
}
341
}
4-
42+

0 commit comments

Comments
 (0)