Quantum Theory

Anyone who is not shocked by quantum theory has not understood it.
Niels Bohr

I think I can safely say that no one understands quantum mechanics.
Richard Feynman

but it is certainly the case that, though we know how to do the sums, we do not understand the theory as fully as we should. We shall see in what follows that important interpretative issues remain unresolved. They will demand for their eventual settlement not only physical insight but also metaphysical decision.
Quantum Theory: A Very Short Introduction, John Polkinghorne


Arts & Culture: Poetry Takes on Quantum Physics
https://physics.aps.org/articles/v11/103

World Lines: A Quantum Supercomputer Poem, by Amy Catanzano

What can the quantum world do for business?
https://physicsworld.com/a/what-can-the-quantum-world-do-for-business/

So every time we turn off our mobile phones, USB sticks, memory drives or data centres, all the stored data doesn’t get wiped. Quantum mechanics delivers again.

And every time you write data onto NAND Flash, you’re using one of the most surprising and successful predictions of quantum mechanics. I’m referring to barrier penetration, or tunnelling, which allows a low-energy particle to penetrate a high potential-energy barrier.

What Has Quantum Mechanics Ever Done For Us?
https://www.forbes.com/sites/chadorzel/2015/08/13/what-has-quantum-mechanics-ever-done-for-us/#31c890740468

February 29

by Jane Hirshfield

An extra day—

Like the painting’s fifth cow,
who looks out directly,
straight toward you,
from inside her black and white spots.

An extra day—

Accidental, surely:
the made calendar stumbling over the real
as a drunk trips over a threshold
too low to see.

An extra day—

With a second cup of black coffee.
A friendly but businesslike phone call.
A mailed-back package.
Some extra work, but not too much—
just one day’s worth, exactly.

An extra day—

Not unlike the space
between a door and its frame
when one room is lit and another is not,
and one changes into the other
as a woman exchanges a scarf.

An extra day—

Extraordinarily like any other.
And still
there is some generosity to it,
like a letter re-readable after its writer has died.

LeetCode - Algorithms - 405. Convert a Number to Hexadecimal

Problem

405. Convert a Number to Hexadecimal

Java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Solution {
public String toHex(int num) {
char hex[]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
String hexdec_num="";
if (num==0)
return "0";
else if (num>0) {
int rem;
while(num>0)
{
rem = num%16;
hexdec_num = hex[rem] + hexdec_num;
num = num/16;
}
return hexdec_num;
}
else {
num = ~num;
String s = "";
for (int i = 0; i < 8; i++) {
int n = 15 - num % 16;
s += hex[n];
num /= 16;
}
char[] charArr = s.toCharArray();
for(int i=charArr.length-1;i>=0;i--)
hexdec_num+=charArr[i];
return hexdec_num;
}
}
}

Submission Detail

  • 100 / 100 test cases passed.
  • Runtime: 11 ms, faster than 8.70% of Java online submissions for Convert a Number to Hexadecimal.
  • Memory Usage: 37.7 MB, less than 8.33% of Java online submissions for Convert a Number to Hexadecimal.

ref

English Conversation for Beginners

texts below are from © English Conversation for Beginners: 45+ Phrases for the English Speaking Adventure of a Lifetime

Starting an English Conversation

If you need a push to start having conversations in English, watch the clip below for motivation.

Then, any polite conversation starts with a greeting (saying hello). There are many ways to greet someone, and your choice will depend on who you are talking to.

It may be an informal conversation with a friend or an acquaintance (someone you know, but not very well). Or you may use a more formal dialogue when having an English conversation with a colleague, a teacher, a stranger or a government employee.

Informal greetings

Let’s start with informal greetings. Here is how you can say hello:

  • Hello!
    (A universal greeting that works for every conversation.)
  • Hi!
    (A neutral and friendly greeting.)
  • Hey!
    (An informal and relaxed greeting.)
  • Greetings!
    (This is quite formal and rare these days, but could be used humorously among friends.)

Formal greetings

