剑指offer-二进制中1的个数-java

题目描述: 输入一个整数,输出该数二进制表示中1的个数。其中负数用补码表示。 思路解析:https://www.nowcoder.com/questionTerminal/8ee967e43c2c4ec193b040ea7fbb10b8 如果一个整数不为0,那么这个整数至少有一位是1。如果我...

2018-09-06 10:05:10

阅读数 48

评论数 0

剑指offer-用栈实现队列-java

题目描述: 用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。 思路解析: 入栈:栈1是用来入栈的,栈2是辅助;           如果栈2是空的,直接入栈到栈1中,如果栈2不为空,那么就先把栈2中的push回栈1中,再入栈。 出栈:栈2是用来出栈的,...

2018-09-05 14:34:08

阅读数 37

评论数 0

前序遍历-后序遍历(递归与非递归实现)——java

前序遍历:顺序为根左右 转载自:https://blog.csdn.net/xuebaobao130526/article/details/80082338 递归实现: 当节点不为空时,每次遍历现将节点值添加进list,之后,左子树补空,遍历左子树;右指数不空,遍历右子树;最终返回list。...

2018-08-24 17:26:19

阅读数 612

评论数 0

LeetCode—subsets(子集dfs)—java

题目描述:Given a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must...

2018-07-15 00:13:04

阅读数 349

评论数 0

LeetCode—sort-colors(颜色012排序)—java

题目描述:Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order...

2018-07-14 00:18:26

阅读数 203

评论数 0

LeetCode—search-a-2d-matrix(排好序的矩阵中查找)—java

题目描述:Write an efficient algorithm that searches for a value in anm x n matrix. This matrix has the following properties:Integers in each row are sort...

2018-07-13 23:48:44

阅读数 111

评论数 0

LeetCode—simplify-path(简化路径)—java

题目描述:Given an absolute path for a file (Unix-style), simplify it.For example,path ="/home/", =>"/home"...

2018-07-13 18:42:51

阅读数 310

评论数 0

LeetCode—plus-one&&sqrtx(加1&&开方)——java

题目描述:Given a number represented as an array of digits, plus one to the number.思路解析:计算加1后的数值高位在数组的开头,所以要从数组的最后开始检查每一位数字是不是小于9,如果是的话,直接加9就行了如果是小于9的就不用循...

2018-07-13 00:37:54

阅读数 68

评论数 0

LeetCode—valid-number(正则表达式匹配)——java

题目描述:Validate if a given string is numeric.Some examples:"0"=>true" 0.1 "=>true"ab...

2018-07-12 23:45:50

阅读数 318

评论数 0

LeetCode—merge-two-sorted-lists(合并链表)—java

题目描述:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.思路解...

2018-07-12 19:42:13

阅读数 57

评论数 0

LeetCode—unique-paths_iiunique-paths_minimum-path-sum_climbing-stairs_edit-distance(动态规划)——java

unique-paths题目描述: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 ...

2018-07-12 19:06:01

阅读数 50

评论数 0

LeetCode—permutation-sequence(全排列的第k个)—java

题目描述:The set[1,2,3,…,n]contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following seque...

2018-07-08 00:05:32

阅读数 292

评论数 0

LeetCode—spiral-matrix-ii(螺旋赋值)—java

题目描述:Given an integer n, generate a square matrix filled with elements from 1 to n 2 in spiral order.For example,Given n =3,You should return the fol...

2018-07-06 00:14:22

阅读数 61

评论数 0

LeetCode—length-of-last-word(最后一个单词的长度)—java

题目描述:Given a string s consists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.If the last ...

2018-07-05 23:52:52

阅读数 347

评论数 0

LeetCode—spiral-matrix(螺旋矩阵)—java

题目描述: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:[...

2018-07-05 00:28:11

阅读数 287

评论数 0

LeetCode—maximum-subarray(最大子数组的和)—java

题目描述: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,−...

2018-06-28 22:01:54

阅读数 174

评论数 0

LeetCode—n-queens-ii(返回解决方案的总数)—java

题目描述:Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.思路解析:跟第一个题一样的解决方法,但是需...

2018-06-28 19:19:04

阅读数 60

评论数 0

LeetCode—n-queens(n皇后问题)—java

题目描述:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return...

2018-06-28 18:05:28

阅读数 427

评论数 0

LeetCode—powx-n(x的n次)—java

题目描述:Implement pow(x, n).思路解析:pow(x,n)分解为pow(x,n/2)*pow(x,n/2) ,但是需要区分奇数偶数。还要看n的正负号。代码:public class Solution { public double pow(double x, int n)...

2018-06-24 14:22:25

阅读数 60

评论数 0

LeetCode—anagrams(返回由相同字母组成的单词)—java

题目描述:Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.思路解析:首先判空然后需要创建HashMap来存储排序好的字符...

2018-06-24 14:00:51

阅读数 245

评论数 0

提示
确定要删除当前文章?
取消 删除
关闭
关闭