论坛首页 招聘求职论坛

迅雷亲历面经:笔试+上机+面试(完整JAVA面试题求解大讨论)

浏览 90208 次
该帖已经被评为精华帖
作者 正文
   发表时间:2010-03-24  
aniu2008 写道
cranehovers 写道
aniu2008 写道
diaodou 写道
C 2) 可以用这个简单方法。
上机题是一样的方法,开个256的数组,count[256],表示每个字母,数字等的出现次数。
class Remove{
 public static void main(String args[]) {
  String str="6sabcsssfsfs33;
    boolean removeChars[256] = {true};
    removeChars['a'] = false;
    removeChars['b'] = false;
    removeChars['3'] = false;
  StringBuffer sb = new StringBuffer();
    for (char ch: str) {
        if (!removeChars[ch]) sb.append(ch);
    }
    String result = sb.toString();
 }
}


高人啊,应该就是这个方法了

 

太强了 我看了好久才看懂  看来菜鸟和大牛区别就是不同……


哇,这个方法,确实好,效率还高,真是另类高人:)

 

 

AbstractStringBuilder#replace就可以的

 

0 请登录后投票
   发表时间:2010-03-24  
package com.jar.test.package1;

public class Worker implements Runnable {

/**
* @author ZHAOXIAOMING993
*
*/

static int count = 0;

static Object lock = new Object();

int index;

