fuRan's Code 皆無は真実、万事が許す。
Posts with the tag 算法:

【算法技巧】求字符串组合(字母不重复)技巧

1
2
3
4
5
6
7
8
9
var list = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101]

function helper(a: string): number {
    let ret = 1
    for (let i = 0; i < a.length; i++) {
        ret *= list[a[i].charCodeAt(0) - 'a'.charCodeAt(0)]
    }
    return ret
}

利用质数映射字母,求出乘积。

【leetcode】57 Insert Intervals

57. 插入区间 题目 Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). 给出一个无重叠的 ,按照区间起始端点排序的区间列表。 You may assume that the intervals were initially sorted according to their start times. 在列表中插入一个

【leetcode】56 Merge Intervals

56. 合并区间 题目 Given a collection of intervals, merge all overlapping intervals. 给出一个区间的集合,请合并所有重叠的区间。 思路 说实话一脸懵逼,查了标签才知道先要排序,然后合并,合并逻辑很简

【leetcode】55 Jump Game

55. 跳跃游戏 题目 Given an array of non-negative integers, you are initially positioned at the irst index of the array. 给定一个非负整数数组,您最初位于该数组的第一个索引处。 Each element in the array represents your maximum jump length at that position. 数组中的每个

【leetcode】54 Spiral Matrix

54. 螺旋矩阵 题目 Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. 给个m * n 的矩阵,返回顺时针转一圈的数组。 思路 感觉有点像纯数学问题,每遍历n次,n -

【leetcode】53 Maximum Subarray

53. 最大子序和 题目 Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. 给个整数数组nums,返回最大子序和。 Follow up: If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach,

【leetcode】51 N Queens

51. N 皇后

题目

The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.
N后问题是: n 皇后在 n x n的棋盘上,且两两不能攻击。
Given an integer n, return all distinct solutions to the n-queens puzzle.
给一个整数, 返回所有解法。
Each solution contains a distinct board configuration of the n-queens' placement, where ‘Q’ and ‘.’ both indicate a queen and an empty space respectively.
解里Q代表皇后,.代表空位