s*******f 发帖数: 1114 | 1 //回报本版,码遍本版
//Given a string of sorted integers, e.g. "1 52 69 456789 994546566";
//and a a number e.g. 69.
//You need to tell if it is in the input, e.g. 69=>true.
//strlen is O(n), don't use C style string for O(log n), suppose
//the string is friendly without lots of blank.
void GetWordPos(const char *mid, const char *left, const char *right, const
char **pstart, const char **pend){
while (isspace(*mid))
++mid;
*pstart = mid;
while (*pstart >= left && !isspace(**pstart))
... 阅读全帖 |
|
r****t 发帖数: 10904 | 2 可能是无递归的最简解法,因为 python int 不限大小,可随便上至 octillion,
whatever
import locale
eng = { '0': '', '1': 'one', '2': 'two', '3': 'three', '4': 'four',
'5': 'five', '6': 'six', '7': 'seven', '8': 'eight', '9': 'nine', '10':
'ten', '11': 'eleven', '12': 'twelve', '13': 'thirteen', '14': 'forteen',
'15': 'fifteen', '16': 'sixteen', '17': 'seventeen', '18': 'eighteen',
'19': 'nineteen', '20': 'twenty', '30': 'thirty', '40': 'forty',
'50': 'fifty', '60': 'sixty', '70': 'seventy', '80': 'eighty','90': 'nighty'
, ... 阅读全帖 |
|
f*******w 发帖数: 1243 | 3 Substring with Concatenation of All Words
You are given a string, S, and a list of words, L, that are all of the same
length. Find all starting indices of substring(s) in S that is a
concatenation of each word in L exactly once and without any intervening
characters.
For example, given:
S: "barfoothefoobarman"
L: ["foo", "bar"]
You should return the indices: [0,9].
我的code如下
之前用unordered_set, 如果L里面有重复元素就跑不过
现在改用multiset, 直接出错……
求助求助……
class Solution {
public:
vector findSubstring(string ... 阅读全帖 |
|
f*******w 发帖数: 1243 | 4 现在能过小case了,大的跑不过去……
class Solution {
public:
vector findSubstring(string S, vector &L) {
unordered_map strset, tmpset;
int numstr = L.size(), strlen = L[0].size();
vector ret;
for(int i = 0; i < numstr; ++i) {
auto it = strset.find(L[i]);
if(it != strset.end()) ++it->second;
else strset.insert(make_pair(L[i], 1));
}
tmpset = strset;
for(int i = 0; i < (int)S.size() - num... 阅读全帖 |
|
m*****k 发帖数: 731 | 5 抛砖:
public static boolean isAbbr(String s, String abbr){
//internationalization”, “i5a11o1”
if(s==null){
return abbr==null;
}
if(s.length()==0){
return abbr.length()==0;
}
abbr+="A";
int lastCharIdxInAbbr = -1;
int lastCharIdxInS = -1;
for(int i = 0; i
if(Character.isLetter(abbr.charAt(i))){
String numStr = abbr.substring(lastCharIdxInAb... 阅读全帖 |
|
f******s 发帖数: 659 | 6 //use string
boolean isPalindrome(int num){
String numStr = String.valueOf(num);
String revStr = new StringBuilder(numStr).reverse().toString();
return numStr.equals (revStr);
} |
|
p****n 发帖数: 294 | 7 来自主题: JobHunting版 - G电面一题 随便写了一下, 用递归
String maps = "abcdefghijklmnopqrstuvwxyz";
public ConvertNumberToString(int num) {
String numStr = String.valueOf(num);
if (false == getCombination(numStr, "")) {
System.out.println("NO");
}
}
private boolean getCombination(String remain, String result) {
if (remain.length() == 0) {
System.out.println(result);
return true;
}
int n = Integer.parseInt(remain.substring(0, 1)) - 1;
if (n < 0){
return false;
}
char... 阅读全帖 |
|
b*******y 发帖数: 32 | 8 你的结果和我的一样,
============================
#include
#include
using namespace std;
void num2str(int num) {
vector str;
vector::reverse_iterator rit;
const int step = 3;
int value;
bool first = true;
while(num != -1) {
value = num % step;
str.push_back('a'+value);
num = num / step -1;
}
for (rit = str.rbegin(); rit < str.rend(); ++rit)
cout << *rit;
cout<
}
int NumString() {
for (int i = 0; |
|
h****b 发帖数: 157 | 9 问一个matlab的简单问题
我想在程序里存n个ascii文件, 第一个文件名1.txt, 第二个2.txt, ...., n.txt
请问有什么办法可以用程序实现
我试过 filename=[numstr(n) '.txt']
save filename variablename.
不过不行,有什么办法可以这样给文件自动命名的?
谢谢a |
|