普通
- 斐波那契数
class Solution {
public int fib(int n) {
if (n == 0 || n == 1){
return n;
}else {
return fib(n-1)+fib(n-2);
}
}
}
链表递归
if (head == null || head.next == null) {
return head;
}
ListNode newHead = reverseList(head.next);
head.next.next = head;
head.next = null;
return newHead;
反转字符串
class Solution {
public void reverseString(char[] s) {
if(s == null || s.length == 0){
return;
}
Change(s,0,s.length -1);
}
public void Change(char[] s , int left , int right){
if(left >= right){
return;
}
Change(s, left+1 , right-1);
char temp = s[left];
s[left] = s[right];
s[right] = temp;
}
}
|