For a more formal way to greet someone, use the model “good + [time of day]”:

  • Good morning!
    (Reserved for any time before noon.)
  • Good afternoon!
    (Typically used between noon and 5-6 p.m.)
  • Good evening!
    (Any time after 6 p.m.)

Remember that “good night” normally means that you are saying goodbye. It is also commonly used right before going to bed.

Introductions

What if you have never met the person you are talking to before? Then, after greeting them, it would be polite to introduce yourself and ask for their name. Here’s how:

  • My name is _____. What’s your name?
    (This is simple, neutral and always works well!)

If you met somebody once before, but you do not remember their name, you can say this:

  • I’m sorry, I don’t remember your name. You are…?
    (This is a bit more informal.)

If you want to introduce a person to someone else, you can simply say:

  • Please meet + [name]
    Please meet my friend Tom!
    (Formal introduction)

  • This is + [name]
    This is Tom!
    (Common introduction)

Now that you have introduced yourself, use one of the phrases below to respond to someone’s introduction.

  • Nice to meet you!
    (The most common)

  • Pleased to meet you!
    (Simple and polite)

  • It’s a pleasure!
    (Informal, but nice)

Making Small Talk in English

names and greeted each other, you may go on to make some “small talk.”

Small talk is common in many English-speaking countries, especially in the U.S., Canada and England. It is considered polite to add small talk to the beginning of the conversation before talking about the subject of the conversation, whether it is personal or professional.

The most widespread (common) question is “How are you?” In fact, it is so common, that it becomes automatic for people to say, even when they hardly know the person! “How are you” is often even considered part of the greeting (i.e. “Hi, how are you?”). That is how necessary it has become!

There are several ways to ask someone how they are doing:

  • How are you? / How are you doing?
    (Neutral)
  • How’s it going?
    (More informal)
  • How are things?
    (Informal)
  • What’s up?
    (Very informal)

An interesting thing about asking these questions is that an answer is not really required. Unless you are very close friends with someone, they are not expecting you to tell them an honest answer about your day

Instead, a simple answer and a “how are you” in return is enough for a typical conversation in English:

  • I’m well. How are you?
  • It’s going well, thank you. How are you doing?
  • Fine, thanks. And yourself?

Note that you might often hear people say “I’m good” when they mean that they are well and doing well. “I’m good” is grammatically incorrect in this context, but it is very common in spoken English

Small talk can also be the primary goal of a conversation, especially when you are talking to people you don’t know and are unlikely to meet again. There are many ways to use small talk successfully, even when you’re still getting comfortable with English conversation for beginners.

Asking and Answering Questions

A conversation is an exchange of ideas, questions and thoughts. The best way to keep a conversation going is to ask questions!

There are two types of questions you may ask: closed-ended and open-ended questions.

Closed-ended questions are also called “yes/no” questions, because their goal is to confirm or deny certain information. For example:

  • Are you having a good day?
  • Did you just get to the office?
  • Have you seen my email?

Compare the examples above to the open-ended questions below. They will ask a person to elaborate—that is, to give more information instead of simply saying “yes” or “no.”

  • How is your day going?
    (A perfect example of small talk!)
  • When did you arrive at the office?
  • What do you think about that email I sent?

Open-ended questions typically begin with “who,” “what,” “where,” “when” and “why.” They are important to make your English conversation informative and productive.

When the person you are talking to is asking you a question, listen for the keywords and pay attention to the verb being used. This will help you construct your answer using proper grammar.

Don’t worry about using difficult words—it is fine to keep things simple! And if you don’t understand a certain question or word, don’t be afraid to ask.

As a beginner, you may have trouble understanding everything being said in English. This is okay! You are still learning.

Asking for Clarification

You are getting good at conversations in English, but suddenly you realize that you are lost. Maybe the other person is speaking too fast. Maybe she has an unfamiliar accent. Maybe you didn’t hear the last thing she said.

It is perfectly normal to ask for clarification or to repeat something. Just remember to be polite!

