File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments