How to ReImplement strStr() in Java
What we want to achieve
Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
Example 1:
Input: …Read Article →
In-depth guides, insights, and best practices for modern software engineering
Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
Example 1:
Input: …Read Article →
Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The …
Read Article →Perhaps you have a screen-share session coming up and you want a nice clean desktop to show everyone. Also, nobody will …
Given a string, find the first non-repeating character in it and return its index. If it doesn’t exist, return -1.
Examples:
s = …Read Article →
What do you do when you create a new Maven Java project, and when you run it, you get the following error:
Error:java: error: release version 5 not …
I noticed an interesting thing with a certain visitor after posting a blog post to Facebook.
The IP address that the Facebook crawler uses to visit …
Read Article →Given a 32-bit signed integer, reverse digits of an integer.
Example 1:
Input: 123 Output: 321
Example 2:
Input: -123 Output: -321 …Read Article →
Write a function that reverses a string. The input string is given as an array of characters char[].
Do not allocate extra space for …
Read Article →Given an array of integers, find if the array contains any duplicates.
Your function should return true if any value appears at least …
Read Article →Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.
Find all the …
Read Article →Students are asked to stand in non-decreasing order of heights for an annual photo.
Return the minimum number of students that must move …
Read Article →Given an array of integers A sorted in non-decreasing order, return an array of the squares of each number, also in sorted …
Given an array A of non-negative integers, return an array consisting of all the even elements of A, followed by all the odd elements of …
Say you have an array of primitive integers and you want to remove all duplicates.
You can find out how many non-duplicate integers are in the array …
Read Article →Given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last …
Given an array A of integers, return true if and only if it is a valid mountain array.
Recall that A is a mountain array if …
Read Article →Java has a built-in called HashMap. It allows you to store and very quickly retrieve key value pairs.
In Python, this is called a …
Read Article →Given an array nums of integers, return how many of them contain an even number of digits.
Example 1:
Input: nums = [12,345,2,6,7896] …Read Article →
Relational databases first made an appearance in the mid-1970s, between the years 1974 and 1977 with the creation of Ingres and System R which led to …
Read Article →A HashSet is an unordered collection containing unique elements. It has the standard collection operations Add, Remove, Contains, …
In an N by N square grid, each cell is either empty (0) or blocked (1).
A clear path from top-left to bottom-right has length k if and …
Given a string s, partition s such that every substring of the partition is a palindrome.
Return all possible palindrome partitioning of s …
Read Article →From time to time you might have some rather big tables that you want to delete all the data quickly and start afresh.
You have a few options at this …
Read Article →Say you have an array prices for which the ith element is the price of a given stock on day i.
Design an algorithm to find the maximum …
Read Article →