Welcome to channel "Leetcode Java".
In this channel I just want to provide my solutions of Leetcode problems in Java programming language.
In this channel I just want to provide my solutions of Leetcode problems in Java programming language.
Forwarded from Leetcode in Java && Oracle
#N1 Two sum
problem link =>https://leetcode.com/problems/two-sum/
problem link =>https://leetcode.com/problems/two-sum/
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
int a = 0, b = 0;
for (int i = 0; i < nums.size() - 1; i ++) {
for (int j = i + 1; j < nums.size(); j ++) {
if ( nums[i] + nums[j] == target) {
a = i;
b = j;
}
}
}
return {a, b};
}
};Forwarded from Leetcode in Java && Oracle
#N26 Remove Duplicates from Sorted Array
problem link=>https://leetcode.com/problems/remove-duplicates-from-sorted-array/
problem link=>https://leetcode.com/problems/remove-duplicates-from-sorted-array/
class Solution {
public int removeDuplicates(int[] nums) {
int i = 0;
for (int n : nums)
if (i == 0 || n > nums[i-1])
nums[i++] = n;
return i;
}
}
