杨辉三角的变形
第n行 第一个 偶数 出现的位置
通过观察每行偶数出现的情况,偶数出现的位置只有-1 2 3 4
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
if(n<=2){
System.out.println("-1");
}else if(n%2==1){
System.out.println("2");
}else if (n%4==0){
System.out.println("3");
}else{
System.out.println("4");
}
}
}
二叉树镜像
**/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
public TreeNode mirrorTree(TreeNode root) {
// if(root==null){
// return root;
// }
// TreeNode node=root.left;
// root.left=root.right;
// root.right=node;
// mirrorTree(root.left);
// mirrorTree(root.right);
// return root;
if(root==null){
return null;
}
//借助个临时节点来避免覆盖后找不到左(右)节点。
TreeNode left=root.left;
root.left=mirrorTree(root.right);
root.right=mirrorTree(left);
return root;
}
}
统计每个月兔子的出生总数
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
System.out.println(getnum(n));
}
public static int getnum(int n){
if(n<3){
return 1;
}else{
return getnum(n-1)+getnum(n-2);
}
}
}