Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public void merge(int[] nums1, int m, int[] nums2, int n) {
- if (n == 0) return;
- int last = n + m - 1;
- m = m - 1;
- n = n - 1;
- while (n >= 0) {
- if (m >= 0 && nums1[m] > nums2[n]) {
- nums1[last--] = nums1[m--];
- } else {
- nums1[last--] = nums2[n--];
- }
- }
- }
- }
- 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 += 1;
- }
- while (left < right && !Character.isLetterOrDigit(s.charAt(right))) {
- right -= 1;
- }
- char leftChar = Character.toLowerCase(s.charAt(left));
- char rightChar = Character.toLowerCase(s.charAt(right));
- if (leftChar != rightChar) {
- return false;
- }
- left += 1;
- right -= 1;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement