leetcode35专题

Leetcode35: Roman to Integer

Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 罗马数字规则: 1, 罗马数字共有7个,即I(1)、V(5)、X(10)、L(50)、C(100)、D(500)和M(1000)。 罗马数字中没有“0”。

代码随想录——搜索插入位置(Leetcode35)

题目链接 class Solution {public int searchInsert(int[] nums, int target) {int len = nums.length;int left = 0;int right = len - 1;int index = -1;while(left <= len / 2){if(nums[left] == target || target <

leetcode35-Search Insert Position

排序数组搜索某个元素,这种思维一定要往二分法上靠 public class searchInsertPosition{public static void main(String[] args) {int arr[] = {1,3,5,6};System.out.println(getIndex(arr,2));}public static int getIndex(int[] arr,int

[LeetCode35]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.

LeetCode35. Search Insert Position-python(easy) 二分法

题目来源:    https://leetcode.com/problems/search-insert-position/description/ 题目分析:    给定一个排好序的数组和一个target,如果target在数组里面,那么返回他的位置,否者返回他应该插入哪个位置。 本题我们可以考虑用二分法查找,如果没有找到,那么和first和last位置的数比较一下就可以得到答案。我们需