|
d****r 发帖数: 80 | 2 看大家都在做leetcode,
八卦一下,谢谢。 |
|
|
|
|
j**c 发帖数: 9 | 6 /*
* 失荆州 - G电面经
*
两道G的电面题:
-----------------------------------------------------------
1. You are going to work with “bigNums”, which are
objects containing a positive integer with an
unlimited number of decimal digits.
a) declare a struct to represent “bigNums”
b) write a function that takes as arguments a bigNum
and a positive integer between 0 and 9, adds them
and returns the answer (a bigNum)
10 - 9 = 1
--------------
2. You are given two very large files of unsigned 64
bit integers. Write t... 阅读全帖 |
|
f*******7 发帖数: 943 | 7 改版前的讲解部分写的很好,而且能让人发散思维联系到相关的内容
改版后只有用户去贴code了,也不会有用户写那么详细的分析讲解了
不知道过段时间那个部分会不会加回来。。。
还有就是OJ有test case 那部分,好像新版也没有
谢谢楼下各位及给我发信的同学:
“http://leetcode.com/users/1/1337c0d3r
看到页面下面,写着76answers,这些都是他的讲解贴。” |
|
m**********e 发帖数: 22 | 8 今天重做leetcode:String Reorder Distance Apart。发现1337c0d3r给出的答案(http://discuss.leetcode.com/questions/31/string-reorder-distance-apart)有较大改进的地方:"used" array and the while loop inside the for loop are not needed. I wrote one with C#:
// String Reorder Distance Apart
public string ReorderDistanceApart(string str, int distance)
{
int[] freq = new int[256];
int[] used = new int[256];
bool[] except = new bool[256];
int n = str.Length... 阅读全帖 |
|
|
l*n 发帖数: 529 | 9 这就来了个流行的word break的题目,真是与时俱进啊。 |
|
|
y***n 发帖数: 1594 | 11 Is this a DP problem, I tried a recursive solution which exceeds time limit
bool wordBreak(string s, unordered_set &dict) {
if(s.length()==0) return true;
bool foundBreak=false;
for(const string& current: dict){
if(s.compare(0, current.size(),current)==0){//find current
foundBreak= wordBreak(s.substr(current.size()), dict);
if(foundBreak)
break;
}
}
return foundBreak;
... 阅读全帖 |
|
l****o 发帖数: 315 | 12 public class Solution {
public boolean wordBreak(String s, Set dict) {
// Note: The Solution object is instantiated only once and is reused
by each test case.
boolean[] f = new boolean[s.length() + 1];
f[0] = true;
for (int i = 0; i <= s.length(); i++)
for (int j = 0; j < i; j++)
if (f[j] && dict.contains(s.substring(j, i))) {
f[i] = true;
break;
}
return f[s.le... 阅读全帖 |
|
|
T*******e 发帖数: 4928 | 14 哈,咱们思路差不多。
bool wordBreak(string s, unordered_set &dict) { //Time: O(n^2)
int sSize=s.size();
if(sSize<=0||dict.empty()) return false;
vector isWord(sSize+1, false);
isWord[0]=true;
for(int i=1; i<=sSize; ++i) {
for(int j=i-1; j>=0; --j) {
if(dict.find(s.substr(j, i-j))!=dict.end() &&isWord[j]) {
isWord[i]=true;
break;
}
}
}
return isWord[sSize];
}
reused |
|
b**m 发帖数: 1466 | 15 其实是前几天有人问那个(10)的简化版:
public class Solution {
public boolean wordBreak(String s, Set dict) {
if(s.length()==0){
return dict.contains(s);
}
boolean[] reachable = new boolean[s.length()+1];
reachable[0] = true;
for(int i=0;i
if(!reachable[i]){
continue;
}
for(int j=i+1;j<=s.length();j++){
String e = s.substring(i,j);
if(dict.con... 阅读全帖 |
|
z*********8 发帖数: 2070 | 16 这个case老是fail在这个test case:
Submission Result: Runtime Error
Last executed input: "aaaaaaa", ["aaaa","aa"]
谁能帮我看看?
public class Solution {
public boolean wordBreak(String s, Set dict) {
// Note: The Solution object is instantiated only once and is reused
by each test case.
boolean[] result = new boolean[s.length()+1];
result[0] = true;
int size = s.length();
for(int i=1; i <= size; ++i)
{
if(result[i] == false && di... 阅读全帖 |
|