Arrays in Java

Arrays An array is a group of like-typed variables that are referred to by a common name.Arrays in Java work differently than they do in C/C++. Following are some important point about Java arrays. In Java all arrays are dynamically allocated.(discussed below) Since arrays are objects in Java, we can find their length using member …

Tree Traversals

Inorder Traversal Algorithm Inorder(tree) Traverse the left subtree, i.e., call Inorder(left-subtree) Visit the root. Traverse the right subtree, i.e., call Inorder(right-subtree) Preorder Traversal Algorithm Preorder(tree) Visit the root. Traverse the left subtree, i.e., call Preorder(left-subtree) Traverse the right subtree, i.e., call Preorder(right-subtree) Postorder Traversal Algorithm Postorder(tree) Traverse the left subtree, i.e., call Postorder(left-subtree) Traverse the …

This is No.63 in Leetcode. My original solution is: class Solution { private int path = 0; public int uniquePathsWithObstacles(int[][] obstacleGrid) { // get i and j int i = obstacleGrid[0].length; int j = obstacleGrid.length; i–; j–; findPath(i, i, path, obstacleGrid); return path; } private void findPath(int i, int j, int path, int[][] obstacleGrid){ // …

Rotate List

This is No.61 in leetcode. The description: Given a linked list, rotate the list to the right by k places, where k is non-negative. This is my original solution: /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = …