自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(82)
  • 资源 (1)
  • 收藏
  • 关注

原创 Tensorflow实现一个CNN分类的例子

使用mnist中的数据,利用CNN将图片进行分类。import tensorflow as tffrom tensorflow.examples.tutorials.mnist import input_datamnist=input_data.read_data_sets('MNIST_data',one_hot=True)def compulate_accuracy(v_xs,v_ys):

2017-08-04 08:48:50 5324

原创 Tensorflow构建一个简单的神经网络

假设输入层一个,隐藏层10个,输出层一个神经元import tensorflow as tfimport numpy as np#define add a neural layerdef add_layer(inputs, in_size, out_size, activition_function=None): # add one more layer and return the o

2017-07-31 20:52:49 448

原创 Keras实现一个简单的CNN的分类例子

import numpy as npnp.random.seed(1337)from keras.datasets import mnistfrom keras.utils import np_utilsfrom keras.models import Sequentialfrom keras.layers import Dense,Activation,Convolution2D,Max

2017-07-29 10:09:56 11788 3

原创 Keras实现一个简单的Regression回归

linux平台下运行,使用Keras框架,其中构建神经网络很简单,例子中指构造了一层神经网络 通过深度学习,将图中的点回归成线性模型,学习直线的W和b#import various of packagesimport numpy as npnp.random.seed(1337)from keras.models import Sequentialfrom keras.layers impo

2017-07-28 16:36:52 2073

原创 leetcode-125. Valid Palindrome(验证含有标点符号String是否为回文串)

https://leetcode.com/problems/valid-palindrome/#/description问题描述:指定含有标点符号空格的字符串,判断是否为回文串。思路解析: [^A-Za-z0-9]正则表达式,过滤掉非数字和大小写字母的字符。 用到了StringBuffer的reverse()与正则表达式过滤的串比较相同则是回文串。代码如下:public class Soluti

2017-06-18 23:00:38 428

原创 leetcode-49. Group Anagrams

https://leetcode.com/problems/group-anagrams/#/description问题描述:Given an array of strings, group anagrams together.For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return:[ ["ate", "ea

2017-06-13 22:55:22 233

原创 leetcode-67. Add Binary(二进制串求和)

https://leetcode.com/problems/add-binary/#/description问题描述:Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".代码如下:public class Solution {

2017-06-13 22:45:40 306

原创 leetcode-17. Letter Combinations of a Phone Number

https://leetcode.com/problems/letter-combinations-of-a-phone-number/#/description问题描述: Input:Digit string "23"Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].思路解析: 将每个按键代表的字符串映射到一个str

2017-06-10 20:15:37 181

原创 leetcode-13. Roman to Integer(罗马数字转化成整数)

https://leetcode.com/problems/roman-to-integer/#/description思路解析: 【罗马数字】1~9: {“I”, “II”, “III”, “IV”, “V”, “VI”, “VII”, “VIII”, “IX”};10~90: {“X”, “XX”, “XXX”, “XL”, “L”, “LX”, “LXX”, “LXXX”, “XC”};10

2017-06-09 22:35:54 192

原创 leetcode-12. Integer to Roman(整数转换成罗马数字)

https://leetcode.com/problems/integer-to-roman/#/description代码如下:public class Solution { public String intToRoman(int num) { String result=""; String[][] roman = { {"",

2017-06-09 22:33:09 248

原创 leetcode-43. Multiply Strings(大整数相乘)

https://leetcode.com/problems/multiply-strings/#/description思路解析: 思路如图片所示。它描述的是我们计算乘法的过程。仔细分析可以发现,对于原来在上面字符串中下标为1的“2”和在下面字符串中下标为0的“4”的相乘结果08出现在了最后的乘法结果字符串的下标1和2处。这一结果对其他下标的数字同样成立:下标i和下标j相乘的高位结果位于下标i+j

2017-06-08 21:04:06 381

原创 leetcode-6. ZigZag Conversion(Z型字符串)

https://leetcode.com/problems/zigzag-conversion/#/description思路解析: 输入:一个字符串和行数 首先将string转换为字符数组使用toCharArray() 所以每一行用一个StringBuilder对象来保存,因为可以更改其值。 主要确定好两个方向的位置,竖向和倾斜。只需要控制好sb的下标即可。注意: 在控制sb下标的同时也

2017-06-05 20:58:25 379

原创 leetcode-14. Longest Common Prefix(寻找字符串数组最长公共前缀)

