A*******e 发帖数: 2419 | 1 下面的算法有什么问题吗?已经是O(n),在C++统计里排到最后,落入C#区间了。
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int result = 0;
int start = 0;
int end = 0;
unordered_map hash;
for (int i = 0; i < s.length(); ++i) {
char ch = s[i];
const auto it = hash.find(ch);
if (it != hash.end() && it->second >= start) {
result = max(result, end - start);
start = it->second + 1;
}
... 阅读全帖 |
|
|
n*********w 发帖数: 71 | 3 不是CS的,所以对这些操作不熟悉
char a[1024] = "welcome";
char* f = a;
strlen(f);//结果是8, 我知道因为有个\0
但是怎么把f后面的\0去掉呢?
简单的说,我怎么比较
if(f == "welcome")呢? |
|
B*****g 发帖数: 34098 | 4 based on my test. 9i and 10g
to_char return char
'abc' is char
please confirm |
|
c*****d 发帖数: 6045 | 5 to_char返还varchar2还是char很重要吗?
varchar2还是char只是内部存储的方式不同 |
|
l**********r 发帖数: 4612 | 6 【 以下文字转载自 Programming 讨论区 】
发信人: linuxbeginer (linux), 信区: Programming
标 题: Char x[] = "abc"; 是在heap还是stack上?
发信站: BBS 未名空间站 (Mon Oct 19 17:15:12 2009, 美东)
Char x[] = "abc";
我认为内存allocated 在heap上。对么? |
|
c*******n 发帖数: 112 | 7 对阿,一个是指向Char×的指针,一个是数组,区别很大啊。。。 |
|
d********i 发帖数: 8 | 8 这是今天的电话面试问题:
问:
struct test{
char a;
int b;
};
这个STRUCT 多大,我回答是: 假设CHAR 一个字节, INT 4个字节,理论上讲应该5个字节
,但是COMPILER应该会做调整, 有PADDING, 所以很多情况是8个字节. 最好用SIZEOF()
来确定而不是自己来算.
我后来用GCC写了小程序, 是8个字节,不过面试官好象不相信我. 我有说错吗? |
|
G****n 发帖数: 618 | 9 Why does default exception use const char* instead of std::string
when defining the what() member function?
const char* const what() const;
I think the reason is to avoid dynamic memory allocation so no
additional exceptions are thrown, which might be caused by
the std::string class. |
|
b***y 发帖数: 2799 | 10 ☆─────────────────────────────────────☆
jyu (jyu) 于 (Fri Mar 14 16:55:32 2008) 提到:
hi All,
I have a problem casting a 4 byte unsigned char into integer.
here is my code:
this is C++ code:
// header is just a structure with a field of 4 byte unsigned char
unsigned int sequence = *(reinterpret_cast(header->m_sequenceNum
));
and the sequence is always some overflow #!
all comments/help are appreciated!
Thank you very much!
☆─────────────────────────────────────☆
Xentar (思考猪) 于 |
|
b***y 发帖数: 2799 | 11 ☆─────────────────────────────────────☆
oOOo (\_/o!o\_/) 于 (Wed Sep 7 01:50:59 2005) 提到:
they are the same
1;"?
☆─────────────────────────────────────☆
cdr (可读可写) 于 (Wed Sep 7 02:18:37 2005) 提到:
1;"?
The second one has a symbal "A" in the symbal table.
☆─────────────────────────────────────☆
thrust (Thrust Jaeina) 于 (Wed Sep 7 13:16:53 2005) 提到:
const char* and char const* are the same. (if you use gdb, gdb always use the
later form.)
#define A 1 and const int A=1 are NOT the |
|
e******d 发帖数: 310 | 12 //why the following assignment is allowed? I think we need use
// const char* str = "this is a test. \n" ; instead.
// then we can prevent assignment like
// str[1] = 'g';
// thanks
char* str = "this is a test. \n";
str[1] = 'g';
|
|
h****b 发帖数: 157 | 13 简单的不好意思问,谢了
int word = 0x1;
char *byte = (char *) &word;
cout<
printf("%d\n", byte[0]);
为啥cout 和 printf 打出来的不一样? printf的对,cout是乱码 |
|
B*******g 发帖数: 1593 | 14 啊啊啊,解释的不错 thx
那还有个问题 如果给出两个char *的话怎么知道它们指向的是rw的stack还是r only的
全局
char
据。 |
|
r*******y 发帖数: 1081 | 15 that is my question: type of p is const char *, why type of p+1 is
also const char * ?
thanks |
|
e****d 发帖数: 895 | 16 sizeof(p) is the size of the pointer, not char size.
also, sizeof(a) includes '\0' |
|
d****i 发帖数: 4809 | 17 string literal in C is treated as const char* type, thus nonmodifiable
*
array. |
|
|
b*******s 发帖数: 5216 | 19 第一个指向常量区,第二个复制分配了一个4个char长度的串
*
array. |
|
G******g 发帖数: 2275 | 20 我是新手,在C++程序里面要指定文件名,我喜欢用string,但看别人的程序里
都是用char[],我这样用会不会引起别人笑话啊? |
|
C********e 发帖数: 219 | 21 为什么char**&最后两个符号不会抵消?
谢谢 |
|
B********9 发帖数: 44 | 22 Right, this is format. I wonder whether we have SAS function to read this
char. date while the format is numeric with datetime22.3.
EX: we can use DHMS function to read char. date and reformat as a numeric
date as date22.3, however, the last SSS will be the default as "000".
Thanks. |
|
B********9 发帖数: 44 | 23 Yes, that's right, it's my typing mistake, sorry~
The input function is not working. Because if we use "input" function to
reformat a char date, the result only return sas date format, which is not
what I want.
In your case: Y=input(X,datetime22.3):
X: 30SEP2011:10:12:31.705 type: Char; length: 22
Y: 1632996751.7 type: Num; Length:8
However, this is what I want:
Y: 30SEP2011:10:12:31.705 type: Num; length: 8; informat: Datetime22.3;
format: Datetime22.3.
Any suggestions? Thanks |
|
|
|
l**********r 发帖数: 4612 | 26 suppose char x[] is defined at global scope.
I think x[] is on heap with 4 bytes memory. Compiler allocated the space and
copied "abc" on the space |
|
l**********r 发帖数: 4612 | 27 Hmmmm. what I mean is for
Char x[] = "abc"
the "abc" that x points to is on *heap* |
|
l**********r 发帖数: 4612 | 28 char * x = "abc"; 这是个literal,一般情况下都在data segment里吧? |
|
b*******y 发帖数: 239 | 29 operator const char*()
一直不知道这个怎么理解,有人说说这个的特殊含义吗?
我知道一般的operator overload,但这个似乎连operator是什么都没有,所以很不理
解。
这个是C++的,请指点,非常感谢。 |
|
S***n 发帖数: 31 | 30 which do you want to access to? "a" or the object "a" pointing to?
If it's "a", use reference "const char& *a" in the argument
if it's the object "a" pointing to, just access by *a, eg. *(a++).
Personal opinion :) |
|
f*********5 发帖数: 576 | 31 can below be considered as O(1) space?
char array or bitmap which can support 256 different situations? |
|
i**c 发帖数: 26 | 32 你这个"很大的CHAR[]",言外之意要不能一次装入内存? |
|
|
g***s 发帖数: 3811 | 34 same idea with the question yesterday.
for first 256 items, a[i], loop check the position a[i], if a[a[i]]!=a[i],
which means it is not a duplicate, swap; otherwise(duplicate), clean.
for the rest, just check/clean.
after the above steps, compact all chars. |
|
s**x 发帖数: 7506 | 35 没看懂。 only process first 256?
clean? clean what?
swap? what the loop start after swap? start next position or the current
position need to be checked again with the swapped char? |
|
g***s 发帖数: 3811 | 36 hehe. i just gave the idea. I assumed char.length is large than 256. |
|
f****4 发帖数: 1359 | 37 那个idea只是在连续整数差一个,两个的情况下才比较合适
这里套的话不合适:题目没说char[]放的东西连续
并且要求in-place,那么用bitmap应该也是不合要求的(??)
如果能放进内存,可以用变形的quicksort来做
Partition好之后
a[0]x a[i+2]>x ..
. a[j]>x
交换 a[j]<=>a[i]; a[j-1]<=>a[i-1]...a[j-k+2]<=>a[i-k+2]
设置j=j-k+1 (重复的元素被交换到了数组尾部,并且不再参与下一次的递归)
继续
最后得到的数组即为无重复数组+尾部所有的重复元素
将重复元素清空即可 |
|
g***s 发帖数: 3811 | 38 1. char的范围是-127到127. 具体实现的时候转换成0到256
2. 我前面已经说了,假设length>255
3. 这个方法不是只能用在却一两个数的情况下
4. 我只是给个大概的方向,具体实现可以考古。 |
|
f****4 发帖数: 1359 | 39 -127~127是ascii编码,char* 支持utf8
a[a[i]]==a[i]的确支持int a[10001]={10,100,10000};但必须有假设a足够大>=10001
(这个面试的人能同意么?特别是我给的这个情况)
我想强调的是,这个题目很多限制不确定,a[a[i]]==a[i]不一定能套上 |
|
f****4 发帖数: 1359 | 40 我用int a[]举例是因为我不知道怎么输入utf8字符
我上面也说了,char *支持utf8,这个题目很多限制不确定,不是a[a[i]]==a[i]就一
定能套上去的 |
|
l******d 发帖数: 530 | 41 考虑这个函数
void foo(char c){
...
}
如果用户传递个大于127的值给c,比如 foo(128),在foo里c是溢出的,得到的值是-
128。如果用户在调用foo前判断传给c的值是不是大于127或小于-128很容易,有没有办
法在foo里检测传给c的值是溢出的呢,就是说,不依赖于函数的用户去检测溢出。 |
|
l*********8 发帖数: 4642 | 42 应该没有办法。 foo()知道的就是char, 不知道之前有没有经过数据类型转换。 |
|
j*****y 发帖数: 1071 | 43 而且这个 p+ 1就是地址的值增加 1 和 char * p 的 +1 是一样的 |
|
l*******b 发帖数: 2586 | 44 void * 不能dereference吧? 另外直接pass 一个别的 Type *给char *会报错? 给void
*没事? |
|
j*****y 发帖数: 1071 | 45 void * 的 p + 1 和 char * 的 p + 1 是一样的 |
|
p****9 发帖数: 232 | 46 n(n >5)年没用java了。。。或者当年就糊涂着呢。。。那个题必须得把char array转
成string才过的了。。 |
|
z*****g 发帖数: 2 | 47 char array的hash code是内存地址。。。 |
|
r****s 发帖数: 1025 | 48 push into stack and popup if next char is the same. |
|
S******2 发帖数: 248 | 49 和rtscts说的一样.
public static String removeDup(String str)
{
if(str == null || str.length() <= 1)
return str;
Stack stack = new Stack();
for(int i = 0; i < str.length(); i++)
{
char ch = str.charAt(i);
if(stack.isEmpty() || ch != stack.peek())
{
stack.push(ch);
}
else if(ch == stack.peek())
{
stack.pop();
}
... 阅读全帖 |
|
r****s 发帖数: 1025 | 50 稍微改一下,stack也可以做出来。
public static String removeDup(String str)
{
if(str == null || str.length() <= 1)
return str;
Stack stack = new Stack();
Character last = ' ';
for(int i = 0; i < str.length(); i++)
{
char ch = str.charAt(i);
if(ch!=last && (stack.isEmpty() || ch != stack.peek()))
{
stack.push(ch);
... 阅读全帖 |
|