### Container with Most Water - Leet Code Solution

Problem Statement Given n non-negative integers a1, a2, …, an , where each…

August 28, 2019

Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.

```
Example 1:
Input: 121
Output: true
Example 2:
Input: -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
Example 3:
Input: 10
Output: false
```

There can be many solutions to this:

- Convert number to character array, and keep on matching characters.
- Reverse whole number and compare
- Get the length of number, and iterate over number digit by digit

```
public class Q9_Palindrome {
private int reverseInt(int x) {
int s = 0;
while (x > 0) {
s = s*10 + x%10;
x = x/10;
}
return s;
}
public boolean isPalindrome(int x) {
if (x < 0) return false;
return x == this.reverseInt(x);
}
}
```

```
public class Q9_Palindrome {
/**
* Example: 1234
* place=0, result=4
* place=1, result=3
*/
private int getDigit(int x, int place) {
x = x / (int)Math.pow(10, place);
return x % 10;
}
public boolean isPalindrome(int x) {
if (x < 0) return false;
int l = 0;
int temp = x;
while (temp > 0) {
l++;
temp /= 10;
}
for (int i=0; i<l; i++) {
if (this.getDigit(x, i) != this.getDigit(x, l-1-i)) {
return false;
}
}
return true;
}
}
```

Problem Statement Given n non-negative integers a1, a2, …, an , where each…

Problem Statement Roman numerals are represented by seven different symbols: I…

A number consists of digits. Example: 843. Its a 3-digit number. Radix sort…

Problem Statement The string “PAYPALISHIRING” is written in a zigzag pattern on…

Problem Statement Given a string, determine if it is a palindrome, considering…

This is kind of preliminary technique of sorting. And, this is the first…

Introduction Lets assume we have a csv something similar to following: Python…

Introduction In last post, we saw How to read CSV with Headers into Dictionary…

Introduction Power BI is a wonderful tool to give life to your data, by…

Problem Statement You are given an array prices where prices[i] is the price of…

Introduction In this post we will see: How to prepare a docker image for your…

Introduction We have a page, for example a . And, upon submission we would want…