LeetCode - Algorithms - 147. Insertion Sort List

Problem

147. Insertion Sort List

Java

enjoy algorithms

https://www.enjoyalgorithms.com/blog/sort-linked-list-using-insertion-sort

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
32
33
34
35
36
37
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode insertionSortList(ListNode head) {
ListNode node = head;
ListNode sortedHead = null;
while (node != null) {
ListNode nextNode = node.next;
sortedHead = sortedInsert(sortedHead, node);
node = nextNode;
}
return sortedHead;
}

private ListNode sortedInsert(ListNode sortedHead, ListNode node) {
if (sortedHead == null || sortedHead.val >= node.val) {
node.next = sortedHead;
return node;
} else {
ListNode temp = sortedHead;
while (temp.next != null && temp.next.val < node.val) {
temp = temp.next;
}
node.next = temp.next;
temp.next = node;
}
return sortedHead;
}
}

Submission Detail

  • Accepted
  • Runtime 18ms Beats 63.20% of users with Java
  • Memory 42.99mb Beats 90.09% of users with Java

The New Mathematics

by Peter Wolfe

Often people ask me what is new
in mathematics, in your view?
Have mathematicians become astuter?
Not really, they’ve just learned to use the computer.

We have all kinds of new hardware
to help us with the load we bear
so now when we want to solve an equation
we just head for the nearest workstation.

Whatever the mathematical task,
whatever question you care to ask,
we can give you the answer then and there
if only we have the right software.

We now have Suns, Apollos and VAX’s
(all paid for with your taxes)
and the software we receive
can do some things you wouldn’t believe.

Inverse a matrix? It’s a snap.
Iterate the Henon map.
Any large integer we can factor
or show the world a strange attractor.

In now takes hardly any time
for the number theorists to find a prime.
The topologists program for the purpose
of making pictures of some strange surface.

The numerical analysts are having a ball.
Computing’s their business, after all.
They are happy to use what they know
to show the rest of us the way to go.

There’s lesson here that’s quite instructive.
The finite element group is more productive.
They all do more than they ever did
using a computer generated grid.

Then there are dynamics boys
who are going wild with their new toys.
They use computer graphics to get
color pictures of a Julia set.

Their computations are so exact they’ll
reveal patterns which are clearly fractal.
They can now shock and dismay us
with even more exmaples of chaos.

So I would say there’s no dispute.
Mathematicians must learn to compute.
Computers have changed the rules of the game
and mathamatics will never be the same.


  • 一首数学诗:新数学(英文)
  • It looks to me as if trying to do this without making heavy use of computer-assisted proofs is like tying one or possibly two hands behind your back, – Charles Fefferman -> Computer Proof ‘Blows Up’ Centuries-Old Fluid Equations
  • A computer is used by a pure mathematician in much the same way that a telescope is used by a theoretical astronomer. … When computers first appeared in mathematicians’ environments the almost universal reaction was that they would never be useful for proving theorems since a computer can never investigate infinitely many cases, no matter how fast it is. But computers are useful for proving theorems despite that handicap. We have seen several examples of how a mathematician can act in concert with a computer to explore a world within mathematics. From such explorations there can grow understanding, and conjectures, and roads to proofs, and phenomena that would not have been imaginable in the pre-computer era. This role of computation within pure mathematics seems destined only to expand over the coming years and to be imbued into our students along with euclid’s axioms and other staples of mathematical education. (The Princeton Companion to Mathematics - VIII.5 Mathematics: An Experimental Science, by Herbert S. Wilf)
  • If Gauss were alive today, he would be a hacker. — Peter Sarnak

Weather Report

by Andrea Perry

What will the weather reporter predict?
I wonder what she will say.
Will Wednesday or Thursday be warmer — or wet?
Will winds blow us away?
Can we water ski this weekend?
Can we walk to watch the tide?
Or will we need our woolens
if we wish to play outside?

from Phonics Through Poetry: Grade Prek-1

My English Words List - August - 2023

slicker

slicker

noun

A child wearing a yellow raincoat with hood

Raincoat

sunburn

sunburn

noun

A sunburned neck

Use sunscreen to prevent sunburn.

Sunburn

paramedic

paramedic

noun

Paramedics of the Australian Capital Territory Ambulance Service during training

She’s training to be a paramedic.

Paramedic

scramble

scramble

verb

Scrambled eggs

Scrambled eggs

mash

mash

verb

A serving of mashed potatoes in a bowl with two whole potatoes

Mashed potato

cipher

cipher

noun

secret communications written in cipher

a cipher that can’t be decoded

Cipher

snoop

snoop

verb

She doesn’t want reporters snooping into her personal life.

noun

No, I didn’t read your e-mail. I’m no snoop.

snub

snub

verb

snub an old acquaintance

She snubbed me in the hallway.

He snubbed their job offer.

obituary

obituary

noun

Traditional street obituary notes in Bulgaria

I read her obituary in the newspaper.

evacuate

evacuate

verb

