VectorCalculus
H
Jakarta Raya, Indonesia
Repeat after me:

∇ ⋅ E = ρ / ε0
∇ ⋅ B = 0
∇ × E = - ∂B / ∂t
∇ × B = μ0 (J + ε0 ∂E / ∂t)
Repeat after me:

∇ ⋅ E = ρ / ε0
∇ ⋅ B = 0
∇ × E = - ∂B / ∂t
∇ × B = μ0 (J + ε0 ∂E / ∂t)
Currently Offline
Information
Submission for Leetcode Problem 212. Word Search II (Hard)
(Java) Trie + DFS Solution

Problem link [leetcode.com]
I don't know what to write so here's my recently accepted Leetcode submission:

class Solution {
⠀⠀⠀private int[][] directions = new int[][] {
⠀⠀⠀⠀⠀{-1, 0}, {1, 0}, {0,-1}, {0, 1}
⠀⠀⠀};
⠀⠀⠀
⠀⠀⠀private TrieNode node = new TrieNode();
⠀⠀⠀private List<String> result = new ArrayList<>();
⠀⠀⠀
⠀⠀⠀public List<String> findWords(char[][] board, String[] words) {
⠀⠀⠀⠀⠀for (String word : words) insertWord(word);
⠀⠀⠀⠀⠀for (int i = 0; i < board.length; i++) {
⠀⠀⠀⠀⠀⠀⠀⠀⠀for (int j = 0; j < board[0].length; j++) {
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀char ch = board[i][j];
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀if (this.node.children[ch - 'a'] == null) continue;
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀StringBuilder sb = new StringBuilder();
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀dfs(board, this.node.children[ch - 'a'], sb.append(ch), i, j);
⠀⠀⠀⠀⠀⠀⠀⠀⠀}
⠀⠀⠀⠀⠀}
⠀⠀⠀⠀⠀return this.result;
⠀⠀⠀}

⠀⠀⠀private void dfs(char[][] board, TrieNode pointer, StringBuilder sb, int i, int j) {
⠀⠀⠀⠀⠀if (pointer.isNodeEnd && !pointer.isAdded) {
⠀⠀⠀⠀⠀⠀⠀⠀⠀this.result.add(sb.toString());
⠀⠀⠀⠀⠀⠀⠀⠀⠀pointer.isAdded = true;
⠀⠀⠀⠀⠀}
⠀⠀⠀⠀⠀char temp = board[i][j];
⠀⠀⠀⠀⠀board[i][j] = 'X';

⠀⠀⠀⠀⠀for (int[] dir : this.directions) {
⠀⠀⠀⠀⠀⠀⠀⠀⠀int x = i + dir[0];
⠀⠀⠀⠀⠀⠀⠀⠀⠀int y = j + dir[1];

⠀⠀⠀⠀⠀⠀⠀⠀⠀if (x >= 0 && x < board.length && y >= 0
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀&& y < board[0].length && board[x][y] != 'X'
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀&& null != pointer.children[board[x][y] - 'a']) {
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀dfs(board, pointer.children[board[x][y] - 'a'],
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀sb.append(board[x][y]), x, y);
⠀⠀⠀⠀⠀⠀⠀⠀⠀}
⠀⠀⠀⠀⠀}

⠀⠀⠀⠀⠀board[i][j] = temp;
⠀⠀⠀⠀⠀sb.setLength(sb.length() - 1);
⠀⠀⠀}

⠀⠀⠀private void insertWord(String word) {
⠀⠀⠀⠀⠀TrieNode pointer = this.node;
⠀⠀⠀⠀⠀for (char ch : word.toCharArray()) {
⠀⠀⠀⠀⠀⠀⠀⠀⠀if (pointer.children[ch - 'a'] == null)
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀pointer.children[ch - 'a'] = new TrieNode();
⠀⠀⠀⠀⠀⠀⠀⠀⠀pointer = pointer.children[ch - 'a'];
⠀⠀⠀⠀⠀}
⠀⠀⠀⠀⠀pointer.isNodeEnd = true;
⠀⠀⠀}
}

class TrieNode {
⠀⠀⠀public boolean isNodeEnd = false;
⠀⠀⠀public boolean isAdded = false;
⠀⠀⠀public TrieNode[] children = null;

⠀⠀⠀public TrieNode() {
⠀⠀⠀⠀⠀this.children = new TrieNode[26];
⠀⠀⠀}
}
Screenshot Showcase
Forza Horizon 4
Recent Activity
21 hrs on record
last played on 1 Jan
691 hrs on record
last played on 1 Jan
61 hrs on record
last played on 31 Dec, 2025
Comments
/) Leomate (\ 6 Dec, 2014 @ 7:18pm 
Hi bim :3