上一页 1 2 3 4 5 6 ··· 10 下一页
摘要: /* 题目: 在不使用加减乘除的前提下,计算两个整数之和。 思路: 不能使用加减乘除则只能考虑位运算。 x=num1^num2,则为抹掉进位的结果。 y=num1&num2,为只有进位的结果。 (y<<1)&x,直到不产生进位。 */ #include<iostream> #include<cstr 阅读全文
posted @ 2020-01-02 19:50 笨宝宝 阅读(159) 评论(0) 推荐(0) 编辑
摘要: /* 题目: 给定一个股价序列,求一次交易的最大利润。 */ #include<iostream> #include<vector> using namespace std; int MaxProfit(vector<int> numbers){ int length = numbers.size( 阅读全文
posted @ 2020-01-01 23:44 笨宝宝 阅读(128) 评论(0) 推荐(0) 编辑
摘要: /* 题目: 约瑟夫环问题。 思路: 数学规律 f(n)=0(n=1),[f(n-1,m)+m]%n(n>1) */ #include<iostream> #include<list> using namespace std; int LastRemaining(unsigned int n,uns 阅读全文
posted @ 2020-01-01 23:16 笨宝宝 阅读(150) 评论(0) 推荐(0) 编辑
摘要: /* 题目: 约瑟夫环问题。 思路: 用链表list实现,注意判断链表在末尾时,使其指向开头, 每次循环删除一个数字,直到只剩下一个数字。 */ #include<iostream> #include<list> using namespace std; int LastRemaining(unsi 阅读全文
posted @ 2020-01-01 22:11 笨宝宝 阅读(128) 评论(0) 推荐(0) 编辑
摘要: Java泛型 解耦类或方法与类型之间的约束。 泛型出现的一个原因:容器类 泛型类 只能持有单个对象的类 如何持有别的类型的对象?使用object 通常来说,我们只持有一种类型的对象,泛型的目的是指定持有哪种对象。 泛型接口 Public interface Generator<T>{ T next( 阅读全文
posted @ 2019-12-30 16:35 笨宝宝 阅读(125) 评论(0) 推荐(0) 编辑
摘要: /* 题目: 从扑克牌中随机抽取n个数字,判断他们是否连续,扑克牌从A~K,大小王可代替任意数字。 */ #include<iostream> #include<cstdlib> #include<stack> #include<cstring> #include<vector> #include< 阅读全文
posted @ 2019-12-29 21:26 笨宝宝 阅读(126) 评论(0) 推荐(0) 编辑
摘要: /* 题目: 计算n个骰子,出现和s的概率。 */ #include<iostream> #include<cstdlib> #include<stack> #include<cstring> #include<vector> #include<deque> #include<cmath> usin 阅读全文
posted @ 2019-12-29 18:07 笨宝宝 阅读(258) 评论(0) 推荐(0) 编辑
摘要: /* 题目: 定义一个含max函数的队列类,并实现pop_front()、push_back()、max()函数。 */ #include<iostream> #include<cstdlib> #include<stack> #include<string> #include<vector> #i 阅读全文
posted @ 2019-12-29 15:17 笨宝宝 阅读(161) 评论(0) 推荐(0) 编辑
摘要: /* 题目: 链接:https://www.nowcoder.com/questionTerminal/1624bc35a45c42c0bc17d17fa0cba788 来源:牛客网 给定一个数组和滑动窗口的大小,找出所有滑动窗口里数值的最大值。例如,如果输入数组{2,3,4,2,6,2,5,1}及 阅读全文
posted @ 2019-12-29 14:36 笨宝宝 阅读(145) 评论(0) 推荐(0) 编辑
摘要: /* 题目: 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C) */ /* 思路: 递归。 */ #include<iostream> #include<cstring> #include<vector> # 阅读全文
posted @ 2019-12-27 21:25 笨宝宝 阅读(154) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 ··· 10 下一页