51CTO博客开发
Divide two integers without using multiplication, division and mod operator. The idea is to use bit operations. The key point is carefully handling corner cases.public int divide(int dividend, i
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal is to re
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example,Given [0,1,0,2,1,0,1,3,2,1,2,1], retur
Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note: You may only use constan
Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array return its inde
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its ne
Sort a linked list using insertion sort.把插入排序应用在linkedlist上面,做一点小小的变动,之前查找到需要改变位置的元素的时候从后往前一步一步挪,因为是singlelinkedlist,则需要从head开始比较,直到找到需要插入的位置。/** * Definition for singly-linked list. * public class
Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1]. DFS的题, 感觉有点像是八皇后问题的变形。 程序
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at any
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]You should return
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the bott
Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.1. 首先,需要先遍历一遍拿到
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [2,1,3,4,1,2,1,5,4],the contiguous subarray [4,1,2,1] has the large
Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space to hold additional elements from B. The number of elements initialized in A and
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.一个变形的对数组的二分搜索/** * Definition for binary tree * public class TreeNode { * int val; * TreeNo
Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.从头开始遍历,如果
二叉树非递归的中序遍历/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution
二叉树的非递归前序遍历 需要一个栈来作为辅助存储/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public cl
Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.Initially, all next pointers are set to NULL.Note:You may only use co
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's.public class Solution { public int num
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?CICT上有差不多的原题, 1. 初始化两个iterator都等于head, 设为a,b。2. 每次迭代,a走一步,b走两步。3. 如果a或者b走到null那就说明链表没有环,返回fa
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra mem
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position. Determine if you a
一个incredibly simple的分类器,基本原理是基于条件概率。要求:1. 特征值需要是可枚举的属性,例如布尔值,枚举值。对于连续的数值类型,在有的情况下可以根据特定逻辑划分范围,从而映射成为可枚举的属性。2. 特征之间需要“条件独立 (conditional distribution)”, 即:p(xi|y, xj ) = p(xi|y) (i != j)注意这里的条件独立的
JMM: Java Memory ModelThe program has a main memory space. And each thread has its own space.Shared values are copied from the common space to the threads’ own spaces.Two Issues in JMM: VisibilityOrde
题目要求:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", wh
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).最简单的思路是用归并排序的第二步:merge, 但是这个算法的复杂度是O(
Copyright © 2005-2024 51CTO.COM 版权所有 京ICP证060544号