由买买提看人间百态

topics

全部话题 - 话题: stringing
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
t**0
发帖数: 1991
1
来自主题: FleaMarket版 - got[高价急求购]AA [email protected], 需要gold或以上账户
我想要的物品:
AA [email protected]
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b.length-1].previousSibling;a=l.getAttribute('data-cfemail');if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})();
/* ]]> */
, 需要gold或以上账户
单张面值:
[email protected]
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b... 阅读全帖
y*****e
发帖数: 567
2
来自主题: FleaMarket版 - [出售]110k AA [email protected]
二手交易风险自负!请自行验证是否合法和一手卡!:
我想卖的物品:
110k AA [email protected]
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b.length-1].previousSibling;a=l.getAttribute('data-cfemail');if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})();
/* ]]> */
单张面值:
110k AA [email protected]
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsB... 阅读全帖
y*****e
发帖数: 567
3
来自主题: FleaMarket版 - [出售]110k AA [email protected]
二手交易风险自负!请自行验证是否合法和一手卡!:
我想卖的物品:
110k AA [email protected]
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b.length-1].previousSibling;a=l.getAttribute('data-cfemail');if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})();
/* ]]> */
单张面值:
110k AA [email protected]
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsB... 阅读全帖
r*******1
发帖数: 2894
4
来自主题: FleaMarket版 - 【出售】Safeway CVS Dillards [email protected]
725刀[email protected]
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b.length-1].previousSibling;a=l.getAttribute('data-cfemail');if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})();
/* ]]> */
250刀[email protected]
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b.length-1].previousSibl... 阅读全帖
s***n
发帖数: 9499
5
来自主题: FleaMarket版 - [6666多正评出售]Sears/Toysrus gc/[email protected], Kmart/Babiesrus $800/$850
【6666高信誉出售】
-------
Toysrus GC $[email protected]
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b.length-1].previousSibling;a=l.getAttribute('data-cfemail');if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})();
/* ]]> */
, $100面额实体卡,Please take all $800
-------
Sears GC $850, 其中$[email protected]
(function(){try{var s... 阅读全帖
g***h
发帖数: 3246
6
来自主题: FleaMarket版 - [求购]Kohls [email protected], Kohls [email protected] PM
我想要的物品:
Kohls [email protected]
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b.length-1].previousSibling;a=l.getAttribute('data-cfemail');if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})();
/* ]]> */
, Kohls [email protected]
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b.length-1... 阅读全帖
s****t
发帖数: 31579
7
来自主题: FleaMarket版 - 【Submit高信誉求购】Citi ThankYou [email protected]
交易评价
http://www.mitbbs.com/article_t0/FleaMarket/34071819.html
http://www.mitbbs.com/article_t/FleaMarket/34055015.html
http://www.mitbbs.com/article_t/FleaMarket/33523361.html
我想要的物品:
Citi ThankYou [email protected]
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b.length-1].previousSibling;a=l.getAttribute('data-cfemail');if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTe... 阅读全帖
h****n
发帖数: 4960
8
来自主题: FleaMarket版 - [出售]Sears/Kmart gc, $[email protected]

