Skip to content

Instantly share code, notes, and snippets.

View tungla's full-sized avatar

Vũ Hoàng Minh Tùng tungla

  • Ho Chi Minh
View GitHub Profile
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 3 + 3*1 + 3*2 + ... + 3*n = 3(1+2+3+...+n) = 3*n*(n+1)/2
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
/**
- When s1 = s2 = 0, longest = 0
- When s1, s2 >= 1, we have two cases:
+ If s1.charAt(largestIndex) == s2.charAt(largestIndex) , currentLongest = 1 + [Longest when s1 and s2 - 1 length]
+ If s1.charAt(largestIndex) != s2.charAt(largestIndex) , currentLongest = max[[Longest when s1, s2 - 1 length],[Longest when s1 - 1, s2 length]]
- So we calculate lcs with s1, s2 length increase by 1 each time
**/
class Solution {
public int longestCommonSubsequence(String text1, String text2) {
// TLE
class Solution {
public int rob(int[] nums) {
int length = nums.length;
int total = 0;
int total1 = 0;
if (length == 0)
{
return 0;
}
class Solution {
public boolean isSubsequence(String s, String t) {
int j = 0;
int sLength = s.length();
if (sLength == 0)
{
return true;
}
for (int i = 0; i < t.length(); i++){
char t1 = t.charAt(i);
// Approach
// [a b] | top optimalCostToTop = min(a,b)
// [a b c] | top optimalCostToTop = min(b,a+c)
// [a b c d] | top optimalCostToTop = min(optimal cost to c + cost(c), optimal cost to d + cost(d))
// optimal cost to c = min(a,b)
// optimal cost to d = min(b, a + c)
// [a b c d e] | top optimalCostToTop = min(optimal cost to d + cost(d), optimal cost to e + cost(e))
// ... and so on
// class Solution {
class Solution {
public int maxProfit(int[] prices) {
int maxProfit;
int lowestBuyDate;
int possibleMaxProfit;
if (prices.length <= 1)
{
return 0;
}
class Solution {
public int[] intersection(int[] nums1, int[] nums2) {
LinkedList<Integer> intersection = new LinkedList<Integer>();
int lastIntersection = -1;
int[] outputArr;
int nums1Length = nums1.length;
int nums2Length = nums2.length;
Arrays.sort(nums2);
Arrays.sort(nums1);
if (nums1Length >= nums2Length)