123
返回列表 发新帖
跳转到指定楼层
上一主题 下一主题
收起左侧

[找工就业] 请教下现在的AMAZON 75分钟的Online test会有摄像头吗

🔗
 楼主| 我一辈子赖美帝 2017-4-20 12:15:12 | 只看该作者
全局:
大家好 我换了个马甲 注册,又拿了个社招OA
又挂了,.--
第一题valid patheless 秒过 ,case全过
第二题,distance between two node  。在我自己的eclipse跑没问题,结果测试case死活有问题。
我也认了,放上代码。小伙伴们帮忙看看哪里错了?

public class BSTDistance {

        private BTreeNode root;
       
        public void CreateBST(int[] values,int n){. From 1point 3acres bbs
                for(int i=0;i<n;i++){
                        add(values[i]);
                }
        }.--
       
        public void add(int item){
                if(root==null){
                        root=new BTreeNode(null,item,null);
                }else{. Waral dи,
                        add(root,item);
                }. ----
        }
       
        public void add(BTreeNode node,int item){-baidu 1point3acres
                if (item < node.val) {
                if (node.left == null) {
                    node.left = new BTreeNode(null, item, null);
                } else {
                    add(node.left, item);. check 1point3acres for more.
                }
            } else if (item > node.val) {
                if (node.right == null) {
                    node.right = new BTreeNode(null, item, null);
                } else {
                    add(node.right, item);
                }. Χ
            }.--
        }. .и
        . 1point 3 acres
       
        public  int bstDistance(int[] values, int n, int node1, int node2){
                int l1=Pathlength(root,node1);. check 1point3acres for more.
                int l2=Pathlength(root,node2);
                int lcaVal = findLCA(root, node1, node2).val;
                int lcaDistance = Pathlength(root, lcaVal);
                return (l1 + l2) - 2 * lcaDistance;.google  и
               
        }
        ..
        public int Pathlength(BTreeNode root, int n) {
                return PathlengthHelp(root,n)-1;
        }
       
        public int PathlengthHelp(BTreeNode root, int n) {
                if (root != null) {
                        int x = 0;
                        if ((root.val == n) || (x = PathlengthHelp(root.left, n)) > 0. ----
                                        || (x = PathlengthHelp(root.right, n)) > 0) {
                                return x+1 ;
                        }
                        return 0;
                }
                return 0;
        }
       
        public BTreeNode findLCA(BTreeNode root, int node1, int node2) {
                if (root != null) {.google  и
                        if (root.val == node1 || root.val == node2) {
                                return root;
                        }
                        BTreeNode left = findLCA(root.left, node1, node2);
                        BTreeNode right = findLCA(root.right, node1, node2);

                        if (left != null && right != null) {
                                return root;
                        }
                        if (left != null) {
                                return left;
                        }
                        if (right != null) {
                                return right;
                        }
                }
                return null;
        }
       
       
        public static void main(String[] args) {.
                BSTDistance test=new BSTDistance();. Χ
                int values[]={5,6,3,1,2,4};
                test.CreateBST(values,6);.
                BTreePrinter.printNode(test.root);
                int res=test.bstDistance(values, 6, 1, 2);
                System.out.println(res);
        }
回复

使用道具 举报

🔗
 楼主| 我一辈子赖美帝 2017-4-20 12:15:56 | 只看该作者
全局:
刚刚做完,估计明天会收到拒信
回复

使用道具 举报

🔗
 楼主| 我一辈子赖美帝 2017-4-20 12:16:32 | 只看该作者
全局:
第一个case 我自己在eclipse上结果是4 正确结果
结果 OA的 case 死活都是-1
回复

使用道具 举报

🔗
vickyer 2017-4-20 14:51:20 | 只看该作者
全局:
感谢楼主分享〜请问有编译按键?然后test case 可以重复跑吗?还是有次数限制?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表