View mergeTwoLists.java
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) { |
View insertionSort.java
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]; |
View merge.java
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; |
View duplicateZeros.java
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; | |
} |
View sortedSquares.java
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; |
View HelloWorldWeb.java
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 { |
View canConstruct1.java
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()) { |
View canConstruct.java
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<Character,Integer> charMap = new HashMap<Character, Integer>(); | |
for(char c : magazine.toCharArray()) { | |
if(charMap.containsKey(c)) { | |
int frequency = charMap.get(c); | |
charMap.put(c, frequency + 1); |
View middleNode1.java
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
/** | |
* Definition for singly-linked list. | |
* public class ListNode { | |
* int val; | |
* ListNode next; | |
* ListNode() {} | |
* ListNode(int val) { this.val = val; } | |
* ListNode(int val, ListNode next) { this.val = val; this.next = next; } | |
* } | |
*/ |
View middleNode.java
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
/** | |
* Definition for singly-linked list. | |
* public class ListNode { | |
* int val; | |
* ListNode next; | |
* ListNode() {} | |
* ListNode(int val) { this.val = val; } | |
* ListNode(int val, ListNode next) { this.val = val; this.next = next; } | |
* } | |
*/ |
NewerOlder