我正在努力解决这个问题,我想以非递归的方式解决这个问题.我的算法似乎没有逻辑错误,73%的测试用例通过了.但它无法处理大数据,报告称"超出时间限制".我很感激,如果有人能给我一些提示,如何在非递归中做到这一点,并避免时间限制超过,提前谢谢!
问题链接
我相信在LeetCode中也有类似的一个.
http://www.lintcode.com/en/problem/binary-tree-maximum-path-sum-ii/
问题描述:
给定二叉树,从根找到最大路径总和.路径可以在树中的任何节点处结束,并且其中包含至少一个节点.
例:
鉴于以下二叉树:
1
/ \
2 3
返回4.(1-> 3)
法官
超出时限
总运行时间:1030毫秒
输入 输入数据
{-790,-726,970,696,-266,-545,830,-866,669,-488,-122,260,116,521,-866,-480,-573,-926,88,733,#,#,483,-935,-285,-258,892,180,279 ,-935,675,2,596,5,50,830,-607,-212,663,25,-840,#,#, - 333754,#817842,-220,-269,9,-862,-78,-473,643,536 - 142,773,485,262,360,702,-661,244,-96,#519566,-893,-599,126,-314,160,358,159,#,#, - 237,-522,-327,310,-506,462,-705,868,-782,300,-945,-3,139, - 193,-205,-92,795,-99,-983,-658,-114,-706,987,292,#,234,-406,-993,-863,859,875,383,-729,-748,-258,329,431,-188,-375 ,-696,-856,825,-154,-398,-917,-70,105,819,-264,993,207,21,-102,50,569,-824,-604,895,-564,-361,110,-965,-11,557,#,202213 ,-141,759,214,207,135,329,15,#,#,244#,334628509627,-737,-33,-339,-985,349,267,-505,-527,882,-352,-357,-630,782,-215,-555,132, - 835,-421,751,0,-792,-575,-615,-690,718,248,882,-606,-53,157,750,862,#,940,160,47,-347,-101,-947,739,894,#, - 658,-90,-277 ,-925,997,862,-481,-83,708,706,686,-542,485,517,-922,978,-464,-923,710,-691,168,-607,-888,-439,499,794,-601,435,-114,-337,422,#, - 855,-859,163 ,-224 ,902,#,577,#, - 386,272,-9 ......
预期
6678
我的代码 C++
/**
* Definition of TreeNode:
* class TreeNode {
* public:
* int val;
* TreeNode *left, *right;
* TreeNode(int val) {
* this->val = val;
* this->left = this->right = NULL; …Run Code Online (Sandbox Code Playgroud) 我想将一列浮点值转换为字符串,以下是我当前的方式:
userdf['phone_num'] = userdf['phone_num'].apply(lambda x: "{:.0f}".format(x) if x is not None else x)
Run Code Online (Sandbox Code Playgroud)
但是,它还会将 NaN 转换为字符串“nan”,当我检查此列中的缺失值时,这很糟糕,有更好的主意吗?
谢谢!
如何并行循环多个变量和不同步骤?
就像在c ++中一样for(int i=0, j=n-1; i<n && j>=0; i++, j--).