美团2015校招研发笔试题--编程

(一).2014.9.11哈尔滨站

1.有一组随机排列的字母数组,请编写一个时间复杂度为O(n)的算法,使得这些字母按照字母从小到大顺序排列好。说明:字母区分大小写,相同的字母,排序后小写排在大写前。例如:R B B b W W B R B W ,排序后: b B B B B R R w W W

1)描述思路 

26个英语字母大小写共52个字母,默认存在一个长度为52的数组count中,顺序为a A b,B c C....

遍历给出的数组ch,如果当前字符是小写,找到对应偶数的位置,将其个数+1,如果当前字符是大写,找到对应奇数的位置,将其个数+1,排序算法为O(n)

下面程序为输出。

2)请用你熟悉的编程语言编码实现

public class Netscape {
    public static void main(String ... args){
        char[] ch = {'R','B','B','b','W','W','B','R','B','w'};
        int[] count = new int[52];
        char lowerStart ='a',upperStart ='A';
        for(int i=0;i
   
   
2.
public class MeiTuan {
    public static void main(String ... args){
        MeiTuan m = new MeiTuan();
        System.out.print(m.getResult(2, 3));
    }
    public int getResult(int x,int n){
        int result = 0,temp=1;
        for(int i=0;i<=n;i++){ 
            result+=temp;
            temp*=x;            
        }
        return result;
    }
}
3.

public class MeiTuan {
    public static void main(String ... args){
        MeiTuan m = new MeiTuan();
        int[][] x={{1,2,3},{4,5,6},{7,8,9}};
        int[][] x1={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};
        m.rotate(x1);
    }
    public void rotate(int[][] x){
        if(x.length!=x[0].length){
             System.out.println("not square");return;
        }
        int[][] ret = new int[2*x.length-1][x.length];
        for(int i= 0;i
     
     
      
      =i;j--){
                ret[x.length-j-1+i][i]=x[i][j];
            } 
            for(int k=x.length,j=i+1;k
      
      
       
       
      
      
     
     

4.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值