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
class RecentCounter { | |
List<Integer> queue; | |
int head; | |
int tail; | |
public RecentCounter() { | |
this.queue = new ArrayList<Integer>(); | |
this.head = -1; | |
this.tail = -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
class Solution { | |
public String decodeString(String s) { | |
var retVal = new StringBuilder(); | |
var len = s.length(); | |
var i = 0; | |
while(i < len){ | |
var chr = s.charAt(i); | |
if (Character.isDigit(chr)){ | |
i = valueOf((i) , s, retVal); | |
} else { |
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
class Solution { | |
public int[] asteroidCollision(int[] asteroids) { | |
var len = asteroids.length; | |
var stk = new ArrayList<Integer>(); | |
for (int cur : asteroids){ | |
if (Objects.nonNull(peek(stk)) && isPositiveNegative(peek(stk), cur)){ | |
if ((peek(stk) + cur) == 0){ | |
pop(stk); | |
} else if ((peek(stk) + cur) < 0){ | |
while( |
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
class Solution { | |
public String removeStars(String s) { | |
var stk = new ArrayList<Character>(); | |
var len = s.length(); | |
for (int i = 0; i < len; i++){ | |
var ch = s.charAt(i); | |
if (Objects.equals(ch, '*')){ | |
pop(stk); | |
} else { | |
stk.add(ch); |
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
class Solution { | |
public boolean uniqueOccurrences(int[] arr) { | |
Arrays.sort(arr); | |
var seen = new HashMap<Integer, List<Integer>>(); | |
var s = 0; | |
var e = 0; | |
var len = arr.length; | |
while (e < len){ | |
while ( e < len && arr[s] == arr[e]){ |
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
class Solution { | |
public int pivotIndex(int[] nums) { | |
var len = nums.length; | |
var l = new int[len]; | |
var r = new int[len]; | |
var ls = 0; | |
var rs = 0; | |
var s = 0; | |
var e = len-1; | |
for (int i = 0; i < len; 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
class Solution { | |
public int maxVowels(String s, int k) { | |
int slen = s.length(); | |
int[] dp = new int[slen]; | |
int vcc = 0; | |
for (int i = 0; i < slen; i++){ | |
if (isVowel(s.charAt(i))){ | |
dp[i] = ++vcc; | |
} else { | |
dp[i] = vcc; |
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
class Solution { | |
public int maxOperations(int[] nums, int k) { | |
var ret = 0; | |
Arrays.sort(nums); | |
var j = nums.length; | |
var i = 0; | |
while (i < j){ | |
if (nums[i]+nums[j] == k){ | |
ret++; | |
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
class Solution { | |
public boolean isSubsequence(String s, String t) { | |
var slen = s.length(); | |
var tlen = t.length(); | |
if (slen == 0){ | |
return true; | |
} | |
if (tlen < slen){ | |
return false; | |
} |
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
class Solution { | |
public void moveZeroes(int[] nums) { | |
var len = nums.length; | |
var mark = 0; | |
for (int i = 0; i < len; i++){ | |
if (nums[i] != 0){ | |
nums[mark] = nums[i]; | |
mark++; | |
} | |
} |
NewerOlder