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
//naive | |
public static void miniMaxSum(List < Long > arr) { | |
// Write your code here | |
long sum = 0; | |
List < Long > arr2 = new ArrayList < Long > (); | |
for (int i = 0; i < arr.size(); i++) { | |
for (int j = 0; j < arr.size(); j++) { | |
if (j == i) { | |
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
func isPalindrome(x int) bool { | |
str := strconv.Itoa(x) | |
if x < 0 { | |
return false | |
} | |
for i := 0; i < len(str)/2; i++ { | |
length := len(str) - 1 | |
if str[i] != str[length-i] { | |
fmt.Println(str[i]) | |
fmt.Println(str[length-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
package main | |
import ( | |
"fmt" | |
"sync" | |
) | |
type Factorial struct { | |
original int | |
fNum int |
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
func twoSum(nums []int, target int) []int { | |
m := make(map[int]int) | |
for i, e := range nums { | |
_, ok := m[e] | |
if ok { | |
return []int{m[nums[i]], i} | |
} else { | |
m[target-e] = 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
package main | |
import "fmt" | |
func main() { | |
arr := []rune{'a', 'b', 'a', 'a', 'b', 'c', 'd', 'e', 'f', 'c', 'a', 'b', 'a', 'd'} | |
m := make(map[rune]int) | |
for _, e := range arr { | |
_, ok := m[e] //search through map with a rune | |
if ok { |
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
//Time Complexity: O(n) linear time | |
public class SumNumbers { | |
public static void main(String[] args) { | |
int[] ans = comp(new int[] { 0, 2, 4, 5, 6 }, 99); | |
if (ans == null) { | |
System.out.println("Not found"); | |
} else { | |
for (int i : ans) { | |
System.out.println(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
/** | |
* Definition for singly-linked list. | |
* public class ListNode { | |
* int val; | |
* ListNode next; | |
* ListNode() {} | |
* ListNode(int val) { this.val = val; } | |
* ListNode(int val, ListNode next) { this.val = val; this.next = next; } | |
* } | |
*/ |
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
class Solution { | |
public boolean isValid(String s) { | |
Stack<Character> stack = new Stack<Character>(); | |
if (s.length() % 2 != 0 ) return false; | |
for (char c : s.toCharArray()) { | |
if (c == '{' || c == '[' || c == '(') { | |
stack.push(c); | |
}else if(c == '}' && !stack.isEmpty() && stack.peek() == '{'){ | |
stack.pop(); |
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
class Solution { | |
public String longestCommonPrefix(String[] strs) { | |
String prefix = strs[0]; | |
for (int i = 1; i <= strs.length - 1; i++) { | |
//first compare 1st element and 2nd element | |
prefix = commonPrefixUtil(prefix, strs[i]); | |
} | |
return prefix; | |
} |
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
class Solution { | |
public int romanToInt(String s) { | |
int[] num = new int[s.length()]; | |
int sum = 0; | |
for (int i = 0; i < s.length(); i++) { | |
num[i] += getNumber(s.charAt(i)); | |
} | |
for (int i = 0; i < num.length - 1; i++) { |
NewerOlder