由买买提看人间百态

topics

全部话题 - 话题: allpath
(共0页)
b*******n
发帖数: 847
1
谢谢!
经过你提醒我改了我的code,这回过了,发现用array的index来referecen简单多了
/**
* Definition for binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
vector > levelOrderBottom(TreeNode *root) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
vector > traversal;
vector path;
vector阅读全帖
b*******n
发帖数: 847
2
如题,我想实现先把整个tree breadth-first traverse,traverse结果放在vector里
(vector allPath)
,每层遍历到了最后加一个tag node,最后把vector从后往前scan。想法很简单,但
code总是有错。我对vector不熟,估计是member function没用对,请大家帮忙看看,
多谢了!
vector > levelOrderBottom(TreeNode *root) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
vector > traversal;
vector allPath;
if(!root) return traversal;
TreeNode *tag=new TreeNode(0);
al... 阅读全帖
d**e
发帖数: 6098
3

不知我有没有理解错,我觉得这个if有可能导致死循环。
比如是
1
/ \
2 3
开始时allPath: 1, tag
it指向1时,allPath: 1, tag, 2, 3
it指向tag时,allPath: 1, tag, 2, 3, tag
it指向2,3时不变,仍是allPath: 1, tag, 2, 3, tag
it指向最后一个tag时,加一个tag,allPath: 1, tag, 2, 3, tag, tag
再指下一个tag,再加一个tag,继续指到下一个tag。。。
right
a********n
发帖数: 1287
4
来自主题: JobHunting版 - 问两道facebook面试题
#include
using namespace std;
// 0 means right, 1 means down
void AllPath(int N, int row, int col, int path[], int idx) {
if(row==N-1 && col==N-1) {
for(int i=0; i<2*N-2; i++) {
cout << path[i] << " ";
}
cout << endl;
}
// go down
if(row != N-1) {
path[idx] = 1;
AllPath(N, row+1, col, path, idx+1);
}
// go right
if(col != N-1) {
path[idx] = 0;
AllPath(N, row, col+1, path, idx+1);
}
}
in... 阅读全帖
e*******i
发帖数: 56
5
来自主题: JobHunting版 - matrix question
The last solution has a bug, it will loop forever.
Following is tested to work.
/*****************************************/
int A[4][4]={
{1,1,1,1},
{0,1,1,1},
{0,1,1,1},
{0,0,0,1}
};
struct Delta
{
int dx;
int dy;
};
Delta d[4]={
{0,1}, {1,0}, {-1, 0}, {0,-1} };
void dfs(vector< pair > &edgeTo, int *A, int m, int n, int i, int
j)
{
if( i>=m || j>=n || *(A+i*m+j)!=1 ) return;
edgeTo.push_back( pair(i,... 阅读全帖
x*******a
发帖数: 11067
6
来自主题: Computation版 - Execute file under a UNC path in Matlab
(UNC path is what you see when you use your network neighbours.
Its usually in the form of \\theOtherComputer\sharedDirectory\ )
I can copy and remove files to a UNC path, however, when I try to
execute the copied executable, Matlab gives error:
??? Error using ==> dos
DOS commands may not be executed when the current directory is a UNC
pathname.
The following is the code:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
allpath='\\node2\share\temp '
cd(allpath)
copyfile E:\DUMMY.EXE
! DUMMY.EXE
%%%%%%%%%%%%%%%%%
f*******i
发帖数: 8492
7
你发帖说沈AP读同济研究生不容易
我就回了一贴说在同济01届经管学院毕业生中没有沈AP的名字,结果你丫就把所有帖子
都删了
你到底是什么意思??
沈AP的CV
http://people.clemson.edu/~shenh/
同济经管学院01届毕业生名单
http://sem.tongji.edu.cn/index/index/alumni_category_classes.js
id=192&allpath=(00172),(00192)
而且同济经管学院根本就没有Information Management这一个方向。
y******g
发帖数: 710
8
应该是03届,00年入学的属于03届,有她名字。
03届 > 管理科学与工程
http://sem.tongji.edu.cn/index/index/alumni_students.jsp?
id=278&name=%B9%DC%C0%ED%BF%C6%D1%A7%D3%EB%B9%A4%B3%CC&allpath=(00172),
(00193),(00278)&origin=alumni_category_classes
不过怎么变成管理科学了,不是计算机系吗
p*****2
发帖数: 21240
9
来自主题: JobHunting版 - 问两道facebook面试题
第一题这样可以吗?
public class Game
{
private void FindPath(int total, int x, int level, List path)
{
if (path.Count == x)
{
foreach (int i in path)
Console.Write("{0} ", i);
Console.WriteLine();
return;
}
for (int i = level; i < total; i++)
{
path.Add(i);
FindPath(total, x,i + 1, path);
path.RemoveAt(path.Count - 1);
}
}
public void AllPaths(int x,... 阅读全帖
l******s
发帖数: 3045
10
两个Queue也可以吧,Queue 和 Queue,保持两个Queue同步就行了

It's accepted by leetcode.
private IList allPath(TreeNode root){
Queue queue = new Queue();
Queue qStr = new Queue();
IList result = new List();
if(root == null) return result;
queue.Enqueue(root); qStr.Enqueue(root.val.ToString());
while(queue.Count != 0){
TreeNode cur = queue.Dequeue();
string curStr = qStr.Dequeue();
if(cur.le... 阅读全帖
(共0页)