diff --git a/combination-sum/xeulbn.java b/combination-sum/xeulbn.java new file mode 100644 index 0000000000..03c7992f12 --- /dev/null +++ b/combination-sum/xeulbn.java @@ -0,0 +1,30 @@ +import java.util.*; + +class Solution { + public List> combinationSum(int[] candidates, int target) { + List> result = new ArrayList<>(); + + backtrack(candidates, target, 0, new ArrayList<>(), result); + + return result; + } + + private void backtrack(int[] candidates, int remain, int start, List current, List> result) { + if (remain == 0) { + result.add(new ArrayList<>(current)); + return; + } + + if (remain < 0) { + return; + } + + for (int i=start; i= 10 && twoDigit <= 26) { + dp[i] += dp[i - 2]; + } + } + + return dp[n]; + } +} diff --git a/maximum-subarray/xeulbn.java b/maximum-subarray/xeulbn.java new file mode 100644 index 0000000000..b4d2f0a77d --- /dev/null +++ b/maximum-subarray/xeulbn.java @@ -0,0 +1,21 @@ +import java.util.*; + +class Solution { + public int maxSubArray(int[] nums) { + int currentSum = nums[0]; + int maxSum = nums[0]; + + for (int i=1; i currentSum + nums[i]) { + currentSum = nums[i]; + } else { + currentSum += nums[i]; + } + + if (currentSum > maxSum) { + maxSum = currentSum; + } + } + return maxSum; + } +} diff --git a/number-of-1-bits/xeulbn.java b/number-of-1-bits/xeulbn.java new file mode 100644 index 0000000000..75cafca464 --- /dev/null +++ b/number-of-1-bits/xeulbn.java @@ -0,0 +1,17 @@ +import java.util.*; + +class Solution { + public int hammingWeight(int n) { + int count = 0; + + while (n > 0) { + if ((n & 1) == 1) { + count++; + } + + n = n >> 1; + } + + return count; + } +} diff --git a/valid-palindrome/xeulbn.java b/valid-palindrome/xeulbn.java new file mode 100644 index 0000000000..7feed164bf --- /dev/null +++ b/valid-palindrome/xeulbn.java @@ -0,0 +1,32 @@ +import java.util.*; + +class Solution { + public boolean isPalindrome(String s) { + int left =0; + int right = s.length()-1; + + while (left < right) { + + while (left < right && !Character.isLetterOrDigit(s.charAt(left))) { + left++; + } + + while (left < right && !Character.isLetterOrDigit(s.charAt(right))) { + right--; + } + + char leftChar = Character.toLowerCase(s.charAt(left)); + char rightChar = Character.toLowerCase(s.charAt(right)); + + if (leftChar != rightChar) { + return false; + } + + left++; + right--; + } + + + return true; + } +}