File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Leetcode_1347
2
+ // 2021.04.18
3
+ // Medium
4
+
5
+ import java .util .HashSet ;
6
+ import java .util .Iterator ;
7
+
8
+ public class MakeAnagram {
9
+ public static void main (String [] args ) {
10
+ System .out .println (new MakeAnagram ().minSteps ("leetcode" ,"practice" ));
11
+ }
12
+ public int minSteps (String s , String t ) {
13
+ StringBuilder str1 = new StringBuilder (s );
14
+ StringBuilder str2 = new StringBuilder (t );
15
+ // HashSet<Character> set = new HashSet<>();
16
+
17
+ if (t .length () == 0 )
18
+ return 0 ;
19
+ if (t .length () != s .length ())
20
+ return -1 ;
21
+
22
+ // for (int i = 0; i < str1.length(); i++)
23
+ // set.add(str1.charAt(i));
24
+
25
+ // Iterator<Character> itr = set.iterator();
26
+ for (int i = 0 ; i < str1 .length (); i ++) {
27
+ char tmp = str1 .charAt (i );
28
+ if (t .contains (String .valueOf (tmp ))) {
29
+ str2 .deleteCharAt (str2 .indexOf (String .valueOf (tmp )));
30
+ t = str2 .toString ();
31
+ }
32
+ }
33
+
34
+ HashSet <Character > resultSet = new HashSet <>();
35
+ if (t .length () != 0 ){
36
+ for (int i = 0 ; i < t .length (); i ++)
37
+ resultSet .add (t .charAt (i ));
38
+ }
39
+
40
+ return resultSet .size ();
41
+ }
42
+ }
You can’t perform that action at this time.
0 commit comments