题目:Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) ->
题目:Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after ca
题目:You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed bas
题目:Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.思路:本题其实比较有趣,方法有很多,
题目:Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2
题目:You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone wi
题目:Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word
题目:Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].Note:Each element in the result must be unique.Th
题目:Write a function that takes a string as input and reverse only the vowels of a string.Example 1:Given s = "hello", return "holle".Example 2:Given s = "leetcode", return "leotcede"
题目:iven an integer (signed 32 bits), write a function to check whether it is a power of 4.Example:Given num = 16, return true. Given num = 5, return false.Follow up: Could you solve it
题目:Given an integer, write a function to determine if it is a power of three.思路:本题和前面的博客power of two的解题思路一样代码:class Solution {public: bool isPowerOfThree(int n) { if(n==1)
本节内容组合相似的分类器来提高分类性能应用AdaBoost算法处理非均衡分类问题元算法(meta-algorithm)是对其他算法进行组合的一种方式。其中AdaBoost是最流行的元算法之一。本节首先讨论不同分类器的集成方法,主要关注boosting方法及其代表分类器Adaboost。接着建立一个单层决策树分类器,并将AdaBoost算法应用在上述单层决策树分类器上。本文将在一个难
题目:Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as
题目:Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.思路:1. 本题在没时间与空间复杂度的情况下,思路很简单,即先求阶乘再求尾随0个数代码:class Solut
题目:Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".思路:本题使用C++ 标准库函数 reverse即可,详情请戳:点击打开链接代码:class Solution {
题目:Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Note:Try to come up as many soluti
题目:Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced
题目:Reverse a singly linked list.思路:递归的方法代码:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL)
题目:Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every ele
题目:Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5思路:本题比较简单,主要考
题目:Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of th
题目:Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front eleme
题目:Given an integer, write a function to determine if it is a power of two.思路:本题思路很简单就是递归的调用代码:class Solution {public: bool isPowerOfTwo(int n) { if(n==1) return
题目:Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Re
题目:Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j i
题目:Given a singly linked list, determine if it is a palindrome.思路:遍历一次链表维护一个数组并存储对应value,再从头遍历链表的同时从尾部遍历数组,并进行比较代码:/** * Definition for singly-linked list. * struct ListNode { * int
题目:Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1思路:1.层次遍历法,每层遍历就替换左右结点;2.递归法代码(层次遍历法):class Solution {p
一、目前存在的问题在getSameWords()方法中,我们使用map临时存放了两个键值对用来测试,实际开发中,往往需要很多的这种键值对来处理,比如从某个同义词词典里面获取值之类的,所以说,我们需要一个类,根据key提供近义词。为了能更好的适应应用场景,我们先定义一个接口,其中定义一个getSameWords()方法,在定义一个实现类,实现getSameWords()方法,当我们需要更换字...
一、同义词分词器的代码实现package com.wsy;import com.chenlb.mmseg4j.Dictionary;import com.chenlb.mmseg4j.MaxWordSeg;import com.chenlb.mmseg4j.analysis.MMSegTokenizer;import org.apache.lucene.analysis.Analy...
索引重构:将所有数据从数据库里取出来,创建相应的IndexField完成索引重构。这里就是将Message对象转换成IndexField对象。项目代码请见百度云盘:链接: https://pan.baidu.com/s/1TTKDv3TJkTiUZHF0yXmeug 提取码: ys36。...