- 博客(4)
- 收藏
- 关注
转载 整数反转:弹出和推入数字
整数反转:弹出和推入数字 核心思路: //pop operation: pop = x % 10; x /= 10; //push operation: temp = rev * 10 + pop; rev = temp; 作者:LeetCode 链接:https://leetcode-cn.com/problems/reverse-integer/solution/zheng-shu-fan-zhuan-by-leetcode/ 来源:力扣(LeetCode) 著作权归作者所有。商业转载请联系作者获
2020-10-11 15:27:14
194
转载 暴力枚举法
暴力枚举法 思路及算法 最容易想到的方法是枚举数组中的每一个数 x,寻找数组中是否存在 target - x。 当我们使用遍历整个数组的方式寻找 target - x 时,需要注意到每一个位于 x 之前的元素都已经和 x 匹配过,因此不需要再进行匹配。而每一个元素不能被使用两次,所以我们只需要在 x 后面的元素中寻找 target - x。 最容易想到的方法是枚举数组中的每一个数 x,寻找数组中是否存在 target - x。 当我们使用遍历整个数组的方式寻找 target - x 时,需要注意到每一个位
2020-10-11 15:20:31
476
原创 C++primer 第一章示例
1.4 控制流 1.4.4 if语句 统计在输入中每个值连续出现了多少次: #include <iostream> using namespace std; int main() { int currVal = 0, val = 0; if (cin >> currVal) { int cnt = 1; while (cin >> val) if (val == currVal) ++cnt; else { cout &
2020-10-09 22:54:53
267
原创 C++primer 第一章练习题
1.4.1节练习 练习1.9 #include <iostream> using namespace std; int main() { int i = 50; int sum = 0; while (i <= 100) { sum += i; i++; } cout << sum<<endl; system("pause"); return 0; } 练习1.10 #include <iostream> using na
2020-10-09 22:52:48
302
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人