https://leetcode.com/problems/longest-common-prefix/#/description思路解析: 因为是字符串数组,对其进行排序,所以只需要比较数组当中的第一个string和最后一个string,找他们两个的最长公共前缀即可,将string转化为字符数组用到了toCharArray方法,将最后的结果放到一个可修改的string当中,所以就用到了Strin

2017-06-04 22:50:20 456

原创 leetcode-5. Longest Palindromic Substring(寻找最长回文子串)

https://leetcode.com/problems/longest-palindromic-substring/#/description问题描述:Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example:

2017-06-04 22:25:57 248

原创 leetcode-3. Longest Substring Without Repeating Characters

https://leetcode.com/problems/longest-substring-without-repeating-characters/#/description代码如下:public class Solution { public int lengthOfLongestSubstring(String s) { Set<Character> set=new

2017-06-02 21:55:47 173

原创 leetcode-96. Unique Binary Search Trees

https://leetcode.com/problems/unique-binary-search-trees/#/description代码如下:思路解析:未完!!!!!!!!!!!!!!!!!!!!!public class Solution { public int numTrees(int n) { int[] d=new int[n+1]; d[0]=

2017-06-01 22:03:38 154

原创 leetcode-121. Best Time to Buy and Sell Stock

https://leetcode.com/problems/best-time-to-buy-and-sell-stock/#/description问题描述: Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to co

2017-05-30 22:53:58 167

原创 leetcode-70. Climbing Stairs(DP)

https://leetcode.com/problems/climbing-stairs/#/description问题描述:楼梯高为n,每次可以爬1或2个台阶问爬到最顶层有多少种方法。思路解析:简单的递归问题。代码如下:public class Solution { public int climbStairs(int n) { int[] num =new int[n];

2017-05-30 21:16:02 173

原创 leetcode-86. Partition List

https://leetcode.com/problems/partition-list/#/description 问题描述:按照指定的值x,将链表分开,将小于x的排序放在x的前面,大于等于x的节点按顺序放在x的后面。思路解析:重新创建两个链表,一个用来按顺序存放小于x的结点,另一个用来按顺序存放大于等于x的结点。最后将两个链表合并。代码如下:/** * Definition for sing

2017-05-28 23:18:28 206

原创 leetcode-24. Swap Nodes in Pairs

https://leetcode.com/problems/swap-nodes-in-pairs/#/description问题描述:将每两个相邻的结点交换 Given a linked list, swap every two adjacent nodes and return its head.For example, Given 1->2->3->4, you should return

2017-05-28 22:27:28 186

原创 leetcode-61. Rotate List

https://leetcode.com/problems/rotate-list/#/description问题描述: 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

2017-05-26 22:59:52 133

原创 leetcode-92. Reverse Linked List II(将单链表部分进行转置)

https://leetcode.com/problems/reverse-linked-list-ii/#/description问题描述: Reverse a linked list from position m to n. Do it in-place and in one-pass.For example: Given 1->2->3->4->5->NULL, m = 2 and n

2017-05-26 21:19:43 237

原创 leetcode-206. Reverse Linked List(单链表转置)

https://leetcode.com/problems/reverse-linked-list/#/description思路解析:头插法代码如下:/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(in

2017-05-25 21:44:50 218

原创 leetcode-82. Remove Duplicates from Sorted List II(删除有序列表中所有重复元素一个不留)

https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/#/description问题描述:重复的元素全都删除,一个不留。思路解析:设立两个指针,一个滑动指向重复元素最后一个。当两个元素相连则同时向后滑动,否则相连。代码如下:/** * Definition for singly-linked list. * pub

2017-05-24 22:27:59 156

原创 leetcode-83. Remove Duplicates from Sorted List(删除有序链表中的重复元素)

https://leetcode.com/problems/remove-duplicates-from-sorted-list/#/description问题描述: Given a sorted linked list, delete all duplicates such that each element appear only once.For example, Given 1->1->

2017-05-24 16:49:04 171

原创 leetcode-19. Remove Nth Node From End of List(删除链表倒数第N个节点)

https://leetcode.com/problems/remove-nth-node-from-end-of-list/#/description假设有一个结构体代表每个链表中的节点 struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {

2017-05-23 19:53:30 238

原创 leetcode-88. Merge Sorted Array

https://leetcode.com/problems/merge-sorted-array/#/description问题描述:将两个有序的数组,合并成一个有序数组,(将第二个合并到第一个里面)。代码如下:public class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) {

2017-05-23 17:00:52 164

原创 leetcode-63. Unique Paths II

https://leetcode.com/problems/unique-paths-ii/#/description问题描述: 参考http://blog.csdn.net/u013275928/article/details/72629236 在这道题的基础上加入了阻碍元素。思路解析: 这道题,没有用到额外的二维数组用来记录方法数,而是直接利用参数数组。当数组中有1的时候,将其置为0,其他

2017-05-22 21:06:02 177

原创 leetcode-62. Unique Paths

https://leetcode.com/problems/unique-paths/#/solutions问题描述:有一个m*n的矩阵,从左上角走到右下角,每次只能走一步,(要么向右走,要么向下走),问有多少中走法。思路解析:DP 建立一个数组g[][]用来存储走到每个位置的步数, 假如,从中间取一个位置,该位置一定是有他的左面和上面过来的,所以他的步数 g[i][j]=g[i-1][j]+g

2017-05-22 19:24:11 160

原创 leetcode-59. Spiral Matrix II(打印蛇形方阵)

https://leetcode.com/problems/spiral-matrix-ii/#/description问题描述: 还是蛇形方阵,但是只输入矩阵的行数或列数,打印含有n*n个元素的蛇形矩阵。思路解析: 参考之前的一道题:http://blog.csdn.net/u013275928/article/details/72627957代码如下:public class Solutio

2017-05-22 19:02:24 287

原创 leetcode-54. Spiral Matrix(打印蛇形矩阵)

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 sh

2017-05-22 17:04:09 712

原创 leetcode-48. Rotate Image

d

2017-05-21 09:52:36 366

原创 leetcode-40. Combination Sum II

https://leetcode.com/problems/combination-sum-ii/#/description 问题描述: 给定一个数组(有重复元素),和一个目标值,找出这个数组的子集,是这个自己的元素和为这个目标值。 数组中的元素只能使用一次。思路解析: 参考http://blog.csdn.net/u013275928/article/details/72588102 稍加

2017-05-20 21:45:14 148

原创 leetcode-39. Combination Sum

https://leetcode.com/problems/combination-sum/#/description问题描述: 给定一个数组(没有重复元素),和一个目标值,找出这个数组的子集,是这个自己的元素和为这个目标值。 数组中的元素可以重复使用。思路解析: 参考http://blog.csdn.net/u013275928/article/details/72230646 完全可以利

2017-05-20 21:31:38 169

原创 leetcode-47. Permutations II(重复元素全排列)

https://leetcode.com/problems/permutations-ii/#/description问题描述: 含有重复元素的全排列思路解析: 参考http://blog.csdn.net/u013275928/article/details/72510351 这次考虑了重复元素,新增了一个用来表示该元素是否已经加入到了tempList中的boolean数组,若为真则已经存在

2017-05-19 21:59:32 254

原创 leetcode-46. Permutations(非重复元素全排列)

https://leetcode.com/problems/permutations/#/description问题描述:全排列问题思路解析:思路同求子集问题 http://blog.csdn.net/u013275928/article/details/72230646 http://blog.csdn.net/u013275928/article/details/72290091 同样是用

2017-05-18 21:20:03 277

原创 leetcode-90. Subsets II(重复元素子集合)

https://leetcode.com/problems/subsets-ii/#/description问题描述: 寻找重复元素子集合,解集合中不可以有相同的子集。Given a collection of integers that might contain duplicates, nums, return all possible subsets.Note: The solution s

2017-05-16 15:38:32 193

原创 leetcode-78. Subsets(非重复元素子集合)

https://leetcode.com/problems/subsets/#/description问题描述:给定一个没有重复元素的数组求所有子集。Given a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.

2017-05-15 22:28:42 282

原创 leetcode-34. Search for a Range

https://leetcode.com/problems/search-for-a-range/#/description问题描述: 一个升序排列的数组,又重复值的那种,制定一个target,找到包含这个target的起始和终止位置,还是使用这般查找,分区间。代码如下:public class Solution { public int[] searchRange(int[] nums,

2017-05-14 10:47:03 177

原创 leetcode-53. Maximum Subarray

https://leetcode.com/problems/maximum-subarray/#/description 问题描述:给定一个序列,求最长子串使其和最大。思路解析:两种方法。一种就是常规,另一种DP,当指针i指向该元素值时,将该元素之前的和保存在数组中,然后判断,dp[i-1]是否小于0,若小于0,则将将其逻辑上重置0,加nums[i],如下: dp[i]=nums[i]+(dp

2017-05-14 09:36:08 202

杨辉三角形的代码

杨辉三角形的源代码,可以参考

2014-01-20

空空如也

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

TA关注的人

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