If you don’t understand something, let’s say a word or even some idea relating to your conversation, you could say:

  • I’m sorry, I don’t understand. Could you please repeat that?
  • I’m sorry, I don’t understand. Could you please explain that?

or even…

  • Care to elaborate?
    (This very informal question is the short version of “Do you care to elaborate on this?”)

If you simply didn’t hear something, just say it like this:

  • I’m sorry, I didn’t hear that. Could you please repeat?
  • I’m sorry, I didn’t catch that. Could you please repeat?

or even…

  • Could you say that again, please?

Don’t be shy to ask for help. People are generally very happy to explain or repeat something! Please don’t forget to thank them after they do.

Bringing an English Conversation to a Close

Say you have got all the information you need from the person. It is time for you to go. Maybe you are running late and want to keep the conversation brief. No matter the reason, it is always nice to let the person know you cannot continue talking to them for much longer.

There are many ways to do it depending on the situation. For example, if you are late, say:

  • I have to get going. / It’s time for me to go.
    (This is polite and neutral.)
  • I have to run—can we continue later?
    (This is more informal, but also polite.)

And if you have all the information you’d wanted:

  • Thank you so much for your help!
    (A very common and useful expression)
  • Got it, thanks!
    (Very informal and friendly)
  • I think I have everything I need, thank you!
    (This is formal and may come across as rude if you don’t thank the person after, so use it with caution.)

Using Small Talk to End a Conversation

Hey, guess what? Small talk can be used at the end of an English conversation too! Before saying goodbye, it is polite to say something like…

  • Have a good day!
    (This works in any situation.)
  • Enjoy your day!
    (This one is a bit more formal.)
  • Good luck!
    (If the person needs it; it will depend on the situation.)
  • Talk to you soon!
    (This is neutral and does not necessarily mean that you will really talk to the person soon.)
  • Great seeing you / Great talking to you!
    (This is informal yet common.)
  • Catch you later!
    (This is very informal and fun.)

And after that, the only thing left to do is…

Saying Goodbye in English

This one is easy. You really cannot go wrong with just a simple “goodbye” or “bye” in spoken English. You can also use any small talk expression to complement your goodbye. For example:

  • Bye! Have a good day!
  • Catch you later! Bye-bye!

And, as mentioned at the very beginning of this guide…

  • Good night!

Useful English Phrases

texts below are from © Basic English: 30+ Golden Phrases That Are Incredibly Useful

Phrases for Anywhere

Thanks so much.

This is a simple sentence you can use to thank someone.

  • Thanks so much for the birthday money.

  • Thanks so much for driving me home.

I really appreciate…

You can also use this phrase to thank someone.

  • I really appreciate your help.
  • Thanks so much for cooking dinner. I really appreciate it.
  • Thanks so much. I really appreciate you cooking dinner.

Excuse me.

When you need to get through but there’s someone blocking your way, say “Excuse me.”

You can also say this phrase to politely get someone’s attention. For example:

  • Excuse me sir, you dropped your wallet.
  • Excuse me, do you know what time it is?

I’m sorry.

Use this phrase to apologize, whether for something big or small. Use “for” to give more detail. For example:

  • I’m sorry for being so late.
  • I’m sorry for the mess. I wasn’t expecting anyone today.

You can use “really” to show you’re very sorry for something:

  • I’m really sorry I didn’t invite you to the party.

What do you think?

When you want to hear someone’s opinion on a topic, use this question.

  • I’m not sure if we should paint the room yellow or blue. What do you think?

How does that sound?

If you suggest an idea or plan, use this phrase to find out what others think.

  • We could have dinner at 6, and then go to a movie. How does that sound?
  • Let’s hire a band to play music, and Brent can photograph the event. How does that sound?

That sounds great.

If you like an idea, you can respond to How does that sound? with this phrase. “Great” can be replaced with any synonym, such as “awesome,” “perfect,” “excellent” or “fantastic.”

A: My mom is baking cookies this afternoon. We could go to my house and eat some. How does that sound?
B: That sounds fantastic!

(Oh) never mind.

