IOS|IOS 算法(基础篇) ----- 数组异或操作
给你两个整数,n 和 start 。输入:n = 5, start = 0
数组 nums 定义为:nums[i] = start + 2*i(下标从 0 开始)且 n == nums.length 。
请返回 nums 中所有元素按位异或(XOR)后得到的结果
输出:8
解释:数组 nums 为 [0, 2, 4, 6, 8],其中 (0 ^ 2 ^ 4 ^ 6 ^ 8) = 8 。
"^" 为按位异或 XOR 运算符
输入:n = 4, start = 3
输出:8
解释:数组 nums 为 [3, 5, 7, 9],其中 (3 ^ 5 ^ 7 ^ 9) = 8.
遍历法 按照题意机械翻译即可
未翻译版
func xorOperation(_ n: Int, _ start: Int) -> Int {var result = start
for i in 1..
翻译版
func xorOperation(_ n: Int, _ start: Int) -> Int {// 定义result, 初始值为start
var result = start// 循环异或操作
for i in 1..
【IOS|IOS 算法(基础篇) ----- 数组异或操作】题目来源:力扣(LeetCode) 感谢力扣爸爸 :)
IOS 算法合集地址
推荐阅读
- 2020-04-07vue中Axios的封装和API接口的管理
- 画解算法(1.|画解算法:1. 两数之和)
- Guava|Guava RateLimiter与限流算法
- iOS中的Block
- Python基础|Python基础 - 练习1
- 一个选择排序算法
- SG平滑轨迹算法的原理和实现
- Java|Java基础——数组
- 记录iOS生成分享图片的一些问题,根据UIView生成固定尺寸的分享图片
- 《算法》-图[有向图]