File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .util .HashSet ;
2
+
3
+ public class candyDistribution {
4
+ public static int distributeCandies (int [] candyType ) {
5
+ HashSet <Integer > set = new HashSet <>();
6
+ for (int candy : candyType ){
7
+ set .add (candy );
8
+ }
9
+ return Math .min (set .size (), candyType .length /2 );
10
+ }
11
+ public static void main (String [] args ) {
12
+ // take inputs accordingly
13
+ }
14
+ }
Original file line number Diff line number Diff line change
1
+ package Strings ;
2
+
3
+ import java .util .HashMap ;
4
+
5
+ public class FirstUniqChar {
6
+ public int firstUniqChar (String s ) {
7
+ HashMap <Character ,Integer > map = new HashMap <>();
8
+ for (int i =0 ; i <s .length (); i ++){
9
+ if (map .containsKey (s .charAt (i ))){
10
+ map .put (s .charAt (i ), map .get (s .charAt (i ))+1 );
11
+ }else {
12
+ map .put (s .charAt (i ), 1 );
13
+ }
14
+ }
15
+ for (int i =0 ; i <s .length (); i ++){
16
+ if (map .get (s .charAt (i ))==1 ){
17
+ return i ;
18
+ }
19
+ }
20
+ return -1 ;
21
+ }
22
+ public static void main (String [] args ) {
23
+ // take user input accordingly
24
+
25
+ }
26
+ }
Original file line number Diff line number Diff line change
1
+ def isPalindrome (self , s : str ) -> bool :
2
+ lst = []
3
+ for i in s :
4
+ if i .isalnum ():
5
+ lst .append (i .lower ())
6
+ l ,r = 0 , len (lst )- 1
7
+ while (l <= r ):
8
+ if lst [l ]!= lst [r ]:
9
+ return False
10
+ l ,r = l + 1 ,r - 1
11
+ return True
You can’t perform that action at this time.
0 commit comments