由买买提看人间百态

topics

全部话题 - 话题: prev
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
w***5
发帖数: 8282
1
来自主题: Seattle版 - 西雅图机场TSA preV
在check point 3
拿到boarding pass赶紧看看是不是TSA preV。
是的话,就找preV的口进机场,一般不用排队。
不用脱外套
不用脱鞋
不用取除laptop
不用解开皮带
不用照X光
。。。
看看DL的月刊,DL的hub机场都可以TSA preV。
其他可以TSA preV的airport
http://www.tsa.gov/sites/default/files/assets/pdf/location_char
w***5
发帖数: 8282
2
来自主题: Travel版 - TSA preV
拿到boarding pass赶紧看看是不是TSA preV。
是的话,就找preV的口进机场,一般不用排队。
不用脱外套
不用脱鞋
不用去除laptop
不用解开皮带
不用照X光
。。。
看看DL的月刊,DL的hub机场都可以TSA preV。
可以TSA preV的airport
http://www.tsa.gov/sites/default/files/assets/pdf/location_char
w*******y
发帖数: 60932
3
Link:
http://store.apple.com/us/browse/home/specialdeals/ipod/ipod_nano?afid=p201|227502&cid=AOS-US-AFFC
Apple Store Outlet has low prices + Free Shipping on the Previous Generation
Factory Recertified Apple iPod Nanos. Various colors available. Tax in most
.
NOTE: There are the previous generation models with video camera and FM
tuner. You get the SAME 1yr warranty you get when you buy new.
iPod Nano 8GB (Prev 5th Generation) $99.00 Free Shipping
Back in Stock. iPod Nano 16GB (Prev 4th Generati... 阅读全帖
v****y
发帖数: 1084
4
来自主题: Seattle版 - 西雅图机场TSA preV
为啥可以 prev?如何防炸弹?
s******x
发帖数: 15232
5
来自主题: Seattle版 - 西雅图机场TSA preV
有良民证的可以节省麻烦一些
注意,是pre✓,不是prev
w***5
发帖数: 8282
i*******y
发帖数: 225
7
Preventing passenger vehicle occupant injuries by vehicle design – a
historical perspective from IIHS.
O'Neill B. Traffic Inj Prev. 2009 Apr;10(2):113-26.
周末两天only. 多谢!
g*********e
发帖数: 14401
8
来自主题: JobHunting版 - leetcode Sort List
我的也很长,但不用每个recursion都寻找中间node的位置。
class Solution {
public:
ListNode *merge(ListNode *a, ListNode *b, ListNode *&last) {
ListNode *res=NULL;
ListNode *prev=NULL;
while(a && b) {
if(res==NULL)
res=(a->val < b->val) ? a:b;
if(a->val < b->val) {
if(prev)
prev->next=a;
prev=a;
a=a->next;
} else {
if(prev)
prev->next=b;... 阅读全帖
D********g
发帖数: 650
9
This is a pretty tricky question, especially for the loop handling. Here is
my java code, tested with looped case and non-looped case.
public static class DLLNode {
DLLNode prev;
DLLNode next;
int value;

public DLLNode(int value) {
this.value = value;
prev = null;
next = null;
}
}
static DLLNode dummy = new DLLNode(-1);
static DLLNode loopDummy = new DLLNode(-2);
static void printLL(final DLLN... 阅读全帖
r**h
发帖数: 1288
10
来自主题: JobHunting版 - 新鲜的T电面题

好几种括号的情况下,就要用stack存下前面出现过的左号({[,而不是仅仅用一个变量
来计数了
然后是漫长的match,不知道code可不可以简化的
def check(a, n, prev):
if n == len(a):
return len(prev) == 0

if a[n] == '{':
prev.append('{')
elif a[n] == '}':
if len(prev)!=0 and prev[len(prev)-1] == '{':
prev.pop()
else:
return False
elif a[n] == '[':
prev.append('[')
elif a[n] == ']':
if len(prev)!=0 and prev[len(prev)-1] == '[':
prev.pop()
else:
... 阅读全帖
b******p
发帖数: 49
11
来自主题: JobHunting版 - leetcode上的Sort List那道题
我来贴个CPP的(注意:以下有乱七八糟的code……)
合并排序确实比较好用,我还在写第一遍leetcode,代码风格也比较乱,带了很多
debug code,还带了测试用例,试了9次才通过…
有一些多边界条件需要判断的。我的方法是加很多debug,或加很多assertion(我做别
的题里面经常用assertion……不知道是不是好习惯)
============================
#include
#include
using namespace std;
/*
Merge sort ?
*/
// Start: 22:40
// End: 23:45 用了一个小时
//Definition for singly-linked list.
struct ListNode {
int val;
ListNode *next;
ListNode(int x) : val(x), next(NULL) {}
};
#define TOMMYDBG
class Solution {
public:
... 阅读全帖
a******e
发帖数: 710
12
来自主题: JobHunting版 - 狗狗家onsite面经
开始只是想到了O(n)的算法。 O(m)的算法可以这么实现
#include
#include
using namespace std;
struct DListNode {
char val;
DListNode *prev;
DListNode * next;
DListNode(char v): val(v), prev(nullptr), next(nullptr) {}
};
void printList(DListNode* head){
while (head!=nullptr) {
cout<val<<", ";
head = head->next;
}
cout< }
void printSet(unordered_set &s) {
for (auto iter=s.begin(); iter!=s.end(); ++iter)
cout<<(*ite... 阅读全帖
a***e
发帖数: 413
13
最近几天的少得可怜的准备时间都在看这个。60多行程序改个地方就通不过了。区别仅
在于
while(1)
{
r.push_back(p->val);
if(p==from)
break;
p = p->right;
}
不能改成
while(p!=from)
{
r.push_back(p->val);
p = p->right;
}
哎,可能还是因为这个算法不是自己想出来的,总是糊涂。
偶尔说起来,别人说那种属于比较偏的题了,如果问道肯定是存心要fail某人。
就是好奇有没有人真被问到。
能通过OJ的,
void reverse(TreeNode *from, TreeNode *to)
{
if (from==to)
return;

TreeNode *... 阅读全帖
H****n
发帖数: 26
14
如题,请大师们帮帮忙,编译器现在主要报错在静态变量打初始化部分,我百思不得其
姐。
#include
using namespace std;
class link{
private:
string ss;
link *prev;
link *next;
static int count; //the counter to show how many nodes
int pos; //the position to insert node
static link* fp; //a temp node for insertion
static link* head;
static link* tail;
public:
link(string s1="", int i=0):ss(s1),pos(i){
if(head==NULL&&tail==NULL){
... 阅读全帖
a***e
发帖数: 413
15
牛。多谢!
但是我看了那个blog写的preorder和inorder OJ里面就是通不过,Inorder的弄到VS里
面debug半天,还是不知道哪里有问题,
Last executed input:
{1,2}
在VS里面能通过,不知道怎么回事。如果要问postorder Morris就简直太无语了,各位
有在面试中碰到的么?
vector inorderTraversal(TreeNode *root) {
vector ret;
TreeNode *r = root;
TreeNode *prev=NULL;
while(r!=NULL)
{
if(r->left==NULL)
{
ret.push_back(r->val);
r=r->right;
}
else
{
//find prede... 阅读全帖
l****p
发帖数: 397
16
来自主题: JobHunting版 - G家onsite面经
确实想不出比mlg(N)更快的算法。这题要在30分钟内做完确实很难,我看了楼主的思路
后还用了近50分钟才写完的……
顺便贴上我的实现(Ruby):
def nearest_nodes root, m, key
node = find_insert root, key
prev = node.prev_node
nex = node.next_node
results = []
m.times do
nearest = nil
if prev and nex
if m-prev.value nearest = prev
prev = prev.next_node
else
nearest = nex
nex = nex.next_node
end
elsif prev
nearest = prev
prev = prev.prev_node
elsif nex
nearest ... 阅读全帖
L*********5
发帖数: 43
17
来自主题: JobHunting版 - M家 onsite 悲剧,同胞们弄死烙印吧
一下程序只用了两个指针 prev 和 post (已经验证过啦 是对的哦)
我分别讨论了三种情况 (1) < 2 node (2) = 2 node (3) > 2 node
对于大于两个node的情况 (初始化 prev = 第一个node,post = 第二个node),
以奇数 node 为 current, prev 设为 current 前一个, post设为current->next。
void PairReverse (Node **headpt) {
//None node or one-node case
if (*headpt == NULL || (*headpt) -> next == NULL) {
printf ("Less than two nodes are in the list.\n");
return;
}
Node *prev = *headpt, *post = (*headpt) -> next;
//Two-node case
//e.g. 1 2, then ... 阅读全帖
L*********5
发帖数: 43
18
来自主题: JobHunting版 - M家 onsite 悲剧,同胞们弄死烙印吧
一下程序只用了两个指针 prev 和 post (已经验证过啦 是对的哦)
我分别讨论了三种情况 (1) < 2 node (2) = 2 node (3) > 2 node
对于大于两个node的情况 (初始化 prev = 第一个node,post = 第二个node),
以奇数 node 为 current, prev 设为 current 前一个, post设为current->next。
void PairReverse (Node **headpt) {
//None node or one-node case
if (*headpt == NULL || (*headpt) -> next == NULL) {
printf ("Less than two nodes are in the list.\n");
return;
}
Node *prev = *headpt, *post = (*headpt) -> next;
//Two-node case
//e.g. 1 2, then ... 阅读全帖
k*****y
发帖数: 744
19
来自主题: Quant版 - 问一个面试题,关于概率的
int main()
{
const int N = 63;
const int MAX = N + 6;
double prob[ MAX+1 ];
double ans[ MAX+1 ];
double visit[ MAX+1 ];
for( int ith=0; ith<=MAX; ++ith ){
prob[ ith ] = ( ith>=1 && ith<=6 ) ? 1./6 : 0;
ans[ ith ] = 0; visit[ ith ] = 0;
}

for( int runtime=2; runtime<=MAX; ++runtime ){
for( int ith=MAX; ith>=0; --ith ){
if( ith <= N) prob[ ith ] = 0; // reset if the state is
transient

for( int num=1;... 阅读全帖
p*****2
发帖数: 21240
20
我写了一个,有点繁琐,还没测试。
void connectSibling(Node root)
{
assert(root!=null);

Node[] layer = new Node[2];
layer[0]=root;
int i=0;

while(layer[i%2]!=null)
{
Node prev=null;
Node curr=layer[i%2];

while(curr!=null)
{
if(curr.left!=null)
{
if(prev==null)
{
prev=curr.left;
... 阅读全帖
p*****2
发帖数: 21240
21
我写了一个,有点繁琐,还没测试。
void connectSibling(Node root)
{
assert(root!=null);

Node curr=root;

while(curr!=null)
{
Node prev=null;
Node next=null;

while(curr!=null)
{
if(curr.left!=null)
{
if(prev==null)
{
prev=curr.left;
next=prev;
}
... 阅读全帖
p*****2
发帖数: 21240
22
来自主题: JobHunting版 - 请教一道单链表问题
import java.io.*;
import java.util.*;
public class test3
{
public static void main(String[] args) throws Exception
{
new test3().run();
}
PrintWriter out = null;
void print(Node head)
{
while (head != null)
{
out.print(head.value + " ");
head = head.next;
}
out.println();
}
Node remove(Node head)
{
Node prev = head;
head = null;
Node pp = null;
while (prev != null)
... 阅读全帖
I****h
发帖数: 33
23
来自主题: JobHunting版 - 请教一道单链表问题
PNode trim_list(PNode begin)
{
Node head = {0};
PNode anchor = NULL;
PNode prev = NULL;
PNode curr = NULL;
int trim = 0;
if ((begin == NULL) || (begin->key != 0))
{
head.key = 0;
}
else
{
head.key = 1;
}
head.next = begin;
anchor = &head;
prev = &head;
curr = begin;
while (curr != NULL)
{
if (prev->key != curr->key)
{
if (trim == 0)
{
anchor = prev;
... 阅读全帖
p*****2
发帖数: 21240
24
来自主题: JobHunting版 - One interview question (A)
代码
size=100
class Element:
def __init__(self,obj,prev):
self.obj=obj
self.prev=prev
self.next=-1

class HashSet:
l=[None]*size
last=-1
def insert(self,obj):
h=hash(obj)%size
if self.l[h]==None:
self.l[h]=Element(obj,self.last)
if self.last!=-1:
self.l[self.last].next=h
self.last=h

def delete(self,obj):
h=hash(obj)%size
if self.l[h]!=None:
pv=self.l[se... 阅读全帖
x******a
发帖数: 6336
25
//main()
#include
#include
#include "linkedlist.h"
int main()
{
LinkedList myList(5, "luke");
Iterator myIterator=myList.begin();
myList.insert(myIterator, "leia");
myIterator.forward();
myList.erase(myIterator);
myList.insert(myIterator, "chewbca"); 《======出问题。
myList[2]="han";
for (int i=0; i std::cout< }
myList.insert(myIterator, "chewbca"); 《======出问题。
这一句运行起来ta... 阅读全帖
l*********h
发帖数: 15
26
贴一个我的
public class LRUCache {
private Map map;
private Entry head;
private int size;
private final int CAPACITY;
private class Entry {
private int key;
private int val;
private Entry prev, next;
private Entry(){}
public Entry (int key, int val) {
this.key = key;
this.val = val;
}
}
public LRUCache(int capacity) {
map = new HashMap();
head = new Entry... 阅读全帖
R*********d
发帖数: 34
27
来自主题: 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
28
来自主题: 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(){
... 阅读全帖
l*****g
发帖数: 685
29
来自主题: JobHunting版 - an interview question
Good question!
I was wrong. It's not really a BST, but rather a BT.
The nodes don't have explicit keys, and line numbers are implied by the in-
order traveral of the tree. Each node holds prevCount, number of all lines
before it, and nextCount, number of all lines after it.
Here is a rough implementation of this idea.
class Line
{
public:
//char * text;
Line * prev;
Line * next;
int prevCount;
int nextCount;
Line(char * text)
{
// clone text data
prev ... 阅读全帖
m******0
发帖数: 222
30
我认为DP很难做,很可能找不到DP解法,如果有的话请贴过来,学习一下。
用递归搜索是可以的,基本思路是每次递归,都记录了之前匹配过的partial的
matching,而且这些matching必须是连续的:
下面的code通过了基本测试:
T = ABA
S = ABABAA, ans=2
S = ABABABAAA, ans=3
S = ABAxxxABA, ans=2
S = ABAxxxABABAA, ans = 3
S = ABAxxxABABAx, ans = 2
(more test cases are welcome... )
string S, T;
// find max matches in S[pos ... end] given previous partial matches:
int search(int pos, vector prevMatch) {
if (pos == S.length()) // search is ended
return 0;
int ans1=-1, ans2=-1, ans3=... 阅读全帖
m********c
发帖数: 105
31
来自主题: JobHunting版 - 发个pure storage的interviewstreet题目
上周末做了pure storage的interviewstreet的题目,总共两道题,30分钟,今天晚
上就收到了拒信,下面是题目。
第一题是Remove all elements from a linked list of integers that have value N
,就是要实现下面的函数
void removeNode(int val, LinkedList **list)。
题目不算难,但是我刚看到pointer to pointer 一下子没想出来怎么做,想了半天,
最后写出来了,test cases5个过了3个,另外两个后来想了想是估计是因为处理修改
list的时候出错。下面是我写的代码。
void removeNode(int val, LinkedList **list) {
LinkedList *prev = *list;
while (prev && prev->val == val)
prev = prev->next;
// 估计是这里出错了,提交的代码里是 list = &prev,这算修改了list... 阅读全帖
m********c
发帖数: 105
32
来自主题: JobHunting版 - 发个pure storage的interviewstreet题目
上周末做了pure storage的interviewstreet的题目,总共两道题,30分钟,今天晚
上就收到了拒信,下面是题目。
第一题是Remove all elements from a linked list of integers that have value N
,就是要实现下面的函数
void removeNode(int val, LinkedList **list)。
题目不算难,但是我刚看到pointer to pointer 一下子没想出来怎么做,想了半天,
最后写出来了,test cases5个过了3个,另外两个后来想了想是估计是因为处理修改
list的时候出错。下面是我写的代码。
void removeNode(int val, LinkedList **list) {
LinkedList *prev = *list;
while (prev && prev->val == val)
prev = prev->next;
// 估计是这里出错了,提交的代码里是 list = &prev,这算修改了list... 阅读全帖
w*******e
发帖数: 395
33
来自主题: JobHunting版 - G电面的一个题
这道题目非常复杂,首先能想到n*log(n)的算法就不简单,即使想到了,能够在面试的
压力下把逻辑coding出来也非常的难。我感觉电面中,问到这种题目而且要coding的,
如果从没有见过,基本就是不让你过。感觉这种题目适合onsite用。
在知道算法后,我大概花了一些时间,写了如下的代码,基本思路就是楼上讨论的。
1. 首先把所有的interval的起点和终点存进一个vector,并且sort
struct timePoint {
int point;
bool startORend;
int vol;
timePoint(int p, bool s, int v): point(p), startORend(s), vol(v) {}
};
2. 建立一个multiset用来存储还没有结束的volume,同时可以用来判断某个时间段是
否被输入的interval cover了。
3. 然后扫描vector开始建立输出的vector:
1)如果碰到start的点,先检查multiset是否为空,如果是,就是i... 阅读全帖
w*******e
发帖数: 395
34
来自主题: JobHunting版 - G电面的一个题
这道题目非常复杂,首先能想到n*log(n)的算法就不简单,即使想到了,能够在面试的
压力下把逻辑coding出来也非常的难。我感觉电面中,问到这种题目而且要coding的,
如果从没有见过,基本就是不让你过。感觉这种题目适合onsite用。
在知道算法后,我大概花了一些时间,写了如下的代码,基本思路就是楼上讨论的。
1. 首先把所有的interval的起点和终点存进一个vector,并且sort
struct timePoint {
int point;
bool startORend;
int vol;
timePoint(int p, bool s, int v): point(p), startORend(s), vol(v) {}
};
2. 建立一个multiset用来存储还没有结束的volume,同时可以用来判断某个时间段是
否被输入的interval cover了。
3. 然后扫描vector开始建立输出的vector:
1)如果碰到start的点,先检查multiset是否为空,如果是,就是i... 阅读全帖
m***p
发帖数: 86
35
single linked list版本:
void reverse(Node head){
Node cur = head;
Node prev = null;
while(cur != null){
Node nextNode = cur.next;
cur.next = prev;
prev = cur;
cur = nextNode;
}
return prev;
}
double linked list版本:
void reverse(Node head){
Node cur = head;
Node prev = null;
while(cur != null){
Node nextNode = cur.next;
cur.next = prev;
cur.prev = nextNode;
prev = cur;
cur = nextNode;
}
re... 阅读全帖
y******g
发帖数: 4
36
来自主题: JobHunting版 - 这道狗家的题有什么好的思路吗?
#include
#include
#include
#include
using namespace std;
struct Item {
int counter;
char c;

Item(): counter(0), c('\0') {};
Item(int counter_, char c_) : counter(counter_), c(c_) {};
Item(const Item &anotherItem): counter(anotherItem.counter), c(
anotherItem.c) {};
};
struct ItemCompare {
Item* prev;

ItemCompare(Item* prevItem): prev(prevItem) {};

bool operator() (const Item &item1, const Item &item2) {
... 阅读全帖
m**q
发帖数: 189
37
来自主题: JobHunting版 - G面经
Good work.
I just coded a version using O(1) extra space, the down side
is it's not as clean (sigh) and I wasn't able to code it bug free
in my first try. The below code works for the specified input.
int water2(int a[], int n)
{
int i=0, prev=INT_MIN, sum=0;
int prev_high, new_high, prev_index;

while (i=prev) {
prev=a[i]; i++;
}
if (i==n)
return 0;

prev_high=prev, prev_index=i-1;

while (i int tmp=0;
while(i int diff... 阅读全帖
m**q
发帖数: 189
38
来自主题: JobHunting版 - G面经
Good work.
I just coded a version using O(1) extra space, the down side
is it's not as clean (sigh) and I wasn't able to code it bug free
in my first try. The below code works for the specified input.
int water2(int a[], int n)
{
int i=0, prev=INT_MIN, sum=0;
int prev_high, new_high, prev_index;

while (i=prev) {
prev=a[i]; i++;
}
if (i==n)
return 0;

prev_high=prev, prev_index=i-1;

while (i int tmp=0;
while(i int diff... 阅读全帖
p*****2
发帖数: 21240
39

import java.io.*;
import java.util.*;
public class test
{
public static void main(String[] args)
{
new test().run();
}
PrintWriter out = null;
void run()
{
Scanner in = new Scanner(System.in);
out = new PrintWriter(System.out);
int[] values = new int[]
{ 1, 4, 5, 6, 3 };
Node head = null;
Node prev = null;
for (int i : values)
{
Node node = new Node(i);
if (head == null)
... 阅读全帖
p*****2
发帖数: 21240
40
来自主题: JobHunting版 - 请教一道单链表问题
想了一个nlongn的,过了小数据,大数据runtime error.
int max = 0;
public int largestRectangleArea(int[] height)
{
max = 0;
find(height, 0, height.length - 1);
return max;
}
void find(int[] height, int x, int y)
{
int lowest = Integer.MAX_VALUE;
for (int i = x; i <= y; i++)
lowest = Math.min(lowest, height[i]);
max = Math.max(max, lowest * (y - x + 1));
int prev = x;
int i = x;
while (prev <= y && i <= y)
{
while (prev <= y && height[prev] == lowest)
prev++;
if(prev>y)
break;
i = prev + 1;
while (i <= y && height... 阅读全帖
j********x
发帖数: 2330
41
来自主题: JobHunting版 - 新鲜G面筋(2)
写了一个小时,没考虑特别的corner case,O(num of intervals of "except"),用了
上面提到的binary search:
#include
#include
#include
#include
#include
struct compareable_interval {
int start;
int end;
int real_start;
int real_end;

compareable_interval(int lhs, int rhs) : start(lhs), end(rhs), real_
start(lhs), real_end(rhs) {
}
compareable_interval(int l, int r, int rl, int rr) : start(l), end(r),
real_start(rl), real_end(rr) {
}
b... 阅读全帖
j********x
发帖数: 2330
42
来自主题: JobHunting版 - 新鲜G面筋(2)
写了一个小时,没考虑特别的corner case,O(num of intervals of "except"),用了
上面提到的binary search:
#include
#include
#include
#include
#include
struct compareable_interval {
int start;
int end;
int real_start;
int real_end;

compareable_interval(int lhs, int rhs) : start(lhs), end(rhs), real_
start(lhs), real_end(rhs) {
}
compareable_interval(int l, int r, int rl, int rr) : start(l), end(r),
real_start(rl), real_end(rr) {
}
b... 阅读全帖
s********x
发帖数: 914
43
来自主题: JobHunting版 - 狗狗家onsite面经
2吧
class CharNode {
private char value;
private CharNode next;
private CharNode previous;
public CharNode getPrevious() {
return previous;
}
public void setPrevious(CharNode previous) {
this.previous = previous;
}
public char getValue() {
return value;
}
public void setValue(char value) {
this.value = value;
}
public CharNode getNext() {
return next;
}
public void setNext(CharNode next) {
this... 阅读全帖
a***e
发帖数: 413
44
这些题看着容易,老是写不对或者代码很冗长,有大牛们指点一下如何提高么?
呜呜,不知道哪年哪月才能刷完一遍,有同学互勉一下么?
比如
Given a linked list and a value x, partition it such that all nodes less
than x come before nodes greater than or equal to x.
You should preserve the original relative order of the nodes in each of the
two partitions.
For example,
Given 1->4->3->2->5->2 and x = 3,
return 1->2->2->4->3->5.
我的
Runtime Error

Last executed input:
{1}, 0
ListNode *partition(ListNode *head, int x) {
... 阅读全帖
l*3
发帖数: 2279
45
来自主题: JobHunting版 - 讨论下lc最新的那道hard题吧
我的c++过了。之前也是超时,改进方法就是要把每一步临时算出来的结果保存,不要
在最后的时候重复算。不过说实话我觉得这个影响不大,理论上讲无非就是把一个最坏
是 O(n * 4^n) 的东西降到了 O(4^n),少了一个factor而已,不过确实是过例子很快
。。只要44ms(我不知道超时一般判定是多少,不过之前有的题跑了600ms也算过了,
不过也不知道是不是所有题的超时判定都一样?我估计是1000ms,如果这么说的话其实
实际上改进还挺大)
贴一段我的代码,最tricky的地方就是楼上说的,你需要知道这些:
乘法运算的优先级比加减法高,所以你要保存一个 “连乘串” 的结果。直到你某一步
走到了某个你想插入加减法的地方,你才把连乘串的结果去添加到临时的sum结果中,
否则就要一直保留。
另外什么是加法和减法呢?其实就相当于你update你临时的sum,并且把新的乘积起始
点赋值成 1 (对应加法) 或者 -1 (对应减法)
code 如下:
class Solution {
public:
//主函数,没有干什么大事,就是预处理一下字符串,把两个位置之间的字符转换的整
数结果都保存下... 阅读全帖
z****o
发帖数: 1
46
来自主题: Programming版 - C memory leak problem help
请教这段代码为什么不能FREE malloc 分配的内存,老是泄漏?
void sp_free(sp_t* a)
{
struct sp_cell *prev, *tmp;
int i;

for (i=0; i < a->num_rows; i++)
{
prev = a->rows[i];

if (prev != NULL)
{
tmp = prev->next;

while(tmp != NULL)
{
prev = tmp;
tmp = prev->next;
free(prev);
}
}
}
for (i=0; i < a->num_cols; i++)
{
prev = a->cols[i];

if (prev != NULL)
a****s
发帖数: 22
47
来自主题: JobHunting版 - 树 inorder下个节点最好办法是啥
不知道这样行不行, 感觉可以,不过没编译试过.基本意思就是Inorder遍历树,记住当
前节点的In-order上一个节点.
void FindInOrderNextInTreeHelper(Node *p, int data, Node *& next, Node *&
prev)
{
if(!p) return;
FindInOrderNextInTreeHelper(p->left, data, next, prev);
if(prev && prev->data == data)
{
next = p;
return;
}
prev = p;

FindInOrderNextInTreeHelper(p->right, data, next, prev);
}
Node * FindInOrderNextInTree(Node *p, int data)
{
if(!p) return NULL;
Node * next = NULL;
Node * prev =... 阅读全帖
h*******0
发帖数: 68
48
来自主题: JobHunting版 - 树 inorder下个节点最好办法是啥
不知道这样行不行, 感觉可以,不过没编译试过.基本意思就是Inorder遍历树,记住当
前节点的In-order上一个节点.
void FindInOrderNextInTreeHelper(Node *p, int data, Node *& next, Node *&
prev)
{
if(!p) return;
FindInOrderNextInTreeHelper(p->left, data, next, prev);
if(prev && prev->data == data)
{
next = p;
return;
}
prev = p;

FindInOrderNextInTreeHelper(p->right, data, next, prev);
}
Node * FindInOrderNextInTree(Node *p, int data)
{
if(!p) return NULL;
Node * next = NULL;
Node * prev =... 阅读全帖
l*****g
发帖数: 685
49
来自主题: JobHunting版 - Amazon的LRU设计题
最近Amazon面试好像喜欢问LRU (least recently used cache)的设计
我用doubly-linked list 和 hashtable 实现了一个简单的LRU, 抛砖引玉,供大家做
参考。祝大家都顺利拿到offer.
using System;
using System.Collections.Generic;
namespace LRU
{
public class Cache
{
public class Container
{
public Object obj;
public Container next;
public Container prev;
public Container(object o)
{
this.obj = o;
}
}
private const int MaxSize ... 阅读全帖
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)