Skip to content

Instantly share code, notes, and snippets.

View engtomhat's full-sized avatar

Hatem Ahmed engtomhat

View GitHub Profile
@engtomhat
engtomhat / Solution.java
Last active June 11, 2019 03:59
157. Read N Characters Given Read4
/**
* The read4 API is defined in the parent class Reader4.
* int read4(char[] buf);
*/
public class Solution extends Reader4 {
/**
* @param buf Destination buffer
* @param n Number of characters to read
* @return The number of actual characters read
*/
@engtomhat
engtomhat / SortColors.java
Created August 9, 2017 19:07
75. Sort Colors
public class SortColors {
public void sortColors(int[] nums) {
if(nums.length > 1) {
int redIndex = 0;
int blueIndex = nums.length-1;
int i = 0;
while(i <= blueIndex) {
if(nums[i] == 2) {
// Send blue node to end of array
swap(nums, i, blueIndex--);
@engtomhat
engtomhat / NumberOfIslands.java
Created August 2, 2017 13:37
Number of Islands
public class NumberOfIslands {
public int numIslands(char[][] grid) {
int numOfIslands = 0;
for (int i = 0; i < grid.length; i++) {
char[] row = grid[i];
for (int j = 0; j < row.length; j++) {
if(grid[i][j] == '1') {
numOfIslands++;
scanIsland(grid, i, row, j+1);
scanIsland(grid, i, row, j-1);
@engtomhat
engtomhat / StringToInteger.java
Created August 2, 2017 03:02
String to Integer (atoi)
public class StringToInteger {
public int myAtoi(String str) {
int result = 0;
int multiplier = 1;
int startIndex = -1;
int endIndex = -1;
int index = 0;
boolean scanNumber = false;
boolean signAllowed = true;
boolean spaceAllowed = true;
@engtomhat
engtomhat / AddTwoNumbers.Java
Created July 24, 2017 17:18
Add Two Numbers
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
public class AddTwoNumbers {
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
226113 silly gunzTarPerm modified mode [ 'fp/invokeArgs.js', 420, 436 ]
226114 silly gunzTarPerm extractEntry fp/partial.js
226115 silly gunzTarPerm modified mode [ 'fp/partial.js', 420, 436 ]
226116 silly gunzTarPerm extractEntry fp/invoke.js
226117 silly gunzTarPerm modified mode [ 'fp/invoke.js', 420, 436 ]
226118 silly gunzTarPerm extractEntry fp/partialRight.js
226119 silly gunzTarPerm modified mode [ 'fp/partialRight.js', 420, 436 ]
226120 silly gunzTarPerm extractEntry fp/invertObj.js
226121 silly gunzTarPerm modified mode [ 'fp/invertObj.js', 420, 436 ]
226122 silly gunzTarPerm extractEntry fp/partition.js