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 List<List<Integer>> combinationSum(int[] candidates, int target) { | |
Arrays.sort(candidates); | |
var ret = new ArrayList<List<Integer>>(); | |
var cLen = candidates.length; | |
for(int com = 1; com <= (cLen); com++){ | |
var got = false; | |
var cur = combOf(com, candidates, target, 0); | |
if (cur.isEmpty()){ | |
continue; |
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 merge(int[] nums1, int m, int[] nums2, int n) { | |
if (n == 0){ | |
return; | |
} | |
var cur = 0; | |
var ptr = 0; | |
while (cur < n && ptr < m){ | |
if (nums1[ptr] == nums2[cur]){ | |
ptr++; |
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 removeDuplicates(int[] ar) { | |
var nui = 1; | |
var cnt = 1; | |
var len = ar.length; | |
for(int cur = 1; cur < len; cur++){ | |
if(ar[cur-1] == ar[cur]){ | |
cnt++; | |
} 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 maxProfit(int[] prices) { | |
var ret = 0; | |
var bp = Integer.MAX_VALUE; | |
for (int sp : prices){ | |
if (bp < sp){ | |
var profit = sp - bp; | |
ret = Math.max(profit, ret); | |
} | |
bp = Math.min(bp, sp); |
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 canJump(int[] nums) { | |
var len = nums.length; | |
//cornor | |
if (len == 1){ | |
return true; | |
} | |
//cornor | |
var canReach = new boolean[len-1]; | |
var target = len - 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 int hIndex(int[] citations) { | |
var len = citations.length; | |
if (len == 1){ | |
if (citations[0] == 0){ | |
return 0; | |
} else { | |
return 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 reverseVowels(String s) { | |
var arr = s.toCharArray(); | |
var l = 0; | |
var r = arr.length - 1; | |
while (l < r && l < arr.length && r >= 0 ){ | |
while (l < arr.length && l < r && !isVowel(arr[l])){ | |
l++; | |
} | |
while (r >= 0 && l < r && !isVowel(arr[r])){ |
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 compress(char[] chars) { | |
var len = chars.length; | |
var count = 1; | |
if (len == 1){ | |
return count; | |
} | |
var mark = 0; | |
var charCnt = 1; | |
for (int i = 1; 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 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++; | |
} | |
} |
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; | |
} |
OlderNewer