This file contains hidden or 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
using System; | |
class Problem { | |
public string error_msg; | |
} | |
class Result<T> { | |
public bool is_success = true; | |
public Problem problem = null; | |
public T value; |
This file contains hidden or 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
using System; | |
class Node<T> { | |
public T data; | |
public Node<T> left; | |
public Node<T> right; | |
public Node(T ele) { | |
data = ele; | |
left = null; |
This file contains hidden or 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
const int pinHigh = A0; | |
const int pinLow = A1; | |
const float Vref = 5.0; | |
const float current = 0.495; | |
void setup() { | |
Serial.begin(115200); | |
} |
This file contains hidden or 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
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"), |
This file contains hidden or 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
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) |
This file contains hidden or 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
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; |
This file contains hidden or 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
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 |
This file contains hidden or 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
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) |
This file contains hidden or 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
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 |
This file contains hidden or 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
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 |
NewerOlder