{{ message }}

Instantly share code, notes, and snippets.

# Gary Wang zcwang

Created Jul 17, 2018
Search 2D Matrix for target
View gist:364a5e8bed4036c81069484faa50d405
 class Solution { public boolean searchMatrix(int[][] matrix, int target) { if (matrix.length == 0) { return false; } if (matrix[0].length == 0) { return false; }
Created Jul 17, 2018
Largest rectangle area in data histogram
View gist:6a0589a1837bc6d9564ce20ce9af3e60
 class Solution { public int largestRectangleArea(int[] heights) { Stack s = new Stack<>(); int result = 0; for (int i = 0; i <= heights.length; ) { final int value = i < heights.length ? heights[i] : 0; if (s.isEmpty() || value > heights[s.peek()]) { s.push(i++);
Created Apr 25, 2018
Leetcode's Word Break-I
View gist:ab7461351317fa899f46b27587e3ea80
 class Solution { public boolean wordBreak(String s, List wordDict) { boolean[] mem = new boolean[s.length() + 1]; mem[0] = true; for (int i = 1; i <= s.length(); i++) { for (int k = 0; k < i; k++) { if (mem[k] && wordDict.contains(s.substring(k, i))) { mem[i] = true; break;
Created Mar 30, 2018
For finding common element in three arrays
View gist:cece6997fb94b586da844ac3a266e763
 #define FOUND 1 #define NOT_FOUND 0 int search(int x[], int y[], int z[], int X, int Y, int Z, int *XX, int *YY, int *ZZ) { *XX = *YY = *ZZ = 0; while (*XX < X && *YY < Y && *ZZ < Z) if (x[*XX] < y[*YY]) { (*XX)++; } else if (y[*YY] < z[*ZZ]) {
Created Mar 30, 2018
index of array with its value...
View gist:e1262079a7084235f487a950e9361ec3
 int index_search(int x[], int n) { int first = 0; int last = n - 1; int middle, index; index = -1; while (first <= last) { /* a modified binary search*/ middle = (first + last) / 2; if (x[middle] == middle) { index = middle;
Created Mar 28, 2018
Good counting sort for reference
View CountingSort.java
 public class CountingSort { static int[] countingSort(int arr[]) { int[] aux = new int[arr.length]; int min = arr[0]; int max = arr[0]; for (int i = 1; i < arr.length; i++) { if (arr[i] < min) { min = arr[i];
Created Apr 25, 2016 — forked from anonymous/gpu process
Stack trace of Chromium when glViewport gets executed from WebGL
View gpu process
 #0 gfx::GLApiBase::glViewportFn (this=0x182605816b60, x=0, y=0, width=248, height=1078) at ../../ui/gl/gl_bindings_autogen_gl.cc:8006 #1 gpu::gles2::GLES2DecoderImpl::DoViewport (this=0x198a38b57c20, x=0, y=0, width=248, height=1078) at ../../gpu/command_buffer/service/gles2_cmd_decoder.cc:8259 #2 0x00007fffe9c78ee4 in gpu::gles2::GLES2DecoderImpl::HandleViewport (this=0x198a38b57c20, immediate_data_size=0, cmd_data=0x7fffd2cf6a88) at ../../gpu/command_buffer/service/gles2_cmd_decoder_autogen.h:3996 #3 0x00007fffe9c84928 in gpu::gles2::GLES2DecoderImpl::DoCommandsImpl (this=0x198a38b57c20, num_commands=20, buffer=0x7fffd2cf6a4c, num_entries=81, entries_processed=0x7fffffffb624) at ../../gpu/command_buffer/service/gles2_cmd_decoder.cc:4378 #4 0x00007fffe9c439bb in gpu::gles2::GLES2DecoderImpl::DoCommands (this=0x198a38b57c20, num_commands=20, buffer=0x7fffd2cf6a4c, num_entries=81, entries_processed=0x7fffffffb624) at ../../gpu/command_buffer/service/gles2_cmd_decoder.cc:4436 #5 0x00007fffe9bfa64f