Redian新闻
>
PARENTS 杂志里有CETAPHIL 2刀胖子
avatar
PARENTS 杂志里有CETAPHIL 2刀胖子# PennySaver - 省钱一族
g*5
1
刚面完
题目不难,不过是烙印,拿不定
1. Given an integer array, place all the zeros to the end.
{4, 0, 5, 0, 8} => { 4, 5, 8, 0, 0}
follow up:不care顺数的话尽量少用write,swap就行
2.The number of valid combinations of a strings for given input array a[],
where a=>1, z => 26, and 0 <= a[i] <= 9
{1,1,1} => { aaa, ak, ka} => 3
{1,1,0} => {aj} => 1
follow up: O(1) memory
20分钟2题就写完了,非要我做了一堆test
他说马上就提交feedback,求bless
avatar
t*s
2
上个月和这个月都有,都是12/31/11过期
avatar
r*e
3
new grad 么?

【在 g*****5 的大作中提到】
: 刚面完
: 题目不难,不过是烙印,拿不定
: 1. Given an integer array, place all the zeros to the end.
: {4, 0, 5, 0, 8} => { 4, 5, 8, 0, 0}
: follow up:不care顺数的话尽量少用write,swap就行
: 2.The number of valid combinations of a strings for given input array a[],
: where a=>1, z => 26, and 0 <= a[i] <= 9
: {1,1,1} => { aaa, ak, ka} => 3
: {1,1,0} => {aj} => 1
: follow up: O(1) memory

avatar
p*t
4
cetaphil是干嘛的?
avatar
g*5
5

intern

【在 r*******e 的大作中提到】
: new grad 么?
avatar
l*a
6
最近有deal么
avatar
d*5
7
啥叫 “不care顺数的话尽量少用write”?
avatar
t*s
8
Rite Aid often has BOGO50%, 2UPR wyb 2

【在 l*******a 的大作中提到】
: 最近有deal么
avatar
r*e
9
不需要维持原来顺序,则可以直接交换0 与最后一个非0的数。

【在 d*******5 的大作中提到】
: 啥叫 “不care顺数的话尽量少用write”?
avatar
r*7
10
follow up是说你先不是swap,不是O(1) memory么?

【在 g*****5 的大作中提到】
: 刚面完
: 题目不难,不过是烙印,拿不定
: 1. Given an integer array, place all the zeros to the end.
: {4, 0, 5, 0, 8} => { 4, 5, 8, 0, 0}
: follow up:不care顺数的话尽量少用write,swap就行
: 2.The number of valid combinations of a strings for given input array a[],
: where a=>1, z => 26, and 0 <= a[i] <= 9
: {1,1,1} => { aaa, ak, ka} => 3
: {1,1,0} => {aj} => 1
: follow up: O(1) memory

avatar
g*5
11

没懂你说什么,follow up的解法是swap
之前我做的时候是把所有非0数往左移动,按顺序的

【在 r****7 的大作中提到】
: follow up是说你先不是swap,不是O(1) memory么?
avatar
k*r
12
intern只一轮电面吗?谢谢
avatar
s*i
13
The first one?
void placeZerosToEnd (int[] A)
{
if (A == null)
{
return;
}

int endPos = A.length - 1;
for (int i = 0; i < endPos; i++)
{
if (A[i] == 0)
{
A[i] = A[endPos];
A[endPos] = 0;
endPos --;
i--; //need to test this newly swapped element
}
}
}

【在 g*****5 的大作中提到】
: 刚面完
: 题目不难,不过是烙印,拿不定
: 1. Given an integer array, place all the zeros to the end.
: {4, 0, 5, 0, 8} => { 4, 5, 8, 0, 0}
: follow up:不care顺数的话尽量少用write,swap就行
: 2.The number of valid combinations of a strings for given input array a[],
: where a=>1, z => 26, and 0 <= a[i] <= 9
: {1,1,1} => { aaa, ak, ka} => 3
: {1,1,0} => {aj} => 1
: follow up: O(1) memory

avatar
n*r
14
谢谢楼主分享经验

【在 g*****5 的大作中提到】
: 刚面完
: 题目不难,不过是烙印,拿不定
: 1. Given an integer array, place all the zeros to the end.
: {4, 0, 5, 0, 8} => { 4, 5, 8, 0, 0}
: follow up:不care顺数的话尽量少用write,swap就行
: 2.The number of valid combinations of a strings for given input array a[],
: where a=>1, z => 26, and 0 <= a[i] <= 9
: {1,1,1} => { aaa, ak, ka} => 3
: {1,1,0} => {aj} => 1
: follow up: O(1) memory

