由买买提看人间百态

topics

全部话题 - 话题: val
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
c*******o
发帖数: 18
1
呵呵,随手写一个,回家吃饭去了。学理科,文笔不好,欢迎大家补充
VAL:
上半场打得不好,不知道是战术考虑还是什么原因。一旦球进入对方半场,进攻队员县
得极其没有信心,缩手缩脚,看不出来进攻的决心。很多的远射,也显得毫无威胁。
下半场开场进攻节奏突然加快,打得有声有色,几次边路进攻和反击都有威胁,让
inter的后防线慌了一阵子。感觉教练有点过于保守,还有20+分钟就把morientes换下
场;三条线似乎也回收不少;让队伍进入防守状态有点过早,球员的心理压力比较大,
最后还是好几次险情出现。VAL的最后8分钟的表现很赞,尽管inter全力进攻,val却毫
不示弱和inter队攻,给人感觉他马上要被淘汰了似的。几次极有有威胁的进攻完全粉
碎inter进球的希望....
VAL这场比赛踢得有点意思,呵呵
Inter:
上半场打得还不错,不过主要原因还是因为后防线的压力较小,让整条中场线更加有效
的投入到进攻中。crespo有几次机会,可惜没有把握住。相比之下,inbra显得有些碌
碌无为。
下半场,59分钟mancini就用cruz换下crespo,有点不理解。从crespo下场前的表现
n*****g
发帖数: 178
2
请问leetcode上这个表达是什么意思:
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
不懂这一行:
ListNode(int x) : val(x), next(NULL) {}
求指教!谢谢!
w***g
发帖数: 5958
3
来自主题: Programming版 - scala的def或val是冗余的
如果都按def写
常数 def three = 3
函数 def inc (x: Int) = (x+1)
常数作为一种0元函数,语法很一致
如果都按val写
常数 val three = 3
函数 val inc = (x:Int) => (x+1)
函数的情况下比def多敲一个字母,好歹也是一致的。
不知道为什么要出来两个关键字。上面这些都可以正常运行,结果也一样。
还有下面的变态语法
{ i: Int =>
println("hello world")
i * 2
}
明明因该是
(i:Int)=>{println("Hello, world!");2}
然后_和curried也有冗余
_: def add (a:Int, b:Int) = (a+b)
def add_currie = (add(5, _:Int))
currie: (这种写法更加一般性,可以currie多次,但是傻逼语法非要在括号后加个_)
def add (a:Int)(b:Int) = (a+b)
def add_currie = add(5)_
Peking2我... 阅读全帖
l**********n
发帖数: 8443
4
来自主题: Programming版 - scala的def或val是冗余的
The compiler can infer the return type from what is being returned but it
can’t infer the types of the parameters so we’ll have to leave those
explicit specifications in.
We can however remove the return keyword to further reduce the amount of
ceremony in the method.
If we don’t use the return statement, the compiler will just assume that we
want to return the value of the last statement.
There's another consequence: in a subclass, you can override a def with a
val or a def, but you can only ove... 阅读全帖
c******o
发帖数: 1277
5
来自主题: Programming版 - scala的def或val是冗余的
def 的每次调用都会重计算。
val 的只会在定义的时候计算。
lazy val 的只会在第一次用的时候计算。
它们是严格不同的。也很有用。
c******o
发帖数: 1277
6
来自主题: Programming版 - scala的def或val是冗余的
lazy val by reference和singleton不一样,内部可是用reflection的,可以做很奇妙
很复杂的东西,比如正反馈自循环的变量定义 :)
Haskell的人会比较熟悉,比如monadfix,arrowloop
val和final也不完全一样, scala 有final key word 的
c******o
发帖数: 1277
7
来自主题: Programming版 - scala要val, var干嘛
var
val
lazy val
def
都不一样,你怎么办?
m*r
发帖数: 37612
8
二手交易风险自负!请自行验证是否合法和一手卡!:
我想卖的物品:
staples local purchase receipt 8% of face val
单张面值:
可接受价格(必须明码标价!):
8% face value, directly use your rewards account
物品新旧要求:
邮寄方式要求:
买卖双方谁承担邮寄损失(Required if not code only):
付款方式说明:
其他补充说明:
广告的有效期:
物品来源(Required for All Cards!):
我的联系方式:
Warranty期限:
能否证明是合法的一手卡?(Required for All Cards!):
state and zip:
c****p
发帖数: 6474
9
早上在Village on Val Vista大门口的对面看见两个摩托警一人举个测速仪测测测……
m*********2
发帖数: 2788
10
我老早上在Village on Val Vista大门口的对面,举个测速表测测测,就看见一个老中
WSN贼头贼脑地开车经过,本来想pull over他来完成本月的定额,想着都是老中,就算
了。
l**********n
发帖数: 8443
11
来自主题: Programming版 - scala的def或val是冗余的
Inside a class, val is evaluated on initialization while def is evaluated
only when, and every time, the function is called.
z****e
发帖数: 54598
12
来自主题: Programming版 - scala的def或val是冗余的
val用java的话说就是final
区别于var
l**********n
发帖数: 8443
13
来自主题: Programming版 - Def and val has a huge difference
Def is a method, while val is a value.
p*****2
发帖数: 21240
14
来自主题: Programming版 - Def and val has a huge difference
感觉val用处不大
l******t
发帖数: 55733
15
来自主题: Programming版 - Def and val has a huge difference
属实。需要val的地方都可以改写成lambda。应该是let或者where更好点
l****u
发帖数: 199
16
来自主题: Statistics版 - p-val's explaination.
Can anybody give a help for following table related question:
1. what does the p-value represent - significance of the model, test of
trend, etc.
2. Does this trend p show the goodness-of-fit?
Variable n OR(95%CI) A B C D P-
val
Ever Eat A
No 200 OR 1.00 - - -
Yes300 OR(Crude) 1.00 0.75 1.69 2.79 0.
004
(0.41-1.37) (0.74-3... 阅读全帖
u*********r
发帖数: 1181
17
上面部分是费用,下面部分是各自相应的average annual total return。
非常感谢啊
Gross Expense Ratio:
=======================
TIER I - LIFECYCLE FUNDS
- show details. - hide details.
LIFEPATH 2015 07/05/2006 Blended Fund Investments* N/A 0.1221
% No additional fees apply.
LIFEPATH 2020 06/30/2006 Blended Fund Investments* N/A 0.1092
% No additional fees apply.
LIFEPATH 2025 07/05/2006 Blended Fund Investments* N/A 0.1237
% No additional fees apply.
LIFEPATH 2030 06/3... 阅读全帖
f*********d
发帖数: 140
18
//我上个代码吧, 没有测试过, 有错误或者bug请指出。。。
//这里假设所有节点的值都不一样, 如果存在一样的节点值, 需要一点修改。。。
struct BSTNode {
BSTNode* left;
BSTNode* right;
int val;
}
//print open interval (min_val, max_val) in r
void PrintBST(BSTNode* r, int min_val, int max_val)
{
if(r == NULL) return;
if(r->val <= min_val) PrintBST(r->right, min_val, max_val);
else if(r->val >= max_val) PrintBST(r->left, min_val, max_val);
else {
PrintBST(r->left, min_val, r->val);
cout << r->vale;
PrintBST(r-... 阅读全帖
z*****u
发帖数: 51
19
来自主题: JobHunting版 - 新鲜C3 energy面经
只要在同一个layer就可以了,parent不一定是兄弟。你一个一个layer的遍历,就可以
发现在这一行里的所有nodes了:
boolean findIfCousins(TreeNode root, TreeNode a, TreeNode b) {
if(root == null || (root.val == a.val|| root.val == b.val) || a.val
== b.val)
return false;

ArrayList preLayer = null, curLayer = new ArrayList<
TreeNode>();
curLayer.add(root);

int count = 0;
while(!curLayer.isEmpty()){
preLayer = curLayer;
curLayer = new ArrayList阅读全帖
j*******e
发帖数: 1058
20
来自主题: JobHunting版 - M家 onsite 悲剧,同胞们弄死烙印吧
我的解法,是一个普遍的k解法。在main里面把k改为2或者是面试官喜欢的k的值就ok。
希望大家指正。
class ListNode {
int val;
ListNode next;
ListNode(int x) {
val = x;
next = null;
}
}
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
*/
public class Solution {
public ListNode reverseKGroup(ListNode head, int k) {
// Start typing your Java solution below
// DO NO... 阅读全帖
j*******e
发帖数: 1058
21
来自主题: JobHunting版 - M家 onsite 悲剧,同胞们弄死烙印吧
我的解法,是一个普遍的k解法。在main里面把k改为2或者是面试官喜欢的k的值就ok。
希望大家指正。
class ListNode {
int val;
ListNode next;
ListNode(int x) {
val = x;
next = null;
}
}
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
*/
public class Solution {
public ListNode reverseKGroup(ListNode head, int k) {
// Start typing your Java solution below
// DO NO... 阅读全帖
l*******s
发帖数: 7316
22
【 以下文字转载自 Prepaid 俱乐部 】
发信人: llaalways (camper), 信区: Prepaid
标 题: Moto E 1526 成功鼓捣成一开机就自动打开hotspot,每月自动拨号一次。
发信站: BBS 未名空间站 (Mon Mar 7 12:38:14 2016, 美东)
还是用Tasker, 就是在上次自动拨号的profile里加了3条。
wifi off
wifi tether on
svc data enable
但wifi tether on 在stock rom里出错,所以刷了flyme. 中间还试过CM13,CM13遇到
GAPP装不好的问题,所以放弃了。
flyme还有一个小问题,就是不能拦截拨号,这个以后再折腾。
将下面的内容保存为onBoot.prf.xml, 然后从Tasker里import profile 就可以了。


1457209583790阅读全帖
r******g
发帖数: 13
23
来自主题: JobHunting版 - leetcode上的4Sum一问
It will ignore the quad containing num[i-1] and num[i], I find it's easier
to deal with it when you find a solution.
This O(n^2) solution without using set, both the (unordered_map) and results
(vector) doesn't contain duplicates by preprocessing the array.
Run Status: Accepted!
Program Runtime: 16 milli secs
Progress: 15/15 test cases passed.
Run Status: Accepted!
Program Runtime: 460 milli secs
Progress: 282/282 test cases passed.
Sorry can't type chinese, please feel free to comment my code, ... 阅读全帖
p*****2
发帖数: 21240
24
来自主题: JobHunting版 - 面试F家让先做programming puzzle
我写了一个。看看有没有问题?
import collection.mutable.{Map, Queue}
object test2 extends App {
val Array(n,k)=readLine.split(" ").map(_.toInt)
val start=readLine.split(" ").map(_.toInt-1).mkString(" ") //pegs and
discs start from 0
val end=readLine.split(" ").map(_.toInt-1).mkString(" ")

val queue=new Queue[String]()
val map=Map[String,String]()

var distance=0
var count=1
queue+=end
map(end)=null
while(count>0){
distance+=1
while(count>0){
... 阅读全帖
p*****2
发帖数: 21240
25
来自主题: JobHunting版 - 面试F家让先做programming puzzle
我写了一个。看看有没有问题?
import collection.mutable.{Map, Queue}
object test2 extends App {
val Array(n,k)=readLine.split(" ").map(_.toInt)
val start=readLine.split(" ").map(_.toInt-1).mkString(" ") //pegs and
discs start from 0
val end=readLine.split(" ").map(_.toInt-1).mkString(" ")

val queue=new Queue[String]()
val map=Map[String,String]()

var distance=0
var count=1
queue+=end
map(end)=null
while(count>0){
distance+=1
while(count>0){
... 阅读全帖
p*****p
发帖数: 379
26
public boolean delete(int val) {
if (_remove(val, root) != null) {
return true;
}
else {
return false;
}
}
private Node _remove(int val, Node t) {
if (t == null) {
return null;
}
else if (val < t.val) {
t.left = _remove(val, t.left);
}
else if (val > t.val) {
t.right = _remove(val, t.right);
}
else if (t.left != null && t.right != null){
//two children
t.val = _findMin(t.right).val;
t.righ... 阅读全帖
s******n
发帖数: 226
27
来自主题: JobHunting版 - 一道rf的面试题
Insert into BST and get score.
This is runnable code.
class node{
int val;
int below;
node left;
node right;
node(int val){this.val = val; left = right = null; below = 0;}
}
class Tree{
node root;
Tree(){root = null;}
int insert(int val){
node N = root;
if(N == null){
root = new node(val);
return 0;
}
int score = 0;
node par = null;
while(N!=null){
if(val <= N.val){
... 阅读全帖
s******n
发帖数: 226
28
来自主题: JobHunting版 - 一道rf的面试题
Complete code:
import java.util.*;
import java.lang.Math.*;
// Customized Tree for sorting ending times and count how many ending times
are earlier than inserted one to compute the racer's score.
// Insertion is O(nlgn)
class node{
int val;
int below;
node left;
node right;
node(int val){this.val = val; left = right = null; below = 0;}
}
class Tree{
node root;
Tree(){root = null;}
int insert(int val){
node N = root;
if(N == null){
root ... 阅读全帖
b******p
发帖数: 49
29
来自主题: JobHunting版 - leetcode上的Sort List那道题
我来贴个CPP的(注意:以下有乱七八糟的code……)
合并排序确实比较好用,我还在写第一遍leetcode,代码风格也比较乱,带了很多
debug code,还带了测试用例,试了9次才通过…
有一些多边界条件需要判断的。我的方法是加很多debug,或加很多assertion(我做别
的题里面经常用assertion……不知道是不是好习惯)
============================
#include
#include
using namespace std;
/*
Merge sort ?
*/
// Start: 22:40
// End: 23:45 用了一个小时
//Definition for singly-linked list.
struct ListNode {
int val;
ListNode *next;
ListNode(int x) : val(x), next(NULL) {}
};
#define TOMMYDBG
class Solution {
public:
... 阅读全帖
a***e
发帖数: 413
30
知道要O(1)space的得用Morris Traversal。但想先写个简单的,却发现改了好几次。
1。 开始没想清楚怎么把那两个错误的node找出来
2. 应该用*& 的地方用了*。 后来发现不作为param来pass还更简单。
但这样也有很多行,等有时间写个Morris的比较下。感觉也不是那么简单啊,sigh!
class Solution {
public:
TreeNode *first, *second, *pre;
void helper(TreeNode *cur)
{
if (cur==NULL)
return;

helper(cur->left);
if (pre)
{
if (pre->val>cur->val)
{
if (first==NULL)
{
first = pre;
sec... 阅读全帖
a***e
发帖数: 413
31
嗯,试图写O(1)的,发现用vector把指针装起来,再pass reference容易一些。但是
不知道为啥初始化的时候下面这个不行
vector m(2, NULL);
Compile Error
required from ‘std::vector<_Tp, _Alloc>::vector(_InputIterator, _
InputIterator, const allocator_type&) [with _InputIterator = int; _Tp =
TreeNode*; _Alloc = std::allocator; std::vector<_Tp, _Alloc>::
allocator_type = std::allocator]’
得换成这几行
vector m;
m.push_back(NULL);
m.push_back(NULL);
还没仔细debug 为什么下面这个答案不对,而后面那个就对。
错... 阅读全帖
w********0
发帖数: 377
32
这时当时的code,我copy下来了。请大牛指点。
Given a nested list of positive integers: {{1,1},2,{1,1}}
Compute the reverse depth sum of a nested list meaning the reverse depth of
each node (ie, 1 for leafs, 2 for parents of leafs, 3 for parents of parents
of leafs, etc.) times the value of that node. so the RDS of {{1,1},2,{1,1}
} would be 8 = 1*1 + 1*1 + 2*2 + 1*1 + 1*1.
{1,{4,{6}}}
6*1 + 4*2 + 1*3 = 6+8+3 = 17
struct Iterm
{
int v;
bool isInteger();
int getInteger();
list getList();
l... 阅读全帖
p*****2
发帖数: 21240
33
来自主题: Programming版 - 为什么这段程序scala慢java很多
java 400多毫秒,scala 1000毫秒超时。
object test6 extends App {
def add(x:Int, y:Int):Unit={
if(x<1 || x>n || y<0) return;
val yy=Math.min(y,a(x)+1)
if(v(x)(yy)) return
queue+=Array(x,yy)
v(x)(yy)=true
}

val sc=new Scanner(new File("input.txt"))
val out=new PrintWriter("output.txt")
val n=sc.nextInt
val a=new Array[Int](n+1)
val v=Array.ofDim[Boolean](105, 100005)
val queue=Queue[Array[Int]]()
for(i<-1 to n) a(i)=sc.nextInt
... 阅读全帖
s*********d
发帖数: 2406
34
来自主题: JobHunting版 - L家phone面,悲剧
我自己做出来了,主要是边界条件的问题。
public boolean bsearch2(int[][] p, int val, int xlo, int xhi, int ylo,
int yhi) {
if (xlo == xhi && ylo == yhi && (p[xlo][ylo] != val))
return false;
if (p[xlo][ylo] > val)
return false;
if (p[xhi][yhi] < val)
return false;// end conditon
int midi = (xlo + xhi) / 2;
int midj = (ylo + yhi) / 2;
//binary search
if (p[midi][midj] == val) {
System.out.println(midi);... 阅读全帖
s****0
发帖数: 117
35
来自主题: JobHunting版 - 一道A家店面题求解
大概是这个意思. 我没理解最后两种情况怎么处理,好像结果不确定。
package myutil;
import java.util.Arrays;
public class FlexSearch {
final Integer[] data;
final boolean asc;
public FlexSearch(Integer[] data) {
if (data == null || data.length < 2)
throw new java.lang.NoSuchFieldError();// whatever.
this.data = data;
asc = data[0] - data[1] < 0;
}
private int getIdx(int val) {
return Arrays.binarySearch(data, val);
}
public int getLTMax(int val) {
int... 阅读全帖
i******t
发帖数: 22541
36
来自主题: JobHunting版 - Binary Tree Maximum Path Sum
这个题目中
假设当前 p
那么最大值可以 为
p->val
p->val + p->left->val
p->val + p->right->val
p->val + p->right->val+ p->left->val
这四种情况
但是为什么不能是单独的
p->left->val
或者
p->right->val
呢?
如果 p->val 本身是负数 ,左子树 最大值 是正 数 那么最大值不应该算上 p本身吧
》?
求解惑
thx
c*********a
发帖数: 8
37
来自主题: JobHunting版 - 两道题,祝大家新年快乐!
Code for G question:
public class Solution {
public static class Pair implements Comparable{
int val;
int count;
public Pair(int val, int count) {
this.val = val;
this.count = count;
}
@Override
public int hashCode() {
return val + count * 3;
}
@Override
public boolean equals(Object obj) {
if ( obj == null ) { return false;}
if ( obj.getClass() != this.get... 阅读全帖
a****r
发帖数: 87
38
C++ R-way trie implementation. Coursera princeton algorithm II 讲的很详细。
const int N = 26;
struct TrieNode{
int val;
vector link;
TrieNode(int x=-1): val(x), link(N){}
};
class Trie{
public:
Trie(){
root = new TrieNode;
}

void put(string &key, int val){
put(root, key, val, 0);
}

int get(string &key){
TrieNode *t = get(root, key, 0);
if(t) return t->val;
else return -1;
}

void remove(string &key){... 阅读全帖
a****r
发帖数: 87
39
C++ R-way trie implementation. Coursera princeton algorithm II 讲的很详细。
const int N = 26;
struct TrieNode{
int val;
vector link;
TrieNode(int x=-1): val(x), link(N){}
};
class Trie{
public:
Trie(){
root = new TrieNode;
}

void put(string &key, int val){
put(root, key, val, 0);
}

int get(string &key){
TrieNode *t = get(root, key, 0);
if(t) return t->val;
else return -1;
}

void remove(string &key){... 阅读全帖
c*********t
发帖数: 2921
40
来自主题: Programming版 - 大家看看这道C语言题是怎么回事?
还有就是同个link里的这个题
11) What will be the output of following program ?
#include
int main(){
char val=250;
int ans;
ans= val+ !val + ~val + ++val;
printf("%d",ans);
return 0;
}
Correct Answer - 2
-6
250 is beyond the range of char, the value of val will be -6.
Consider the expression:
ans= val+ !val + ~val + ++val;
Operator! , ~ and ++ have equal precedence. And it associative is right to
left.
So, First ++ operator will perform the operation. So value val will -5
Now,... 阅读全帖
f**********g
发帖数: 2989
41
麻烦版主给换个行吧。。
ZZ
瑞士温泉大集锦(总结前人贴)
因为打算2月初从法国出发去瑞士泡温泉,所以翻了不少前人关于温泉的帖子,加上自
己在网上查到的一些东东,整理了一下,拿出来和大家一起分享吧。
目前资料比较齐备的是七个温泉,希望驴友们接着补充。
1、伊韦尔东YVERDON-LES-BAINS VD:www.thermes-yverdon.ch
2、洛伊克巴德温泉 www.leukerbad.ch
3、塞永温泉中心SAILLON VS: www.bainsdesaillon.ch
4、OVRONNAZ VS:www.thermalp.ch
5、瓦尔斯温泉(Therme Vals) www.therme-vals.ch.
6、Lavey-les-bains http://www.lavey-les-bains.ch/index_en.htm
7、拉格斯温泉Bad Ragaz http://www.spavillage.ch/en/welcome.cfm
伊韦尔东YVERDON-LES-BAINS VD:www.thermes-yverdon.ch
1、交通:离日内瓦最近,也要1个小... 阅读全帖
i**********e
发帖数: 1145
42
来自主题: JobHunting版 - 刚电面完,分享两个题目
我今天写的代码,通过了我的一些随机数据测试(与 brute force 的方法进行比较)。
基于我上次贴的方法,有一些错误,造成一些混乱,不好意思。
1) First, we store the contiguous sum from the first element to a cumulative
array called cum[], where cum[i] = cum[i-1] + A[i-1], and cum[0] = 0. Using
the cum[] array, we can easily find the contiguous sum from i to j, A[i...j
] = cum[j+1] - cum[i], i <= j. Here is an easy trap to fall into, you MUST
define cum[0] = 0 and the size of the cum[] array must be n+1, or else it
would miss including the first element in the c... 阅读全帖
g*****k
发帖数: 623
43
来自主题: JobHunting版 - 刚电面完,分享两个题目
Your solution is actually the same as ibread's solution.
in ibread's solutio's last step, j starts from n to 0, so binary search
in the sorted cum array s.t. cum[i]<= cum[j]-k. Once you find i, you just
get the smallest index by min_index[i].
min_index[i]= min{k | cum[k] j-min_index[i] is the length of the subarray starting at min_index[i]+1.

我今天写的代码,通过了我的一些随机数据测试(与 brute force 的方法进行比较)。
基于我上次贴的方法,有一些错误,造成一些混乱,不好意思。
1) First, we store the contiguous sum from the first element to a cumul... 阅读全帖
i**********e
发帖数: 1145
44
来自主题: JobHunting版 - 求顺时针打印矩阵code
这是用矩阵来储存,利用 spiral 的形式填满矩阵,最后再一行一行打印。
感觉面试时利用这方法比较直观,不容易出错。
#include
#include
using namespace std;
const int N_MAX = 100;
void fill(int row, int col, int dx, int dy, int startVal, int numToFill, int
mat[][N_MAX]) {
int currVal = startVal;
int endVal = startVal + numToFill - 1;
for (int r = row, c = col; currVal <= endVal; r += dy, c += dx) {
mat[r][c] = currVal;
currVal++;
}
}
void generateMatrix(int n, int mat[][N_MAX]) {
if (n <= 0) return;

int row = ... 阅读全帖
d******i
发帖数: 76
45
来自主题: JobHunting版 - Uni_value subtree problem
谢谢@wwwyhx大牛贡献的题。看了帖子里面的回复后,有了些思路,虽然对于牛人们,
这道题很简单,对于还是菜鸟的我还是很难的,发个帖子,供大家讨论,希望最
终得出正确的答案吧。
“我面的时候有一简单题一定要O(n), 找树的unival个数(就是这个节点开始所有子树都
一样的节点数) ”
题的意思是,找到这样的子树,满足子树中所有节点的值相等。计算满足此条件的子树
中节点的总个数。(希望没有理解错。)
例子1:
1
结果为 1
例子2:
1
1 1
结果为 3
例子3:
1
2 3
结果为2(2, 3)
例子4:
1
2 3
2
结果为:3 ({2,2}, {3})
例子 5:
1
2 3
2
4
结果为: 2 (4,3);
下面是C++代码,大家指正
---------------更新:不需要看我写的了,直接看楼下的解法吧,哈哈。-----------
----
#include
#include
using namespace std;
struct TreeN... 阅读全帖
b***m
发帖数: 5987
46
再写一段Perl代码,大家就知道更多实现细节了:
my val = "I love you".
val = int(val) + 100;
print val, "\n";
val = "100I love you";
val = int(val) + 100;
print val, "\n";
val .= "100";
print val;
输出结果:
100
200
200100
上面第一个帖子写错了一个地方。
j*****s
发帖数: 189
47
class Solution {
public:
string intToRoman(int num) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
string s;
s += toRoman(num / 1000, "", "", "M");
s += toRoman(num / 100 % 10, "M", "D", "C");
s += toRoman(num / 10 % 10, "C", "L", "X");
s += toRoman(num % 10, "X", "V", "I");
return s;
}
string toRoman(int val, string ten... 阅读全帖
e****e
发帖数: 418
48
来自主题: JobHunting版 - g 两轮店面面经 失败告终
DFS approach. My code is lousy, the point is to show the DFS approach.
Thanks.
public int[] dFS(TreeNode root ) {
int depth = depth( root );
int[] r = new int[depth];
boolean[] m = new boolean[depth];

if ( root == null )
return r;

dFSCore( root, new MutableInt(0), r, m );

return r;
}

private void dFSCore( TreeNode node, MutableInt level, int[] r, boolean[
] m ) {
if ( node == null )
... 阅读全帖
p*****2
发帖数: 21240
49
来自主题: JobHunting版 - 准备转回Java了

object test6 extends App {
val sc=new Scanner(System.in)
val n=sc.nextInt
val m=sc.nextInt
val mat=new Array[String](n)
val start=System.currentTimeMillis()
for(i<-0 until n) mat(i)=sc.next()

def check(i:Int, j:Int, k:Int, l:Int):Boolean={
val minX=math.min(i,k)
val maxX=math.max(i,k)
val minY=math.min(j,l)
val maxY=math.max(j,l)

var minR=true
var maxR=true
var minC=true
var maxC=true
... 阅读全帖
N******t
发帖数: 43
50
贴代码,如有错误,请私信。
/**
* Implement insert and delete in a trinary tree.
*
*/
public class TrinaryTree {
/**
* define a trinary tree's node
*
*/
static class TreeNode{
public int val; // node's value
public TreeNode left, right, mid; // represent left, right, middle
node
public TreeNode(int v){
this.val = v;
left = null;
right = null;
mid = null;
}
}
TreeNode root;

public TrinaryTre... 阅读全帖
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)