由买买提看人间百态

topics

全部话题 - 话题: last2
(共0页)
z*********n
发帖数: 1451
1
直接上干货, leetcode已经有这题了 (* 代表1~9 而非0~9),这是我过了的一个解:
class Solution {
int base = 1000000007;
public:
int numDecodings(string s) {
//last1: decode ways of s ending at i-1, last2 decode ways of s
ending at i-2, nlast1 : next last1.
long long last1 = 1, last2 = 1, nlast1 = 0; //there is only 1 way to
decode "", so initialized with 1.
for (int i = 0; i < s.size(); ++ i)
{
//Just look at current character
if (s[i] == '*')
nla... 阅读全帖
r****t
发帖数: 10904
2
来自主题: JobHunting版 - fb电面面经
可能是无递归的最简解法,因为 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'
, ... 阅读全帖
g*******n
发帖数: 214
3
来自主题: JobHunting版 - G电面一题
如果不用recursion的话代码太长是不是面试的时候不能用?
public ArrayList numString2Char(String num) {
//map to store all the previous possibilities
HashMap> map = new HashMap ArrayList>();
int[] numbers = new int[num.length()];
for (int i = 0; i < num.length(); i++) {
numbers[i] = Integer.parseInt(num.charAt(i) + "");
}
if(numbers[0]==0) return null;
ArrayList tempList;
... 阅读全帖
t****a
发帖数: 1212
4
来自主题: JobHunting版 - G电面一题
; quick clojure solution: dp with memoize function.
(use 'clojure.string)
;; define the map
(def alphabet (map #(str (char %)) (range 97 123)))
(def number (map #(str (inc %)) (range 26)))
(def n2a (apply assoc {} (interleave number alphabet)))
;; implement dp with memoize function
(def number-translate (memoize (fn [long]
(cond (blank? long) [""]
(= (count long) 1) (if (contains? n2a long)
[(n2a long)]
[])
:else (let ... 阅读全帖
u*****b
发帖数: 14
5
来自主题: Statistics版 - SAS lag function question
the purpose is to get the previous visit number of a same id
the following lines give me an unexpected result. Anyone knows the reason?
thanks
data aaa;
input id $ visit;
cards;
10 1
10 2
10 4
2 1
2 2
;
run;
data last2;
set aaa;
if (id = lag(id)) then previst = lag(visit);
else previst=0;
run;
'last2' looks like this
id visit previst
10 1 0
10 2 .
10 4 2
2 1 0
2 2 4
s******7
发帖数: 1758
6
对,写得疏忽了,应该考虑最后出现的可能是last1, 也可能是last2,然后后指针再直
接跳到这个位置,更新最后出现的字符。
上面的code更正了,多谢指点
o******6
发帖数: 538
7
来自主题: Statistics版 - SAS lag function question
data last2;
set aaa;
by id;
previst = lag(visit);
if first.id then previst=0;
run;
(共0页)