由买买提看人间百态

topics

全部话题 - 话题: curative
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
d********w
发帖数: 363
1
来自主题: JobHunting版 - 一道google 面试题
需要逻辑缜密阿,
我实现的好像有bug,大家能想到比较好的办法么
static int encode(String str) {
int num = 0;
int sum = 0;
int cur = 0;
boolean vowelBefore = false;
boolean vowel;
str = str.toLowerCase();
for ( int i=0; i< str.length(); i++) {
if (map.get(str.charAt(i)) != null) {
cur = map.get(str.charAt(i));
vowel = true;
} else {
vowel = false;
}

if (str.char... 阅读全帖
c***p
发帖数: 221
2
来自主题: JobHunting版 - 刚做了一道题挺有意思
我觉得就是字符串的匹配问题吧。 用u匹配s的每个等长字串,看看有多少个字符不同
。考虑到u的开始和结束的特殊情况,可以在u的前后加上足够的pad.
#include
#include
using namespace std;
const char PAD = '$';
int match(string p, string q, size_t len)
{
int count = 0;
for(size_t i = 0; i < len; i++){
if (p.at(i) != q.at(i)){
count++;
}
}
return count;
}
size_t edit (string from, string to, string& sub)
{
string pad;
pad.append( to.length()-1, PAD)... 阅读全帖
c***p
发帖数: 221
3
来自主题: JobHunting版 - 刚做了一道题挺有意思
我觉得就是字符串的匹配问题吧。 用u匹配s的每个等长字串,看看有多少个字符不同
。考虑到u的开始和结束的特殊情况,可以在u的前后加上足够的pad.
#include
#include
using namespace std;
const char PAD = '$';
int match(string p, string q, size_t len)
{
int count = 0;
for(size_t i = 0; i < len; i++){
if (p.at(i) != q.at(i)){
count++;
}
}
return count;
}
size_t edit (string from, string to, string& sub)
{
string pad;
pad.append( to.length()-1, PAD)... 阅读全帖
d********w
发帖数: 363
4
来自主题: JobHunting版 - M家 onsite 悲剧,同胞们弄死烙印吧
我来写一个java的
public ListNode swapPairs(ListNode head) {
// Start typing your Java solution below
// DO NOT write main() function
if (head == null || head.next == null)
return head;

ListNode newNode = head.next;
ListNode p;
ListNode cur = head;
while(head != null && head.next != null) {
p = head.next.next;

head.next.next = head;
if (p != null)
head.next = p.next;
... 阅读全帖
d********w
发帖数: 363
5
来自主题: JobHunting版 - M家 onsite 悲剧,同胞们弄死烙印吧
我来写一个java的
public ListNode swapPairs(ListNode head) {
// Start typing your Java solution below
// DO NOT write main() function
if (head == null || head.next == null)
return head;

ListNode newNode = head.next;
ListNode p;
ListNode cur = head;
while(head != null && head.next != null) {
p = head.next.next;

head.next.next = head;
if (p != null)
head.next = p.next;
... 阅读全帖
l*****y
发帖数: 90
6
来自主题: JobHunting版 - career cup上面一题递归求解
The recursive method could be very similar to the iterative approach:
node* findNtolast(node* head, int n){
for (node*tmp = head, int i=0; inext; tmp=tmp->next){}
recurs(head, tmp);
}
node* recurs(node* head, node* cur){
if (!cur->next)
return head;
else
return rev(head->next, cur->next);
}
z******e
发帖数: 82
7
来自主题: JobHunting版 - 发个M家的题
cell zeroX, zeroY;
cell [n*2][n*2] target;
int[n][n] mixedCells;
target[n][n] = mixedCells[0][0];
put all mixedCells in a list(cellList), except [0][0];
while(!cellList.empty())
{
loop(cur) cellList
loop(curTarget) target
if 关系(cur, curTarget) then
remove from cellList
put cur to target
update zeroX, zeroY
end if
end loop;
end loop
}
output(target, zeroX, zeroY)
d****o
发帖数: 1055
8
来自主题: JobHunting版 - 谈谈刚面的一个design题
class vendingMachine{
private:
hash_map > m;
public:
bool getBeverage(int type){
if(m.find(type)==m.end()){
return false;
}
vector& cur = m[type];
if(cur.size()==0){
return false;
}
cur.pop_back();
return true;
}
}
d****o
发帖数: 1055
9
来自主题: JobHunting版 - 谈谈刚面的一个design题
class vendingMachine{
private:
hash_map > m;
public:
bool getBeverage(int type){
if(m.find(type)==m.end()){
return false;
}
vector& cur = m[type];
if(cur.size()==0){
return false;
}
cur.pop_back();
return true;
}
}
w***o
发帖数: 109
10
二爷真要较真的话,这样写并不好。因为java里array其实是一个object,每次不管是
读还是写,都要做越界检查。你这段代码虽然短,但除了第一个和最后一个element之
外,每个都读了两遍。还是不如用一个pre变量来cache前一个读数。
int ans = 0;
int pre = prices[0];
for(int i = 1; i < prices.length; i++)
{
int cur = prices[i];
ans += Math.max(0, cur - pre);
pre = cur;
}
return ans;
如果追求短的话,还可以更短:
int ret = 0;
for(int i = 1; i< prices.length; ret += Math.max(0, prices[i] - prices[i++ -
1]));
return ret;
三行就好了。
r*****e
发帖数: 146
11
来自主题: JobHunting版 - 如何随机找二叉树中的任意节点?
写了一个。弱问一句,初始ret的时候有些糊涂。一定要遍历的第一个?
TreeNode* get_random_node(TreeNode* root){
srand(time(NULL));
InOrderNextIterator it(root);
int cnt = 0;
int j = 0;
TreeNode* ret = root;//or一定要遍历的第一个?也就是in-order的最小?
TreeNode* cur = NULL;
while(it.has_next()){
cur = it.next();
cnt++;
j = rand()%cnt;
if(0 == j)
ret = cur;
}
return ret;
}
n****r
发帖数: 120
12
可以过
public class Solution {

public static class Bar{
int height, startIdx;
Bar(int h, int i){ height = h; startIdx = i; }
}
public int maximalRectangle(char[][] matrix) {
if (matrix.length == 0 || matrix[0].length == 0) return 0;
int n = matrix.length, m = matrix[0].length;
int[][] aux = new int[n][m];

for (int i=0; i aux[0][i] = matrix[0][i] - '0';
}
for (int i=1; i ... 阅读全帖
j********x
发帖数: 2330
13
来自主题: JobHunting版 - jump game II solved in 1 loop(Q(n))
int jump_gameII(const std::vector& input) {
int cur = 0;
int step = 0;
int max = 0;
for (int i = 0; i < input.size(); ++i) {
if (i > cur && i <= max) {
++step;
cur = max;
} else if (i > max) {
return -1; // cannot reach i;
}
max = std::max(max, i + input[i]);
}
return step;
}
l*******0
发帖数: 63
14
来自主题: JobHunting版 - Binary Tree Maximum Path Sum
if(maxLeft>0) cur+=maxLeft;
if(maxRight>0) cur+=maxRight;
处的cur应改为maxAcrossCurNode?
L********e
发帖数: 159
15
来自主题: JobHunting版 - 遇到了一个很奇怪的C++问题
替换前后cur的值不一样呀,一个是cur另一个是cur->left
z****e
发帖数: 54598
16
来自主题: JobHunting版 - leetcode - 130的答案
java的,二爷博客上的java的bfs有个bug
不过在leetcode上测不出来就是了,当m!=n的时候,二爷代码就出错了
这题真心坑爹,尤其用java做
递归的调用很容易就超时了
所以我在二爷代码的基础之上做了点优化
大概能优化50ms左右,对于小oj来说
大oj还是需要连点两次,激活jvm的jit才能过
public class Solution {

char[][] board;
int m,n;
Stack queue = new Stack();

private void fill(int i, int j){
if(i<0||j<0||i>=m||j>=n||board[i][j]!='O') return;

board[i][j] = 'D';
queue.push(i*n+j);

}

private void bfs(int i, int j){
fill(i,j)... 阅读全帖
J*****a
发帖数: 4262
17
下面是反序列化
public static Node deserialize(String filename){
Node root = null;
File file = new File(filename);
try{
Scanner scanner = new Scanner(file);
if(scanner.hasNext()) {
String tmp = scanner.next();
if(tmp.equals("#")) {scanner.close();return null;}
else {
Node node = new Node(Integer.parseInt(tmp));
root = node;
}
}
else {scanner.close(); return null;}
Queue q = new LinkedList();
q.add(roo... 阅读全帖
e***m
发帖数: 92
18
来自主题: JobHunting版 - Dropbox电话面经
if cur-300>last
整个数组清零
else
(last-300,cur-300]对应的counters清零
再把cur对应的counter加一
Q*****a
发帖数: 33
19
来自主题: JobHunting版 - Dropbox电话面经
#include "stdafx.h"
#include
#include
#include
namespace {
class IStopWatch {
public:
virtual void Start() = 0;
virtual double SecondsFromStart() = 0;
};
class StopWatch: public IStopWatch {
private:
time_t start_;
public:
StopWatch(bool start) {
if (start) {
Start();
}
}
virtual void Start() {
time(&start_);
}
virtual double... 阅读全帖
e***m
发帖数: 92
20
来自主题: JobHunting版 - Dropbox电话面经
if cur-300>last
整个数组清零
else
(last-300,cur-300]对应的counters清零
再把cur对应的counter加一
Q*****a
发帖数: 33
21
来自主题: JobHunting版 - Dropbox电话面经
#include "stdafx.h"
#include
#include
#include
namespace {
class IStopWatch {
public:
virtual void Start() = 0;
virtual double SecondsFromStart() = 0;
};
class StopWatch: public IStopWatch {
private:
time_t start_;
public:
StopWatch(bool start) {
if (start) {
Start();
}
}
virtual void Start() {
time(&start_);
}
virtual double... 阅读全帖
a**d
发帖数: 85
22
来自主题: JobHunting版 - fb电面面经
static class Log {
int in,out;
Log(int a,int b) {
in=a;
out=b;
}
}
public String log(Log[] l) {
String[] s=new String[2*l.length];
for(int i=0,j=0;i s[j++]=l[i].in+"i";
s[j++]=l[i].out+"o";
}
Arrays.sort(s);
LinkedHashMap lh=new LinkedHashMap();
int counter=1;
for(int i=1;i char cur=s[i].charAt(0),pre=s[i-1].charAt(0);
if(cur!=pre) {
... 阅读全帖
a**d
发帖数: 85
23
来自主题: JobHunting版 - fb电面面经
static class Log {
int in,out;
Log(int a,int b) {
in=a;
out=b;
}
}
public String log(Log[] l) {
String[] s=new String[2*l.length];
for(int i=0,j=0;i s[j++]=l[i].in+"i";
s[j++]=l[i].out+"o";
}
Arrays.sort(s);
LinkedHashMap lh=new LinkedHashMap();
int counter=1;
for(int i=1;i char cur=s[i].charAt(0),pre=s[i-1].charAt(0);
if(cur!=pre) {
... 阅读全帖
b*********s
发帖数: 115
24
来自主题: JobHunting版 - 问一个面试题
array hooper
给一个array,每个元素都是大于等于0的数字,每个数字代表可以向右跳的最大步数。
从第一个元素出发,要跳出数组。跟leetcode的jump gameII差不多,区别在于
1. 这里要求跳出数组,leetcode是要求跳到最后一个元素
2. 如果能跳出数组,给出其中一组最少步数的跳法,如不能跳出,输出failure。
leetcode是只要求给出答案能不能跳到最后
examples:
input: 1, 1 output: 0, 1, out
input: 2, 1, 3, 1, 1 output: 0, 2, out
input: 5, 6, 0, 4, 2, 4, 1, 0, 0, 4 output: 0, 5, 9, out
input: 1, 2, 1, 0, 2 output: failure
我的代码是
def hopper(a):
a.append(0)
path = []
cur = 0
maxCenter = 0
maxRange = 0
for i, n in enumerat... 阅读全帖
p****o
发帖数: 46
25
来自主题: JobHunting版 - 问一个面试题
ok, I only had a glimpse on a.append(0), and quickly skip it... :-), have
not written python for quite some time.
then I think it is correct. but personally, I feel it is tricky to append "0
" at the end of input, and also the input has to change. Another
controversial case is the empty input, you will output "out".
Well, maybe the reviewer did not see that "append", or did not think too
much. or there is still something wrong we have not checked out.
Your code is not far from not modifying inpu... 阅读全帖
b*****6
发帖数: 179
26
来自主题: JobHunting版 - 小弟求问LinkedIn那道Deep Iterator的题
我也被问过这个问题,当时没写好,现在再写一个:
public class DeepIterator {
private Stack stack;
public DeepIterator(List list) {
stack = new Stack();
stack.push(list);
advanceToNext();
}
public boolean hasNext() {
return !stack.isEmpty();
}
public int next() {
if (!hasNext())
throw new RuntimeException("no next");
int result = (Integer) stack.pop();
advanceToNext();

return result;
}
... 阅读全帖
b*****6
发帖数: 179
27
来自主题: JobHunting版 - 小弟求问LinkedIn那道Deep Iterator的题
我也被问过这个问题,当时没写好,现在再写一个:
public class DeepIterator {
private Stack stack;
public DeepIterator(List list) {
stack = new Stack();
stack.push(list);
advanceToNext();
}
public boolean hasNext() {
return !stack.isEmpty();
}
public int next() {
if (!hasNext())
throw new RuntimeException("no next");
int result = (Integer) stack.pop();
advanceToNext();

return result;
}
... 阅读全帖
w********8
发帖数: 55
28
来自主题: JobHunting版 - 请教一道Groupon的题目
借鉴楼上各位大牛的做法,我也写了一份Java的代码。。。。
public void mySolution(int num) {
if (num >= 5) {
String str = String.valueOf(num);
helper(num, "", 0, str.length(), false);
}
}
private void helper(int max, String prefix, int pos, int len, boolean
have5) {
if (pos == len) {
int cur = Integer.parseInt(prefix);
if (cur <= max) {
System.out.print(cur + ", ");
}
return;
}
for (int... 阅读全帖
w********8
发帖数: 55
29
来自主题: JobHunting版 - 请教一道Groupon的题目
借鉴楼上各位大牛的做法,我也写了一份Java的代码。。。。
public void mySolution(int num) {
if (num >= 5) {
String str = String.valueOf(num);
helper(num, "", 0, str.length(), false);
}
}
private void helper(int max, String prefix, int pos, int len, boolean
have5) {
if (pos == len) {
int cur = Integer.parseInt(prefix);
if (cur <= max) {
System.out.print(cur + ", ");
}
return;
}
for (int... 阅读全帖
A****L
发帖数: 138
30
public class WordLadderII {
public class Ladder { //Define Ladder class it's important
public Ladder parent;
public String word;
public Ladder(Ladder prev,String w) {parent=prev;word=w;}
}
public ArrayList> findLadders(String start, String end
, HashSet dict) {
ArrayList> ladders = new ArrayList String>>();
Ladder ladder = new Ladder(null,end); //Here we look from end to
start ... 阅读全帖
a**********0
发帖数: 422
31
来自主题: JobHunting版 - amazon电面跪了
为什么一定要用DFS 不是类似surrounded reigions 吗 可以用 BFS
只不过要设一个variable用于记录cluster的数目
而且BFS过后的要label一下表示不能继续使用 我试着贴一下代码
private void bfs(char[][] board, int i, int j) {

int row = board.length;
int col = board[0].length;
ArrayList queue = new ArrayList();

queue.add(i * col + j);
board[i][j] = 'P';

while (!queue.isEmpty()) {
int cur = queue.get(0);
queue.remove(0);
int x = cur / col;... 阅读全帖
a**********0
发帖数: 422
32
来自主题: JobHunting版 - amazon电面跪了
为什么一定要用DFS 不是类似surrounded reigions 吗 可以用 BFS
只不过要设一个variable用于记录cluster的数目
而且BFS过后的要label一下表示不能继续使用 我试着贴一下代码
private void bfs(char[][] board, int i, int j) {

int row = board.length;
int col = board[0].length;
ArrayList queue = new ArrayList();

queue.add(i * col + j);
board[i][j] = 'P';

while (!queue.isEmpty()) {
int cur = queue.get(0);
queue.remove(0);
int x = cur / col;... 阅读全帖
f**********t
发帖数: 1001
33
来自主题: JobHunting版 - 那位大牛做过这道题
class CompanyDB:
def __init__(self, fname):
self.industries = defaultdict(set)
self.companies = defaultdict(set)
fp = open(fname);
for line in fp.readlines:
items = line.split('|')
if len(items) < 3:
continue
if items[0] == "industry":
self.industries[items[2].strip()].add(items[1].strip())
elif items[0] == "company":
self.companies[items[2].strip()].add(items[1].st... 阅读全帖
l*****0
发帖数: 13
34
来自主题: JobHunting版 - 讨论一个g题
bool isSquare(int n)
{
int num = 0;
while (n)
{
if (n&0x01)
num++;
n =>>1;
}
if (num >= 2)
return false;
else
return true;
}
int getComb(int n, int tmp[])
{
int l = n/2, r = n-l;
int min = tmp[l] + tmp[r];
while (l > 0 && r < n)
{
int cur = tmp[l] + tmp[r];
if (min > cur)
min = cur;
l--;
r++;
}
return min;
}
int getSmallestK(int n)
{
if (n <= 0)
retu... 阅读全帖
l*****a
发帖数: 14598
35
来自主题: JobHunting版 - 问个简单的atoi的问题
u want to do
result=result*10+cur-'0';
then need to make sure that it is less than or equal to Integer.MAX_VALUE
if(result (result==Integer.MAX_VALUE/10&&cur-'0'<=Integer.MAX_VALUE%10)) {
result=result*10+cur-'0';
} else {
//overflow
}
a***e
发帖数: 413
36
来自主题: JobHunting版 - InsertionSort和ShellSort
请问下面两种不同 的InsertionSort的implementation有啥优劣么?我觉得都一样
哈。另外面试的时候如果问道shellsort下面那个基于InsertionSort的是不是就可以了
?发现现在要求sort linkedlist了。还在看基本算法。
void InsertionSort(vector &v)
{
int j;
for (int i = 1; i < v.size(); i++)
{
int cur = v[i];
for (j = i - 1; j >= 0 && v[j]>cur; j--)
{
v[j + 1] = v[j];
}
v[j+1] = cur;
}
}
void insertionSort2(vector &v)
{
int n = v.size()... 阅读全帖
b*****i
发帖数: 76
37
来自主题: JobHunting版 - 说一个Amex电话面试的经历
前段时间电面了Amex,他家的技术中心貌似在Arizona,因为recruiter和电面的人都是
从那边打来的电话。
面我的是另一人口大国的,Title好像是tech architecture lead之类,之前上
linkedin偷瞄了一下背景,将近二十年经验吧,但没看出来有前端相关的经验。
面试是structured,也就是拿着一堆问题隔着电话问,电话声音质量非常差劲,应该是
IP电话或者类似LiveMeeting之类的,中间还断线两次,面试官的口音各位自己脑补吧
,加上杂音问题,使得我每一个问题都要重复一遍以确保自己听明白了。没多久高潮来
了:
面试官:There is a div with a width of 185, padding of 10, and margin of 20.
What is the width of the div?
此题明显是个陷阱啊,没提box model,没说后一个width的定义,于是我就把content-
box和border-box说了一下,然后分别说明答案。然后他问,shouldn't the margin be
included? 我... 阅读全帖
H******i
发帖数: 5
38
来自主题: JobHunting版 - leetcode的count and say
class Solution:
# @return a string
def countAndSay(self, n):
if n==1:
return '1'
pre=self.countAndSay(n-1)
start=0
next=''
while start count=0
cur=pre[start]
while start count+=1
start+=1
next=next+str(count)+cur
return next
t**r
发帖数: 3428
39
import java.util.HashMap;
public class LRUCache {
private HashMap map
= new HashMap();
private DoubleLinkedListNode head;
private DoubleLinkedListNode end;
private int capacity;
private int len;
public LRUCache(int capacity) {
this.capacity = capacity;
len = 0;
}
public int get(int key) {
if (map.containsKey(key)) {
DoubleLinkedListNode latest = map.get(key);
removeNode(latest);
setHead(latest);
return latest.val;
} else {
return -1;
... 阅读全帖
r****7
发帖数: 2282
40
来自主题: JobHunting版 - fb家面试题讨论
leetcode上就有吧,inorder visit,把prev->right设置成cur,cur->left = prev,
然后在prev = NULL的时候设置curr为head,不停的将head->left设置为cur
r****7
发帖数: 2282
41
来自主题: JobHunting版 - fb家面试题讨论
leetcode上就有吧,inorder visit,把prev->right设置成cur,cur->left = prev,
然后在prev = NULL的时候设置curr为head,不停的将head->left设置为cur
C****t
发帖数: 53
42
来自主题: JobHunting版 - 一道老题
Q1.
def swap(nums):
n = len(nums)
for i in range(n):
tmp = origIdx(i, n//2)
while tmp < i: tmp = origIdx(tmp, n//2)
nums[i], nums[tmp] = nums[tmp], nums[i]
print(nums)
def origIdx(cur, n):
return (cur%2)*n + cur//2
k*******q
发帖数: 5493
43
来自主题: JobHunting版 - 这道Amazon面试题怎么做
两个HASHSET 一个叫LAST 一个叫CUR
把第一个LIST放进LAST
然后遍历 2 - N 的LIST,每次把 LAST 里出现在新LIST里的 加进 CUR SET
每次循环结束时 LAST = CUR 这样LAST里面的内容会越来越少
到最后就是出现在所有LIST里的邮件了
边吃早饭边想的,如果有问题,麻烦指出

list
/* */
/* */, [email protected]
/* */
/* */, [email protected]
/* */, [email protected]
/* */
/* */ == [email protected]
/* */
/* */ => [email protected]
/* */, [email protected]
/* */ => [email protected]
/* */
k*******q
发帖数: 5493
44
来自主题: JobHunting版 - 这道Amazon面试题怎么做
我写了一下, 可以用的啊

public List findEmails(List> emails) {
List ret = new ArrayList();
if (emails == null || emails.size() == 0) {
return ret;
}
Set last = new HashSet();
for (String s : emails.get(0)) {
last.add(s.toLowerCase());
}
for (int i = 1;i < emails.size(); i++) {
Set cur = new HashSet();
for (String s : ... 阅读全帖
p****6
发帖数: 724
45
来自主题: JobHunting版 - FLGU面经offer及杂谈

public static boolean canIWin(int rangeMax, int target) {
if(rangeMax * (rangeMax + 1) /2 < target)
return false;
boolean[] visited = new boolean[rangeMax+1];
return recursive(0, rangeMax, target, visited);
}

private static boolean recursive(int cur, int rangeMax, int target,
boolean[] visited){
if(cur >= target) return false;
for(int i = 1; i <= rangeMax; i++){
if(!visited[i]){
visited[i] = true;
... 阅读全帖
m******3
发帖数: 346
46
来自主题: JobHunting版 - FLGU面经offer及杂谈
非常感谢,结合楼主发的tutorial,基本懂了,加点我理解的吧
public static boolean canIWin(int rangeMax, int target) {
if(rangeMax * (rangeMax + 1) /2 < target)
return false;
boolean[] visited = new boolean[rangeMax+1];
return recursive(0, rangeMax, target, visited);
}

private static boolean recursive(int cur, int rangeMax, int target,
boolean[] visited){
if(cur >= target) return false;
// 说明对手拿完以后,和>=target,所以对手获胜,我输
//尝试我所有可能的拿法,如果我拿了以后,对其中一个拿法,有heWin=false,则我可
以保证获... 阅读全帖
p****6
发帖数: 724
47
来自主题: JobHunting版 - FLGU面经offer及杂谈

public static boolean canIWin(int rangeMax, int target) {
if(rangeMax * (rangeMax + 1) /2 < target)
return false;
boolean[] visited = new boolean[rangeMax+1];
return recursive(0, rangeMax, target, visited);
}

private static boolean recursive(int cur, int rangeMax, int target,
boolean[] visited){
if(cur >= target) return false;
for(int i = 1; i <= rangeMax; i++){
if(!visited[i]){
visited[i] = true;
... 阅读全帖
m******3
发帖数: 346
48
来自主题: JobHunting版 - FLGU面经offer及杂谈
非常感谢,结合楼主发的tutorial,基本懂了,加点我理解的吧
public static boolean canIWin(int rangeMax, int target) {
if(rangeMax * (rangeMax + 1) /2 < target)
return false;
boolean[] visited = new boolean[rangeMax+1];
return recursive(0, rangeMax, target, visited);
}

private static boolean recursive(int cur, int rangeMax, int target,
boolean[] visited){
if(cur >= target) return false;
// 说明对手拿完以后,和>=target,所以对手获胜,我输
//尝试我所有可能的拿法,如果我拿了以后,对其中一个拿法,有heWin=false,则我可
以保证获... 阅读全帖
f*********l
发帖数: 46
49
来自主题: JobHunting版 - 问一道uber onsite题目
写了一个用list的版本
public static String reverse(String s) {
List list = new ArrayList();
boolean word = Character.isLetter(s.charAt(0));
int i = 0, n = s.length(), start = 0;
while(i < n) {
char cur = s.charAt(i);
while(i < n && ((word&&Character.isLetter(cur)) || (!word&&
Character.isLetter(cur)))) {
++i;
}
list.add(s.substring(start, i));
start = i;
word = !word... 阅读全帖

发帖数: 1
50
来自主题: JobHunting版 - read4 vs read4II 到底啥区别?
读4
这道题给了我们一个Read4函数,每次可以从一个文件中最多读出4个字符,如果文件中
的字符不足4个字符时,返回准确的当前剩余的字符数。现在让我们实现一个最多能读
取n个字符的函数
int read(char *buf, int n) {
int res = 0;
for (int i = 0; i <= n / 4; ++i) {
int cur = read4(buf + res);
if (cur == 0) break;
res += cur;
}
return min(res, n);
}
读4 II Read N Characters Given Read4的拓展,那道题说read函数只能调用一次,而
这道题说read函数可以调用多次
int read(char *buf, int n) {
for (int i = 0; i < n; ++i) {
if (readPos == writ... 阅读全帖
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)