Let’s say someone doesn’t understand an idea you’re trying to explain. If you’ve explained it over and over and want to stop, just say “oh, never mind.” You can now talk about something else!

You can also use “never mind” to mean “it doesn’t matter” or “just forget it.” In these situations, say it with a smile and positive tone, though. Otherwise, when you say this phrase slowly with a falling low tone, it can mean you’re bothered or upset.

A: Are you going to the grocery store today?
B: No, I’m not. But why—do you need something?
A: Oh, never mind. It’s okay, I’ll go tomorrow.

Phrases for Learning English

As an English learner, you’ll need to tell others that English is not your first language. You’ll also need to ask native speakers to repeat phrases and words or to speak slower. The following phrases will be useful for this.

I’m learning English.

This simple phrase tells people that English is not your native language. If you’re a total beginner, add “just started” after I: “I just started learning English.”

  • My name is Sophie and I’m learning English.

I don’t understand.

Use this phrase when you don’t understand what someone means.

  • Sorry, I don’t understand. The U.S. Electoral College seems very confusing!

Could you repeat that please?

If you’d like someone to say a word, question or phrase again, use this question. Since “to repeat” means “to say again,” you can also ask, “Could you say that again please?”

We can say “please” either at the end of the question or right after “you,” like this:

  • Could you please repeat that?
  • Could you repeat that please?

Could you please talk slower?

Native speakers can talk very fast. Fast English is hard to understand! This is an easy way to ask someone to speak more slowly.

Note: This phrase is not grammatically correct. However, it’s used often in everyday (casual) speech. The grammatically correct question would be, “Could you please talk more slowly?”

That’s because “slowly” is an adverb, so it describes verbs (like “talk”). “Slower” is a comparative adjective, which means it should be used to describe nouns (people, places or thing), not verbs. (For example: My car is slower than yours.)

A: You can give us a call any weekday from 8:00 a.m. to 5:00 p.m. at five five five, two five zero eight, extension three three—
B: I’m sorry, could you please talk slower?

Thank you. That helps a lot.

After someone starts speaking more slowly for you, thank them with this phrase.

You can use it in many other situations, too.

A: Ben, could you please make the font bigger? It’s hard for me to read the words.
B: Sure! I’ll change it from size 10 to 16. How’s this?
A: Thank you. That helps a lot

What does _____ mean?

When you hear or see a new word, use this phrase to ask what it means.

A: What does “font” mean?
B: It’s the style of letters, numbers and punctuation marks when you type. A common font in the USA is Times New Roman.

How do you spell that?

English spelling can be tricky, so make sure to learn this question. You could also ask someone, “Could you spell that for me?”

A: My name is Robbertah Handkerchief.
B: How do you spell that?

What do you mean?

When you understand the words one by one, but not what they mean together, use this question. You can ask it whenever you’re confused about what someone is telling you.

A: The Smiths do have a really nice house, but the grass is always greener on the other side.
B: What do you mean?
A: I mean that if we had the Smith’s house, we probably wouldn’t be happier. We always think other people have better lives than us, but other people have problems too.

Phrases for Introducing Yourself and Making Friends

Here are some phrases for introducing yourself when you meet new people, and questions to learn more about them.

Hi! I’m [Name]. (And you?)

Here’s an informal greeting you can use when you meet new friends. If the person doesn’t tell you their name, you can ask “And you?” or “And what’s your name?”

Hi! I’m Rebecca. And you?

Nice to meet you.

After you learn each other’s names, it’s polite to say this phrase.

A: Hi Rebecca, I’m Chad.
B: Nice to meet you, Chad.
A: Nice to meet you too.

Where are you from?

Ask this question to find out which country someone is from. You answer this question with “I’m from ~.”

Can you answer this question in English? Say both the question and answer aloud right now. (Four times, remember?)

A: Nice to meet you, Sergio. So, where are you from?
B: I’m from Spain.

What do you do?

Most adults ask each other this question when they meet. It means what do you do for a living (what is your job).

I think this question is boring, so I ask other questions. But many people will probably ask you this, so it’s important to know what it means.

