Skip to content

Commit 43bb7b3

Browse files
authored
Merge pull request #1 from ankitgautam03/Problems
Leetcode Problems on Arrays and Strings
2 parents 49c9209 + 756f106 commit 43bb7b3

3 files changed

Lines changed: 55 additions & 0 deletions

File tree

Leetcode/JewelsAndStones.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//Problem Link:- https://leetcode.com/problems/jewels-and-stones/
2+
3+
//Problem Solution in Java:
4+
5+
class Solution {
6+
public int numJewelsInStones(String jewels, String stones) {
7+
int count=0;
8+
for(int i=0;i<stones.length();i++){
9+
for(int j=0;j<jewels.length();j++){
10+
if(jewels.charAt(j) == stones.charAt(i)){
11+
count = count+1;
12+
}
13+
}
14+
}
15+
return count;
16+
}
17+
}

Leetcode/SquaresOfSortedArray.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//Problem Link:- https://leetcode.com/problems/squares-of-a-sorted-array/
2+
3+
//Solution Of the Problem:
4+
5+
class Solution {
6+
public int[] sortedSquares(int[] nums) {
7+
for(int i=0;i<nums.length;i++){
8+
nums[i] = nums[i]*nums[i];
9+
}
10+
for(int j=1;j<nums.length;j++){
11+
int key = nums[j];
12+
int k=j-1;
13+
14+
while(k>=0 && nums[k]>key){
15+
nums[k+1] = nums[k];
16+
k=k-1;
17+
}
18+
nums[k+1] = key;
19+
}
20+
return nums;
21+
}
22+
}

Leetcode/duplicateZeroes.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public void duplicateZeros(int[] arr) {
3+
for(int i=0;i<arr.length;i++){
4+
if(arr[i] == 0){
5+
for(int j=arr.length-1;j>=i+1;j--)
6+
{
7+
arr[j] = arr[j-1];
8+
}
9+
i=i+1;
10+
}
11+
}
12+
for(int i=0;i<arr.length;i++){
13+
System.out.println(arr[i]);
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)