    int pCount;

public Worker(int index) {
this.index = index;
}

public void run() {
synchronized (lock) {
for (;;) {
if (count % 3 == index) {
System.out.print(Thread.currentThread().getName());
count++;
pCount++;
lock.notifyAll();
if (pCount == 10){
break;
}
} else {
try {
lock.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}

/**
* @param args
*/
public static void main(String[] args) {
new Thread(new Worker(0), "A").start();
new Thread(new Worker(1), "B").start();
new Thread(new Worker(2), "C").start();
}
}

0 请登录后投票
   发表时间:2010-03-24  
aniu2008 写道
wfwkiss 写道
public class GoodCode{
	//假如有字符串“6sabcsssfsfs33” ,
	//用最有快速的方法去掉字符“ab3”,不能用java内置字符串方法(indeOf,substring,replaceAll等)? 
	
	public void isGood(){
		String str = "6sabcsssfsfs33";
		char c1 ='a';
		char c2 ='b';
		char c3 ='3';
		
		char[] c = str.toCharArray();
		StringBuilder sl = new StringBuilder();
		for(char temp:c){
			if(temp != c1 && temp !=c2 && temp !=c3)
				sl.append(temp);
		}
		
		System.out.println(sl.toString());
		
	}
	
	public static void main(String[] args){
		GoodCode g = new GoodCode();
		g.isGood();
	}
}



这是种好方法,呵呵 

我想没那么简单,如果真的是这样,只要会java的基本上都能写出来,何况是工作了几年的lz呢
0 请登录后投票
   发表时间:2010-03-24  
linghongli 写道
aniu2008 写道
wfwkiss 写道
public class GoodCode{
	//假如有字符串“6sabcsssfsfs33” ,
	//用最有快速的方法去掉字符“ab3”,不能用java内置字符串方法(indeOf,substring,replaceAll等)? 
	
	public void isGood(){
		String str = "6sabcsssfsfs33";
		char c1 ='a';
		char c2 ='b';
		char c3 ='3';
		
		char[] c = str.toCharArray();
		StringBuilder sl = new StringBuilder();
		for(char temp:c){
			if(temp != c1 && temp !=c2 && temp !=c3)
				sl.append(temp);
		}
		
		System.out.println(sl.toString());
		
	}
	
	public static void main(String[] args){
		GoodCode g = new GoodCode();
		g.isGood();
	}
}



这是种好方法,呵呵 

我想没那么简单,如果真的是这样,只要会java的基本上都能写出来,何况是工作了几年的lz呢



你想复杂了,JDK是专家写的,这些东西别人已经考虑到了~
0 请登录后投票
   发表时间:2010-03-25  
不能用java内置字符串方法(indeOf,substring,replaceAll等)

自己实现遍历统计就是了
0 请登录后投票
   发表时间:2010-03-29   最后修改:2010-03-29
pan_java 写道
8、描术算法,如何有效合并两个文件:一个是1亿条的用户基本信息,另一个是用户每天看电影连续剧等的记录,5000万条。内存只有1G???
9、在1亿条用户记录里,如何快速查询统计出看了5个电影以上的用户?

怎么处理????


问题8:
假设用户信息文件仅存在用户信息:
用户A:姓名,性别,生日,……
用户B:姓名,性别,生日,……
用户Z:姓名,性别,生日,……
用户D:姓名,性别,生日,……
……
看电影纪录仅存在“看过”电影的用户纪录,每次一条:
用户A:电影a
用户Z:电影c
用户A:电影d
……

处理思路:
1、用较简单的数据存储方式预处理5000万条用户看电影的记录,使每个用户最多仅生成一条记录,生成中间文件“TEMP”:
用户A:电影a,电影d
用户Z:电影c
……
2、将TEMP文件读入内存,此时数据量应小于5000万,极端情况下等于5000万,1G内存够用。再顺序读入1亿用户基本信息(顺序处理所占用的内存忽略不计),将当前读入的用户信息与内存中的TEMP数据进行匹配查找,查找结果存入合并文件。

仅思考了一下思路,这个思路下可以满足功能要求和内存限制,未过多考虑性能。性能方面考虑应着重在5000万数据的预处理以及第2步的匹配过程中。


问题9:如果是数据库,一个SQL语句可以满足功能要求,但基础数据量较大,估计无法满足性能要求,尤其是有一定并发的情况下。我们一般处理这样类似的需求时,一定有其他数据表专门存储。如建立一个表专门存储用户看电影的数量,每当生成一条用户看电影的日志数据时,这个表对应的数据条目+1,这样在需要的时候仅需要简单查询即可。实际操作时可通过触发器和存储过程自动处理。


0 请登录后投票
   发表时间:2010-03-30  
NeighborWolf 写道
linyvlu 写道
		StringBuilder sb = new StringBuilder("6sabcsssfsfs33");
		sb.delete(2, 4);
		sb.delete(sb.length()-2, sb.length());

哈哈,看到你的帖子,我想到一个更简单的方法,人工识别:
StringBuilder sb = new StringBuilder("6sabcsssfsfs33");
//使用“眼睛”去掉ab3
System.out.println("6scsssfsfs");


显然可以证明,这样耗时最少,效率最高^_^


该答案得分1000分
0 请登录后投票
   发表时间:2010-03-30  
5、hibernate支持集群吗?如何实现集群?

hibernate 怎么还有集群的概念
0 请登录后投票
   发表时间:2010-03-30  
linyvlu 写道
lantb1986 写道
linyvlu 写道
		StringBuilder sb = new StringBuilder("6sabcsssfsfs33");
		sb.delete(2, 4);
		sb.delete(sb.length()-2, sb.length());




绝对的高手,,,,这也太简单了吧   

人家的问题你都想太少了

这是个比较拼人品的答案,如果拼对了可能让人对你有深刻的印象,如果拼错了。。。。换一家吧。
这也是个非常直接的答案,如果只限制在这一题内,这个答案肯定没错,而且算是很高效的。很多时候没必要让算法多通用,通用的算法未必都高效。很多时候能让我们快速直接解决实际问题的方法才是最省成本的


这个是亮点
0 请登录后投票
   发表时间:2010-06-03  
 
package runnable.com.cn;

import thread.com.cn.Intent;

public class FirstRunner implements Runnable {

	private Intent i;

	public FirstRunner(Intent i) {
		this.i = i;
	}

	@Override
	public void run() {
		Intent temp = this.getI();
		synchronized (temp) {
			while (!temp.isA()) {
				try {
					temp.wait();
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			System.out.print("A");
			temp.setA(false);
			temp.setB(true);
			temp.setC(false);
			temp.notifyAll();
		}
	}

	public synchronized Intent getI() {
		return i;
	}

	public void setI(Intent i) {
		this.i = i;
	}

}

 

 

package runnable.com.cn;

import thread.com.cn.Intent;

public class SecondRunner implements Runnable {

	private Intent i;

	public SecondRunner(Intent i) {
		this.i = i;
	}

	@Override
	public void run() {
		Intent temp = this.getI();
		synchronized (temp) {
			while (!temp.isB()) {
				try {
					temp.wait();
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			System.out.print("B");
			temp.setA(false);
			temp.setB(false);
			temp.setC(true);
			temp.notifyAll();
		}
	}

	public synchronized Intent getI() {
		return i;
	}

	public void setI(Intent i) {
		this.i = i;
	}

}
 
package runnable.com.cn;

import thread.com.cn.Intent;

public class ThirdRunner implements Runnable {
	private Intent i;

	public ThirdRunner(Intent i) {
		this.i = i;
	}

	@Override
	public void run() {
		Intent temp = this.getI();
		synchronized (temp) {
			while (!temp.isC()) {
				try {
					temp.wait();
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			System.out.print("C");
			temp.setA(true);
			temp.setB(false);
			temp.setC(false);
			temp.notifyAll();
		}
	}

	public synchronized Intent getI() {
		return i;
	}

	public void setI(Intent i) {
		this.i = i;
	}

}
 
package thread.com.cn;

public class Intent {
	
	private volatile  boolean a;
	
	private volatile boolean b;
	
	private volatile boolean c;
	

	public boolean isA() {
		return a;
	}

	public void setA(boolean a) {
		this.a = a;
	}

	public boolean isB() {
		return b;
	}

	public void setB(boolean b) {
		this.b = b;
	}

	public boolean isC() {
		return c;
	}

	public void setC(boolean c) {
		this.c = c;
	}
}
 
package thread.com.cn;

import runnable.com.cn.*;

public class MainThread {

	public static void main(String[] args) {

		Intent intent = new Intent();
		intent.setA(true);
		intent.setB(false);
		intent.setC(false);

		for (int i = 0; i < 10; i++) {
			Thread firstthread = new Thread(new FirstRunner(intent));
			Thread secondtthread = new Thread(new SecondRunner(intent));
			Thread thirdthread = new Thread(new ThirdRunner(intent));

			thirdthread.start();
			firstthread.start();
			secondtthread.start();
		}
	}
}
 
0 请登录后投票
论坛首页 招聘求职版

跳转论坛:
Global site tag (gtag.js) - Google Analytics