A: What do you do, Cathleen?
B: I work at the university as a financial specialist.

What do you like to do (in your free time)?

Instead of asking for someone’s job title, I prefer to ask what they enjoy doing. The responses (answers) are usually much more interesting!

A: So Cathleen, what do you like to do in your free time?
B: I love to read and to garden. I picked two buckets of tomatoes last week!

What’s your phone number?

If you want to keep in contact with someone you just met, ask this question to find out their phone number. You can replace “phone number” with “email address” if you want to know their email address.

You might also hear people use the more casual “Can I get your ~?,” as in, “Can I get your phone number?”

It would be great to meet up again sometime. What’s your phone number?

Do you have Facebook?

Many people keep in touch (contact) through Facebook. Use this question to find out if someone has a Facebook account. You might also ask, “Are you on Facebook?”

Let’s keep in touch! Do you have Facebook?

Phrases for Work

Finally, here are seven basic phrases you might use at a job.

How can I help you?

If you work in customer service, you’ll use this phrase a lot. It’s also a common phrase when answering the phone.

[On the phone]: Hello, this is Rebecca speaking. How can I help you?

I’ll be with you in a moment.

When someone wants to see you, use this phrase if you need a minute to finish something first. If a client is waiting at a store, you can also use this phrase to show that their turn is next.

You can replace “moment” with “minute”: “I’ll be with you in (just) a minute.”

Another common phrase for this situation is “I’ll be right with you.”

Good morning! I’ll be with you in a moment.

What time is our meeting?

You can use this question’s structure to ask the time of any event: “What time is [event]?”

If you want to ask about a meeting on a certain day, add “on [day].” For example, “What time is our meeting on Thursday?”

What time is our meeting on Wednesday?

Please call me (back) at…

When you want someone to call you or to call you back (to return your call), use this phrase to give your phone number.

Hi, this is Cathleen from the financial office.
I’m wondering if you found those missing receipts.
Please call me back at 555-5555. Thanks!

(Oh really?) Actually, I thought…

When you disagree with someone, “Actually, I thought…” will make you sound kinder and more polite than saying “No” or “You’re wrong.” This phrase is useful when you have a different idea than someone else.

A: So Sam’s coming in tonight at 8, right?
B: Actually, I thought he wasn’t working at all this week.
A: Oh, ok. I’ll have to look at the schedule again.

Actually, I [verb]…

Just like in #28, you can use “actually, I…” with many different verbs: “heard,” “learned,” “am,” “can,” “can’t,” etc. You should use it for the same situation as above: when you have a different idea than someone else.

A: Did you finish the reports?
B: Actually, I am running a bit behind, but they’ll be done by noon!

C: When you type, always put two spaces between sentences.
D: Actually, I learned to put a single space between sentences.

I’m (just) about to [verb]…

When you’re going to start something very soon, you’re “just about to” do something.

I’m just about to send those faxes.

I’m about to go and pick up some coffee. Do you want anything?

LeetCode - Algorithms - 1037. Valid Boomerang

It’s easy indeed once you think about the slope of a line.

Zoomerang a Boomerang

by Ruth I. Dowell

Zoomerang a boomerang
Around a maple tree!
Zoomrang a boomerang
But don’t hit me!

from Poems to make your belly laugh

Problem

1037. Valid Boomerang

A boomerang is a set of 3 points that are all distinct and not in a straight line.

Java

cross product

1
2
3
4
5
class Solution {
public boolean isBoomerang(int[][] points) {
return (points[2][1]-points[0][1])*(points[1][0]-points[0][0]) == (points[1][1]-points[0][1])*(points[2][0]-points[0][0])?false:true;
}
}

Submission Detail

  • 190 / 190 test cases passed.
  • Runtime: 0 ms, faster than 100.00% of Java online submissions for Valid Boomerang.
  • Memory Usage: 37.2 MB, less than 100.00% of Java online submissions for Valid Boomerang.

Heron’s formula