People who live along the coast are being evacuated as the hurricane approaches.

unravel

unravel

verb

unravel a mystery

Scientists are still unraveling the secrets of DNA.

impeccable

impeccable

adjective

She has impeccable taste in music.

spoke impeccable French

epiphany

epiphany

noun

Seeing her father again when she was an adult was an epiphany that changed her whole view of her childhood.

exude

exude

verb

The flowers exuded a sweet fragrance.

Pine trees exude a sticky substance.

penultimate

penultimate

adjective

the penultimate chapter of a book

the penultimate syllable of the word

pauper

pauper

noun

Rule 54: Breakfast like a king, lunch like a prince, dinner like a pauper. - Michael Pollan, Food Rules: An Eater’s Manual

The goal is not to make Putin a pauper. - Los Angeles Times, 3 Mar. 2022

paupers on welfare

landfill

landfill

noun

One of several landfills used by Dryden, Ontario, Canada

using landfill to dispose of trash

Landfill

delve

delve

verb

delved into her handbag in search of a pen

He tried to delve inside his memory for clues about what had happened.

the book delves into the latest research

busker

busker

noun

Billy Waters, a London busker from the 19th century

Street performance

critter

critter

noun

The woods are filled with skunks, raccoons, and other critters.

pulley

pulley

noun

Illustration of pulley

Pulley in oil derrick

Pulley

In Flanders Fields

by John McCrae

An autographed copy of the poem from In Flanders Fields and Other Poems. Unlike the printed copy in the same book, McCrae's handwritten version ends the first line with "grow".

In Flanders Fields, the poppies blow
Between the crosses, row on row,
That mark our place; and in the sky
The larks, still bravely singing, fly
Scarce heard amid the guns below.

We are the dead. Short days ago
We lived, felt dawn, saw sunset glow,
Loved and were loved, and now we lie,
In Flanders fields

Take up our quarrel with the foe:
To you from failing hands we throw
The torch; be yours to hold it high.
If ye break faith with us who die
We shall not sleep, though poppies grow
In Flanders fields.


My English Words List - July - 2023

sin

sin

noun

it’s a sin to waste food

verb

bless me, Father, for I have sinned

milkshake

milkshake

noun

A strawberry milkshake topped with a strawberry

a chocolate milkshake

Milkshake

philanthropist

philanthropist

noun

William Wilberforce, a prominent British philanthropist and anti-slavery campaigner

James Harris Simons is an American mathematician, billionaire hedge fund manager, and philanthropist.

Philanthropy

genuinely

genuinely

adverb

a genuinely funny movie

The audience was genuinely moved by the performance.

We are genuinely grateful to still have our jobs.

When a passing tanker rescued them five days later, both men were genuinely sorry that they had to leave. - Lesson 12 Life on a desert island, New Concept English Book 3

topographic

topographic

adjective

Curvimeter used to measure a distance on a topographic map

a topographic map

puncture

puncture

verb

a nail punctured the tire

bland

bland

adjective

a bland smile

bland diet

a bland oil

the bland climate of the southern coast

The vegetable soup was rather bland.

steward

steward

noun

teaching our children to be good stewards of the land

stewardship

stewardship

noun

stewardship of natural resources

she believes that stewardship of the environment is everyone’s responsibility

fiddlehead

fiddlehead

noun

Bucket of newly collected fiddleheads

Fiddlehead

goosefoot

goosefoot

noun

Chenopodium berlandieri

Chenopodium

firewood

firewood

noun

Stack of firewood next to a building

Firewood

court

court

noun

Costco food court

Citizen Of The World

by Joyce Kilmer

No longer of Him be it said
“He hath no place to lay His head.”

In every land a constant lamp
Flames by His small and mighty camp.

There is no strange and distant place
That is not gladdened by His face.

And every nation kneels to hail
The Splendour shining through Its veil.

Cloistered beside the shouting street,
Silent, He calls me to His feet.

Imprisoned for His love of me
He makes my spirit greatly free.

And through my lips that uttered sin
The King of Glory enters in.


Trees

by Joyce Kilmer

I think that I shall never see
A poem lovely as a tree.

A tree whose hungry mouth is prest
Against the earth’s sweet flowing breast;

A tree that looks at God all day,
And lifts her leafy arms to pray;

A tree that may in Summer wear
A nest of robins in her hair;

Upon whose bosom snow has lain;
Who intimately lives with rain.

Poems are made by fools like me,
But only God can make a tree.


My English Words List - Jun - 2023

pediatrician

pediatrician

noun

A pediatrician examines a neonate.

Pediatrics

pedestrian

pedestrian

noun

Pedestrian signal in Santa Ana, California.

The car slid off the road and almost hit a group of pedestrians.

Pedestrian

adjective

pedestrian traffic

gondola

gondola

noun

  • an enclosed car suspended from a cable and used for transporting passengers
    especially : one used as a ski lift

paradigm

paradigm

noun

the Freudian paradigm of psychoanalysis

lucid

lucid

adjective

