由买买提看人间百态

topics

全部话题 - 话题: inputs
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)

发帖数: 1
1
来自主题: JobHunting版 - 一道Coding面试题目
class Pair {
Pair(String s, String e) {
_1 = s;
_2 = e;
}
public int hashCode() {
return _1.hashCode() | _2.hashCode();
}
public boolean equals(Object obj) {
if (obj == null) return false;
else {
if (obj instanceof Pair) {
Pair pair = (Pair)obj;
return _1.equals(pair._1) && _2.equals(pair._2);
} else {
return false;
}
}
}
String _1;
S... 阅读全帖
T***B
发帖数: 137
2
来自主题: Java版 - 工作中遇到的并行处理问题
照着mectite,goodbug二位的思路写了一下,代码如下. 试着跑了一下,运行结果和预
期吻合。我有一个问题:我在PredictRequest.call()里面把current thread cast成
PredictorThread从而拿到predictor object. 还有更好的办法把predictor (inside
the thread) 和callable联系起来吗?
Predictor.java
public class Predictor {
private String name;

public Predictor(String name) {
// heavy lifting stuff.
this.name = name;
System.out.println("Created predictor " + name);
}
public synchronized String predict(String input) throws
InterruptedExcept... 阅读全帖
s*****u
发帖数: 164
3
来自主题: Quant版 - Quant 面试问题求解答!
Oh no! Disaster has struck some of ACME's redundant data centers. The
administrators have managed to restore backups, but some data sets are
still missing from some data centers. Fortunately, every data set can be
found at least once in one or more of the data centers. However, before
ACME can resume normal operations, it needs to ensure that each data
center has a copy of every data set.
Your goal is to help ACME resume normal operations by writing a program
to synchronize data sets between dat... 阅读全帖
H*******r
发帖数: 98
4
来自主题: Statistics版 - 编程菜鸟问一个sas编程问题
one is...
data select;
set original;
where var1 in (value1 value2 value3 value4 value5 value6 value7 value8)
or
var1 between minvalue and maxvalue or
var2 in (number1 number2 number3) or
var3 in (number1 number2 number3) or
var4 in (number1 number2 number3) or
var5 in (number1 number2 number3) or
var6 in (number1 number2 number3) or
var7 in (number1 number2 number3) or
var8 in (number1 number2 number3) or
... 阅读全帖
k*z
发帖数: 4704
5
来自主题: Statistics版 - 牛牛 Xie Liang关于 Erlang C的Model应用
http://saslist.com/blog/2012/07/13/sas-functions-for-computing-
http://listserv.uga.edu/cgi-bin/wa?A2=ind1210c&L=sas-l&F=&S=&P=
SAS functions for computing parameters in Erlang-C model
Call center management is both Arts and Sciences. While driving moral and
setting up strategies is more about Arts, staffing and servicing level
configuration based on call load is in the domain of Sciences.
The science part of call center management is based on Queueing Theory,
which studies "the Phenomena of sta... 阅读全帖
w*******y
发帖数: 60932
6
US Appliance has the TC-P65GT30 Panasonic Viera 65" Plasma 3D 1080p HDTV
with 600Hz Subfield & Viera Connect for $2,220.00 with free white glove
delivery and no tax for most. Must go through checkout to see final price.
Link:
http://www.us-appliance.com/tcp65gt30.html
65" Class VIERAGT30 Series Plasma (64.7" Diagonal)
Flush Design - Trim and elegant design to compliment any d閏or
Full HD 3D - Revolutionary VIERA Full HD 3D Technology delivers award-
winning realism that immerses you in the image
... 阅读全帖
s********3
发帖数: 31
7
Moving sale:
This TV is pretty new with great performace (please check it out by the
attached pictures)! I brought it half of years ago with the orignal price is
$380. The features is as the blow:
HD 720p resolution panel
Enjoy crisp, detailed and vibrant images in 720p picture quality while
watching movies, sports and primetime HD television broadcasts via the 16:9
wide screen panel (1366 x 768).
Digital noise reduction
Cleaner, clearer, more vivid pictures from all inputs, even USB and PC! Now... 阅读全帖
s********3
发帖数: 31
8
Moving sale:
This TV is pretty new with great performace (please check it out by the
attached pictures)! I brought it half of years ago with the orignal price is
$380.Now you can pick up it with price as low as $200. The features is as
the blow:
HD 720p resolution panel
Enjoy crisp, detailed and vibrant images in 720p picture quality while
watching movies, sports and primetime HD television broadcasts via the 16:9
wide screen panel (1366 x 768).
Digital noise reduction
Cleaner, clearer, more viv... 阅读全帖
l******g
发帖数: 6771
9
新手,最近看看音响,看看电影,唱唱卡拉OK,人笨不太会考古搜精华,所以就放狗搜
,看到这个深入浅出,转到版上分享一下,抛砖引玉。。。
http://thecreativealternative.com/best-home-theater-receiver-gu
#####################################################################
AV Receiver Guide – Home Theater
Posted on April 14, 2013 by mychaelp
Check out some of the latest models with 4K Ultra HD compatibility now
included in this AV Receiver Guide for Home Theater
The A/V Receiver… Some have referred to this device as “The “Heart of the
Home Theater”. And for good reas... 阅读全帖
z******w
发帖数: 36
10
来自主题: JobHunting版 - 问个facebook 面试题
j是对于每个i是从0开始一直到max的。为什么会没有input[i] dp[i][j] = Math.min(input[i]+dp[i-1][j], dp[i-1][input[i]]);
这个状态转移是如果input[i] input[i]+dp[i-1][j]. 另外一种就是保留input[i],那么前i-1个元素都要小于input[i
], cost为dp[i-1][input[i]].
h****n
发帖数: 1093
11
来自主题: JobHunting版 - Amazon intern first phone interview
17:12
1.
vector > FindAllPairs(vector input, int givenSum)
{
vector > res;
vector oneRes;
if(input.size()<1) return res;
int i = 0; j = input.size()-1;
while(i {
if(input[i]+input[j] else if(input[i]+input[j]>givenSum) j--;
else
{
oneRes.clear();
oneRes.push_back(input[i]);
oneRes.push_back(input[j]);
if(find(res.begin(), res.end(), oneRes)==res.en... 阅读全帖
D********g
发帖数: 650
12
来自主题: JobHunting版 - 一道G家店面题
加上了backtracking:
static class DPElement {
int value;
int prevCostIdx; // 0-based cost idx
int takenThisElement; // 0/1, indicating whether taking current
element, idx 0 based.
public DPElement() {
value = 0;
prevCostIdx = 0;
takenThisElement = 0;
}
}
static String word2Anagram(final String word) {
if (word == null) {
return null;
}

int ht[] = new int[256];
f... 阅读全帖
h****n
发帖数: 1093
13
来自主题: JobHunting版 - 继续分享G家phone interview题目
static int[] IncrementByOne(int[] input)
{
//Carry is initialized as 1 to simulate add one
int carry = 1;
int res;
int[] output;
if (input == null) return null;
for (int i = input.Length - 1; i >= 0; i--)
{
res = input[i] + carry;
carry = res > 9 ? 1 : 0;
input[i] = res % 10;
}
if (carry == 1)
{
output = new int[input.Length + 1];
for (int i = input.Length - 1; i >= 0; i--)
{
output[i + 1] = input... 阅读全帖
i*********n
发帖数: 58
14
Pseudocode and implementation needs to be optimized:
set PowerSet(set input)
if (input.empty())
return set.insert(EmptySet);
else
e = input.first();
input.removeFirst();
input = PowerSet(input);

for (iter = input.second(); iter != input.end(); ++iter)
set.insert(SetUnion(e, *iter));
return SetUnion(set, input);
h****n
发帖数: 1093
15
来自主题: JobHunting版 - 贡献一道题
写了一个,没测,楼主测测有问题告诉我
bool isWord(string s)
{
if(s=="this") return true;
if(s=="is") return true;
if(s=="desk") return true;
if(s=="top") return true;
if(s=="desktop") return true;
return false;
}
void Helper(string &inputS, int start, string &tmpStr, vector &res)
{
if(start == inputS.size())
{
//删除多余的空格
tmpStr.erase(tmpStr.end()-1);
res.push_back(tmpStr);
//补回来以便正确的backtracking
tmpStr.push_back(' ');
return;
}
int i;
stri... 阅读全帖
j*****y
发帖数: 1071
16
来自主题: JobHunting版 - G 家电面面经
这是最后的 code
vector plusOne(vector &input)
{
if(input.size() == 0)
{
return vector(1, 1);
}

int remainder = 1;
for(int i = input.size() -1 ; i > -1; --i)
{
int tmp = input[i] + remainder;
if(tmp >= 10)
{
input[i] = tmp - 10;
remainder = 1;
}
esle
{
input[i] = tmp;
remainder = 0;
break;
}
}
if(remainder != 0)
{
vector tmp(1, remainder);
input.insert(input.begin(),... 阅读全帖
j**7
发帖数: 143
17
来自主题: JobHunting版 - 攒RP,ZocDoc 面经
第二题:
int list []={2,3,-2,-1};
System.out.println(zeroSum(list));
static boolean zeroSum(int [] input)
{

if (input[0] == 0) {
return true;
}

HashSet set = new HashSet();
set.add(0);
set.add(input[0]);

for (int i = 1; i < input.length; i++) {
input[i] = input[i] + input[i - 1];
if (set.contains(input[i]) == false) {
set.add(input[i]);
} els... 阅读全帖
p*****2
发帖数: 21240
18
来自主题: JobHunting版 - G 家电面题目, 欢迎讨论!
p = (x)->
console.log x
dfs=(input, i, res)->
if i==input.length
p res
return

if input[i]!='?'
dfs input, i+1, res+input[i]
else
dfs input, i+1, res+'0'
dfs input, i+1, res+'1'

f=(input)->
dfs input, 0, ""

f "1??"
f "100100?00?"
r****s
发帖数: 1025
19
来自主题: JobHunting版 - 不要对烙印有一丝好感
here you go, 是不是太复杂了?
public Class TwoSum {
Map searchMap = new HashMap();
public void get2Sum (int[] input, int sum){
for (int i=0; i< input.length; i++) {
searchMap.put(sum-input, i);
}
for (int i=0; i if (searchMap.containsKey(input[i] && searchMap.get(input[i]!=i)
System.out.println("2sum: "+input[i]+" "+input[searchMap.get(
input[i]));
}
}
}
M**********g
发帖数: 59
20
其实再store的方法加个synchronized 就可以了,
每当有线程调用store方法的时候,这个对象就上锁了,其他线程就不能访问了。
下面是原题,和我写的实现
public interface TwoSum {
/**
* Stores @param input in an internal data structure.
*/
void store(int input);

/**
* Returns true if there is any pair of numbers in the internal data
structure which
* have sum @param val, and false otherwise.
* For example, if the numbers 1, -2, 3, and 6 had been stored,
* the method should return true for 4, -1, and 9, but false for 10, ... 阅读全帖
t******n
发帖数: 2939
21
☆─────────────────────────────────────☆
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
的素数整除) 的前提下, 居然有人会认为这个证明是错的, 或者是不完备的.
我实在不能理解.
求问一下大家, 是不是有的人的脑子天生有缺陷, 根本怎么教都不会明白... 阅读全帖
w*******t
发帖数: 960
22
来自主题: Hardware版 - 熟悉iptables的看进来
一个困惑了一天的iptables问题要请教,
ubuntu V14,我设置了22等几个端口允许,其他的都block了。 但为何我的asterisk里
还能看见人不停的试我的密码,端口就不在允许范围内
下面是我的iptables -S输出
=====================================================================
-A INPUT -p tcp -m multiport --dports 22 -j fail2ban-ssh
-A INPUT -i lo -j ACCEPT
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 5060:5061 -j ACCEPT
-A INPUT -p tcp -m tcp --dpo... 阅读全帖
t******k
发帖数: 599
23
来自主题: Biology版 - chip-qpcr 结果分析的问题
分析chip-qpcr的结果头大了。求教!
1和2两个样品。1是取10%作为input,90%做抗体ip。
2是300取10做input,150左右做抗体ip,剩下的做igg。
用了两种计算方法,一个是%input。还有一个是用内参算。发现用%input的方法算光
两组内参就有10倍的差别。第二种方法是用公式 2^(ct input基因-ct 抗体基因)/2^(
ct input内参-ct 抗体内参),但是这个方法的话没有考虑当时取内参的百分比。查了
文献,感觉%input的方法用的比较多,而且也矫正了取input时候的%,但是没有算内
参,觉得整个操作过程中如果有损失的话就不能靠内参矫正了。第二种方法比较适合我
这种低智商程度,觉得很直接,而且也用内参矫正,不过不知道需不需要考虑取input
时候的%?
w*******y
发帖数: 60932
24
Link:
http://accessories.us.dell.com/sna/productdetail.aspx?sku=A3913945
The 42" class (42" diagonal) LC-42SB48UT, with full HD spec 1080p resolution
and an elegant design, produces superb picture quality. The LC-42SB48UT
features high contrast, a fast response time and wide viewing .
Market Value1 $949.99
Total Savings $490.00
Dell Price $459.99
10% cashback from Discover Card if you shop through their site and pay using
their CC.
Highlights
Experience full HD 1080p... 阅读全帖
w*******y
发帖数: 60932
25
Onkyo HT-S7409 5.1 Package:
http://www.amazon.com/gp/product/B005EP2HKW/ref=oh_o02_s00_i00_
From google market search:
http://www.google.com/products/catalog?q=Onkyo HT-S7409&hl=en&prmd=imvns&bav=on.2,or.r_gc.r_pw.,cf.osb&biw=1150&bih=887&um=1&ie=UTF-8&tbm=shop&cid=16681874398136302789&sa=X&ei=03PWTpTnGM2gtwfd5tmeCA&ved=0CGIQgggwAA#scoring=p
#scoring=p" rel="nofollow" target="_blank" onclick="_gaq.push(['_trackEvent'
, 'thread', 'click', '3639242 - onkyo-hts7409-5.1-receiverspeaker-package-
488-... 阅读全帖
w*******y
发帖数: 60932
26
Link:
http://www.target.com/p/Westinghouse-40-Class-1080p-120hz-LED-L
$399.00 Online Price
Save $100.99 (20%)
Westinghouse 40" Class 1080p 120hz LED LCD HDTV - Black (LD-4055)
Put your Westinghouse 40" HD TV wherever you'd like. The screen is big
enough to mount on the wall, but small enough to fit on a tabletop using its
detachable base. The 1080p resolution will provide bright, clear imagery.
Watching TV and movies has never been so fun.
o Screen Size: 40.0 "
o Video Resolution: HD - 10... 阅读全帖
w*******y
发帖数: 60932
27
Link:
http://www.walmart.com/ip/Element-55-ELGFW551/15190106
Catch the game in full HD on this Element 55" 1080p HDTV. The full-HD 120Hz
picture shows you all the details you've been missing, and its 16:9 aspect
ratio makes it perfect for watching widescreen movies and TV shows. Plus,
the three HDMI inputs on this Element LCD HDTV help you get the most out of
your HD-capable components.
Note: You must have a source of HD programming in order to take full
advantage of the Element 55" 1080p HDTV. ... 阅读全帖
w*******y
发帖数: 60932
28
Target had this TV for $399 as their BF deal. It's now $349.
Features:
Screen Size: 40.0 "
Video Resolution: HD - 1080p
Maximum Resolution: 1920 x 1080
Television Features: 120Hz
Mounting Features: Detachable Base Stand, Wall Mountable
Electronic Functions: Built-in Speakers, Computer Monitor
Screen Refresh Rate: 120 Hz
Response Time: 6ms Response Time
Contrast Ratio: 4000:1
Video Upconversion: 1080p
Comb Filter Type: 3D Y/C Digital
Tuner Type: Digital, ATSC/NTSC
HD Compatibility: ATSC/NTSC, HD ... 阅读全帖
w*******y
发帖数: 60932
29
Marantz SR5006 7.1 Home Theater Receiver (Refurbished w/ 1-year warranty)
$469 Shipped from www.accessories4less .com.:
http://www.accessories4less.com/make-a-store/item/MARSR5006/Mar
Manufacturer's Link:
http://us.marantz.com/us/Products/Pages/ProductDetails.aspx?Cat
AUDIO/VIDEO CONNECTIONS
? 7.1 Channels
? AM/FM Tuner
? 56Tuner Presets: Group A-G: each 8 channels
? 6 RCA Analog inputs (incl. Front RCA)
? 2 Optical, 2 Coaxial SPDIF Digital Inputs
? 6/1 HDMI ver.1.4a In/Out
CEC (Control)
ARC (A... 阅读全帖
w*******y
发帖数: 60932
30
Newegg.com:
http://www.newegg.com/Product/Product.aspx?Item=N82E16882117397
has the Pioneer VSX-821-K for $169.99 with free shipping. Tax applied in
some states. The price shows up as $179.99, so make sure to enter in Promo
Code "EMCYTZT1306". This deal ends 3/15. Below are some specs.
Also here is a link to the cnet review:
http://reviews.cnet.com/av-receivers/pioneer-vsx-821-k/4505-646
Product Description:
Product Type AV receiver .
Width 17.1 in .
Depth 14.3 in .
Height 6.6 in .
Weight 2... 阅读全帖
d******a
发帖数: 32122
31
来自主题: Military版 - 激光陀螺的秘密程序编码泄露了
原始basic
10 INPUT "What is your name: ", U$
20 PRINT "Hello "; U$
30 INPUT "How many stars do you want: ", N
40 S$ = ""
50 FOR I = 1 TO N
60 S$ = S$ + "*"
70 NEXT I
80 PRINT S$
90 INPUT "Do you want more stars? ", A$
100 IF LEN(A$) = 0 THEN GOTO 90
110 A$ = LEFT$(A$, 1)
120 IF A$ = "Y" OR A$ = "y" THEN GOTO 30
130 PRINT "Goodbye "; U$
140 END
QBasic / QuickBasic
CLS
PRINT "Guess the number!"
INPUT "Would you like to play? (Y/N): ", choice$ ' An input statement,
that takes what the user inputs... 阅读全帖
z**x
发帖数: 3629
32
http://blogs.youwheel.com/2015/03/31/acura-sh-awd-comprehensive
Acura SH-AWD: A Comprehensive Analysis
Written By Editor on 2015-03-31, Posted in Car Chat, Technical Talk | 2
comments
The Acura SH-AWD system (short for: Super Handling-All Wheel Drive) is often
described ambiguously in most automobile literature. Some articles even
said it is an enhanced version of the Honda VTM-4, which is incorrect.
2012_Acura_TL_Rear
In this article, we will analyze the SH-AWD in detail, focusing on these
thre... 阅读全帖
c*****o
发帖数: 178
33
O(n) and no extra space.
int delete_dup(int* input, int length_d){
if(length_d <= 1 || !input)
return -1;
int pilot_d = 0;
int pilot_u = 0;
while(pilot_d < length_d){
do{
input[pilot_u++] = input[pilot_d++];
}while(input[pilot_d] != input[pilot_d+1] && pilot_d < length_d);
do{
pilot_d++;
}while(input[pilot_d] == input[pilot_d+1] && pilot_d < length_d);
}
return pilot_u;
}
j**l
发帖数: 2911
34
这道题就是那道被讨论得热火朝天的MS老题,如何把负数扫到左边,正数扫到右边。对
所有的正数和所有的负数,都不能改变原有的相对次序
/*
{1, 5, -5, -8, 2, -1, 15}
要把负的扫到左边,正的扫到右边。
不能改变顺序
得到{-5 -8 -1 1 5 2 15}
*/
void swap_numbers(int input[], int n)
{
int temp;
for (int i = 0; i < n; )
{
if (input[i] > 0 && i < n - 1 && input[i + 1] < 0)
{
temp = input[i];
input[i] = input[i+1];
input[i+1] = temp;
if (i > 0 && input[i-1] > 0)
i--;
else
i++;
Z*****Z
发帖数: 723
35
来自主题: JobHunting版 - google interview question
这是我今天interview的homework,正在写测试样例呢。帮我想想,呵呵。这是我现在有
的:
input:[0]
output:[zero dollar]
input:[0.01]
output:[zero dollar and one cent]
input:[1.100]
output:[one dollar and ten cents]
input:[1.00]
output:[one dollar]
input:[3.5]
output:[three dollars and fifty cents]
input:[000123004.56]
output:[one hundred twenty-three thousand and four dollars and fifty-six cen
ts]
input:[99123004.56]
output:[ninety-nine million and one hundred twenty-three thousand and four d
ollars and fifty-six cents]
input:[12345
s*******e
发帖数: 93
36
来自主题: JobHunting版 - 一道有关String的面试题
因为只是词被打乱,空格被删除,没有打乱整个词组,所以我想到的做法是
(应该可以work,但是可能效率不是最高的)
bool equals(string s1, string s2);
string firstNString(string s, int count);
string substringFromIndex(string input, int index);
string sort(string);
(以上几个function应该可以意会,就不implement了)
bool beginsWith(string input, string word)
{
return equals(sort( firstNString(input,word.length) ) , sort(word) );
}
struct result
{
string str;
bool ok;
}
typedef struct result Result;
Result function(string input, string[] words)
{
found=false;... 阅读全帖
d***n
发帖数: 832
37
来自主题: JobHunting版 - Amazon 面经
//pseudo code (c# like). it can be updated to record the path(s).
public bool CanReachTheMazeEnd(int[] input)
{
if(input == null || input.Length == 0) return false;
return CanReachTheMazeEndRecursive(input, 0, 0);
}
private bool CanReachTheMazeEndRecursive(int[] input, int index, int step)
{
if(index+step == input.Length-1) return true;

for(int i=1; i {
if(CanReachTheMazeEndRecursive(input, index+step, i))
{
return true;
... 阅读全帖
x*******i
发帖数: 777
38
来自主题: JobHunting版 - 求助C/C++高手:一道音频编程题
Write a program for mixing soundfiles, with the following
characteristics:
写一个音频合并的程序,包括以下内容
(a) accepting any soundfile formats supported by libsndfile
输入的音频文件的格式要被libsndfile支持。
libsndfile :a crossplatform library for soundfile manipulation.
(b) taking only uncompressed PCM format, in any (integer or floating-
point)
precision (8-bit (signed/unsigned), 16-bit, 24-bit, 32-bit, floats,
doubles).
接受未经压缩过的PCM编码格式的音频,这些音频的量化精度为浮点数或者整数(每个
sample分为
1 -100 就是整数,每个sample的值只有100个可能; 每个sample 分为1.00-10... 阅读全帖
y****n
发帖数: 743
39
这个应该可以,大家挑挑毛病
private static List FindMissing(List input)
{
List missing = new List();
int count = input.Count;
for (int i = 0; i < count; i++)
{
int value = input[i];
if (value < 0)
value += count;
if (input[value] >= 0)
input[value] -= count;
}
for (int i = 0; i < input.Count; i++)
{
if (input[i] >= 0)
missing.Add(i);
else
input[i] += count;
}
return missing;
}
A***o
发帖数: 358
40
来自主题: JobHunting版 - find the first missing positive integer.
O(n) time, O(n) space
int find(vector & input){
vector check;
check.resize(input.size(),0);
for(int i=0;i if(input[i]>0 && input[i]<=input.size())
check[ input[i]-1 ]=input[i];
}
for(int i=0;i if(check[i]==0)
return i+1;
}
return check.size()+1;
}
A***o
发帖数: 358
41
来自主题: JobHunting版 - find the first missing positive integer.
O(n) time, O(n) space
int find(vector & input){
vector check;
check.resize(input.size(),0);
for(int i=0;i if(input[i]>0 && input[i]<=input.size())
check[ input[i]-1 ]=input[i];
}
for(int i=0;i if(check[i]==0)
return i+1;
}
return check.size()+1;
}
D********g
发帖数: 650
42
来自主题: JobHunting版 - 一道G家店面题
20分钟写了大约下面的code,如果要输出string,还要backtrack:
static String word2Anagram(final String word) {
if (word == null) {
return null;
}

int ht[] = new int[256];
for (int i = 0; i < word.length(); ++i) {
int charVal = (int) word.charAt(i);
ht[charVal] ++;
}

StringBuilder anagram = new StringBuilder();
for (int i = 0; i < ht.length; ++i) {
if (ht[i] > 0) {
anagram.append((cha... 阅读全帖
p*****2
发帖数: 21240
43
写了一个deserialize的
class Element:
def __init__(self,str):
self.str=str
self.l=[]

def add(self,e):
self.l.append(e)

def ifstr(self):
return self.str!=None

input="[Apple,[Orange,Banana,[A,B,C]]"
i=0
def dfs():
global i
e=None
while input[i]==',' or input[i]==' ':
i+=1
if input[i]=='[':
e=Element(None)
i+=1
while input[i]!=']':
e.add(dfs())
else:
j=i+1
while inpu... 阅读全帖
r*c
发帖数: 167
44
来自主题: JobHunting版 - 问一道题(6)
贴个pattern字符串有重复字符的解法, 是dek,cpp1等大牛的解法的扩展。
#include
#include
#include
#include
using namespace std;
#define INT_MAX 2147483647
#define INT_MIN -2147483648
class MinWindowSolution
{
public:
struct TreeNode
{
TreeNode *parent;
int val;
vector children;
TreeNode(int i, TreeNode *p) : val(i), parent(p){}
};
void FindMinWindow_Tree(const vector& input , const vector&
query , int& nStart,... 阅读全帖
r*c
发帖数: 167
45
来自主题: JobHunting版 - 问一道题(6)
之前写了个C#的。思路都一样, use tree matching algorithm to determine the
candidate window.
//using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
class MinWindowSolution
{
class TreeNode
{
public TreeNode parent;
public int val;
public List children;
public TreeNode(int i, TreeNode p) { val = i; parent = p; children =
new List(); }
};
public void FindMinWindow_Tree(int[] input, int[] query, out int nS... 阅读全帖
S******6
发帖数: 55
46
来自主题: JobHunting版 - 几道FG的面试题
探讨下,我觉得这道题目是为了找每个id下面链接id的weight和,要避免死循环。
所以我在您code基础上做了点修改:
void PrintSubTreeSum(vector > &Input)
{
int size = Input.size();
if(size == 0) return;
vector res(size, 0);
for(int i = 0; i < size; i++)
{
map mp;
res[i] += Input[i][2];
mp.push_back(Input[i][0]);
int p = Input[i][1];
while(mp.find(p) == mp.end())
{
mp.push_back(p);
res[i] += Input[p][2];
p = Input[p][1];
}
}... 阅读全帖
w*****j
发帖数: 226
47
来自主题: JobHunting版 - 秒杀valid number
用自动机写的
求批判
个人觉得自动机的好处是可视化,只要图画对,代码不容易写错
corner case看得也比较清楚
enum State
{
ErrorState
{
@Override
public boolean isValid() { return false; }
},
EndState,
StartState
{
@Override
public State readDigit() { return DigitState; }
@Override
public State readPlus() { return PlusState; }

@Override
public State readMinus() { return MinusState; }

@Override
public State readPoin... 阅读全帖
w*****j
发帖数: 226
48
来自主题: JobHunting版 - 秒杀valid number
用自动机写的
求批判
个人觉得自动机的好处是可视化,只要图画对,代码不容易写错
corner case看得也比较清楚
enum State
{
ErrorState
{
@Override
public boolean isValid() { return false; }
},
EndState,
StartState
{
@Override
public State readDigit() { return DigitState; }
@Override
public State readPlus() { return PlusState; }

@Override
public State readMinus() { return MinusState; }

@Override
public State readPoin... 阅读全帖
p*****2
发帖数: 21240
49

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);
... 阅读全帖
r*****n
发帖数: 35
50
Scala code, not tested
object Parenthesis {
def main(args: Array[String]) {
val ret = constructTree("1+3*5")
println("start")
ret.foreach(println)
}
def wrap(c: Char): (Int, Int)=>Int = {
c match {
case '+' => (x, y) => x + y
case '-' => (x, y) => x - y
case '*' => (x, y) => x * y
}
}
def constructTree(input: String): Array[Int] = {
var split = false
var ret = (0 until input.length).flatMap{ idx =>
input(idx) match {
case '+' ... 阅读全帖
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)