码迷,mamicode.com
首页 > 编程语言 > 详细

Developer Test-Java

时间:2017-06-04 00:53:01      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:lag   false   int   amp   decide   []   ide   toc   eth   

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;
  }

 

Developer Test-Java

标签:lag   false   int   amp   decide   []   ide   toc   eth   

原文地址:http://www.cnblogs.com/xiaoma-ge/p/6938964.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!