1
2
3
4
5
6
7
8
9
10
class Solution {
public boolean isBoomerang(int[][] points) {
double a = Math.sqrt(Math.pow(points[1][0] - points[0][0], 2) + Math.pow(points[1][1] - points[0][1], 2));
double b = Math.sqrt(Math.pow(points[2][0] - points[1][0], 2) + Math.pow(points[2][1] - points[1][1], 2));
double c = Math.sqrt(Math.pow(points[2][0] - points[0][0], 2) + Math.pow(points[2][1] - points[0][1], 2));
double s = (a + b + c) / 2;
double A = Math.sqrt(s * (s - a) * (s - b) * (s - c));
return A != 0;
}
}

Submission Detail

  • 190 / 190 test cases passed.
  • Runtime: 0 ms, faster than 100.00% of Java online submissions for Valid Boomerang.
  • Memory Usage: 36.9 MB, less than 83.23% of Java online submissions for Valid Boomerang.

Gauss’s area formula

Shoelace formula

let \( \mathbf {A} \) be the area of the triangle whose vertices are given by the coordinates \( (x_{1},y_{1}) \), \( (x_{2},y_{2}) \), and \( (x_{3},y_{3}) \).

\( \mathbf {A} \) can be written as a determinant

\( {\displaystyle \mathbf
{A} ={\frac {1}{2}}
{
\begin{vmatrix}1&1&1 \\
x_{1}&x_{2}&x_{3} \\
y_{1}&y_{2}&y_{3}
\end{vmatrix}
}
}
\)

If the coordinates are written in a clockwise order, the value of the determinant will be \( {\displaystyle -\mathbf {A} } \)

Rearranging another way

\( {\displaystyle \mathbf {A} ={\frac {1}{2}}|x_{1}y_{2}+x_{2}y_{3}+x_{3}y_{1}-x_{2}y_{1}-x_{3}y_{2}-x_{1}y_{3}|} \)

which is the form of the shoelace formula. This formula can be extended to find the area of any polygon since a simple polygon can be divided into triangles.

1
2
3
4
5
6
7
class Solution {
public boolean isBoomerang(int[][] points) {
int A = points[0][0] * points[1][1] + points[1][0] * points[2][1] + points[2][0] * points[0][1]
- points[1][0] * points[0][1] - points[2][0] * points[1][1] - points[0][0] * points[2][1];
return A != 0;
}
}

Submission Detail

  • 190 / 190 test cases passed.
  • Runtime: 0 ms, faster than 100.00% of Java online submissions for Valid Boomerang.
  • Memory Usage: 37.7 MB, less than 15.65% of Java online submissions for Valid Boomerang.

LeetCode - Algorithms - 35. Search Insert Position

Problem

35. Search Insert Position

Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.

You may assume no duplicates in the array.

Java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution {
public int searchInsert(int[] nums, int target) {
int left=0, right=nums.length-1;
int mid=0;
while(left<=right) {
mid = (left+right)/2;
if (nums[mid]>target) {
right = mid-1;
}
else if (nums[mid]<target){
left = mid+1;
}
else
return mid;
}
if (target>nums[mid])
return mid+1;
else
return mid;
}
}

Submission Detail

  • 62 / 62 test cases passed.
  • Runtime: 0 ms, faster than 100.00% of Java online submissions for Search Insert Position.
  • Memory Usage: 38.9 MB, less than 100.00% of Java online submissions for Search Insert Position.

JPA and Hibernate

  • Hibernate, as an ORM solution, effectively “sits between” the Java application data access layer and the Relational Database.
  • As a JPA provider, Hibernate implements the Java Persistence API specifications.

JPA annotations

@Entity

The @Entity annotation is used to specify that the currently annotate class represents an entity type. Unlike basic and embeddable types, entity types have an identity and their state is managed by the underlying Persistence Context.

@Table

The @Table annotation is used to specify the primary table of the currently annotated entity.

@Column

The @Column annotation is used to specify the mapping between a basic entity attribute and the database table column.

@Id

The @Id annotation specifies the entity identifier. An entity must always have an identifier attribute which is used when loading the entity in a given Persistence Context.

