(LintCode) No 5: Swap Two Integers in Array
2018-03-16 21:20
330 查看
题目描述:交换一个数列中两个数字的位置。
代码如下:public class Solution {
/**
* @param A: An integer array
* @param index1: the first index
* @param index2: the second index
* @return: nothing
*/
public void swapIntegers(int[] A, int index1, int index2) {
int n;
n = A[index1];
A[index1] = A[index2];
A[index2] = n;// write your code here
}
}
代码如下:public class Solution {
/**
* @param A: An integer array
* @param index1: the first index
* @param index2: the second index
* @return: nothing
*/
public void swapIntegers(int[] A, int index1, int index2) {
int n;
n = A[index1];
A[index1] = A[index2];
A[index2] = n;// write your code here
}
}
相关文章推荐
- LeetCode解题报告—— Swap Nodes in Pairs & Divide Two Integers & Next Permutation
- [LintCode]Swap Two Nodes in Linked List
- lintcode-medium-Swap Two Nodes in Linked List
- [LintCode] Swap Two Nodes in Linked List 交换链表中的两个结点
- [LintCode] Swap Two Nodes in Linked List 交换链表中的两个结点
- [TS] Swap two element in the array (mutation)
- LintCode:Swap Two Nodes in Linked List
- Maximum XOR of Two Numbers in an Array
- [Lintcode]Find Minimum in Rotated Sorted Array II
- Find the kth smallest element in two sorted array
- No. 47 - Search in a Rotation of an Array
- 421. Maximum XOR of Two Numbers in an Array
- 【LeetCode】 421. Maximum XOR of Two Numbers in an Array
- lintcode-medium-Divide Two Integers
- 前缀树及应用两数异或Leetcode之 Maximum XOR of Two Numbers in an Array
- lintcode :search in rotated sorted array 搜索旋转排序数组
- 421. Maximum XOR of Two Numbers in an Array
- Two Dimensional TInt Array in Symbian(二维数组)
- 421. Maximum XOR of Two Numbers in an Array
- leetcode 421. Maximum XOR of Two Numbers in an Array