Skip to content

Instantly share code, notes, and snippets.

View jglatts's full-sized avatar

John Glatts jglatts

View GitHub Profile
@jglatts
jglatts / result_pattern.cs
Last active August 29, 2025 20:20
simple result pattern in c#
using System;
class Problem {
public string error_msg;
}
class Result<T> {
public bool is_success = true;
public Problem problem = null;
public T value;
using System;
class Node<T> {
public T data;
public Node<T> left;
public Node<T> right;
public Node(T ele) {
data = ele;
left = null;
@jglatts
jglatts / milliohm_meter.ino
Created August 29, 2025 17:25
Low Resistance Arduino Meter
const int pinHigh = A0;
const int pinLow = A1;
const float Vref = 5.0;
const float current = 0.495;
void setup() {
Serial.begin(115200);
}
@jglatts
jglatts / lc_12.cs
Created August 9, 2025 19:07
12. Integer to Roman
public class Solution {
public string IntToRoman(int num) {
List<KeyValuePair<int, string>> romanMap = new List<KeyValuePair<int, string>> {
new KeyValuePair<int, string>(1000, "M"),
new KeyValuePair<int, string>(900, "CM"),
new KeyValuePair<int, string>(500, "D"),
new KeyValuePair<int, string>(400, "CD"),
new KeyValuePair<int, string>(100, "C"),
new KeyValuePair<int, string>(90, "XC"),
new KeyValuePair<int, string>(50, "L"),
@jglatts
jglatts / lc_112.cs
Created August 8, 2025 01:39
112. Path Sum
public class Solution {
public bool HasPathHelper(TreeNode curr_node, int target, int curr_val)
{
if (curr_node == null)
return false;
curr_val += curr_node.val;
if (curr_node.left == null && curr_node.right == null)
@jglatts
jglatts / lc_98.cs
Created August 6, 2025 01:28
lc-98
public class Solution {
public bool IsValidBST(TreeNode root) {
return IsValidBSTHelper(root, long.MinValue, long.MaxValue);
}
public bool IsValidBSTHelper(TreeNode node, long min, long max) {
bool check = false;
if (node == null) return true;
@jglatts
jglatts / lc_17.cs
Created August 5, 2025 12:52
17. Letter Combinations of a Phone Number
public class Solution {
/*
Given a string containing digits from 2-9 inclusive,
return all possible letter combinations that the number could represent.
Return the answer in any order.
for each digit in digits:
dynamically build string with digit
@jglatts
jglatts / lc_73.cs
Created August 5, 2025 11:53
73. Set Matrix Zeroes
public class Solution {
public void SetZeroes(int[][] matrix) {
Dictionary<int, List<int>> map = new Dictionary<int, List<int>>();
// get locations of 0s
for (int i = 0; i < matrix.Length; i++)
{
for (int j = 0; j < matrix[0].Length; j++)
{
if (matrix[i][j] == 0)
@jglatts
jglatts / lc_53.cs
Created August 5, 2025 01:31
53. Maximum Subarray
public class Solution {
public int MaxSubArray(int[] nums) {
int currentSum = nums[0]; // running tally for check
int maxSum = nums[0]; // max sum
for (int i = 1; i < nums.Length; i++) {
// do we need to restart subarray?
if (nums[i] > (currentSum + nums[i]))
currentSum = nums[i];
else
@jglatts
jglatts / LC_22_Generate_Parentheses.cs
Created August 4, 2025 17:32
22. Generate Parentheses
public class Solution {
public void GenerateHelper(List<string> ret, string curr_str, int open_count, int close_count, int n)
{
if (curr_str.Length == n*2)
{
ret.Add(curr_str);
return;
}
// trace this out