@GeneratedValue

The @GeneratedValue annotation specifies that the entity identifier value is automatically generated using an identity column, a database sequence, or a table generator. Hibernate supports the @GeneratedValue mapping even for UUID identifiers.

@Temporal

The @Temporal annotation is used to specify the TemporalType of the currently annotated java.util.Date or java.util.Calendar entity attribute.

@Enumerated

The @Enumerated annotation is used to specify that an entity attribute represents an enumerated type.

@ManyToOne

The @ManyToOne annotation is used to specify a many-to-one database relationship.

@JoinColumn

The @JoinColumn annotation is used to specify the FOREIGN KEY column used when joining an entity association or an embeddable collection.

@OneToMany

If the @OneToMany doesn’t have a mirroring @ManyToOne association on the child side, the @OneToMany association is unidirectional. If there is a @ManyToOne association on the child side, the @OneToMany association is bidirectional and the application developer can navigate this relationship from both ends.

Every bidirectional association must have one owning side only (the child side), the other one being referred to as the inverse (or the mappedBy) side.

@OneToOne

The @OneToOne annotation is used to specify a one-to-one database relationship.

Hibernate annotations

@Where

The @Where annotation is used to specify a custom SQL WHERE clause used when fetching an entity or a collection.

ref

24. Mapping annotations
https://docs.jboss.org/hibernate/orm/5.3/userguide/html_single/Hibernate_User_Guide.html#annotations

All JPA Annotations: Mapping Annotations
Let’s take a look at ALL the JPA mapping annotations.
https://dzone.com/articles/all-jpa-annotations-mapping-annotations

javax.persistence
Annotation Type OneToMany
https://docs.oracle.com/javaee/7/api/javax/persistence/OneToMany.html

The best way to map a @OneToMany relationship with JPA and Hibernate
https://vladmihalcea.com/the-best-way-to-map-a-onetomany-association-with-jpa-and-hibernate/

LeetCode - Algorithms - 50. Pow(x, n)

Problem

50. Pow(x, n)

Java

Accepted

In mathematics and computer programming, exponentiating by squaring is a general method for fast computation of large positive integer powers of a number, or more generally of an element of a semigroup, like a polynomial or a square matrix.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Solution {
public double myPow(double x, int n) {
if (x==0.0d && n==0)
return Double.POSITIVE_INFINITY;
if (n>=0) {
return myPow_recur(x, n);
}
else {
double reciprocal = myPow_recur(x, -n);
return 1.0/reciprocal;
}
}

private double myPow_recur(double x, int n) {
if (n==0) return 1;
double square = myPow_recur(x,n/2);
if ( (n & 1) == 1 ) {
return x*square*square;
}
return square*square;
}
}

Submission Detail

  • 304 / 304 test cases passed.
  • Runtime: 0 ms, faster than 100.00% of Java online submissions for Pow(x, n).
  • Memory Usage: 36.6 MB, less than 5.88% of Java online submissions for Pow(x, n).

Time Limit Exceeded

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Solution {
public double myPow(double x, int n) {
if (x==0.0d && n==0)
return Double.POSITIVE_INFINITY;
double y = 1;
if (n==0)
y=1;
if (n>0) {
for(int i=n;i>0;i--)
y*=x;
}
if (n<0) {
double reciprocal = 1;
for(int i=-n;i>0;i--)
reciprocal*=x;
y = 1.0/reciprocal;
}
return y;
}
}

Submission Detail

  • 299 / 304 test cases passed.
  • Status: Time Limit Exceeded

ref

The Green Grass Under The Snow

By Annie A. Preston

The Work of the sun is slow,
But as sure as heaven, we know;
So we’ll not forget,
When the skies are wet,
There’s green grass under the snow.

When the winds of winter blow,
Wailing like voices of woe,
There are April showers,
And buds and flowers,
And green grass under the snow.

We find that it’s ever so
In this life’s uneven flow;
We’ve only to wait,
In the face of fate,
For the green grass under the snow.