使用 Resilience4j 框架實現重試機制
阿新 • • 發佈:2021-11-22
- Java實現
1 //方式一 2 /* 3 public class ListNode { 4 int val; 5 ListNode next = null; 6 7 ListNode(int val) { 8 this.val = val; 9 } 10 }*/ 11 public class Solution { 12 public ListNode ReverseList(ListNode head) { 13 if(head == null || head.next == null) returnhead; 14 ListNode newN = null; 15 ListNode s = head; 16 while(s!=null){ 17 ListNode nextp = s.next; 18 s.next=newN; 19 newN=s; 20 s = nextp; 21 } 22 return newN; 23 } 24 } 25 26 //方式二 27 /* 28 public class ListNode {29 int val; 30 ListNode next = null; 31 32 ListNode(int val) { 33 this.val = val; 34 } 35 }*/ 36 import java.util.Stack; 37 public class Solution { 38 public ListNode ReverseList(ListNode head) { 39 if(head == null || head.next==null) return head; 40 Stack<ListNode> stackP = newStack<>(); 41 while(head!=null){ 42 stackP.push(head); 43 head = head.next; 44 } 45 head = stackP.pop(); 46 ListNode lastP = head; 47 while(!stackP.isEmpty()){ 48 lastP.next=stackP.pop(); 49 lastP=lastP.next; 50 } 51 lastP.next=null; 52 return head; 53 } 54 }