lucid writing

concordance

concordance

noun

a concordance of Shakespeare’s plays

funnel

funnel

noun

the funnel cloud of a tornado

rinse

rinse

verb

He washed the dishes and then rinsed them thoroughly.

I rinsed my face in the sink.

soapsuds

soapsuds

plural noun

Repeat this step as necessary until all the soap suds are gone.

ignition

ignition

noun

There’s a problem with the car’s ignition.

clothespin

clothespin

noun

Plastic clothespins on a clothesline

Clothespin

flask

flask

noun

Vacuum flask

marsh

marsh

noun

Marshlands are often noted within wetlands, as seen here in the New Jersey Meadowlands at Lyndhurst, New Jersey, U.S.

Marsh

swamp

swamp

noun

A black alder swamp in Germany

Swamp

precipitation

precipitation

noun

A thunderstorm with heavy precipitation

The weather forecast calls for some sort of frozen precipitation tomorrow—either snow or sleet.

a 50 percent chance of precipitation

Precipitation

drizzle

drizzle

noun

Drizzle in Norfolk, England.

Yes, it’s raining, but it’s only a drizzle.

Drizzle

verb

It was beginning to drizzle, so she pulled on her hood.

sleet

sleet

noun

An accumulation of ice pellets

The snow turned to sleet and made driving very dangerous.

Ice pellets

Ice pellets (Commonwealth English) or sleet (American English) is a form of precipitation consisting of small, hard, translucent balls of ice.

draft

draft

noun

  • a current of air in a closed-in space

felt a draft

gale

gale

noun

After a Gale – Wreckers by James Hamilton

  • a strong current of air

The boat was damaged in a strong gale.

Gale

blast

blast

noun

  • a violent gust of wind

She opened the door and felt a cold blast.

a cold blast of air

drought

drought

noun

Droughts cause a range of impacts and are often worsened due to climate change. Clockwise from top left: a dry lakebed in California, which is in 2022 experiencing its most serious megadrought in 1,200 years; Sandstorm in Somaliland due to drought; drought and high temperatures worsened the 2020 bushfires in Australia.; Droughts negatively impact agriculture in Texas.

The drought caused serious damage to crops.

Drought

breezy

breezy

adjective

breezy beaches

a breezy day

gluten

gluten

noun

Examples of sources of gluten (clockwise from top): wheat as flour, spelt, barley, and rye as rolled flakes

Gluten

Gluten-free diet

dimple

dimple

noun

the dimples on a golf ball

She noticed his dimples when he smiled.

how a massive object, such as the sun, causes a local dimple-like curvature of spacetime. – Relativity, a very short introduction, by Russell Stannard

verb

a baby’s dimpled hands

archery

archery

noun

Archery at the Summer Olympics

Archery

Archery at the Summer Olympics

track-and-field

track-and-field

adjective

Part of a track and field stadium

  • of, relating to, or being any of various competitive athletic events (such as running, jumping, and weight throwing) performed on a running track and on the adjacent field

Track and field

shot put

shot put

noun

Shot put area

  • a field event in which a shot is heaved for distance

Shot put

prerequisite

prerequisite

noun

the course is a prerequisite for advanced study

blogosphere

blogosphere

noun

The blogosphere as a network of interconnections

Blogosphere

augment

augment

verb

She took a second job to augment her income.

The money augmented his fortune.

Heavy rains augmented the water supply.

compost

compost

verb

We compost leaves in our backyard.

noun

While mulches and compost are slow-release fertilizers, liquid feeds release nutrients for a much quicker uptake to give plants a boost.

determinate

determinate

adjective

determinate tomato plants

a determinate period of time

a determinate answer

nanny

nanny

noun

A child and her nanny

  • a child’s nurse or caregiver

When I was growing up, I had a nanny.

During this time, Mi Li says a confinement nanny, called a yuesao, comes to live with the family.

Nanny

reaffirm

reaffirm

verb

a story that reaffirmed her belief in the goodness of humanity

reaffirmed her debt in order to keep her car

reaffirming the defendant’s innocence

hackathon

hackathon

noun

Engineers can build their network and get inspired during dedicated meetups, hackathons, sessions and lightning talks.

Hackathon

stab

stab

noun

the injection left a small stab on her upper arm

verb

He stabbed her with a dagger.

Stabbings at University of Waterloo send 3 to hospital, 1 person in custody

My English Words List - May - 2023

ethic

ethic

noun

an old-fashioned work ethic

professional ethics

introvert

introvert

noun

Bill Gates is quiet and bookish, but apparently unfazed by others’ opinions of him: he’s an introvert, but not shy.

creep

creep

verb

A spider was creeping along the bathroom floor.

Age creeps up on us.

chore

chore

noun

The children were each assigned different household chores.

Doing taxes can be a real chore.

buggy

buggy

noun

A roller buggy, 2005

  • baby carriage

we’ll need a new buggy if we have another baby

Baby transport

judder

judder

verb

the engine stalled and kept juddering