mirror of
https://github.com/krahets/hello-algo.git
synced 2026-08-18 14:30:58 +00:00
Fix multilingual content typos (#1958)
This commit is contained in:
@@ -14,7 +14,7 @@ int binarySearchInsertion(int *nums, int numSize, int target) {
|
||||
if (nums[m] < target) {
|
||||
i = m + 1; // target is in the interval [m+1, j]
|
||||
} else {
|
||||
j = m - 1; // The first element less than target is in the interval [i, m-1]
|
||||
j = m - 1; // The rightmost element less than target is in the interval [i, m-1]
|
||||
}
|
||||
}
|
||||
// Return insertion point i
|
||||
@@ -64,4 +64,4 @@ int main() {
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ int binarySearchInsertion(int *nums, int numSize, int target) {
|
||||
} else if (nums[m] > target) {
|
||||
j = m - 1; // target is in the interval [i, m-1]
|
||||
} else {
|
||||
j = m - 1; // The first element less than target is in the interval [i, m-1]
|
||||
j = m - 1; // The rightmost element less than target is in the interval [i, m-1]
|
||||
}
|
||||
}
|
||||
// Return insertion point i
|
||||
|
||||
@@ -14,7 +14,7 @@ int binarySearchInsertion(const vector<int> &nums, int target) {
|
||||
if (nums[m] < target) {
|
||||
i = m + 1; // target is in the interval [m+1, j]
|
||||
} else {
|
||||
j = m - 1; // The first element less than target is in the interval [i, m-1]
|
||||
j = m - 1; // The rightmost element less than target is in the interval [i, m-1]
|
||||
}
|
||||
}
|
||||
// Return insertion point i
|
||||
|
||||
@@ -33,7 +33,7 @@ int binarySearchInsertion(vector<int> &nums, int target) {
|
||||
} else if (nums[m] > target) {
|
||||
j = m - 1; // target is in the interval [i, m-1]
|
||||
} else {
|
||||
j = m - 1; // The first element less than target is in the interval [i, m-1]
|
||||
j = m - 1; // The rightmost element less than target is in the interval [i, m-1]
|
||||
}
|
||||
}
|
||||
// Return insertion point i
|
||||
|
||||
@@ -34,7 +34,7 @@ public class binary_search_insertion {
|
||||
} else if (nums[m] > target) {
|
||||
j = m - 1; // target is in the interval [i, m-1]
|
||||
} else {
|
||||
j = m - 1; // The first element less than target is in the interval [i, m-1]
|
||||
j = m - 1; // The rightmost element less than target is in the interval [i, m-1]
|
||||
}
|
||||
}
|
||||
// Return insertion point i
|
||||
|
||||
@@ -31,7 +31,7 @@ int binarySearchInsertion(List<int> nums, int target) {
|
||||
} else if (nums[m] > target) {
|
||||
j = m - 1; // target is in the interval [i, m-1]
|
||||
} else {
|
||||
j = m - 1; // The first element less than target is in the interval [i, m-1]
|
||||
j = m - 1; // The rightmost element less than target is in the interval [i, m-1]
|
||||
}
|
||||
}
|
||||
// Return insertion point i
|
||||
|
||||
@@ -40,7 +40,7 @@ func binarySearchInsertion(nums []int, target int) int {
|
||||
// target is in the interval [i, m-1]
|
||||
j = m - 1
|
||||
} else {
|
||||
// The first element less than target is in the interval [i, m-1]
|
||||
// The rightmost element less than target is in the interval [i, m-1]
|
||||
j = m - 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class binary_search_insertion {
|
||||
} else if (nums[m] > target) {
|
||||
j = m - 1; // target is in the interval [i, m-1]
|
||||
} else {
|
||||
j = m - 1; // The first element less than target is in the interval [i, m-1]
|
||||
j = m - 1; // The rightmost element less than target is in the interval [i, m-1]
|
||||
}
|
||||
}
|
||||
// Return insertion point i
|
||||
|
||||
@@ -33,7 +33,7 @@ function binarySearchInsertion(nums, target) {
|
||||
} else if (nums[m] > target) {
|
||||
j = m - 1; // target is in the interval [i, m-1]
|
||||
} else {
|
||||
j = m - 1; // The first element less than target is in the interval [i, m-1]
|
||||
j = m - 1; // The rightmost element less than target is in the interval [i, m-1]
|
||||
}
|
||||
}
|
||||
// Return insertion point i
|
||||
@@ -47,7 +47,7 @@ console.log('\nArray nums = ' + nums);
|
||||
// Binary search for insertion point
|
||||
for (const target of [6, 9]) {
|
||||
const index = binarySearchInsertionSimple(nums, target);
|
||||
console.log('Element ' + target + ''s insertion point index is ' + index);
|
||||
console.log('Element ' + target + "'s insertion point index is " + index);
|
||||
}
|
||||
|
||||
// Array with duplicate elements
|
||||
@@ -56,7 +56,7 @@ console.log('\nArray nums = ' + nums);
|
||||
// Binary search for insertion point
|
||||
for (const target of [2, 6, 20]) {
|
||||
const index = binarySearchInsertion(nums, target);
|
||||
console.log('Element ' + target + ''s insertion point index is ' + index);
|
||||
console.log('Element ' + target + "'s insertion point index is " + index);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -35,7 +35,7 @@ fun binarySearchInsertion(nums: IntArray, target: Int): Int {
|
||||
} else if (nums[m] > target) {
|
||||
j = m - 1 // target is in the interval [i, m-1]
|
||||
} else {
|
||||
j = m - 1 // The first element less than target is in the interval [i, m-1]
|
||||
j = m - 1 // The rightmost element less than target is in the interval [i, m-1]
|
||||
}
|
||||
}
|
||||
// Return insertion point i
|
||||
@@ -62,4 +62,4 @@ fun main() {
|
||||
val index = binarySearchInsertion(nums, target)
|
||||
println("Insertion point index for element $target is $index")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ def binary_search_insertion(nums: list[int], target: int) -> int:
|
||||
elif nums[m] > target:
|
||||
j = m - 1 # target is in the interval [i, m-1]
|
||||
else:
|
||||
j = m - 1 # The first element less than target is in the interval [i, m-1]
|
||||
j = m - 1 # The rightmost element less than target is in the interval [i, m-1]
|
||||
# Return insertion point i
|
||||
return i
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ Created Time: 2024-05-22
|
||||
Author: Xuan Khoa Tu Nguyen (ngxktuzkai2000@gmail.com)
|
||||
=end
|
||||
|
||||
require 'set'
|
||||
|
||||
### Backtracking: permutations II ###
|
||||
def backtrack(state, choices, selected, res)
|
||||
# When the state length equals the number of elements, record the solution
|
||||
|
||||
@@ -39,7 +39,7 @@ def binary_search_insertion(nums, target)
|
||||
elsif nums[m] > target
|
||||
j = m - 1 # target is in the interval [i, m-1]
|
||||
else
|
||||
j = m - 1 # The first element less than target is in the interval [i, m-1]
|
||||
j = m - 1 # The rightmost element less than target is in the interval [i, m-1]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ pub fn binary_search_insertion(nums: &[i32], target: i32) -> i32 {
|
||||
} else if nums[m as usize] > target {
|
||||
j = m - 1; // target is in the interval [i, m-1]
|
||||
} else {
|
||||
j = m - 1; // The first element less than target is in the interval [i, m-1]
|
||||
j = m - 1; // The rightmost element less than target is in the interval [i, m-1]
|
||||
}
|
||||
}
|
||||
// Return insertion point i
|
||||
|
||||
@@ -35,7 +35,7 @@ public func binarySearchInsertion(nums: [Int], target: Int) -> Int {
|
||||
} else if nums[m] > target {
|
||||
j = m - 1 // target is in the interval [i, m-1]
|
||||
} else {
|
||||
j = m - 1 // The first element less than target is in the interval [i, m-1]
|
||||
j = m - 1 // The rightmost element less than target is in the interval [i, m-1]
|
||||
}
|
||||
}
|
||||
// Return insertion point i
|
||||
|
||||
@@ -35,7 +35,7 @@ public func binarySearchInsertion(nums: [Int], target: Int) -> Int {
|
||||
} else if nums[m] > target {
|
||||
j = m - 1 // target is in the interval [i, m-1]
|
||||
} else {
|
||||
j = m - 1 // The first element less than target is in the interval [i, m-1]
|
||||
j = m - 1 // The rightmost element less than target is in the interval [i, m-1]
|
||||
}
|
||||
}
|
||||
// Return insertion point i
|
||||
|
||||
@@ -26,8 +26,8 @@ enum Queue {
|
||||
|
||||
/* Element dequeue */
|
||||
// When simulating with Array, pop complexity is O(n)
|
||||
let pool = queue.removeFirst()
|
||||
print("Dequeue element pop = \(pool), after dequeue queue = \(queue)")
|
||||
let pop = queue.removeFirst()
|
||||
print("Dequeue element pop = \(pop), after dequeue queue = \(queue)")
|
||||
|
||||
/* Get the length of the queue */
|
||||
let size = queue.count
|
||||
|
||||
@@ -36,7 +36,7 @@ function binarySearchInsertion(nums: Array<number>, target: number): number {
|
||||
} else if (nums[m] > target) {
|
||||
j = m - 1; // target is in the interval [i, m-1]
|
||||
} else {
|
||||
j = m - 1; // The first element less than target is in the interval [i, m-1]
|
||||
j = m - 1; // The rightmost element less than target is in the interval [i, m-1]
|
||||
}
|
||||
}
|
||||
// Return insertion point i
|
||||
@@ -50,7 +50,7 @@ console.log('\nArray nums = ' + nums);
|
||||
// Binary search for insertion point
|
||||
for (const target of [6, 9]) {
|
||||
const index = binarySearchInsertionSimple(nums, target);
|
||||
console.log('Element ' + target + ''s insertion point index is ' + index);
|
||||
console.log('Element ' + target + "'s insertion point index is " + index);
|
||||
}
|
||||
|
||||
// Array with duplicate elements
|
||||
@@ -59,7 +59,7 @@ console.log('\nArray nums = ' + nums);
|
||||
// Binary search for insertion point
|
||||
for (const target of [2, 6, 20]) {
|
||||
const index = binarySearchInsertion(nums, target);
|
||||
console.log('Element ' + target + ''s insertion point index is ' + index);
|
||||
console.log('Element ' + target + "'s insertion point index is " + index);
|
||||
}
|
||||
|
||||
export { binarySearchInsertion };
|
||||
|
||||
Reference in New Issue
Block a user