This file contains 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
/// <summary> | |
/// The main program class. | |
/// </summary> | |
class Program | |
{ | |
// filename for dataset | |
private static string dataPath = Path.Combine(Environment.CurrentDirectory, "amazon0302.txt"); | |
/// <summary> | |
/// The main entry point of the program. |
This file contains 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[] TwoSum(int[] nums, int target) { | |
//Get length of the array | |
int len = nums.Length; | |
//Create a dictionary of array elements | |
var map = new Dictionary<int,int>(); | |
for(int i=0;i<len;i++){ | |
if(map.ContainsKey(nums[i])){ |
This file contains 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 Reverse(int x) { | |
if(x<=Int32.MinValue){ | |
return 0; | |
} | |
int temp = x; | |
long rev = 0; | |
temp = Math.Abs(temp); | |
while(temp>0){ |
This file contains 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 RemoveDuplicates(int[] nums) { | |
int len = nums.Length; | |
if(len == 0 || len == 1){ | |
return len; | |
} | |
int j = 0; | |
int i=1; |
This file contains 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 RemoveElement(int[] nums, int val) { | |
int len = nums.Length; | |
int i = 0; | |
int j = 0; | |
while(i<len){ | |
while(i<len && nums[i] == val){ | |
i++; | |
} | |
if(i<len){ |
This file contains 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 RomanToInt(string s) { | |
int len = s.Length; | |
int num = 0; | |
int i=0; | |
while(i<len){ | |
if(i-1>=0 && s[i] == 'V' && s[i-1] == 'I'){ | |
num = num + 4; | |
} |
This file contains 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 TrieNode{ | |
public bool isEndOfWord; | |
public TrieNode[] children; | |
public TrieNode(){ | |
isEndOfWord = false; | |
children = new TrieNode[26]; | |
for(int i=0;i<26;i++){ | |
children[i] = null; | |
} | |
} |
This file contains 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 IsValid(string s) { | |
int len = s.Length; | |
if(len == 0){ | |
return true; | |
} | |
var stack = new Stack<char>(); |
This file contains 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
/** | |
* Definition for singly-linked list. | |
* public class ListNode { | |
* public int val; | |
* public ListNode next; | |
* public ListNode(int val=0, ListNode next=null) { | |
* this.val = val; | |
* this.next = next; | |
* } | |
* } |
OlderNewer