avatar
h*o
15
双指针可以了吧。
第二题 你给的DP 解法?
O(1)是指递归吗?多谢

【在 g*****5 的大作中提到】
:
: 没懂你说什么,follow up的解法是swap
: 之前我做的时候是把所有非0数往左移动,按顺序的

avatar
y*i
16
谁给解释一下第二题的题意?
avatar
v*a
17
Leetcode Decode Ways

【在 y*****i 的大作中提到】
: 谁给解释一下第二题的题意?
avatar
l*8
18
{1,1,1} 有三种可能:
[1, 1, 1] 对应 aaa
[1, 11] 对应 ak
[11, 1] 对应 ka

【在 y*****i 的大作中提到】
: 谁给解释一下第二题的题意?
avatar
y*i
19
谢谢!

【在 l*********8 的大作中提到】
: {1,1,1} 有三种可能:
: [1, 1, 1] 对应 aaa
: [1, 11] 对应 ak
: [11, 1] 对应 ka

avatar
x*a
20
递归应该不算O(1)?
avatar
g*r
21
array的swap怎么做的?不用write吗?

【在 g*****5 的大作中提到】
: 刚面完
: 题目不难,不过是烙印,拿不定
: 1. Given an integer array, place all the zeros to the end.
: {4, 0, 5, 0, 8} => { 4, 5, 8, 0, 0}
: follow up:不care顺数的话尽量少用write,swap就行
: 2.The number of valid combinations of a strings for given input array a[],
: where a=>1, z => 26, and 0 <= a[i] <= 9
: {1,1,1} => { aaa, ak, ka} => 3
: {1,1,0} => {aj} => 1
: follow up: O(1) memory

avatar
p*j
22
public static void placeZerosToEnd(int[] A) {
if (A == null || A.length == 0) {
return;
}
int start = 0;
int end = A.length - 1;
while (start < end) {
if (A[start] == 0) {
while (A[end] == 0) {
end--;
}

if (end <= start) {
break;
}
A[start] = A[end];
A[end] = 0;
end--;
}
start++;
}
for (int i = 0; i < A.length; i++) {
System.out.print(A[i] + ",");
}
System.out.println("--------------");
}
avatar
l*a
23
这样写是不是更好呢
while(startif(A[start]!=0) {
start++;
} else if(A[end]==0) {
end--;
} else {
swap();
start++;
end--;
}
}

【在 p*********j 的大作中提到】
: public static void placeZerosToEnd(int[] A) {
: if (A == null || A.length == 0) {
: return;
: }
: int start = 0;
: int end = A.length - 1;
: while (start < end) {
: if (A[start] == 0) {
: while (A[end] == 0) {
: end--;

avatar
p*j
24
public static int validCombinations_O1(int[] A) {
if (A == null || A.length == 0) {
return 0;
}
int prepre = 1;
int pre = (A[0] == 0) ? 0 : 1;
int current = pre;
for (int i = 2; i <= A.length; i++) {
current = 0;
if (A[i - 1] != 0) {
current = pre;
}
int num = A[i - 2] * 10 + A[i - 1];
if (num <= 26 && num >= 10) {
current += prepre;
}
prepre = pre;
pre = current;
}
return current;
}
avatar
p*j
25
学习了,赞成!

【在 l*****a 的大作中提到】
: 这样写是不是更好呢
: while(start: if(A[start]!=0) {
: start++;
: } else if(A[end]==0) {
: end--;
: } else {
: swap();
: start++;
: end--;

avatar
g*5
26

递归明显不是O(1)啊
DP优化一下就可以O(1)了
因为DP其实只是用到数组的最后3个数,把这三个数记下来就行了,每次update

【在 h*********o 的大作中提到】
: 双指针可以了吧。
: 第二题 你给的DP 解法?
: O(1)是指递归吗?多谢

avatar
g*5
27

这已经是第二轮电面了

【在 k****r 的大作中提到】
: intern只一轮电面吗?谢谢
avatar
a*a
28
第一题,直接一直把不是0的往前移动,然后最后再把空余的位置赋值为0.这样也可以
保持顺序。
#include
#include
using namespace std;
void place_zeros(vector & v) {
int L = 0;
while(v[L] != 0) L++;
int R = L+1;
while(Rif (v[R] == 0) {
R++;
continue;
}
v[L] = v[R];
L++; R++;
}
while(Lv[L] = 0;
L++;
}
}
int main(int argc, const char *argv[])
{
vector v = {0, 1, 2, 3};
place_zeros(v);
for(auto i: v) cout << i << endl;
return 0;
}
avatar
g*5
29
刚面完
题目不难,不过是烙印,拿不定
1. Given an integer array, place all the zeros to the end.
{4, 0, 5, 0, 8} => { 4, 5, 8, 0, 0}
follow up:不care顺数的话尽量少用write,swap就行
2.The number of valid combinations of a strings for given input array a[],
where a=>1, z => 26, and 0 <= a[i] <= 9
{1,1,1} => { aaa, ak, ka} => 3
{1,1,0} => {aj} => 1
follow up: O(1) memory
20分钟2题就写完了,非要我做了一堆test
他说马上就提交feedback,求bless
__________________________________
I got the offer, thx everyone
avatar
r*e
30
new grad 么?

【在 g*****5 的大作中提到】
: 刚面完
: 题目不难,不过是烙印,拿不定
: 1. Given an integer array, place all the zeros to the end.
: {4, 0, 5, 0, 8} => { 4, 5, 8, 0, 0}
: follow up:不care顺数的话尽量少用write,swap就行
: 2.The number of valid combinations of a strings for given input array a[],
: where a=>1, z => 26, and 0 <= a[i] <= 9
: {1,1,1} => { aaa, ak, ka} => 3
: {1,1,0} => {aj} => 1
: follow up: O(1) memory

avatar
g*5
31

intern

【在 r*******e 的大作中提到】
: new grad 么?
avatar
d*5
32
啥叫 “不care顺数的话尽量少用write”?
avatar
r*e
33
不需要维持原来顺序,则可以直接交换0 与最后一个非0的数。

【在 d*******5 的大作中提到】
: 啥叫 “不care顺数的话尽量少用write”?
avatar
r*7
34
follow up是说你先不是swap,不是O(1) memory么?

【在 g*****5 的大作中提到】
: 刚面完
: 题目不难,不过是烙印,拿不定
: 1. Given an integer array, place all the zeros to the end.
: {4, 0, 5, 0, 8} => { 4, 5, 8, 0, 0}
: follow up:不care顺数的话尽量少用write,swap就行
: 2.The number of valid combinations of a strings for given input array a[],
: where a=>1, z => 26, and 0 <= a[i] <= 9
: {1,1,1} => { aaa, ak, ka} => 3
: {1,1,0} => {aj} => 1
: follow up: O(1) memory

avatar
g*5
35

没懂你说什么,follow up的解法是swap
之前我做的时候是把所有非0数往左移动,按顺序的

【在 r****7 的大作中提到】
: follow up是说你先不是swap,不是O(1) memory么?
avatar
k*r
36
intern只一轮电面吗?谢谢
avatar
s*i
37
The first one?
void placeZerosToEnd (int[] A)
{
if (A == null)
{
return;
}

int endPos = A.length - 1;
for (int i = 0; i < endPos; i++)
{
if (A[i] == 0)
{
A[i] = A[endPos];
A[endPos] = 0;
endPos --;
i--; //need to test this newly swapped element
}
}
}

【在 g*****5 的大作中提到】
: 刚面完
: 题目不难,不过是烙印,拿不定
: 1. Given an integer array, place all the zeros to the end.
: {4, 0, 5, 0, 8} => { 4, 5, 8, 0, 0}
: follow up:不care顺数的话尽量少用write,swap就行
: 2.The number of valid combinations of a strings for given input array a[],
: where a=>1, z => 26, and 0 <= a[i] <= 9
: {1,1,1} => { aaa, ak, ka} => 3
: {1,1,0} => {aj} => 1
: follow up: O(1) memory

avatar
h*o
38
双指针可以了吧。
第二题 你给的DP 解法?
O(1)是指递归吗?多谢

【在 g*****5 的大作中提到】
:
: 没懂你说什么,follow up的解法是swap
: 之前我做的时候是把所有非0数往左移动,按顺序的

avatar
y*i
39
谁给解释一下第二题的题意?
avatar
v*a
40
Leetcode Decode Ways

【在 y*****i 的大作中提到】
: 谁给解释一下第二题的题意?
avatar
l*8
41
{1,1,1} 有三种可能:
[1, 1, 1] 对应 aaa
[1, 11] 对应 ak
[11, 1] 对应 ka

【在 y*****i 的大作中提到】
: 谁给解释一下第二题的题意?
avatar
y*i
42
谢谢!

【在 l*********8 的大作中提到】
: {1,1,1} 有三种可能:
: [1, 1, 1] 对应 aaa
: [1, 11] 对应 ak
: [11, 1] 对应 ka

avatar
x*a
43
递归应该不算O(1)?
avatar
g*r
44
array的swap怎么做的?不用write吗?

【在 g*****5 的大作中提到】
: 刚面完
: 题目不难,不过是烙印,拿不定
: 1. Given an integer array, place all the zeros to the end.
: {4, 0, 5, 0, 8} => { 4, 5, 8, 0, 0}
: follow up:不care顺数的话尽量少用write,swap就行
: 2.The number of valid combinations of a strings for given input array a[],
: where a=>1, z => 26, and 0 <= a[i] <= 9
: {1,1,1} => { aaa, ak, ka} => 3
: {1,1,0} => {aj} => 1
: follow up: O(1) memory

avatar
p*j
45
public static void placeZerosToEnd(int[] A) {
if (A == null || A.length == 0) {
return;
}
int start = 0;
int end = A.length - 1;
while (start < end) {
if (A[start] == 0) {
while (A[end] == 0) {
end--;
}

if (end <= start) {
break;
}
A[start] = A[end];
A[end] = 0;
end--;
}
start++;
}
for (int i = 0; i < A.length; i++) {
System.out.print(A[i] + ",");
}
System.out.println("--------------");
}
avatar
l*a
46
这样写是不是更好呢
while(startif(A[start]!=0) {
start++;
} else if(A[end]==0) {
end--;
} else {
swap();
start++;
end--;
}
}

【在 p*********j 的大作中提到】
: public static void placeZerosToEnd(int[] A) {
: if (A == null || A.length == 0) {
: return;
: }
: int start = 0;
: int end = A.length - 1;
: while (start < end) {
: if (A[start] == 0) {
: while (A[end] == 0) {
: end--;

avatar
p*j
47
public static int validCombinations_O1(int[] A) {
if (A == null || A.length == 0) {
return 0;
}
int prepre = 1;
int pre = (A[0] == 0) ? 0 : 1;
int current = pre;
for (int i = 2; i <= A.length; i++) {
current = 0;
if (A[i - 1] != 0) {
current = pre;
}
int num = A[i - 2] * 10 + A[i - 1];
if (num <= 26 && num >= 10) {
current += prepre;
}
prepre = pre;
pre = current;
}
return current;
}
avatar
p*j
48
学习了,赞成!

【在 l*****a 的大作中提到】
: 这样写是不是更好呢
: while(start: if(A[start]!=0) {
: start++;
: } else if(A[end]==0) {
: end--;
: } else {
: swap();
: start++;
: end--;

avatar
g*5
49

递归明显不是O(1)啊
DP优化一下就可以O(1)了
因为DP其实只是用到数组的最后3个数,把这三个数记下来就行了,每次update

【在 h*********o 的大作中提到】
: 双指针可以了吧。
: 第二题 你给的DP 解法?
: O(1)是指递归吗?多谢

avatar
g*5
50

这已经是第二轮电面了

【在 k****r 的大作中提到】
: intern只一轮电面吗?谢谢
avatar
a*a
51
第一题,直接一直把不是0的往前移动,然后最后再把空余的位置赋值为0.这样也可以
保持顺序。
#include
#include
using namespace std;
void place_zeros(vector & v) {
int L = 0;
while(v[L] != 0) L++;
int R = L+1;
while(Rif (v[R] == 0) {
R++;
continue;
}
v[L] = v[R];
L++; R++;
}
while(Lv[L] = 0;
L++;
}
}
int main(int argc, const char *argv[])
{
vector v = {0, 1, 2, 3};
place_zeros(v);
for(auto i: v) cout << i << endl;
return 0;
}
avatar
p*9
52
mark
avatar
p*9
53
mark
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。