Developer Test-Java

Java

    1. Give two String, write a method  to decide if one is a permutation of the other.

  for example: string s1="dog" string s2="god" is true; string  s3="dgo" is also true;

public boolean isPermutation(String s1,String s2){
         boolean flag=false;
         if(s1.length()==0 && s1.length()!=s2.length()){
             flag = false;
         }else {
             String str1=new String(s1);
             String str2=new String(s2);
             char[] str1ToChar=s1.toCharArray();
             char[] str2ToChar=s2.toCharArray();
              Arrays.sort(str1ToChar);
              Arrays.sort(str2ToChar);
             if(Arrays.equals(str1ToChar,str2ToChar)){
                 flag = true;
             }
         }
         return flag;
   }
    

 2. F(0)=0;F(1)=0; F(n)=F(n-1)+F(n-2) for n>1(递归)

 

public int recursion(int n){
        if(n==1 || n==2){
            n=1;
        }else{
            n=recursion(n-1)+recursion(n-2);
        }
        return n;
  }

 

转载于:https://www.cnblogs.com/xiaoma-ge/p/6938964.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值