首页 > 代码库 > Developer Test-Java
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; }
Developer Test-Java
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。