首页 > 试题广场 >

无判断max

[编程题]无判断max
  • 热度指数:8881 时间限制:C/C++ 3秒,其他语言6秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解

给定int a和intb,在不使用if-else等比较和判断运算符的情况下返回较大的那个数。若两数相同则返回任意一个。

测试样例:
1,2
返回:2
头像 Dfine
发表于 2025-07-07 03:01:47
class Max { public: int getMax(int a, int b) { // write code here int sym = (a-b) >> 31; return a+(a-b) *sym; } 展开全文
头像 黑眼X
发表于 2025-09-27 11:07:09
import java.util.*; public class Max { public int getMax(int a, int b) { return b& (a-b)>>31 | a& ~(a-b) >> 31; 展开全文
头像 牛客710153440号
发表于 2025-09-04 21:54:24
class Max { public: int getMax(int a, int b) { // write code here int c = a - b; return a - (c & (c >> 31));//c 展开全文
头像 牛客710153440号
发表于 2025-09-04 21:54:37
class Max { public: int getMax(int a, int b) { // write code here int c = a - b; return a - (c & (c >> 31));//c 展开全文
头像 小小车
发表于 2021-10-16 10:43:45
class Max { public: int getMax(int a, int b) { // write code here return a > b ? a : b; } };