Skip to content

Instantly share code, notes, and snippets.

View RakhmedovRS's full-sized avatar
👀
Watching you

Ruslan Rakhmedov RakhmedovRS

👀
Watching you
View GitHub Profile
public String reverseWords(String s)
{
String[] words = s.split(" ");
StringBuilder result = new StringBuilder(words.length);
for (int i = words.length - 1; i >= 0; i--)
{
if (words[i].length() != 0)
{
if (result.length() != 0)
{
public ListNode mergeKLists(ListNode[] lists)
{
if (lists == null || lists.length == 0)
{
return null;
}
ListNode dummy = new ListNode(0);
ListNode prev = dummy;
ListNode current;
public int[][] merge(int[][] intervals)
{
Arrays.sort(intervals, (a, b) ->
{
if (a[1] == b[1])
{
return a[0] - b[0];
}
return a[1] - b[1];
class Node
{
int val;
Node next;
Node random;
public Node(int val)
{
this.val = val;
this.next = null;
Map<Node, Node> map = new HashMap<>();
Node temp = head;
while (temp != null)
{
map.put(temp, new Node(temp.val));
temp = temp.next;
}
public Node copyRandomList(Node head)
{
Map<Node, Node> map = new HashMap<>();
Node temp = head;
while (temp != null)
{
map.put(temp, new Node(temp.val));
temp = temp.next;
}
List<Integer> result = new ArrayList<>();
if (root == null)
{
return result;
}
Map<Integer, Boolean> visited = new HashMap<>();
private void rightSideView(TreeNode root, List<Integer> result, Map<Integer, Boolean> visited, int currentLevel)
{
if (root == null)
{
return;
}
if (!visited.getOrDefault(currentLevel, false))
{
visited.put(currentLevel, true);
public List<Integer> rightSideView(TreeNode root)
{
List<Integer> result = new ArrayList<>();
if (root == null)
{
return result;
}
Map<Integer, Boolean> visited = new HashMap<>();
rightSideView(root, result, visited, 1);