由买买提看人间百态

topics

全部话题 - 话题: integer
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
p*********g
发帖数: 911
1
来自主题: JobHunting版 - 求问FB题目
不错。看明白了。
我也贴一下,求各位大牛给给意见。如果没问题, credits归IFloating和bunnih。
public static String shortestString(String s, String p){
String result = null;
if (s== null || p == null || p.length() >s.length()) return null;
if (s.length() ==0 || p.length() ==0) return "";
Map indexMap = new HashMap();
int min = s.length() +1;
for(int i =0 ;i < s.length(); i++){
for(Entry ent: indexMap.entrySet()){
... 阅读全帖
R*********d
发帖数: 34
2
来自主题: JobHunting版 - 刷了半天题
方便起见,就用了ArrayList,不过意思是一样的。
public class PositiveIntegerIterator
{
private int prev = -1;
private Iterator it;
public PositiveIntegerIterator(Iterator it){
this.it = it;
}
public boolean hasNext(){
if(prev > 0){
return true;
}
while(it.hasNext()){
prev = it.next();
if(prev > 0){
return true;
}
}
return false;
}
public Integer next(){
... 阅读全帖
R*********d
发帖数: 34
3
来自主题: JobHunting版 - 刷了半天题
方便起见,就用了ArrayList,不过意思是一样的。
public class PositiveIntegerIterator
{
private int prev = -1;
private Iterator it;
public PositiveIntegerIterator(Iterator it){
this.it = it;
}
public boolean hasNext(){
if(prev > 0){
return true;
}
while(it.hasNext()){
prev = it.next();
if(prev > 0){
return true;
}
}
return false;
}
public Integer next(){
... 阅读全帖
D***n
发帖数: 149
4
来自主题: JobHunting版 - 好挫的F家面经
A more easy understanding solution.
================================================================
public int findMaxLengthSubArrayEqY(int[] A, int target) {
if ( A == null || A.length == 0 ) return 0;
Map> map = new HashMap>(
);
int sum = 0;
for ( int i = 0 ; i < A.length ; i++) {
sum+=A[i];
if ( map.containsKey(sum)) {
map.get(sum).add(i);
} else {
... 阅读全帖
j**7
发帖数: 143
5
来自主题: JobHunting版 - F面经的一题
public String window(String S, String P) {
HashMap> indexMap = new HashMap<
Character, LinkedList>();
for (int i = 0; i < S.length(); i++) {
char c = S.charAt(i);
LinkedList list = indexMap.get(c);
if (list == null) {
list = new LinkedList();
list.add(i);
indexMap.put(c, list);
} else {
list.add(i);
}... 阅读全帖
b*****p
发帖数: 9649
6
来自主题: JobHunting版 - FB Onsite新题,有人能看看吗?
我的伪码
假设有N个房间,strategy[0..k]
首先initialize一个N+2的数组[0..N+1],其中0和N+1是dummy
boolean eval(int N, int[] strategy)
{
//assert N>1
ArrayList room = new ArrayList();
//room[0..N+1]都为initialized为1

for (i=0;i if (finished(room)){
return true;
}
room[strategy[i]] = 0; //执行strategy
expand(room); //根据题意来确定下一状态
}
if (finished(room)){
return true;
}
return false;
}
boolean finish(ArrayList room){
if room[1..room.size()-2] 都为 ... 阅读全帖
S**********5
发帖数: 896
7
来自主题: JobHunting版 - HashMap这样写对吗?
面试一个简单题,想到用hashmap来做。
我是这样写的:
Map map = new HashMap<>();
题做完后没问题,但是烙印面试官说我JAVA基础不行,因为hashmap用了上面的写法,
他说会写代码的有经验的人是这样写的:
HashMap map = new HashMap();
不知道最后会不会给过,但是我觉得我写的没问题,网上看到大家也这么写啊。谁能给
说一下?他是不是想黑我?还是以后面试按他的写法比较保险?
t**r
发帖数: 3428
8
public class Solution {

private List> ret;
private List curList;

public List> combinationSum2(int[] candidates, int target)
{
ret = new ArrayList>();
curList = new ArrayList();
Arrays.sort(candidates);
getSum(candidates,target,0);
return ret;
}
private void getSum(int[] candidates, int target, int lastIndex){
if(target == 0){
ret.add(new ArrayList阅读全帖
f*y
发帖数: 876
9
来自主题: JobHunting版 - 请问一道关于binary tree的题
post-order travesal,return the path to the current max in the subtree.

public static void maxPath(TreeNode root) {
if (root == null) return;
ArrayList path = get(root);
System.out.println(path);
}
public static ArrayList get(TreeNode root) {
if (root == null) return null;
ArrayList left = get(root.left);
ArrayList right = get(root.right);
ArrayList list;
if (left == null && ri... 阅读全帖
p*****2
发帖数: 21240
10

boolean isOp(char c){
return c == '+' || c == '-' || c == '*';
}

int cal(char c, int x, int y){
switch(c) {
case '+':
return x+y;
case '-':
return x-y;
case '*':
return x*y;
default:
return -1;
}
}

List dfs(String input, int s, int e){
List al = new ArrayList<>();
for(int i=s; i char c = input.charAt(i);
... 阅读全帖
I*******x
发帖数: 69
11
来自主题: JobHunting版 - 我又fail了面试
来两个Queue和一个List
一个queue里面装了当前Level的node,从左往右放好的,再一个一个取出来,将他们的
值放进List,
另外一个queue放下一level的node,将当前level取出来的node的left和right放进去,
直到当前level的queue为空,然后将currentQueue = nextQueue;nextQueue = new
LinkedLIst(); list放进最终的List> 里面的第一个。
直接上code:
public List> levelOrderBottom(TreeNode root) {
List> result = new ArrayList>();
if(root == null) return result;

LinkedList cq = new LinkedList();
LinkedList阅读全帖
I******c
发帖数: 163
12
来自主题: JobHunting版 - LinkedIn onsite一道题
我的java实现,参考了Blaze的思路,不过不知道真正理解了他的思路没有,因为我不
太看得懂javascript.下面是几个点:
1. 这个题目用的是backtracking而不是dp,因为dp不可能给你产生排列组合。dp通常
就是给你一个最值。
2. 时间复杂度是指数级。
3. 题目的本质是产生排列。
4. 一般的backtracking来形成字符串的话,从现有字母集中每次任意挑一个字母,然后
从剩下的字母里继续挑。把所有字母都加到字符串里面去了,这轮程序也就完了。这个
题目因为有个顺序的限制条件,决定程序怎样进行下去并不能用剩下多少字符来决定,
而应该是用已经加入字符串的字母的位置来决定。
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Set;
public class Example5 {
public static void main(String [] args){
... 阅读全帖
M***6
发帖数: 895
13
来自主题: JobHunting版 - 一道用叶子过河题
原题在这。https://codility.com/demo/results/demoH5GMV3-PV8/
A small frog wants to get to the other side of a river. The frog is
currently located at position 0, and wants to get to position X. Leaves fall
from a tree onto the surface of the river.
You are given a non-empty zero-indexed array A consisting of N integers
representing the falling leaves. A[K] represents the position where one leaf
falls at time K, measured in seconds.
The goal is to find the earliest time when the frog can jump to the ot... 阅读全帖
T******7
发帖数: 1419
14
public class Solution {
public List> generate(int numRows)
{
List> ret = new ArrayList>();

List res = new ArrayList();
for(int i = 0;i res.add(1);
for(int j=i-1;j>0;j--) {
res.set(j, res.get(j-1)+res.get(j));
}
ret.add(new ArrayList(res));
}

return ret;

}
}
y*******d
发帖数: 1674
15
just started leetcode practice.
has a question about #113:
public class Solution {
public List> pathSum(TreeNode root, int sum) {
List> all = new ArrayList();
findPathSum(root, sum, all, new ArrayList());
return all;
}

private void findPathSum(TreeNode node, int sum, List>
result, List l) {
if (node == null) {
return;
}
l.add(node.val);
if (node.left == null && n... 阅读全帖
y*******d
发帖数: 1674
16
来自主题: JobHunting版 - 问一道leetcode上的题目 combination sum
LC 39
code 如下
两处不明白
1. 为什么要先排序?
2. 为什么helper(res, target-candidates[i], tmp, candidates, i); 是i不是
i+1??
多谢指点
public List> combinationSum(int[] candidates, int target) {
List> res = new ArrayList>();
if (candidates == null || candidates.length == 0) {
return res;
}
Arrays.sort(candidates);
helper(res, target, new ArrayList(), candidates, 0);

return res;
}

void ... 阅读全帖
a*****g
发帖数: 19398
17
摘要——
How can children's natural perceptuo-motor skills be harnessed for teaching
and learning mathematical structure? We address this question in the case of
the integers. Existing research suggests that adult mental representations
of integers recruit perceptuo-motor functionalities involving symmetry.
Building on these findings, we designed a hands-on curriculum that
emphasizes symmetry to teach integer concepts to fourth graders. Compared to
two control conditions, children who went through t... 阅读全帖
a*****g
发帖数: 19398
18
文章摘要——
How can children's natural perceptuo-motor skills be harnessed for teaching
and learning mathematical structure? We address this question in the case of
the integers. Existing research suggests that adult mental representations
of integers recruit perceptuo-motor functionalities involving symmetry.
Building on these findings, we designed a hands-on curriculum that
emphasizes symmetry to teach integer concepts to fourth graders. Compared to
two control conditions, children who went through... 阅读全帖
t******n
发帖数: 2939
19
☆─────────────────────────────────────☆
l63 (l63) 于 (Thu May 23 00:34:22 2013, 美东) 提到:
假设素数只有有限个, 记为 p_1,p_2,...,p_k
考察 N = p_1*p_2*...*p_k + 1
可知: 对于任意i = 1,2,3,...,k, p_i 不能整除 N
由素数的定义:
a是素数 <=> a是大于1的自然数, 且a不被任何小于a的素数整除
可知: N是素数
这与素数只有p_1,p_2,...,p_k矛盾.
故假设不成立.
所以素数有无穷多个.
☆─────────────────────────────────────☆
l63 (l63) 于 (Thu May 23 00:37:03 2013, 美东) 提到:
在承认素数的这个等价定义 (即 a是素数 <=> a是大于1的自然数, 且a不被任何小于a
的素数整除) 的前提下, 居然有人会认为这个证明是错的, 或者是不完备的.
我实在不能理解.
求问一下大家, 是不是有的人的脑子天生有缺陷, 根本怎么教都不会明白... 阅读全帖
b**l
发帖数: 51
20
No Need JNI. try this:
===
/*
* @(#)WinRegistry.java 1.4 03/12/19
*
* Copyright (c) 2004 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
met:
*
* -Redistribution of source code must retain the above copyright notice,
this
* list of conditions and the following disclaimer.
*
* -Redistribution in binary form must reproduce the above copyright notice,
* th... 阅读全帖
r*****l
发帖数: 2859
21
enum和integer,float从语言层面上讲是很不同的东西。你前面提到了大小写的问题,
相信你对大小写是重视的。Java里面有int,有Integer。“integer”这个东西在Java
里面是什么呢?
我相信你是想写Integer,Float的。
编译以后一致不能说明编译以前就是一致(虽然编译以后enum和Integer是否一致还有
待商榷)。
enum能保证serialization/deserialization safe。能保证用“==”有一致的结果,
等等。Integer能吗?
r*****l
发帖数: 2859
22
enum和integer,float从语言层面上讲是很不同的东西。你前面提到了大小写的问题,
相信你对大小写是重视的。Java里面有int,有Integer。“integer”这个东西在Java
里面是什么呢?
我相信你是想写Integer,Float的。
编译以后一致不能说明编译以前就是一致(虽然编译以后enum和Integer是否一致还有
待商榷)。
enum能保证serialization/deserialization safe。能保证用“==”有一致的结果,
等等。Integer能吗?
c********p
发帖数: 1969
23
前几天在job问过,但还是想不通,所有又来这里问了。
这回我按网友建议把求hashtable size改成直接count删去的个数了,还是不能通过大
oj。所以又跑来问问我到底哪里出了问题?!
http://www.mitbbs.com/article_t0/JobHunting/32465791.html
原帖在这里。
我新的代码:
import java.util.*;
public class Solution {
public int longestConsecutive(int[] num) {

if(num == null || num.length == 0){
return 0;
}
int max = 1;
int count = 1;
Hashtable hash = new Hashtable();
for(int i = 0; i < num.leng... 阅读全帖
y******x
发帖数: 31
24
来自主题: Java版 - 问个java lambda的问题
这个code如果用lambda应该怎么写?
Map map = new LinkedHashMap(
capacity, 0.75f, true) {
@Override
protected boolean removeEldestEntry(Map.Entry
eldest) {
return size() > capacity;
}
};
w****g
发帖数: 44
25
3. We define a simple unbalanced binary search tree of integers as
follows:
- Each node in the tree contains an integer, and possibly pointers to
a left subtree and/or a right subtree
- Each node in the left subtree contains an integer that is smaller
than the integer in this node
- Each node in the right subtree contains an integer that is larger
than the integer in this node
- The tree either has a root node or it is empty
To insert a number into the tree, we start a
h*****4
发帖数: 4219
26
来自主题: Programming版 - Haskell; Standard ML类语言的问题
Define
case numberToListWithBase 256(number:Integer,m:[Integer])=[number]++m
when number<256
case numberToListWithBase 256(number:Integer,m:[Integer])=
numberToListWithBase 256((number div 256), ([number mod 256]++m)).
运行时编译报错,错误类型是type mismatch
Differences:
type 1. Integer
type 2. (*->*)
(Integer and (*->*) do not match)
错误语句位置是第二个case。
疑问:编译器怎么无法识别recursive的?左右function一模一样
v******y
发帖数: 84
27
这是我做的10题,大家试试
以后公布答案
Which of the following is the most portable way to declare a C preprocessor
constant for the number of seconds in a (non-leap) calendar year?
Response:
#define SECONDS_PER_YEAR 60 * 60 * 24 * 365
#define SECONDS_PER_YEAR 60 * 60 * 24 * 365;
#define SECONDS_PER_YEAR (60 * 60 * 24 * 365UL)
#define SECONDS_PER_YEAR (60 * 60 * 24 * 365)
Score 1 of 1
Question:
Which of the following is the most flexible way to declare a C preprocessor
macro that takes two arguments and returns th... 阅读全帖
y****e
发帖数: 1012
28
来自主题: Mathematics版 - 能问大家几个数值分析的问题吗?
大家过年好~~有几个题目不是很清楚~
给了几段matlab程序,问题问发生了什么问题?
1.
close all
k=0;
n=100;
for delta = [.1 .01 .008 .007 .005 .003 ]
x = linspace(1-delta,1+delta,n)';
y = x.^6 - 6*x.^5 + 15*x.^4 - 20*x.^3 + 15*x.^2 - 6*x + ones(n,1);
k = k+1;
subplot(2,3,k)
plot(x,y,x,zeros(1,n))
axis([1-delta 1+delta -max(abs(y)) max(abs(y))])
end
2.
% p = smallest positive integer so 1+1/2^p = 1.
x=1; p=0; y=1; z=x+y;
while x~=z
y=y/2;
p=p+1;
z=x+y;
end
disp(sprintf('p = %2.0f is the smallest positive ... 阅读全帖
b***k
发帖数: 2673
29
☆─────────────────────────────────────☆
wealdg (wwwnet) 于 (Wed Aug 6 18:05:11 2008) 提到:
3. We define a simple unbalanced binary search tree of integers as
follows:
- Each node in the tree contains an integer, and possibly pointers to
a left subtree and/or a right subtree
- Each node in the left subtree contains an integer that is smaller
than the integer in this node
- Each node in the right subtree contains an integer that is larger
than the integer in this node
-
s*****n
发帖数: 2174
30
来自主题: Statistics版 - 其实R有的方面也很BT
问了一个公司的大牛同事, 终于搞明白怎么回事了.
a <- 1:100 # class(a) is integer
tracemem(a)
b <- a
b[1] <- 1 # 注意1是numeric双精度, 不是integer
出现的两行转换, 第一次是将b复制一次, 第2次是转换成双精度, 然后才赋值.
看下面的例子, 如果直接赋值integer,就没有这个问题.
a <- 1:100
tracemem(a)
b <- a
b[1] <- 1L
有趣的是下面这个例子, 把一个integer赋值进双精度的vector, 只生成一次转换
a <- c(1,2,3) # a是numeric
tracemem(a)
b <- a
b[1] <- 1L # 只生成一次copy.
也就是说, 将numeric scalar赋值进一个integer的向量, R会首先把vector转换成双精
度, 然后再赋值. 但是把integer scalar赋值进一个numeric向量, R会把scalar先转换
成双精度, 然后赋值进去.
l**1
发帖数: 1875
31
来自主题: Faculty版 - 本版杜绝无证据的人身攻击
// Algorithm that accepts the NP-complete language SUBSET-SUM.
//
// this is a polynomial-time algorithm if and only if P=NP.
//
// "Polynomial-time" means it returns "yes" in polynomial time when
// the answer should be "yes", and runs forever when it is "no".
//
// Input: S = a finite set of integers
// Output: "yes" if any subset of S adds up to 0.
// Runs forever with no output otherwise.
// Note: "Program number P" is the program obtained by
// writing the integer P in binary, then
// consi... 阅读全帖
a***r
发帖数: 981
32
☆─────────────────────────────────────☆
amour (amour) 于 (Sun Feb 3 00:14:28 2013, 美东) 提到:
仅此删贴警告, 如再有同类情况, 3天内不得发帖.
☆─────────────────────────────────────☆
jingang (jingang) 于 (Sun Feb 3 02:32:13 2013, 美东) 提到:
应该的。有些急功近利的手段见不得光,但是烙印老美干类似的事情的人只多不少。
WSN们只会在自己人身上动刀,真无聊。

☆─────────────────────────────────────☆
lot1 (花开花落知多少) 于 (Sun Feb 3 10:22:35 2013, 美东) 提到:
如果讲的是事实,就应该发表。我们都是科学家,应该有科学精神。
你同样没有证据证明别人说的话是错误的。
你不要自以为是,照样把你人肉出来
☆─────────────────────────────────────☆
digua (姚之FA... 阅读全帖
T*T
发帖数: 421
33
☆─────────────────────────────────────☆
happyangel (快乐的天使) 于 (Fri Dec 8 15:25:42 2006) 提到:
1 . 用预处理指令#define 声明一个常数,用以表明1年中有多少秒(忽略闰年问题)
2 . 写一个"标准"宏MIN ,这个宏输入两个参数并返回较小的一个。
3. 预处理器标识#error的目的是什么?
4. 嵌入式系统中经常要用到无限循环,你怎么样用C编写死循环呢?
5. 用变量a给出下面的定义 a) 一个整型数(An integer) b)一个指向整型数的指针
( A pointer to an integer) c)一个指向指针的的指针,它指向的指针是指向一个
整型数( A pointer to a pointer to an intege)r d)一个有10个整型数的数组(
An array of 10 integers) e) 一个有10个指针的数组,该指针是指向一个整型数的
。(An array of 10 pointers to integers) f) 一个指向有10个整型数
P**********3
发帖数: 77
34
来自主题: JobHunting版 - [合集] M$ 面试问题
☆─────────────────────────────────────☆
jenkin (西瓜太郎) 于 (Wed Mar 14 02:07:09 2007) 提到:
白板编程:
1. 删除 duplicate integers in an array.
2. 转换 the given string of integers to
(integers that appear >=1 times)
(integers that appear >=2 times)
...
(integers that appear >=n times)
preserving the original order.

For example: 12223314->12342312
3. 检查 whether an expression is valid.
There are {, [, (, ), ], } symbols in the
expression. something like
{a+(b+c)} is valid, b
x******e
发帖数: 13
35
来自主题: JobHunting版 - 我花了一个小时才调通过这个程序
bitmap should give you a O(n) solution if all numbers are integer.
1. find min and max of all the input integers. O(n)
2. define a binary array in the range of [min, max] (or binary map)
3. when reading each pair of integers [a, b], set the bits between a and b
to 1 if they are 0s. - O(n)
4. finally, scan the bitmap and output the continuous region. O(n).
I didn't implement it, but it should work for integer inputs. If any number
is not integer, the method doesn't work.
Any comments?
I**********s
发帖数: 441
36
来自主题: JobHunting版 - Google点面
问了1) 研究, 2) 多线程程序设计, 3) 任意无穷字符串流, 内存有限, 找出唯一一对
重复字符串, 这个我说了哈希表和外部排序, 但是面试人说有更好的办法(后来想也许
是bloom filter), 然后追问外部排序的细节到结束. 估计要挂 :(
总结: 面试既是技术活, 又是运气活.
无论如何, 把我的准备工作放下面, 攒点rp, 希望对大家有所帮助.
Interview Qs
Data Structures
1. Integer
- find number of 1s
- next largest smaller
- smallest larger number
- determine if is palindrom
- itoa, atoi
- add 2 numbers w/o using + or arithmetic operators
- implement *, -, / using only +
- find max of two numbers w/o co... 阅读全帖
w******1
发帖数: 520
37
写函数实现一个数组找2个数的和是一个固定值。
code:bool has_num(int *integers, int target)
{
for (int i=0;i {
if(num_hashtable(target-*(integers+i))
{
return true;
}
}
return false;
}
====================
1. 边界条件是否需要做个判断呢? 比如*integers 如果是NULL? int target 如果长
度小于等于0?
2.
sizeof(char *) = 4 bytes 或者2 BYTES 或者其他数字,根据不同的编译环境。
sizeof(integers) 可能得到的结果不是你想要的, 结果也许就是指针的SIZE =4
g***s
发帖数: 3811
38
来自主题: JobHunting版 - 求解比硬币找零稍难的一题
Since the DP stores all the values, we don't need to handle (log v_N) times.
So, it is same time complexity of Knapsack problem.
new_V < 2*V
Knapsack can be handle in O(N*V), so this question can be handled in O(N*2*V
) = O(N*V). N is the type of coins.
the O(N*V) codes for knapsack are hard to read. following is sample codes,
time = O(V * sigma log s_i) .
public static int getMinStampNum(Coin[] coins, int V) {
ArrayList p = new ArrayList();
for (Coin coin ... 阅读全帖
k*****t
发帖数: 161
39
来自主题: JobHunting版 - 问道面试题
Given an NxN integer matrix, in which the integers in each row and column
have been already sorted from smallest to largest. Please provide an
algorithm to get the ith smallest integer from the integer matrix.
For example,
1, 5, 20, 33
9, 10, 50, 51
12,15, 59,80
60,70,91, 92
the 4th smallest integer should be 10.
a*****g
发帖数: 110
40
来自主题: JobHunting版 - 贡献一道面试题
面的时候一时没想出来比较理想的方法
还请高手指点
Unsighed 30-bit integer B, 0 <= B < 2^30,
we say integer A conforms to integer B if A has bits set to 1 in all
positions where B has bits set to 1.
e.g. 00 0000 1111 0111 1101 1110 conforms to
00 0000 1100 0110 1101 1010
Write function which takes three 30-bit unsighed integer as input, and
returns the number of unsighed 30-bit integers that conform to at least one
of unsighed 30-bit A, B, C
e.g. A = 11 1111 1111 1111 1111 1111 1111 1001
B = 11 1111 1111 11... 阅读全帖
s******d
发帖数: 61
41
我的返回结果是这个,不知道哪里错了
d:1e:1h:1l:1o:1r:1w:1
import java.util.Collection;
import java.util.Collections;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
public class Findfrequency {
public String find(String s){
char[] ch=s.toCharArray();
Hashtable hash=new Hashtable();
for(int i=0;i Character temp=new Character(ch[i]);
if(!hash.contains(temp)){
hash.put(temp, new Integer(1));
}
else{
Integer in=hash.get(temp);
in++;... 阅读全帖
c**********e
发帖数: 2007
42
来自主题: JobHunting版 - C++ Q93 - Q95
C++ Q93: formal parameter T
What is the purpose of declaring the formal parameter T?
A. T specifies that any data sent to the function template must be of type T
B. T is a place-holder for a C++ data type
C. T can only hold a single data type int
D. T can hold any language data type
C++ Q94: Pointer
Multiple choices: Identify the true statements about the use of pointers in
C++.
A. A pointer is a variable that can contain the memory address of another
variable as its value
B. Although not necess... 阅读全帖
c**********e
发帖数: 2007
43
来自主题: JobHunting版 - C++ Q93 - Q95
Q95 Answer: A and D.

C++ Q95: Files and Streams
Multiple choice: Which of the following statements are true about writing an
integer to a file?
A. The write() function must know the exact location of the integer and the
address operator (&) enables it to locate it
B. The write() function must know the size of the integer and the address
operator (&) returns the amount of storage needed for it
C. The write() function must know the exact location of the integer and the
sizeof operator enables it ... 阅读全帖
k***t
发帖数: 276
44
来自主题: JobHunting版 - 一道题:Vertical Sticks
interviewstreet上的。brute-force很straightforward。
有没有妙招降复杂度?
===================================================
Vertical Sticks
Given array of integers Y=y1,...,yn, we have n line segments such that
endpoints of segment i are (i, 0) and (i, yi). Imagine that from the top of
each segment a horizontal ray is shot to the left, and this ray stops when
it touches another segment or it hits the y-axis. We construct an array of n
integers, v1, ..., vn, where vi is equal to length of ray shot from the top... 阅读全帖
w***y
发帖数: 6251
45
我就是自己做了一个main部分测试了一下, 其他部分都是copy书上的
import java.util.Comparator;
import java.util.PriorityQueue;

public class heap {
/*
* careercup里答案部分
*/
private Comparator maxHeapComparator, minHeapComparator;
private static PriorityQueue maxHeap;
private static PriorityQueue minHeap;
public static void addNewNumber(int randomNumber) {
if (maxHeap.size() == minHeap.size()) {
if ((minHeap.peek() != null) && randomNumber > minHeap.peek()) {... 阅读全帖
m***n
发帖数: 2154
46
找到问题了,确实有情况没考虑到。现在的代码还是不行,崩溃啊。。
import java.util.*;
public class Solution {
public ArrayList> threeSum(int[] num) {
// Start typing your Java solution below
// DO NOT write main() function
if(num==null || num.length==0) return null;
ArrayList> ret = new ArrayList>();
Arrays.sort(num);
int begin = 0;
int end = num.length-1;
for(int i=0;i阅读全帖
i**********e
发帖数: 1145
47
来自主题: JobHunting版 - 总结版上常见的面实题
F:
3Sum
Add Binary
Combination Sum
Count and Say
Divide Two Integers
Edit Distance
Implement strStr()
Letter Combinations of a Phone Number
Longest Palindromic Substring
Merge Intervals
Multiply Strings
Next Permutation
Permutations, Permutations II
Regular Expression Matching
Remove Duplicates
Remove Element
Search in Rotated Sorted Array
String to Integer (atoi)
Sqrt(x)
Substring with Concatenation of All Words
Trapping Rain Water
Unique Paths, Unique Paths II
G:
3Sum
Climbing Stairs
Container... 阅读全帖
a********r
发帖数: 218
48
来自主题: JobHunting版 - interview quiz
For questions 1-4, assume that an array stores integers and has a maximum
size of 100. The array is used to store two distinct data structures, BOTH
a queue and a stack. The answer should be written in C or C++ and should
not use any existing data structure libraries.
1.Write a function that pushes an integer into the stack.
2.Write a function that pops an integer from the stack.
3.Write a function that enqueues an integer into the queue.
4.Write a function that dequeues an integer from the qu... 阅读全帖
t**i
发帖数: 314
49
来自主题: JobHunting版 - leetcode上的3sum
编译过了,运行出错,帮忙看看哪儿出了问题,多谢。
import java.util.*;
public class Solution {
public ArrayList> threeSum(int[] num) {
assert(num.length >= 3);
ArrayList> triplet = new
ArrayList>();
for(int i = 0; i < num.length - 2; i++) {
for(int j = i + 2; j < num.length; j++) {
for(int k = i + 1; k < j; k++) {
if((num[i] + num[j] + num[k]) == 0) {
int[] th... 阅读全帖
t**i
发帖数: 314
50
来自主题: JobHunting版 - leetcode上遇到的问题
多谢啊,好人呐。
下面是4sum这道题的code,刚才又试了一下,去掉if(num.length < 4) return null;
这个运行就没问题了,其实没有这一行return的也是null啊,怎么就会runtime error
呢?
import java.util.*;
public class Solution {
public ArrayList> fourSum(int[] num, int target) {
if(num.length < 4) return null;
ArrayList> a = new ArrayList>(
);

for(int i = 0; i < num.length - 3; i++){
for(int j = i + 3; j < num.length; j++){
for(int m = i + ... 阅读全帖
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)