夏普 2021 技术岗面试题

小编:管理员 2301阅读 2021.10.11

第1题:

两个人依次抛硬币,最先抛出正面的人获胜,求第一个人获胜的概率,给出分析过程



第2题:

求一个实数的指数值,a^b,补充完整下面的代码。
  double exponention(double a, unsigned long b)
  {
  double c=1.0;
  while(b)
  { if(b&1)c*=a;
  a=_a*a______________;
  b=_b>>1______________;
  }
  return c;
  }



第3题:

判断两个矩形是否相交,不相交,返回0,相交则返回相交的面积。
  struct rect
  {
  int left;
  int right;
  int top;
  int bottom
};
 
  int intersection(rect A, rect B)
  {
  }
  提示:
  求两个矩形的最大左边值,最大上底值,最小右边值,最小下底值,
  即maxleft, maxtop, minright, minbottom;
  如果maxleft>minright || maxtop > minbottom,则两个矩形相交,否则不相交
  int intersection(rect A, rect B)
  { int maxleft, maxtop,minright, minbottom;
  maxleft=A->left > B->left?A->left:B->left;
  maxtop=A->top > B->top?A->top:B->top;
  minright=A->right right?A->right : B->right;
  minbottom=A->bottom bottom? A->bottom : B-> bottom;
  if(maxleft>minright || maxtop> minbottom)return 0;
  else return (minright -maxleft)*(minbottom-maxtop);
  }



第4题:

写一个递归函数交换一颗二叉树的左右子树



第5题:

一个整型数组包含N个整数,其中有3个整数出现的次数均大于N/4,找出这3个数,并分析时间复杂度。


关联标签: