由买买提看人间百态

topics

全部话题 - 话题: getpath
(共0页)
Z**********4
发帖数: 528
1
来自主题: JobHunting版 - matrix question
vector > matrixPath(vector > matrix){
vector > paths;
int m = matrix.size();
if(m==0) return paths;
int n = matrix[0].size();
if(n==0) return paths;
vector solution;
getPath(matrix, paths, 0, 0, solution, m, n);
return paths;
}
void getPath(vector >& matrix, vector >& paths,
int i, int j, vector solution, int m, int n){
if(i==m-1 && j==n-1){
solution.push_back(indexToString(i,... 阅读全帖
f*********5
发帖数: 576
2
void GetPath(node * root, vector&vec,int target)
{
if(!root) return;
if(vec.size()>0)
{ sum=0;
for(int i=vec.size()-1;i>=0;i--)
{ sum+=vec[i];
if(sum==target) { PRINT;break;}
}
}
vec.push_back(root->data);
if (root->left) GetPath(root->left,vec,target);
if (root->right) GetPath(root->right,vec,target);
return;
}

level
Design an
d*******l
发帖数: 338
3
来自主题: JobHunting版 - 这个facebook puzzle样题怎么做?
这学期试着在学习python,用python也写了一个。力求简练,效率应该不怎么高。
def getpath(now, visited, steps):
if now == visited[h(now)]:
print steps;
return ;
prev = visited[h(now)];
p = [i for i in xrange(0, len(now)) if now[i] != prev[i]][0];
getpath(prev, visited, steps + 1);
print prev[p], now[p];
def h(node):
return ''.join([str(n) for n in node]);

def solve(N, K, init, target):
q = [init];
visited = {h(init):init};
while q != []:
now = q.pop(0);
if no... 阅读全帖
l*****a
发帖数: 14598
4
来自主题: JobHunting版 - 问道amazon面试题
void GetPath(int size, int x,int y,vector& vec)
{
if(x==size&&y==size)
{ vector::iterator it;
for(it=vec.begin();it!=vec.end();++it) { cout<<*it; }
cout< return;
}
if(x vec.push_back('R');
GetPath(size,x+1,y,vec);
vec.pop_back();
}
if(y vec.push_back('D');
GetPath(size,x,y+1,vec);
vec.pop_back();
}
return;
}
v***n
发帖数: 562
5
下面那个is_free方法是什么作用?谢谢!
下面第四版的解答:
􀀙􀀏􀀓􀀁 Imagine a robot sitting on the upper left hand corner of an NxN
grid. The robot can
only move in two directions: right and down. How many possible paths are
there for
the robot?
FOLLOW UP
Imagine certain squares are “o$ limits”, such that the robot can not
step on them.
Design an algorithm to get all possible paths for the robot.
pg 64
Part 1: (For clarity, we will solve this part assuming an X by Y grid)
Each path has (X-... 阅读全帖
j********g
发帖数: 80
6
来自主题: JobHunting版 - leetcode出了新题word ladder
第二个过了Large的 轻拍
class Solution {
public:
vector> findLadders(string start, string end, unordered_
set &dict) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int size=dict.size();
int res=1;
int done=0;
stack stk[2];
unordered_set used;
unordered_map > path;
unordered_set level;
int index=0;
stk[index%2].push(start);
used.insert(start);
vector<... 阅读全帖
j********g
发帖数: 80
7
来自主题: JobHunting版 - leetcode出了新题word ladder
第二个过了Large的 轻拍
class Solution {
public:
vector> findLadders(string start, string end, unordered_
set &dict) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int size=dict.size();
int res=1;
int done=0;
stack stk[2];
unordered_set used;
unordered_map > path;
unordered_set level;
int index=0;
stk[index%2].push(start);
used.insert(start);
vector<... 阅读全帖
a*****a
发帖数: 46
8
来自主题: JobHunting版 - leetcode word break II DFS 超时
光用DP还不行,必须得等结束后回溯找所有路径才过了测试。。。
我在DP里存的是可能路径的所有节点(也可以只存上一个节点,但是那样回溯不好写)
,这样的话和仅DP的区别在于每次拷贝的只是节点,省掉的时间就是拷贝生成字符串的
时间。
呵呵,这测试真严格啊。C++的有没有可能不回溯也能过测试?
贴出code来,欢迎各位牛人指正~
private ArrayList getPath(String s, int n, ArrayList Integer>> pres) {
ArrayList res = new ArrayList();
for (int pre : pres.get(n-1)) {
if (pre == 0) {
res.add(s.substring(0, n));
} else {
ArrayList preres = getPath(s,... 阅读全帖
h*********d
发帖数: 336
9
来自主题: JobHunting版 - 大牛帮我看一段code
phone interview, 实现一个in-memory filesystem. 刚开始面试,还没有摸到门路,
请大牛指点
Write an in memory filesystem! This is a simplified file system that only
supports directories. Your code needs to read from a file and parse the
commands listed below.
cd - Changes the current working directory. The working
directory begins at '/'. The special characters '.' should not modify the
current working directory and '..' should move the current working directory
to the parent.
mkdir - Creates a new dire... 阅读全帖
c*****t
发帖数: 1879
10
来自主题: Database版 - recursive query help
我有一 DAG table T,里面是
src name,
dst name,
value int
比如
a, b, 1
b, c, 2
a, d, 3
我现在需要做很多 path 的 query,需要得到 int[],也就是说
select getPath ('a', 'c');
结果应该是
[1,2]
有可能有多种 path,可以取最短的。
我之所以需要做该 query,是我有另外一个 table inputTable 是 pair,
需要得到。注意的是该 table 里有很多重复的 src, dst 。
select compute (getPath (T.src, T.dst), T.cost)
from inputTable T;
有什么好的办法?
多谢
n********6
发帖数: 1511
11
来自主题: Database版 - recursive query help
没看懂啊。
getPath(a,c)怎么就从
里面得到(1,2)呢?
b***i
发帖数: 3043
12
网上有一个从本地用ZipFile读的,但是我要applet,就不知道怎么做了。
那个网页说用JarURLConnection,也用了,具体到了读入就读入了-1,大侠帮帮妈忙?
URL url0 = baseClass.class.getResource(jarFileName);
String ok = "jar:file:"+ url0.getPath()+"!/"+name; // name is file name
inside
URL url=new URL(ok);
JarURLConnection conn = (JarURLConnection)url.openConnection();
ZipEntry ze=(ZipEntry)conn.getJarEntry();
int size=(int)ze.getSize();
InputStream fis= conn.getInputStream();
BufferedInputStream bis=new BufferedInputStream(fis);
ZipInputStream zis=new ZipInpu
e*****t
发帖数: 1005
13
not sure, but have you tried to use
File.getCanonicalPath(), File.getPath() or File.getAbsolutepath()?
(共0页)