我觉得你没有理解人家的思路。这里是我的Java实现,仅供参考。
//- 5.2.3 Generation with minimal changes
package mylib;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class Perm implements Iterable>, Iterator> {
final int n;
final int pos[];
final Integer perm[];
final boolean dir[];
final T[] data;
int cnt;
public Perm(List data) {
this.n = data.size();
pos = new int[n];
perm = new Integer[n];
dir = new boo... 阅读全帖
我试着写了下,用java bitset会简单点,assume Location里有block的index, 这种题
没见过估计和楼主一样死翘翘
class Location{
int idx; //block index
public Location(int idx){
this.idx=idx;
}
}
public class myPBuffer extends pBuffer{
BitSet bitSet = new BitSet(1024);
@Override
public Location allocate() throws RuntimeException {
return new Location(bitSet.nextClearBit(0));
}
@Override
public void put(Location l, byte[] data) {
int p = l.idx*1024;
int len = Math.m... 阅读全帖
大棋局与9/11
来源: ognc 于 2013-02-22 16:08:44[档案] [博客] [旧帖] [转至博客] [给我悄悄
话] 本文已被阅读:63次
字体:调大/调小/重置 | 加入书签| 打印| 所有跟帖 | 加跟贴| 查看当前最热讨论主题
The Moral Decoding of 9-11
By Prof. John McMurtry
(Journal of 9/11 Studies) - I was sceptical of the 9-11 event from the first
time I saw it on television. It was on every major network within minutes.
All the guilty parties were declared before any evidence was shown. The
first questions of any criminal investigation were erased. Who had the most
compelling motives for... 阅读全帖
那是容器用的方法
一般不需要override
就是ejbpassive和ejbactive,都可以不要override
提供给你,唯一的目的就是问问用户
你有没有额外需要寄存或者销毁的东西,比如在构造器里面打开一个jdbc连接并寄存为
状态
在remove的时候,最好关闭连接,因为有些时候
用户会主动申请关闭不了的资源,尤其是涉及到io的时候
但是这个都是不提倡的,一般没人这么用,这种容器用的方法,大多数时候不推荐
override
如果是以前版本,就是有home接口的话,override后方法体留空就可以了
如果没有什么需要关闭的话
用ejb最好的地方就是容器托管,如果连销毁ejb都要自己手动编码
那不成写core java了
随手google的,参考
Re: Should i call EJB′s remove?[ GO TO TOP ]
POSTED BY: Jeryl Cook POSTED ON: June 22 2007 10:56 EDT in response to sawan
parihar
Never used it..in most cases u don't n... 阅读全帖
原来java里有balanced的BST, 比C++的好用些,就是接口太多了,记不住。
写了一个求2d overlap矩形面积的题,
核心代码没多少,code都是定义各种结构各种override各种comparator去了:
public class EPI_14_20_3 {
static class Rectangle {
public int xBeg;
public int xEnd;
public int yBeg;
public int yEnd;
public Rectangle(int xb, int xe, int yb, int ye) {
xBeg = xb;
xEnd = xe;
yBeg = yb;
yEnd = ye;
}
}
first, if both B and C override a virtual function foo(), but D did not, the
program is ill-formed anyway. so if both B and C override foo(), D must
also override foo().
Using foo(), this->foo(), or ((A*)this)->foo() are all equivalent since this
always points to an object D, with final overrider D::foo(). so your method
is wrong.
Christie is also being touted as a future presidential nominee of a party
dominated by social conservatives who fear gay marriage will destroy the
nation's moral foundations, even Western civilization itself. It's a party
that gives serious consideration to adulterer and thrice-married Newt
Gingrich, but it has no tolerance for a candidate who supports a tolerant
pro-gay marriage law. Given that reality, why would anyone think Christie, a
possible 2016 candidate for president, will "evolve" like... 阅读全帖
NJ Senate Leaders Challenge Christie on Marriage Referendum
By Julie Bolcer
NJSenateDemocratsGayMarriagex390 (Screengrab) | Advocate.com
Following approval of the marriage equality bill in the New Jersey senate
judiciary committee on Tuesday, the trio of Democratic leaders backing the
measure rejected a suggestion from Governor Chris Christie that the issue be
put to voters in a referendum this fall.
“We do not put civil rights questions on the ballot,” said Senate Majority
Leader Loretta Weinbe... 阅读全帖
But the timing of the president’s veto is designed to erode congressional
support for the bill and put off a politically damaging override vote until
after the November elections.
Obama waited until the very end of the 10-day period he had to issue a veto,
hoping to buy time to lobby members of Congress against the measure.
White House officials also hope congressional leaders will leave Washington
to hit the campaign trail before trying for an override, kicking a vote to
the lame-duck session a... 阅读全帖
http://www.npr.org/2011/02/08/133594656/no-electronic-flaws-in-
The Obama administration's investigation into Toyota safety problems has
found no electronic flaws to account for reports of sudden, unintentional
acceleration and other safety problems. Government investigators said
Tuesday the only known cause of the problems are mechanical defects that
have been addressed by previous recalls.
The Transportation Department, which was assisted by engineers with NASA,
said its 10-month study of Toyo... 阅读全帖
已调查案例里都发现自动加速几乎全都是人为错误造成的。刚开车头几年我也有过一两
次踩错的经历,相信别人都一样。这样的情况,什么系统都帮不了你。当然为了避免设
备故障,刹车override油门是有道理的,不过我希望手动车不要装这个东西,首先手动
车里已经有两套override system了,叫离合和空挡,另外我等遗老遗少们还以每天
heel and toe downshift为乐呢,装了override怎么降档?
Phone order已经in store pick up了的东西如何改换一张卡付钱?电话了bestbuy他们说只能跑去店里return and rebuy,但是我的东西现在价格已经变了,有没有办法让bb的小二(或者经理)override,return一单,然后override一个一样的价格刷到我的新卡上面去?
另外就是如果return了,结果他们没办法override价格,还能void之前的return么?不想到时候被被逼得return了。
多谢
报个面经,攒一下RP。
几个问题,都是经典题,另外考了不少Java的基础知识,还有一道设计题。
== Java ==
1. interface vs abstract class
2. the usages of 'final' keyword
3. overload vs override
4. concept of 'equals' and how to override (need to override hashCode() also)
5. checked vs unchecked exception
== Misc ==
1. 50,000 HTML pages, extract the ones with phone numbers (regex)
2. Find the odd-occurence number in an array (I told him that I have seen
the problem before and he asked the next one)
3. Find the duplicate number in an array of ... 阅读全帖
不少书上将overloading说成是polymorphism的一种实现方式,但是wiki上有这段话
"Polymorphism is only concerned with the application of specific
implementations to an interface or a more generic base class. Method
overloading refers to methods that have the same name but different
signatures inside the same class. Method overriding is where a subclass
replaces the implementation of one or more of its parent's methods.
Neither method overloading nor method overriding are by themselves
implementations of polymorphism... 阅读全帖
Use factory pattern:
//Define a abstract class Cell which the application (Excel) will
//process.
public abstract class Cell {
....
public TValue getValue();
}
// Define concrete cell class
public class LiteralCell : Cell { // '500'
public override TValue getValue() { ... }
}
public class ExpressionCell :Cell { // 'A5 + A10'
public override TValue getValue() { ....}
}
public class FunctionCell : Cell { // 'f(A1, A2, A5)'
public override TValue getValue() { ....}
}
// define ... 阅读全帖
这个是我CrimeTypeKey的class,生成composite key object:
public class CrimeTypeKey implements Writable, WritableComparable<
CrimeTypeKey>
{
private Text key = new Text();
private IntWritable year = new IntWritable();
public CrimeTypeKey() { }
public CrimeTypeKey(String k, int y)
{
key.set(k);
year.set(y);
}
public static CrimeTypeKey read(DataInput in) throws IOException
{
CrimeTypeKey keytp = new CrimeTypeKey();
keytp.readFields(... 阅读全帖
攒了个段子请大牛点评一下:
// Not thread-safe
// Talk about validation requirement: none vs in next() vs in constructor
private static class DeepIterator implements Iterator {
private final Iterator
攒了个段子请大牛点评一下:
// Not thread-safe
// Talk about validation requirement: none vs in next() vs in constructor
private static class DeepIterator implements Iterator {
private final Iterator myIterator;
private final Class eleType;
private final Iterator empty = new ArrayList().iterator();
Code for G question:
public class Solution {
public static class Pair implements Comparable{
int val;
int count;
public Pair(int val, int count) {
this.val = val;
this.count = count;
}
@Override
public int hashCode() {
return val + count * 3;
}
@Override
public boolean equals(Object obj) {
if ( obj == null ) { return false;}
if ( obj.getClass() != this.get... 阅读全帖
网上申请的,回复的挺快,安排了code challenge,一道题,不限时,半个小时写完了
,发过去,第二天收到了thank you but 88.不知道哪里的问题。
* Write a function that takes two parameters:
* (1) a String representing a text document and
* (2) an integer providing the number of items to return.
* Implement the function such that it returns a list of Strings ordered by
word frequency,
* the most frequently occurring word first.
* Use your best judgement to decide how words are separated.
* Your solution should run in O(n) time where n is the number of cha... 阅读全帖
也写一下最近面的bloomberg 的面经。
总共两次phone interview 每次两个题目。
第一次phone interview
第一题 max stack : 这个是 leetcode 上 min stack 的原题,只是 getMin
改成getMax
第二题 输入 一个String s 在 s 后添加最少的 String s' 得到 新的
String T 是一个 palindromic。
第二次phone interview
第一题 input array of number {1,2,3,4,5,6} return number of array {2
*3*4*5*6, 1*3*4*5*6,1*2*4*5*6,1*2*3*5*6,1*2*3*4*6,1*2*3*4*5 }, 要求 不允许用
除法。
my soluction :
publicList getResult(int[] num) {
List res = new ArrayLis... 阅读全帖
最后他老婆的最后他老婆的gc statuc被h1b override了
------------------------------------------
I don't think that is the case. The wording is wrong.
Green Card is for future employment opportunity which has nothing to do with
current VISA status. You can be in the US with any kind of legal status (F1
/H1B/AP advanced parole) or you can simply stay in foreign countries.
But at any given time, you can only be ONE legal status. That's why once you
use AP to get back to US, H1B is invalid. Otherwise, H1B is valid e... 阅读全帖
5月期的RT看到这么篇有趣的文章,机器流 VS 野兽流, 俺应该算机器流 :)
Of Machines and Beasts http://www.runnersworld.com/race-training/of-machines-and-beast
THE RUNNER AS MACHINE
THE RUNNER AS BEAST
or Hybrid? :D
Two weeks before the 2012 New York City marathon, I decided to test my
fitness at a small 5K in Queens. I was in my late 30s, and my training had
been solid. Based on the previous year's times, I thought I might be able to
win. Or not.
As I warmed up near the course, I saw two guys doing strides with the form
of col... 阅读全帖
1. rule of thumb: if you override equals, you have to override
hashCode...(though if you don't put your class as key used in
collection/map/set etc, i don't see any point of override hashCode ;-)...well,
if your class is distinct for every instance of it...no need to do this too...
2. (true or not? don't know...though make sense) HashMap/Hashtable will first
check if any two objects hash to the same bucket...by comparing the result
from hashCode...if the two objects map to the same bucket, they
Let me guess what the interviewer want to know one by one:
1) It's java convention that if you override equals method, you should also
override hashcode method. In real situation, it is always true. Otherwise
you don't override either.
2) I think the default hash function should give memory address instead of
constant, because it is much more efficient. So default equals and hashcode
compare the same thing.
3) Constant returned hashcode method is OK (compliable), but actually not a good choice. ... 阅读全帖