Instantly share code, notes, and snippets.

🎯
Focusing

# Vallarasu Sambathkumar VallarasuS

🎯
Focusing
Last active March 21, 2023 02:42
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 class ListNode { int val; ListNode next; ListNode() {} ListNode(int val) { this.val = val; } ListNode(int val, ListNode next) { this.val = val; this.next = next; } } public class HelloWorld { public static void printList(ListNode node) {
Created March 16, 2023 05:45
Insertion Sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 class Solution { public void insertionSort(int[] numbsers) { for(int i = 1; i < numbsers.length; i++) { int item = numbsers[i]; int j = i - 1; while (j >= 0 && item < numbsers[j]) { numbsers[j + 1] = numbsers[j];
Last active March 16, 2023 04:54
88. Merge Sorted Array - https://leetcode.com/problems/merge-sorted-array/description/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) { int capacity = m + n; for(int i = capacity -1; i >= 0; i--) { if(n < 1) { return;
Created March 15, 2023 14:28
1089. Duplicate Zeros - https://leetcode.com/problems/duplicate-zeros/description/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 class Solution { public void duplicateZeros(int[] arr) { for(int i = 0; i < arr.length; i++) { if(arr[i] == 0) { shiftRight(arr, i); i += 1; }
Created March 14, 2023 16:56
977. Squares of a Sorted Array - https://leetcode.com/problems/squares-of-a-sorted-array/description/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 class Solution { public int[] sortedSquares(int[] nums) { for(int i=0; i < nums.length; i++) { nums[i] *= nums[i]; } this.quickSort(nums, 0, nums.length - 1); return nums;
Last active March 12, 2023 17:22
HelloWorldWeb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import java.io.*; import java.net.ServerSocket; import java.net.Socket; import java.nio.charset.StandardCharsets; public class HelloWorldWeb { public static final int PORT = 80; public static void main(String [] args) throws IOException {
Created March 11, 2023 13:09
383. Ransom Note - https://leetcode.com/problems/ransom-note/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 class Solution { public boolean canConstruct(String ransomNote, String magazine) { int[] charCount = new int[26]; for (char c: magazine.toCharArray()) { charCount[c - 'a']++; } for (char c: ransomNote.toCharArray()) {
Created March 11, 2023 12:48
383. Ransom Note - https://leetcode.com/problems/ransom-note/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 class Solution { public boolean canConstruct(String ransomNote, String magazine) { HashMap charMap = new HashMap(); for(char c : magazine.toCharArray()) { if(charMap.containsKey(c)) { int frequency = charMap.get(c); charMap.put(c, frequency + 1);
Created March 11, 2023 07:32