由买买提看人间百态

topics

全部话题 - 话题: charater
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
g*****c
发帖数: 106
1
来自主题: JobHunting版 - 求问一道面试题
求问一道pocket gems的面试题 :
写一个mutable string。 里面有三个methods, charAt(int i), substring(int
beginIndex, int endIndex), setcharAt(int i, char c); 只能是O(1) space
毫无头绪。。。这些不是c++ stl 自带的函数么。。。跪求指导。。。最好用c++
谢谢!
g*****c
发帖数: 106
2
来自主题: JobHunting版 - 求问一道面试题

只知道一些基本的。是malloc一个内存,然后用指针吗?这个string class里的变量是
指针和一个内存。因为要求O(1)的space,第一个method charat可以指针在O(1) time
and O(1) space 返回对应的char即可。
第二个method substring 怎么达到O(1) space的呢?返回reference?可是新建一个
class的instance来放这个substring还是要内存啊。
第三个method setcharAt(int i, char c) 就完全不知道了。连字符都改了,又要求O(
1)的space,这个新字符放到哪呢?我想原string是不能改的,因为会有别的instance
指向这个string。那这个新的char又怎么和原string组合成新string呢?
网上搜了一下有人提了一句用tree,我没明白。
还请高人指点!谢谢!
k****r
发帖数: 807
3
来自主题: JobHunting版 - 贡献一道电面题
练个手我:
public static String encodeString(List l) {
String res = "";
for (String s : l) {
res += s.length();
res += "#";
res += s;
}
return res;
}
public static List decodeString(String s) {
List list = new ArrayList<>();
int index = 0;
while (index < s.length()) {
int start = index;
while (s.charAt(index) != '#') {
index++;
... 阅读全帖
k****r
发帖数: 807
4
来自主题: JobHunting版 - Google 电面
是这样的solution吗?
其中returnPosition的function应该不难写,但面试会要求写吗?
应该像上面的牛人说的,建个char-》position的表格最好了,不然每次还要算。
结果应该不唯一,估计面试follow up需要decode。
public class remoteControl {
String[] dic = {"abcde", "fghij", "klmno","pqrst", "uvwxy", "z"};
public String remoteControl(String name) {
int x = 0;
int y = 0;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < name.length(); i++) {
Point curr = returnPosition(name.charAt(i), dic);
for (int j = y... 阅读全帖
p*****2
发帖数: 21240
5

boolean isOp(char c){
return c == '+' || c == '-' || c == '*';
}

int cal(char c, int x, int y){
switch(c) {
case '+':
return x+y;
case '-':
return x-y;
case '*':
return x*y;
default:
return -1;
}
}

List dfs(String input, int s, int e){
List al = new ArrayList<>();
for(int i=s; i char c = input.charAt(i);
... 阅读全帖
j**7
发帖数: 143
6
来自主题: JobHunting版 - G家最新电面
public TreeNode createTree(String s) {
Stack st = new Stack();
TreeNode root = null;
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == ')') {
root = st.pop();
} else if (c >= 'A' && c <= 'Z') {
TreeNode newNode = new TreeNode(c);
if (st.isEmpty() == false) {
st.peek().children.add(newNode);
}
st.pus... 阅读全帖
d****m
发帖数: 1008
7
来自主题: JobHunting版 - 问一道最近的onsite题
design a string class , with implementation of charAt() and substring(b,e),
with substring() requires O(1) time and O(1) space complexity
followup:
a new method setCharat(index, char) is added, a substring must keep the
changes of parent string that are made before its creation, but both the
parrent string and the substring will not affect each other after the
creation of the substring, requires O(1) space complexity。
前面的没啥好说的了,就是java里面string的原封不动的code,substring只要改下
char[]的offset和count就行了。没太明白后面... 阅读全帖
l**h
发帖数: 893
8
来自主题: JobHunting版 - 请教个面试题
写了个java的:
String toCsv(String str) throws Exception {
boolean insideQuote = false;
Stack stack = new Stack();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (c == '[') {
stack.push(c);
} else if (c == ']') {
if (stack.isEmpty() || stack.peek() != '[') {
throw new Exception("Found unmatched ]");... 阅读全帖
S*******C
发帖数: 822
9
想出来了
最优解是
public int digitCounts(int k, int n) {
int res = k == 0 ? 1 : 0;
for (long powerOf10 = 1; powerOf10 <= n; powerOf10 *= 10) {
long left = n / powerOf10, right = n % powerOf10;
if (k != 0)
res += (left + 9 - k) / 10 * powerOf10;
else
res += left / 10 * powerOf10;
if (left % 10 == k && k > 0)
res += right + 1;
}
return res;
}
你可以用Brute force的解法来测试
public int ... 阅读全帖
e*******s
发帖数: 1979
10
来自主题: JobHunting版 - 问一个Anagram的参考程序
Given an array of strings, return all groups of strings that are anagrams.
All inputs will be in lower-case
Given ["lint", "intl", "inlt", "code"], return ["lint", "inlt", "intl"].
Given ["ab", "ba", "cd", "dc", "e"], return ["ab", "ba", "cd", "dc"].
9章的参考程序如下, 他给每一个string换成26长度的int array. 然后用这个array生
成一个hash code. 问题是这个hashcode能够唯一对应一个anagram么. 不同的anagram
有没有对应同一个hashcode的可能 (考虑int overflow的情况下).
public class Solution {
private int getHash(int[] count) {
int hash = 0;
int a ... 阅读全帖
c********t
发帖数: 5706
11
来自主题: JobHunting版 - 求两道题目的代码,学习一下
public static int cooldown(String s, int k){
if(s==null || s.isEmpty()) return 0;
int n = s.length();
if(k<=0) return n;
Map indexMap = new HashMap<>();
int inc=0;
for(int i=0; i char ch = s.charAt(i);
int depart=i+inc-indexMap.getOrDefault(ch, -k-1);
if(depart<=k) inc+=k-depart+1;
indexMap.put(ch, i+inc);
}
return n+inc;
}
n*******n
发帖数: 45
12
木有用DP....
public int lengthOfLongestSubstring(String s) {
if (s == null) {
return 0;
}
if (s.length() < 2) {
return s.length();
}
int maxLength = 0;
int totalLen = s.length();
int currentLen = 0;
int cStart = 0;
Map indexMap = new HashMap<>();
while((totalLen - cStart) > maxLength) {
for(int i = cStart; i < totalLen; i++) {
Character cur = s.char... 阅读全帖
r********r
发帖数: 208
13
来自主题: JobHunting版 - LC 387 怎么优化
Java code.
Time & space: both O(n).
public int firstUniqChar(String s) {
int[] freq = new int[26];
Map map = new LinkedHashMap<>();
for (int i = 0; i < s.length(); ++i) {
char c = s.charAt(i);
switch(freq[c - 'a']++) {
case 0: map.put(c, i); break;
case 1: map.remove(c); break;
}
}
return map.isEmpty() ? -1 : map.values().iterator().next();
}
b*********d
发帖数: 2105
14
Not 100% true. My pp is very 能干. But her character is very soft (so called
"包子性格"), so I'm very happy to be with her.
The most horrible charater is "不能干却什么都要管", I think.
B******1
发帖数: 9094
15
来自主题: Parenting版 - 孩子的自白(给老师的一封信)
This kid only scribles NONSENSE picture or cartoon charaters, which are not
suitable for logo or anything in that nature.
Sorry.
n****m
发帖数: 1283
16
Sure. Then give the audience a whole picture.
If he is to write a fiction and tell the audience so, tears are for the
faked charaters in the fiction not him.
If he pretends to write a documentary with skewed description, he became a
liar. He should expect the comments asking for truth.
w*********o
发帖数: 3030
17
来自主题: Parenting版 - Fresh Off the Boat
I thought your purpose is to increase the influence of chinese culture. If
you don't care about audience, you might achieve the opposite effect of what
you are preaching with the intolerance.
Well, you keep on claiming you didn't attack anybody. Looks to me that only
you think so on this thread. You seem to think people gives their children
English first name instead of pinyin translations for assimilation purpose
only and it didn't work well. There can be all kinds of purposes. Some might
just ... 阅读全帖
n********h
发帖数: 13135
18
来自主题: Parenting版 - Fresh Off the Boat
” And unless US law allows chinese charaters on passports, the
pinyin translated chinese names are not "中文名字" at all. ”
你说美国法律不允许CHINESE CHARACTERS, 那您的姓肯定也是PINYIN TRANSLA
TION吧。按照您的说法, PINYIN TRANSLATED CHINESE LAST
NAMES ARE NOT “中文名字”。 和着您连姓都不姓中文姓了,所以你的名字完全不C
ARRY 任何 CHINESE HERITAGE。  你融入得太彻底了。

what
only
might
much
F***r
发帖数: 1685
19
比如助学助残基金这类基金
只是帮一个朋友问问,是不是非要成立非营利机构才行?如果有人知道的,请指点一二,非常感谢
z***t
发帖数: 10817
20
来自主题: Chicago版 - 邻居怪老头

"oh sh*t I can not write chinese charater."
a*****0
发帖数: 128
21
来自主题: Michigan版 - 找房
If you have rented an one or two bedroom apartment and want to find a quite/
clean/nosmaking roomate, I am one of choice. (Sorry in offcie cannot input
chinese charater.)
M*******c
发帖数: 4371
22
来自主题: SanFrancisco版 - 眼袋为什么这么严重?
If you could not recognize who this boy is, I feel so sorry for you.
You know nothing more than recognizing several Chinese charaters or how to
count.
G**********e
发帖数: 11693
23
你搞得我很想剧透。。。。。
第一季火力不够武器少也有一个原因是剧情需要,这一季主要是charater building,
之后角色们会一点点变枪,女人小孩才会开始用枪,一开始每个人就这么厉害,之后就
没有发展空间了。你就看吧,之后有个小孩和女的都是神枪手。
实际上杀zombie用火力不是最好的武器,一颗子弹只能杀一只zombie,而子弹是易耗品
。冷兵器可以反复用下去,是比较好的选择。ar ak都是远程射击的武器,zombie少的
时候应该尽量不发出巨大响声的解决掉。有一大群zombie袭来的时候应该赶紧走掉,打
是打不完的,而且响声还会引来更多的zombie,子弹也不够,远程射击速度还不够快,
等走近了就更是来不及了。
你说到处都有遗弃的枪支子弹,是,但那些被遗弃的房子车子商店里,也到处都有
zombie。这些幸存者就是靠到处scavenge资源过活的,每一次scavenge东西都是一次冒
险,同时还有其他幸存者也在到处搜刮这些东西,不是已经被搜刮过了,就是也被其他
人盯上要去搜刮的目标,人和人之间的信任很成问题,一碰上就要为资源厮杀。zombie
就像蚂蚁一样没有思维,人们真正的对... 阅读全帖
b**********y
发帖数: 7371
24
来自主题: NCAA版 - 哈巴那几次暂停算什么意思
Jimmy has nvr been short of supply of haters, and that really explains what
kind of a charater he is
L********g
发帖数: 4204
25
来自主题: TVGame版 - 欲哭无泪啊!mhp3存档坏了
I save a copy every week just in case.
well, maybe it is time for you to pick a new charater (e.g. choose the male
one) and start to use a new type of weapon.
m*****t
发帖数: 4923
26
来自主题: TVGame版 - 那个Drake真牛逼啊
yes i was also amazed by the footprints in the snow the first time i play it. I love Nepal scenes the best. At the Tipet village chapter, don't forget to talk to every single person you meet, especially the bull/cow!!
Finish normal->hard-> crushing mode. Crushing mode is crazy dude.
Don't forget to hunt the treasure
Don't forget to TURN ON SPECIAL EFFECT in bonus menu: not gravity mode is really fun, or slow/fast mode. And don't forget to unlock the power weapon in bonus menu!
In online multipla... 阅读全帖
t******g
发帖数: 17520
27
来自主题: TVGame版 - Borderland 2 有谁入?
挑山工的故事听说过吗?
你昨天打有几个鸡友?用的啥charater?
k****0
发帖数: 172
28
关于有没有隐藏女主这个问题我特意去找了找, 还以为自己忘了
PS2 Shinibi没有隐藏女主
Secret Characters
To unlockk the secret charaters you must collect a certain number of gold
oboro coins:
when you collect 30 coins you unlock the first of the characters who is
Moritsune the main characters brother he is about 2 times as strong as
hotsuma but his sword gauge depletes about twice as fast
The 2nd character you get at 40 gold oboro coins his name is Joe Musashi he
is weaker then hotsuma and his sword doesnt power up as fast either he ... 阅读全帖
i**e
发帖数: 19242
29
来自主题: LeisureTime版 - 见到了韩寒
你的意思,HH同学没有original thoughts?
他有标榜过自己是思想家/文学家么?
有original thoughts的又有几个呢?
大家都不过是对一些事情发表一下自己的看法罢了
罗卜白菜各喜各爱嘛
孔雀开屏
可以拿臭鸡蛋在旁边砸
你也完全可以开屏持靓行凶么
来,推荐几个有思想的让俺见识见识
讲别人傻,并不能证明自己就聪明啊
一个人行文走字,讲的不过是TA自己的charater
m**********2
发帖数: 6568
30
reservoir dogs is like a preview of Pulp fiction. If Pulp fiction is his PhD
thesis, RD is like his prelim exam.
It is just a different way of making the B-movies. If you watch enough bad
cop/mob movies of the 70s and 80s, you see how sterotyped every charater was.
But in RD, first of all, the bad guys used really girly nicknames, pink,
white, blue, etc. (got it, bad guys, girly names, haha)
And they started the movie with bad guys discussing current cultural events
(madona, like virgin)--see, b
g*********n
发帖数: 1055
31
来自主题: Movie版 - 非诚勿扰2
I hate that charater, xiaoxiao. A person with arms and legs, why does she
need to marry someone she doesn't like. Not classic at all! She is not
lovely. I am sadened by her! haha,,
The guy, 40+,,,sigh, no words,,,
g*********n
发帖数: 1055
32
Not nataral relationship. Crapy love story! Or not love story at all!
That charater, xiaoxiao, a person with arms and legs, why does she need to
marry someone she doesn't like. Not classic at all! She is not lovely. I am
sadened by her! haha,,
c**i
发帖数: 6973
33
(1) Leave "ruomu" alone.
He is certainly guilty of piracy/theft of itellectual property right, by
copying a (so called) news report without attribution--but nothing else.
And we do not shoot a messenger.
Don't kill the messenger. The Phrase Finder, undated.
http://www.phrases.org.uk/bulletin
_board/3/messages/520.html
In fact this is a terrific "teachable moment."
(2) Judging from the timing, I presume ruomu's piracy is inspired by my
recent posting:
兰州拉面 in Manhattan. Food Board, Feb 3, 2011.
... 阅读全帖
g***m
发帖数: 465
34
来自主题: Comic版 - Re: 冥界篇真的狠精彩呀
Achilles is the greatest hero, but he was doomed by fate, later slain by Apolo.
As for his friendship with that warrior, you see, he risked his own life fighting
for his loss of loyal friend. That's all.
Helen is pretty to death, I doubt Jin Yong copied her chapter in Shu Jian En Chou
Lu, and put her charaters on Xiang Xiang princess.
Hermes was the tutor of Unicorn warrior, named under Mr. Han, hehe. He is also
living in China.
BTW, I think 希路达 is prttier than 沙织.
j****g
发帖数: 591
35
来自主题: paladin版 - 刘慈欣去起点能成大神么?
re
more than 10K charaters per day ==> possible aunt
m*******c
发帖数: 41
36
来自主题: Reader版 - The Da Vinci Code
I don't know about the others, by I am very disappointed by
"Digital Fortress" from the same author. The story revolves
around cryptology, but the author obviously didn't do his homework.
The mistakes are so glaring that when he put those words into
the mouths of the supposedly smart and competent main characters,
it totally destroys the charaters for me (and I don't claim to
be an expert in that area, by any mean).
So if you know absolutely nothing about information security
(or have superhuma
A****t
发帖数: 69
37
Hear, hear! Well said!
There are several dimensions to the appreciation of any fictional work: to
what extend is it creative, consistent, readable; the depth and richness of
charaters, intricacies of storylines, etc, etc. All of them are equally
legitimate. That said, people have different priorities; when we come to
sci-fi, we have certain expectation. The point of this classification into
sci-fi, fantasy, triller, romance, ..., is we know what to expect and don't
waste time picking up some
r******s
发帖数: 2155
38
来自主题: BNU版 - Re: CEO是心理系的
I used to believe that charater determines your life.
I do too now, to a lesser extent.
You are so interested in Psychology. ru zi ke jiao,
I'll say something here then. hehe.
Personally, I believe people seldom make 'wrong' decisions
on important life matters. Think about Runnaway Bride, it could
happen. When two persons who loved each other seperated, it's
sad but probably not wrong. What makes it sad is that people value
truth feelings and feel bad when losing something valuable. What
makes i
s****r
发帖数: 2386
39
来自主题: SCU版 - anyone watching Glee?
Just found out both main charaters are gay
z*h
发帖数: 22
40
来自主题: BuildingWeb版 - [转载] how to determine the end of socket?
【 以下文字转载自 Java 讨论区 】
【 原文由 zwh 所发表 】
I am writing a simple http server for one of my courses.
but how can I determine the end of socket stream? which
charater I should compare with? null, "\n\r" or ""? thanks
a lot.
l****e
发帖数: 359
41
来自主题: BuildingWeb版 - 问高手如何JS解密?
加密的那段解密以后是:
function RrRrRrRr(teaabb) {var tttmmm="";l=teaabb.length;www=hhhhffff=Math.
round(l/2);if(l<2*www) hhhhffff=hhhhffff-1;for(i=0;i<2*www) tttmmm = tttmmm
+ teaabb.charAt(l-1);document.write(tttmmm);};

LANGUAGE=
52
3b%
c*******o
发帖数: 1722
42
来自主题: Database版 - another sql operation question
have a huge dataset. dumped for 7 hours. unfortunatley, had a small mistake.
here is the problem.
col_1 is a string and col_2 is also a string but very similar to col_1. The
only difference is that col_2 has one or two more charactors than col_1. I
only need to keep the last one or two charators of col_2. How do I do it?
Here is an example:
I now have:
col_1 col_2
1string 1string1
2string 2string23
what I want:
col_1 col_2
1string
t*********i
发帖数: 217
43
来自主题: Database版 - remove special character
Thanks all. But I am always a little confused about the concept of '
printable' when I searched online in the last a few days. Does printable or
non-printable simply mean those characters can be print out? I tried to
write a PL/SQL to print out all charater form chr(1) to chr(10000), and did
see many characters could not show. But specifically for these 5 digits code
like 49816, 49792, they actually were printed out but look like garbage
characters. Any one could clear me out of this?
on the ot
d*x
发帖数: 9
44
来自主题: Java版 - Re: 请教一个问题...
Get a chinese font.
Bitmap fonts are everywhere...and each character is indeed a
b/w bitmap already...so easy to generate GIF etc, but quality
may not be great if you want to scale the charaters.
Vector/True-Type/Type-1 fonts are harder to get, and you will
need non-trivial rendering algorithms. True-Type fonts are better
if you are using Windows platform, as I believe windows has
built-in rendering for true type fonts.
Hope this helps.
p******m
发帖数: 65
45
来自主题: Java版 - 问几个菜问题2
Question 2
Write a complete Java program that will prompt the user to enter: 1) a stude
nt name, and 2) a student number. After inputting the data, the program shou
ld calculate and output the number of odd digits in the student number. Som
e details:
Input: Input the name and student number via JOptionPane.
Do not use charAt() in your solution: Although string methods could be used
to solve this problem, our class has not yet covered string methods, and we
want you to solve this problem usin
s**********r
发帖数: 5
46
来自主题: Java版 - What does this mean?
i = ( Integer ) map.get( new Character( names[ count ].charAt( 0 ) ) );
l*****c
发帖数: 1153
47
用String.charAt()得到的是字符,是經過encoding的。怎麼能得到第i個raw byte?
getBytes()似乎得到的也是encoding過的。
l*****c
发帖数: 1153
48
Or say, I want the string internal memory block, I do not want any encoding
applied when I retrieve this memory block. I'm C++ guru, not Java guru. In C
++, I always have the raw memory block.
Currently, when I call String.charAt(), it does the encoding for me. Say,
they string is Unicode, it give me the the ith char, but I want the ith byte.
k***r
发帖数: 4260
49
来自主题: Java版 - Eclipse不能保存UTF-8文件?
I saved a JSP file with an external text editor (Notepad++)
as UTF-8 with BOM. Eclipse reads it fine after I set in
project properties, resource, source file encoding as UTF-8.
However, when I try to save, I get an error:
"Save could not be completed.
Reason:
Some characters cannot be mapped using "ISO-8859-1" charater
encoding ..."
Any idea how I can save JSP in UTF-8?
x****a
发帖数: 1229
50
// public void postfix (String input)
// {
// Stack s1 = new Stack();
// String output = "";//to store the postfix expression
//
// for (int i =0; i // {
// //get the single letter
// char letter = input.charAt(i);
//
// //convert infix to postfix
// if (letter =='1'||letter =='2'|| letter =='3'||letter =='4'||
letter =='5'||letter =='6'||
// letter =='7'||le... 阅读全帖
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)