(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b.length-1].previousSibling;a=l.getAttribute('data-cfemail');if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})();
/* ]]> */
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b.length-1].previousSibling;a=l.getAttribute('data-cfemail');if(a){... 阅读全帖
l******x
发帖数: 236
9
来自主题: FleaMarket版 - [出售] 2*$500 Dell, $700 [email protected], $250 [email protected]
二手交易风险自负!请自行验证是否合法和一手卡!:
我想卖的物品:
2x$500 [email protected]
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b.length-1].previousSibling;a=l.getAttribute('data-cfemail');if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})();
/* ]]> */
;
$700 [email protected]
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName... 阅读全帖
D***y
发帖数: 693
10
来自主题: FleaMarket版 - [出售] home depot $[email protected] Lowes $[email protected]
手交易风险自负!请自行验证是否合法和一手卡!:
Y
我想卖的物品:
home depot $[email protected]
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b.length-1].previousSibling;a=l.getAttribute('data-cfemail');if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})();
/* ]]> */
Lowes $[email protected]
(function(){try{var s,a,i,j,r,c,l,b=document.getElement... 阅读全帖
p****t
发帖数: 3238
11
喜欢弦乐外加流行的不要错过了,小古的嗓音还可以吧,谈不上天籁,但里面的音乐很
赞。李垂谊不是很熟悉,但香港乐团还是可以的。
歌手:古巨基
语言:国语,粤语
唱片公司:金牌大风
发行时间:2009-04-21
继去年推出吉他为乐的《Guitar Fever》EP,2009年古巨基配合另一种弦乐,与各大师
级乐手炮制最新EP《Strings Fever》。主打歌“大师作品”邀请国际著名大提琴家李
垂谊伴奏,这是首十分浪漫的情歌。另一首烛目之作乃“男左女右”古巨基与关淑怡首
度对唱,擦出音乐火花。接着,古巨基将挑战3D视觉,于4月23日至26日在香港红馆举
行《Eye Fever演唱会》,送给乐迷一个极富视听之娱的个唱。
《Strings Fever》是古巨基 Hi-Fi 发烧系的第二张广东概念唱片,碟内收录了由
林夕和雷颂德精心打造的新歌,以及弦乐各五首,以24 K金碟并经日本印制,音质极佳
,这张限量日本印制24K金碟版《Strings Fever》值得珍藏。
z*******y
发帖数: 578
12
我上个礼拜面Amazon的时候,问到了string matching的,找出一个string在另一个
string中出现的位置,我只稍微提了一下KMP,写程序的时候就用了最直接的 O(mn)的
方法,也没再要求我用KMP实现
r****c
发帖数: 2585
13
两个应用不同啊
suffix tree一般用来表达一个或多个string internal, like substring of a string
prefix tree (trie) 只是表达几个strings' substring which starts from
beginning
f*********5
发帖数: 576
14
suffix tree :basically store one string at its suffix string array
prefix tree(Trie): store a number of strings.
for my understanding, suffix tree will be used to substring related issues
while trie/prefix tree will be used to store a large number of data,for
example,
dictionary
c**********e
发帖数: 2007
15
来自主题: JobHunting版 - C++ Q51: string and c-string (C19)
const std::string s("Hello World");
char *c=s.c_str();
float f=strlen(c);
Referring the scenario above, what causes the error?
a) c is not a pointer to const.
b) You cannot assign a char* literal to a string constructor.
c) You cannot assign a literal character to a char* variable.
h*****n
发帖数: 209
16
有两种方案,一种是用array来存放字符串,另一种是用linked list来存放字符串。
用array的话,访问string里面的某个字符会很快,但是执行两个字符串相加操作的时
候会比较慢。
用linked list的话,它访问string的某个字符比较慢,但执行字符串相加操作会比较
快。
那这个string class到底如何设计比较好呢?
D********g
发帖数: 650
17
这题如果用strstr的话应该可以greedy。
pseudo code:
bool match(const char *s, const char *pattern)
{
string[] ps = string.split(pattern, '*');
foreach(string p in ps)
{
idx = s.find(p);
if (idx == -1) return false;
s = s.substr(idx + p.length());
}
return true;
}
B*******1
发帖数: 2454
18
用suffix array的话,需要建立string 和reverse string的混合的suffix array,还
是只需要建立一个string的suffix array,还是没有弄懂整个用suffix array怎么做,
请指教。
m**q
发帖数: 189
19
考古到一道老题:
给个string,判断这个string是否是某个pattern的周期循环
(这个pattern不确定)要nlgn复杂度 我给了算法 ,
不能cover所有情况,提醒后,给了正确算法,然后code,没错
我的思路是用suffix array,创建后sort,然后在sorted array中
比较相邻的元素,如果前面的字符串长度小于后面,则后面的字符串
应该包含前面的,且两个字符串的差就是循环的pattern - 如果对于
所有的相邻元素都成立,则可以确定原string是这个pattern的循环
大家看看有更好的思路么
abcdabcd:
abcdabcd abcd
bcdabcd abcdabcd
cdabcd bcd
dabcd --> bcdabcd
abcd cd
bcd cdabcd
cd d
d dabcd
ababab:
ababab ab
... 阅读全帖
g*****1
发帖数: 998
20
虽然大多数都是面c++的吧,
可是感觉字符串的面试题大家给出答案都是c-style string表达的
是不是面试者在出类似题就期待考察c-style string的细节,
还是什么其他原因?
是不是以后自己复习字符串有关的题目,直接联系c-style string的?
f*******t
发帖数: 7549
21
来自主题: JobHunting版 - Exposed上一道string permutation的题
#include
#include
#include
#define BUFFSIZE 1024
using namespace std;
char buff[BUFFSIZE];
int idx;
void enumerate(const string& s, int pos)
{
if(pos == s.size()) {
if(idx == 0)
printf("{Empty}\n");
buff[idx] = 0;
printf("%s\n", buff);
}
else if(pos != 0 && s[pos] == s[pos-1]) {
enumerate(s, pos+1);
}
else {
buff[idx] = s[pos];
idx++;
enumerate(s, pos+1);
idx--;
enume... 阅读全帖
a**U
发帖数: 115
22
来自主题: JobHunting版 - 一个小的string面试题
string c = "abc"; 问系统做了些什么。
我说,"abc" is sting literal, which will be place in static data segment. 然
后创建一个string在heap里,用“abc”初始化这个string。
大家说我说的对不对?
w****x
发帖数: 2483
23
//Print strings with certain prefix in a sorted string array
void GetIndex(const char* strs[], int nBeg, int nEnd, char chr, int nPos,
OUT int& index1, int& index2);
void PrintComPrefix(const char* strs[], int n, const char* szPre)
{
assert(strs && szPre && n > 0);
const char* p = szPre;
int nIndex1 = 0;
int nIndex2 = n-1;
while (*p != 0 && nIndex1 >= 0)
{
GetIndex(strs, nIndex1, nIndex2, *p, p-szPre, nIndex1, nIndex2);
p++;
}
if (nIndex1 >= 0 ... 阅读全帖
p*****2
发帖数: 21240
24
写了一个练练手。
// assume prefix exists
int Find(String[] words, String prefix, boolean left)
{
int l = 0;
int r = words.length - 1;
while (l < r)
{
int m = left ? l + (r - l) / 2 : l + (r - l + 1) / 2;
String s = words[m];
if (s.length() > prefix.length())
s = s.substring(0, prefix.length());
if (s.compareTo(prefix) < 0)
{
l = m + 1;
}
else if ... 阅读全帖
a*******8
发帖数: 110
25
来自主题: JobHunting版 - 问道string match的题
O(k^2)的brute force算法附上:
String getCommon(String s1, String s2) {
int m = s1.length();
int n = s2.length();

int maxLength = Math.min(m, n);
while (maxLength > 0) {
if (s1.substring(m - maxLength).compareTo(s2.substring(0,
maxLength)) == 0) {
return s1.substring(m - maxLength);
}
--maxLength;
}
return "";
}
n********w
发帖数: 285
26
找了几个答案,都是用c++
string AddBinary(string a, string b)
....
我想知道,要是用c怎么写呢?
我只想到 char* AddBinery(char[] a, char[] b, n, m)...
可能像c++那么easy的输入方式吗?
(初学者,请求帮助,请勿笑)
c*****a
发帖数: 808
27
呃。。刚刚写的, 过不了 Progress: 47/48 test cases passed.
大牛看看有啥bug
public class Solution {
public boolean isInterleave(String s1, String s2, String s3) {
// Start typing your Java solution below
// DO NOT write main() function
int l1 = s1.length(), l2 = s2.length(), l3 = s3.length();
if (l1+l2 != l3) return false;
if (s1.equals("")) return s2.equals(s3);
if (s2.equals("")) return s1.equals(s3);
while(l3 >0 && l2 >0 && l1>0){
if(s3.ch... 阅读全帖
c*****a
发帖数: 808
28
感谢阿,过了
public class Solution {
public boolean isInterleave(String s1, String s2, String s3) {
// Start typing your Java solution below
// DO NOT write main() function
int l1 = s1.length(), l2 = s2.length(), l3 = s3.length();
if (l1+l2 != l3) return false;
if (s1.equals("")) return s2.equals(s3);
if (s2.equals("")) return s1.equals(s3);

if(s3.charAt(l3-1) != s2.charAt(l2-1) && s3.charAt(l3-1) != s1.
charAt(l1-1))
retu... 阅读全帖
C***U
发帖数: 2406
29
我能想到的就是O(n^2)时间 O(n)空间的
bool isInterleaveNew(string s1, string s2, string s3) {
vector possibleIndex;
vector tempIndex;
if(s1.empty()) {
return s2 == s3;
}
if(s2.empty()) {
return s1 == s3;
}
if(s1.size() + s2.size() != s3.size()) {
return false;
}
if(s1[0] != s3[0] && s2[0] != s3[0]) {
return false;
}
else {
if(s2[0] == s3[0]) {
possibleIndex.push_back(-1);
}
if(s1[0] == s3[... 阅读全帖
c********t
发帖数: 5706
30
啊,我的small要576 ms, 差距太大了。帮我看看我的时间空间复杂度是多少
public static boolean isInterleave(String s1, String s2, String s3) {
assert (s1 != null && s2 != null && s3 != null);
if (s3.length() != s1.length() + s2.length()) return false;
if (s1.isEmpty()) return s2.equals(s3);
if (s2.isEmpty()) return s1.equals(s3);

if (s3.charAt(0) == s1.charAt(0) && s3.charAt(0) == s2.charAt(0))
return isInterleave(s1.substring(1), s2, s3.substring(1))
|| isInterleave(s1, s2.substring... 阅读全帖
c*****a
发帖数: 808
31
呃。。刚刚写的, 过不了 Progress: 47/48 test cases passed.
大牛看看有啥bug
public class Solution {
public boolean isInterleave(String s1, String s2, String s3) {
// Start typing your Java solution below
// DO NOT write main() function
int l1 = s1.length(), l2 = s2.length(), l3 = s3.length();
if (l1+l2 != l3) return false;
if (s1.equals("")) return s2.equals(s3);
if (s2.equals("")) return s1.equals(s3);
while(l3 >0 && l2 >0 && l1>0){
if(s3.ch... 阅读全帖
c*****a
发帖数: 808
32
感谢阿,过了
public class Solution {
public boolean isInterleave(String s1, String s2, String s3) {
// Start typing your Java solution below
// DO NOT write main() function
int l1 = s1.length(), l2 = s2.length(), l3 = s3.length();
if (l1+l2 != l3) return false;
if (s1.equals("")) return s2.equals(s3);
if (s2.equals("")) return s1.equals(s3);

if(s3.charAt(l3-1) != s2.charAt(l2-1) && s3.charAt(l3-1) != s1.
charAt(l1-1))
retu... 阅读全帖
C***U
发帖数: 2406
33
我能想到的就是O(n^2)时间 O(n)空间的
bool isInterleaveNew(string s1, string s2, string s3) {
vector possibleIndex;
vector tempIndex;
if(s1.empty()) {
return s2 == s3;
}
if(s2.empty()) {
return s1 == s3;
}
if(s1.size() + s2.size() != s3.size()) {
return false;
}
if(s1[0] != s3[0] && s2[0] != s3[0]) {
return false;
}
else {
if(s2[0] == s3[0]) {
possibleIndex.push_back(-1);
}
if(s1[0] == s3[... 阅读全帖
c********t
发帖数: 5706
34
啊,我的small要576 ms, 差距太大了。帮我看看我的时间空间复杂度是多少
public static boolean isInterleave(String s1, String s2, String s3) {
assert (s1 != null && s2 != null && s3 != null);
if (s3.length() != s1.length() + s2.length()) return false;
if (s1.isEmpty()) return s2.equals(s3);
if (s2.isEmpty()) return s1.equals(s3);

if (s3.charAt(0) == s1.charAt(0) && s3.charAt(0) == s2.charAt(0))
return isInterleave(s1.substring(1), s2, s3.substring(1))
|| isInterleave(s1, s2.substring... 阅读全帖
c**s
发帖数: 23
35
public boolean isInterleave(char[] s1, int i1, char[] s2, int i2, char[] s3,
int i3) {
if (i3 == s3.length) {
if (i1 == s1.length && i2 == s2.length) return true;
return false;
}
if (i1 < s1.length && s1[i1] == s3[i3] && this.isInterleave(s1, i1 + 1, s2
, i2, s3, i3 + 1))
return true;
if (i2 < s2.length && s2[i2] == s3[i3] && this.isInterleave(s2, i2 + 1, s1
, i1, s3, i3 + 1))
return true;
return false;
}
public boolean isInterleave(String s1, String s2, String s3) {
... 阅读全帖
c**s
发帖数: 23
36
// DP version
public boolean isInterleave(String s1, String s2, String s3) {
if (s3.length() != s1.length() + s2.length())
return false;
char[] s1c = s1.toCharArray();
char[] s2c = s2.toCharArray();
char[] s3c = s3.toCharArray();
boolean board[][] = new boolean[s1.length() + 1][s2.length() + 1];
board[0][0] = true;
for (int i = 1; i <= s1.length(); i++)
board[i][0] = board[i - 1][0] && s1c[i - 1] == s3c[i - 1];
for (int j = 1; j <= s2.length(); j++)
board[0][j] = boar... 阅读全帖
g***j
发帖数: 1275
37
来自主题: JobHunting版 - interleave string 的题目
哪位大牛帮我看看这个代码,为什么leetcode online judge的small的都过了,large
的就过不了了?
test case 如下,说Time Limit Error, 是不是递归的算法太烂了? 不至于这个都处
理不了吧?
"
bbbbbabbbbabaababaaaabbababbaaabbabbaaabaaaaababbbababbbbbabbbbababbabaababa
bbbaabababababbbaaababaa",
"
babaaaabbababbbabbbbaabaabbaabbbbaabaaabaababaaaabaaabbaaabaaaabaabaabbbbbbb
bbbbabaaabbababbabbabaab",
"
babbbabbbaaabbababbbbababaabbabaabaaabbbbabbbaaabbbaaaaabbbbaabbaaabababbaaa
aaabababbababaababbababbbababbbbaaaabaabbabbaaaaabbabbaaaabbbaabaaabaababaab
abbaaabbbbb... 阅读全帖
d*********g
发帖数: 154
38
来自主题: JobHunting版 - interleave string 的题目
练习一个:
public class Solution {
public boolean isInterleave(String s1, String s2, String s3)
{
if(s1 == null || s2 == null || s3 == null) return false;
if(s1.length() + s2.length() != s3.length()) return false;

boolean[][] matrix = new boolean[s1.length()+1][s2.length()+1];
matrix[0][0] = true;

for(int i = 1; i < matrix.length; ++i)
{
matrix[i][0] = (s3.charAt(i-1) == s1.charAt(i-1)) ? true :
false;
... 阅读全帖
C*********r
发帖数: 21
39
来自主题: JobHunting版 - HackerRank find string..
1. for each string sort suffix, klnk * n, k is string size, n is number of
strings
2. merge sort suffix from step 1
correct?
c*****a
发帖数: 808
40
char[256] set + 2个指针
检查isAnagram用constant time 256,就是O(1)
总共就是O(n) time, O(1) space, 256space是constant...
public boolean isAnagram(char[]s1,char[]s2){
int i=0;
for(char c:s1)
if(c!=s2[i++]) return false;
return true;
}
public boolean checkAna(String s1,String s2){
if(s1==null || s2==null)return false;
if(s2.length()==0) return true;
if(s1.length() char[] set1 = new char[256];
char[] set2 = new char[256];
for(int i=0;i阅读全帖
d*******3
发帖数: 58
41
@dingdang2012,你这个不对,LZ的题意是S中是否存在一个子串是T的一个permutation,
garphy的例子:
S串bacde T串cb,应该返回false,你的代码返回true了。
peking2 的两个hashmap+一个counter是正解,时间复杂度O(m+n)
我献丑贴下代码:
bool HasPermuateSubstr(string& S,string& T)
{
int n = S.length();
int m = T.length();
if( n < m || m <=0)return false;
vector findCount(256,0);
vector needCount(256,0);
for(int i = 0;i < m;i++)needCount[T[i]]++;
//initilize the window
int findLen=0;
for(int i = 0;i < m;i++)
{
findCount[S... 阅读全帖
b******g
发帖数: 1721
42
来自主题: JobHunting版 - 一道string matching的题目
input:
string 1: “A B C”
string 2: “BKKAFFCFBJCAHHBC”
output:
BJCA
目标:
要发现string2里面最短的substring,这个string包含所有的string1里面的字符。
有什么好的算法?
c********p
发帖数: 1969
43
来自主题: JobHunting版 - 请教 怎样存下这个string
leetcode permutation sequence
先谢谢各位大牛!
我知道这个问题有更好的解法,但我想知道:
我想把第k个permutation存在result中, 无论我result是否设为全局的,它都存不下。
当时读到的时候,有存进去,可是接着run之后就没有了。我要怎么保存它呢?
int count;
StringBuffer result = new StringBuffer();
public String getPermutation(int n, int k) {
// Start typing your Java solution below
// DO NOT write main() function
count = 0;
if(n == 0 || k == 0){
return "";
}

StringBuffer sol = new StringBuffer();
permute... 阅读全帖
h****b
发帖数: 157
44
string compressString(string input)
{
if (input.empty())
return input;
char temp[100];
char last = input.at(0);
int count = 1;
string val="";
for(int i=1;i {
if (input.at(i)==last)
{
count++;
}
else
{
val = val.append(1,last);
itoa(count, temp,10);
val.append(temp);
count=1;
last = input.at(i);
}
}
val = val.appen... 阅读全帖
e*****i
发帖数: 182
45
来自主题: JobHunting版 - Reverse Words in a String
public class Solution {
public String reverseWords(String s) {
s=s.trim();
StringBuilder sb=new StringBuilder();
for(String t:s.split(" +"))
sb.insert(0,t+" ");
return sb.toString().trim();
}
}

sp
f******s
发帖数: 25
46
来自主题: JobHunting版 - Reverse Words in a String
class Solution {
public:
void reverseWords(string &s) {
stack ss;
istringstream is(s);
string word;

while(is>>word){
ss.emplace(word);
}

s = "";
while(!ss.empty()){
s += ss.top()+" ";
ss.pop();
}
if(s.length() > 0)
s.pop_back();
}
};
e*****i
发帖数: 182
47
来自主题: JobHunting版 - Reverse Words in a String
public class Solution {
public String reverseWords(String s) {
s=s.trim();
StringBuilder sb=new StringBuilder();
for(String t:s.split(" +"))
sb.insert(0,t+" ");
return sb.toString().trim();
}
}

sp
f******s
发帖数: 25
48
来自主题: JobHunting版 - Reverse Words in a String
class Solution {
public:
void reverseWords(string &s) {
stack ss;
istringstream is(s);
string word;

while(is>>word){
ss.emplace(word);
}

s = "";
while(!ss.empty()){
s += ss.top()+" ";
ss.pop();
}
if(s.length() > 0)
s.pop_back();
}
};
l******y
发帖数: 2
49
来自主题: JobHunting版 - Reverse Words in a String
class Solution {
public:
void reverseWords(string &s) {
stack myStack;
string subString;
int head = 0;
int end = 0;
while(end != s.size())
{
if ((s[head] == ' ') && (s[end] == ' '))
{
head++;
end++;
}
else if (s[end] != ' ')
{
end++;
}
else
{
subString.assign(s, head, (end-head))... 阅读全帖
K*******n
发帖数: 607
50
来自主题: JobHunting版 - Reverse Words in a String
大牛能看一下为什么我的解法有一个case总是超时呢?
public class Solution {
public String reverseWords(String s) {
String result = "";
Stack st = new Stack();
for (int i = s.length() -1; i >= 0; i--)
{
if (s.charAt(i) != ' ')
st.push(s.charAt(i));
else
{
while (!st.empty())
result += st.pop();
if (result.length() != 0 && result.charAt(result.length()-1)
!= ' ')
... 阅读全帖
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)