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
| // https://leetcode.com/problems/best-time-to-buy-and-sell-stock/submissions/ | |
| var maxProfit = function(prices) { | |
| let buyIndex = 0; | |
| let lastProfit = 0; | |
| for(let i = 1; i < prices.length; i++) { | |
| let currentProfit = prices[i] - prices[buyIndex]; | |
| // stock down |
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
| /** | |
| * https://leetcode.com/problems/maximum-subarray/ | |
| * @param {number[]} nums | |
| * @return {number} | |
| */ | |
| var maxSubArray = function(nums) { | |
| let maxSum = Number.MIN_SAFE_INTEGER; | |
| let runningSum = 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
| // https://leetcode.com/problems/count-sorted-vowel-strings/ | |
| function countVowelStrings(n: number): number { | |
| return traverse(n, 0, 0);; | |
| }; | |
| const vowels: string[] = [ 'a', 'e', 'i', 'o', 'u' ]; | |
| function traverse(n: number, runningCombination: number, runningIdx: number): number { | |
| if(runningCombination == n) { | |
| return 1; | |
| } |
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
| // https://leetcode.com/problems/count-square-submatrices-with-all-ones/ | |
| function countSquares(matrix: number[][]): number { | |
| let count = 0; | |
| for(let row = 0; row < matrix.length; row++) { | |
| for(let column = 0; column < matrix[row].length; column++) { | |
| let squareLength = 0; | |
| while(squareLength < matrix.length) { | |
| if(isOneMatrix(matrix, row, column, squareLength)) { | |
| count++; | |
| } |
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
| export function cycleInGraph(edges: number[][]) { | |
| // 1. loop through all vertices of the graph | |
| for (let v = 0; v < edges.length; v++) { | |
| if (hasCycle(edges, v, new Set<Number>())) | |
| return true; | |
| } | |
| return false; | |
| } |
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 MyAtoi(string s) { | |
| sbyte sign = 1; | |
| int runningNumber = 0; | |
| bool isReadNumber = false; | |
| bool isOverflow = false; | |
| for(int i = 0; i < s.Length; i++) | |
| { | |
| if(Char.IsWhiteSpace(s[i]) && !isReadNumber) continue; |
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.Collections.Generic; | |
| public class Solution { | |
| public IList<IList<int>> ThreeSum(int[] nums) { | |
| var tripletsCollection = new List<IList<int>>(nums.Length); | |
| var tripletSet = new HashSet<string>(nums.Length); | |
| var numOccurance = new Dictionary<int, HashSet<int>>(nums.Length); | |
| for(int i = 0; i < nums.Length; i++) | |
| AddNumOccurance(numOccurance, nums[i], i); |
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; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| public class Solution { | |
| public bool IsValidSudoku(char[][] board) { | |
| List<List<HashSet<int>>> sudokuSection = Enumerable.Range(1, 3) | |
| .Select(x => Enumerable.Range(1, 3).Select(x1 => new HashSet<int>(9)).ToList()).ToList(); | |
| List<HashSet<int>> rows = Enumerable.Range(1, 9).Select(x => new HashSet<int>(9)).ToList(); |
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.Text; | |
| public class Solution { | |
| public string CountAndSay(int n) { | |
| if(n == 1) return "1"; | |
| var previousSay = CountAndSay(n - 1); | |
| StringBuilder sb = new StringBuilder(); | |
| int runningOcc = 1; |
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.Text; | |
| using System.Collections.Generic; | |
| public class Solution { | |
| public string Convert(string s, int numRows) { | |
| StringBuilder sb = new StringBuilder(); | |
| List<int> pillarIndexes = new List<int>(); | |
| int i = 0; | |
| int h = numRows - 1; |