- Two Sum
class Solution {
public int[] twoSum(int[] nums, int target) {
int arr[] = new int[2];
for(int i = 0 ; i < nums.length ; i++){
for(int j = i+1 ; j < nums.length ; j++){
if(nums[i] + nums[j] == target){
arr[0] = i;
arr[1] = j;
}
}
}
return arr;
}
}
- Best Time to Buy and Sell Stock
- Merge Sorted Array
class Solution {
public void merge(int[] nums1, int m, int[] nums2, int n) {
System.arraycopy(nums2 , 0 , nums1 , m , n);
Arrays.sort(nums1);
}
}
class Solution {
public void merge(int[] nums1, int m, int[] nums2, int n) {
for(int j = 0 , i = m ; j < n ; j++){
nums1[i] = nums2[j];
i++;
}
Arrays.sort(nums1);
}
}