Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public void allPossibleWords(char C[][], int i, int j, int N, int M, char res[], int idx) {
- if (i > N || j > M) {
- return;
- }
- res[idx] = C[i][j];
- for (int l = 0; l <= idx; l++) {
- System.out.print(res[l]);
- }
- System.out.println();
- allPossibleWords(C, i + 1, j, N, M, res, idx + 1);
- allPossibleWords(C, i, j + 1, N, M, res, idx + 1);
- allPossibleWords(C, i + 1, j + 1, N, M, res, idx + 1);
- }
- public String[] findWords(String[] grid, String[] wordlist) {
- char C[][] = new char[51][51];
- for (int i = 0; i < grid.length; i++) {
- for (int j = 0; j < grid[i].length(); j++) {
- C[i][j] = grid[i].charAt(j);
- }
- }
- allPossibleWords(C, 0, 0, grid.length, grid[1].length(), new char[2001], 0);
- for (int i = 0; i < grid.length; i++) {
- for (int j = 0; j < C[i].length; j++) {
- System.out.print(C[i][j] + " ");
- }
- System.out.println();
- }
- return null;
- }
- public void run() {
- findWords(new String[]{"TE",
- "GO"}, new String[]{"", ""});
- }
- public static void main(String[] args) {
- new Main().run();
- }
- class Node {
- char letter;
- boolean fullWord;
- Node child[];
- String index = "";
- public Node(char letter) {
- this.letter = letter;
- child = new Node[26];
- fullWord = false;
- }
- public void insertWord(Node root, String word) {
- int l = word.length();
- Node curNode = root;
- char c[] = word.toCharArray();
- for (int i = 0; i < c.length; i++) {
- if (curNode.child[c[i] - 'A'] == null) {
- curNode.child[c[i] - 'A'] = new Node(c[i]);
- }
- curNode = curNode.child[c[i] - 'A'];
- }
- fullWord = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement