Leetcode in Java && Oracle
422 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
Channel photo updated
Welcome to channel "Leetcode Java".
In this channel I just want to provide my solutions of Leetcode problems in Java programming language.
#N1 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};
}
};
#N26 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;
}
}
#N1431 Kids With the Greatest Number of Candies
problem link=>https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/

class Solution {
public List<Boolean> kidsWithCandies(int[] candies, int extra) {
ArrayList<Boolean> ans = new ArrayList<Boolean>();
int max=0;
for(int candy: candies){
max=Math.max(candy, max);
}
for(int candy: candies){
ans.add(candy+extra>=max);
}

return ans;
}
}