Notes
Notes - notes.io |
// Scanner sc = new Scanner(expression).useDelimiter("/|(?=[-+])");
// int A = 0, B = 1;
// while (sc.hasNext()) {
// int a = sc.nextInt(), b = sc.nextInt();
// A = A * b + a * B;
// B *= b;
// int g = gcd(A, B);
// A /= g;
// B /= g;
// }
// return A + "/" + B;
// }
// private int gcd(int a, int b) {
// return a != 0 ? gcd(b % a, a) : Math.abs(b);
// }
// https://discuss.leetcode.com/topic/90061/small-simple-c-java-python/2
// private long gcd(long a, long b) {
// if (b == 0)
// return a < 0 ? -a : a; // always return positive gcd
// return gcd(b, a % b);
// }
class Solution {
public int countHoles (int num) {
int[] holes = new int[] {1, 0, 0, 0, 1, 0, 1, 2, 1};
char[] arr = String.valueOf(num).toCharArray();
int count = 0;
for (char ch : arr) {
count += holes[ch - '0'];
}
return count;
}
public int[] getMin(String[] a, String[] b) {
if (a == null || b == null) {
return new int[];
}
int[] results = new int[a.length];
for (int i = 0; i < a.length; i++) {
String s1 = a[i];
String s2 = b[i];
if (s1.length() != s2.length()) {
results[i] = -1;
continue;
}
HashMap<Character, Integer> charCount = new HashMap<>();
for (int j = 0; j < s1.length(); j++) {
char c1 = s1.charAt(j);
char c2 = s2.charAt(j);
if (charCount.get(c1) != null) {
charCount.put(c1, charCount.get(c1) + 1);
} else {
charCount.put(c1, 1);
}
if (charCount.get(c2) != null) {
charCount.put(c2, charCount.get(c2) - 1);
} else {
charCount.put(c1, -1);
}
}
for(Integer n : charCount.values()) {
results[i] += Math.abs(n);
}
results[i] /= 2;
}
return results;
}
public long countSteps(String[] steps) {
// if (steps == null || steps.length == 0) {
// return 0;
// }
int minR = Integer.MAX_VALUE;
int minC = Integer.MAX_VALUE;
for (String step : steps) {
String[] rc = step.split(" ");
int r = Integer.valueOf(rc[0]);
int c = Integer.valueOf(rc[1]);
minR = Math.min(minR, r);
minC = Math.min(minC, c);
}
return (long) minC * (long) minR;
}
public String[] reduced(String[] expressions) {
if (expressions == null || expressions.length == 0) {
return new String[];
}
String[] results = new String[expressions.length];
for (int i = 0; i < expressions.length; i++) {
String[] cur = expressions[i].split("[+/]");
int a = Integer.valueOf(cur[0]);
int b = Integer.valueOf(cur[1]);
int c = Integer.valueOf(cur[2]);
int d = Integer.valueOf(cur[3]);
int n = a * d + b * c;
int d = b * d;
int g = gcd(n, d);
n /= g;
d /= g;
results[i] = n + "/" + d;
}
}
private int gcd(int a, int b) {
if (a == 0) {
return Math.abs(b);
}
return gcd(a % b, b);
}
}
var lengthOfLIS = function(nums) {
const dp = new Array(nums.length).fill(1);
for (let i = 1; i < nums.length; i++) {
for (let j = 0; j < i; j++) {
if (nums[j] < nums[i]) {
dp[i] = Math.max(dp[i], dp[j] + 1);
}
}
}
return Math.max(0, ...dp);
};
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=286040&highlight=ixl
public int maxHeight(int[] predators){
int n = predators.length;
int[] res = new int[n];
Arrays.fill(res, 1);
for (int i = 0; i < n; i++){
int dir = predators[i];
if (dir == -1){
continue;
}else{
int pre = i;
while (dir != -1){
res[dir] = Math.max(res[dir], res[pre]+1);
pre = dir;
dir = predators[dir];
}
}. From 1point 3acres bbs
}
int max = 0;
for (int number: res){
max = Math.max(max, number);
}
return max;
}
public class Solution {
public int lengthOfLIS(int[] nums) {
int[] dp = new int[nums.length];
int len = 0;
for(int x : nums) {
int i = Arrays.binarySearch(dp, 0, len, x);
if(i < 0) i = -(i + 1);
dp[i] = x;
if(i == len) len++;
}
return len;
}
}
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team