Advertisement
LeatherDeer

Untitled

Dec 8th, 2022
621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. class Solution {
  2.     public void merge(int[] nums1, int m, int[] nums2, int n) {
  3.         if (n == 0) return;
  4.        
  5.         int last = n + m - 1;
  6.         m = m - 1;
  7.         n = n - 1;
  8.        
  9.         while (n >= 0) {
  10.             if (m >= 0 && nums1[m] > nums2[n]) {
  11.                 nums1[last--] = nums1[m--];
  12.             } else {
  13.                 nums1[last--] = nums2[n--];
  14.             }
  15.         }
  16.     }
  17. }
  18.  
  19.     public boolean isPalindrome(String s) {
  20.         int left = 0;
  21.         int right = s.length() - 1;
  22.        
  23.         while (left < right) {
  24.             while (left < right && !Character.isLetterOrDigit(s.charAt(left))) {
  25.                 left += 1;
  26.             }
  27.            
  28.             while (left < right && !Character.isLetterOrDigit(s.charAt(right))) {
  29.                 right -= 1;
  30.             }
  31.            
  32.             char leftChar = Character.toLowerCase(s.charAt(left));
  33.             char rightChar = Character.toLowerCase(s.charAt(right));
  34.             if (leftChar != rightChar) {
  35.                 return false;
  36.             }
  37.            
  38.             left += 1;
  39.             right -= 1;
  40.         }
  41.        
  42.         return true;
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement