自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(45)
  • 收藏
  • 关注

原创 华为机试(字符串最后一个单词长度,计算字符串的个数,明明的随机数) Java实现

题目来源:牛客网题目描述计算字符串最后一个单词的长度,单词以空格隔开。 输入描述:一行字符串,非空,长度小于5000。输出描述:整数N,最后一个单词的长度import java.util.*;/** * Created by a819 on 2017/8/30. */public class H_zuihouyigedanci {

2017-08-30 19:52:14 406

原创 《剑指offer2》问题16 数值的整数次乘方 Java实现

题目来源:剑指offer给定一个double类型的浮点数base和int类型的整数exponent。求base的exponent次方。思路:较简单,但是要考虑的边界情况较多public class Solution { public double Power(double base, int exponent) { double res=1.0;

2017-08-30 10:20:02 296

原创 《剑指offer2》问题14 剪绳子 Java实现

题目来源:剑指offer给你一根长度为n的绳子,请把绳子剪成m段 (m和n都是整数,n>1并且m>1)每段绳子的长度记为k[0],k[1],...,k[m].请问k[0]*k[1]*...*k[m]可能的最大乘积是多少?例如,当绳子的长度为8时,我们把它剪成长度分别为2,3,3的三段,此时得到的最大乘积是18.思路:动态规划,状态转移方程为f(n)=max(f(i)*f(n

2017-08-25 17:27:42 1032 3

原创 《剑指offer2》问题15 二进制中1的个数 Java实现

题目来源:剑指offer输入一个整数,输出该数二进制表示中1的个数。其中负数用补码表示。思路:统计中1的个数,将其分别右移,判断位置二进制数是不是1,但是如果是负数循环右移会造成死循环(负数向移动最高位不变)故将标志位左移就可以;public class Solution { public int NumberOf1(int n) { int fl

2017-08-25 17:08:54 173

转载 剑指offer2 问题12 矩阵中的路径 Java实现

题目来源:剑指offer请设计一个函数,用来判断在一个矩阵中是否存在一条包含某字符串所有字符的路径。路径可以从矩阵中的任意一个格子开始,每一步可以在矩阵中向左,向右,向上,向下移动一个格子。如果一条路径经过了矩阵中的某一个格子,则该路径不能再进入该格子。 例如 a b c e s f c s a d e e 矩阵中包含一条字符串"bcced"的路径,但是矩阵中不包含"abcb"路径,因为字符串

2017-08-24 20:18:02 182

原创 《剑指offer2》问题10 青蛙跳台阶&&变态跳台阶 Java实现

题目来源:剑指offer1.一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法。思路:斐波那契。动态规划public class Solution { public int JumpFloor(int target) { //dp if(target<=0) return 0;

2017-08-24 12:32:48 242

原创 《剑指offer2》问题9 用两个栈实现队列 Java实现

题目来源:剑指offer用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。思路:stack1负责插入,stack2负责弹出。当调用淡出时候,讲stack1中的所有元素弹出并压入到stack2,再出栈,这就保证了先进先出。import java.util.Stack;public class J_TwoSTACKQueue { Stack st

2017-08-24 09:57:19 157

原创 《剑指offer2》问题8 二叉树的下一个节点 Java实现

题目来源:剑指offer给定一个二叉树和其中一个节点,如何找出中序遍历序列的下一个节点?书中的节点除了有两个分别指向左右的指针,还有一个指向父节点的指针思路:见程序(剑指offer)/** * 1.如果该节点的右孩子不为空,则下一个节点位右孩子的最左子孙 * 2.如果该节点的有孩子为空,并且为父亲的左孩子,则中序遍历的下一个节点为父亲 * 3.如果该节点的右孩子节点为空,

2017-08-23 22:30:23 214

原创 《剑指offer》问题7 重建二叉树 Java实现

题目来源:剑指offer输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5,3,8,6},则重建二叉树并返回。思路:前序序列第一个字母一定是根节点,在中序遍历序列中找到根节点的位置(不存在重复),该节点将中序遍历分为左右子树,递归调用

2017-08-23 21:33:36 165

原创 《剑指offer》问题6 从尾到头打印链表 Java实现

题目来源:剑指offer输入一个链表,从尾到头打印链表每个节点的值。思路;见程序,Java实现简单import java.util.*;/** * 1遍历存入数组,返乡打印数组 * 2后进先出栈 * 3递归 */public class J_FanxiangLianBiao { public ArrayList printListFromTailToHead

2017-08-23 18:57:47 148

原创 《剑指offer》问题5 替换空格 Java实现

题目来源:剑指offer请实现一个函数,将一个字符串中的空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。思路;循环遍历每个字符,若遇到空格,就将其替换为%20 这道题Java可以有方法直接用public class Solution { public String replaceSpace(Stri

2017-08-23 16:30:08 231

原创 模拟题(今日头条)

题目来源:今日头条模拟题主要体会一下自己写输入输出敢接求数列的和(编程题须知)(参考答案)时间限制:C/C++语言 2000MS;其他语言 4000MS内存限制:C/C++语言 32768KB;其他语言 557056KB题目描述:数列的定义如下: 数列的第一项为n,以后各项为前一项的平方根,求数列的前m项的和。

2017-08-22 17:32:07 614

原创 Leetcode 91. Decode Ways&&639.Decode ways

题目来源:leetcodeDecode IWays IA message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digit

2017-08-21 15:16:57 201

转载 Leetcode 97. Interleaving String

题目来源:leetcodeGiven s1, s2, s3, find whether s3 is formed by the interleaving ofs1 and s2.For example,Given:s1 ="aabcc",s2 ="dbbca", When s3 ="aadbbcbcac", return true.When s3 ="aadbbba

2017-08-21 11:48:43 140

原创 Leetcode 78. Subsets & 90. Subsets II

题目来源:leetcodeGiven a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets. For example,If nums = [1,2,3], a solution is: 思路:h

2017-08-21 09:35:10 180

原创 Leetcode72. Edit Distance

题目来源:LeetcodeGiven two words word1 and word2, find the minimum number of steps required to convertword1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permit

2017-08-20 15:26:11 136

原创 Leetcode64. Minimum Path Sum

题目来源:LeetcodeGiven a m x n grid filled with non-negative numbers, find a path from top left to bottom right whichminimizes the sum of all numbers along its path.Note: You can only move either do

2017-08-20 11:06:52 137

原创 Leetcode 21. Merge Two Sorted Lists

题目来源:leetcodeMerge 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.思路:以两个链表的头结点进行比较,找出较小的一个,从他开始分别比较两个链表的

2017-08-20 09:47:48 137

原创 Leetcode 139. Word Break I&&II

题目来源:leetcodeWord Break I Word Break I Given a non-empty string s and a dictionary wordDict containing a list ofnon-empty words, determine if s can be segmented into a space-separated sequence

2017-08-19 15:50:48 198

原创 leetcode89. Gray Code

题目来源:leetcodeThe gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the

2017-08-19 11:48:09 197

原创 Leetcode 115 Distinct Subsequences

题目来源:leetcodeGiven a string S and a string T, count the number of distinct subsequences ofS which equals T.A subsequence of a string is a new string which is formed from the original string by d

2017-08-19 10:21:49 192

原创 leetcode120 triangle

题目来源:leetcodeGiven a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle [ [2],

2017-08-18 21:35:43 238

转载 LeetCode132 Palindrome Partitioning II&I

1 Palindrome Partitioning转自:http://blog.csdn.net/yutianzuijin/article/details/16850031问题来源:Palindrome Partitioning该问题简单来说就是给定一个字符串,将字符串分成多个部分,满足每一部分都是回文串,请输出所有可能的情况。       该问题的难度比较大,很可能第一次遇到没有思路,这很正

2017-08-18 20:29:34 225

原创 Leetcode135 candy

题目来源:leetcodeThere are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must

2017-08-18 17:40:12 216

原创 binary-tree-preorder-traversal

题目来源:leetcodeGiven a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3]. 思路:dfs递归(题目简单不要

2017-08-17 21:05:02 123

转载 single-number-ii

public int singleNumber(int[] A) {      int[] digits = new int[32];      for(int i=0;i<32;i++)      {          for(int j=0;j<A.length;j++)          {              digits[i] += (A[j]>>i)&1;     

2017-08-17 20:28:25 163

转载 Leetcode 22 Generate Parentheses

题目来源:leetcodeGiven n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is: "((()))", "(()())", "(())()", "()

2017-08-17 17:47:17 334

原创 leecode 73Set Matrix Zeroes

题目来源:leetcodeGiven a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. Follow up:Did you use extra space?A straight forward solution using O(mn) space is pr

2017-08-17 16:00:01 224

原创 spiral-matrix I&II

题目来源:LeeicodeGiven an integer n, generate a square matrix filled with elements from 1 ton 2 in spiral order.For example,Given n =3, You should return the following matrix:[ [ 1, 2, 3 ],

2017-08-17 14:43:52 235

原创 sort-colors&Remove Duplicates from Sorted Array

题目来源:Leetcode自己思路:因为只有三个颜色,分别由0,1,2代表,第一次统计三种颜色的数量,第二次按照数量放进去(感觉投机取巧)public class Solution { public void sortColors(int[] A) { int ones=0,twos=0,zero=0; for(int i=0;i<A.length;

2017-08-16 20:31:36 163

原创 search-insert-position

题目来源:leetcodeGiven 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 duplicate

2017-08-15 22:12:53 147

转载 WebService的相关概念

一、序言转自:http://www.cnblogs.com/xdp-gacl/p/4048937.html  大家或多或少都听过 WebService(Web服务),有一段时间很多计算机期刊、书籍和网站都大肆的提及和宣传WebService技术,其中不乏很多吹嘘和做广告的成 分。但是不得不承认的是WebService真的是一门新兴和有前途的技术,那么WebService到底是什么?何时应该用?

2017-08-13 16:37:47 250

转载 远程通信的几种选择(RPC,Webservice,RMI,JMS的区别)

RPC(Remote Procedure Call Protocol)RPC使用C/S方式,采用http协议,发送请求到服务器,等待服务器返回结果。这个请求包括一个参数集和一个文本集,通常形成“classname.methodname”形式。优点是跨语言跨平台,C端、S端有更大的独立性,缺点是不支持对象,无法在编译器检查错误,只能在运行期检查。 Web ServiceWeb Service提

2017-08-13 10:48:46 311

原创 AddBinary

题目来源:leetcode/** * Created by a819 on 2017/8/10. */public class AddBinary { public String addBinary(String a, String b) { a=new StringBuilder(a).reverse().toString(); b=new St

2017-08-12 21:29:29 243

原创 Zigzag Convert

题目来源:leetcodeThe string"PAYPALISHIRING"is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)/** * Zigzag

2017-08-10 16:37:55 176

原创 Count and Say

题目来源:leetcodeThe count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1is read off as"one 1"or11.11is read off as"two 1s"or21.21is read off as"

2017-08-10 14:28:20 156

原创 rotate-image

题目来源:leetcodeYou are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Follow up:Could you do this in-place? 思路:先将矩阵转置,然后调整列的顺序reversepublic class

2017-08-09 20:00:47 134

原创 unique-binary-search-trees I&II

1.Given n, how many structurally unique BST's (binary search trees) that store values 1...n?(1)递归时间复杂度高public class USearchTree { public int numTrees(int n) { int num=0; int su

2017-08-09 16:19:31 176

转载 populating-next-right-pointers-in-each-node II

I Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set toNULL.Initially, all next pointers are set toNULL. 简单递归/** * Crea

2017-08-08 21:49:29 234

原创 climbing-stairs &unique-paths

1.You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?2.A robot is located at th

2017-08-07 19:38:46 191

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

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