Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package code;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.LinkedHashMap;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.Scanner;
- /**
- *
- * @author manth
- */
- public class Code {
- /**
- * @param args the command line arguments
- */
- /*
- Given a string s and a non-empty string p, find all the start indices of p's anagrams in s.
- Strings consists of lowercase English letters only and the length of both strings s and p will not be larger than 20,100.
- The order of output does not matter.
- Example 1:
- Input:
- s: "cbaebabacd" p: "abc"
- Output:
- [0, 6]
- Explanation:
- The substring with start index = 0 is "cba", which is an anagram of "abc".
- The substring with start index = 6 is "bac", which is an anagram of "abc".
- */
- public static void main(String[] args) {
- Scanner sc=new Scanner(System.in);
- String s=sc.nextLine();
- permutations(0,"abc");
- }
- public static void permutations(int depth,String input)
- {
- if(depth==input.length())
- {
- System.out.println(input);
- return;
- }
- // char input_arr[]=input.toCharArray();
- for(int i=depth;i<input.length();i++)
- {
- char input_arr[]=input.toCharArray();
- char tmp=input_arr[depth];
- input_arr[depth]=input_arr[i];
- input_arr[i]=tmp;
- String swaped=new String(input_arr);
- permutations(depth+1,swaped);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement