编程题
ld851
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
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 · 212 阅读 · 0 评论 -
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 · 187 阅读 · 0 评论 -
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 · 205 阅读 · 0 评论 -
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 · 204 阅读 · 0 评论 -
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 · 240 阅读 · 0 评论 -
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 · 193 阅读 · 0 评论 -
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 · 266 阅读 · 0 评论 -
container-with-most-water
Given n non-negative integers a1, a2 , ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai ) and (i, 0原创 2017-08-07 11:27:01 · 287 阅读 · 0 评论 -
Roman to Integer/Integer to Roman
题目出处https://leetcode.com/problems/roman-to-integer/https://leetcode.com/problems/integer-to-roman/思路:对于整数转罗马数字:可以使用组合数字来进行拆分,使程序能够实现连加的方法。对于罗马数字转整数: 需要得用放在大数左边的数字只能使用一个的特点来判断对当前字母是加还是减。转载 2017-08-07 16:00:13 · 440 阅读 · 0 评论 -
剑指offer2 问题12 矩阵中的路径 Java实现
题目来源:剑指offer请设计一个函数,用来判断在一个矩阵中是否存在一条包含某字符串所有字符的路径。路径可以从矩阵中的任意一个格子开始,每一步可以在矩阵中向左,向右,向上,向下移动一个格子。如果一条路径经过了矩阵中的某一个格子,则该路径不能再进入该格子。 例如 a b c e s f c s a d e e 矩阵中包含一条字符串"bcced"的路径,但是矩阵中不包含"abcb"路径,因为字符串转载 2017-08-24 20:18:02 · 249 阅读 · 0 评论 -
《剑指offer2》问题15 二进制中1的个数 Java实现
题目来源:剑指offer输入一个整数,输出该数二进制表示中1的个数。其中负数用补码表示。思路:统计中1的个数,将其分别右移,判断位置二进制数是不是1,但是如果是负数循环右移会造成死循环(负数向移动最高位不变)故将标志位左移就可以;public class Solution { public int NumberOf1(int n) { int fl原创 2017-08-25 17:08:54 · 226 阅读 · 0 评论 -
《剑指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 · 1194 阅读 · 3 评论 -
模拟题(今日头条)
题目来源:今日头条模拟题主要体会一下自己写输入输出敢接求数列的和(编程题须知)(参考答案)时间限制:C/C++语言 2000MS;其他语言 4000MS内存限制:C/C++语言 32768KB;其他语言 557056KB题目描述:数列的定义如下: 数列的第一项为n,以后各项为前一项的平方根,求数列的前m项的和。原创 2017-08-22 17:32:07 · 701 阅读 · 0 评论 -
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 · 328 阅读 · 0 评论 -
《剑指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 · 304 阅读 · 0 评论 -
《剑指offer》问题6 从尾到头打印链表 Java实现
题目来源:剑指offer输入一个链表,从尾到头打印链表每个节点的值。思路;见程序,Java实现简单import java.util.*;/** * 1遍历存入数组,返乡打印数组 * 2后进先出栈 * 3递归 */public class J_FanxiangLianBiao { public ArrayList printListFromTailToHead原创 2017-08-23 18:57:47 · 202 阅读 · 0 评论 -
《剑指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 · 234 阅读 · 0 评论 -
《剑指offer2》问题8 二叉树的下一个节点 Java实现
题目来源:剑指offer给定一个二叉树和其中一个节点,如何找出中序遍历序列的下一个节点?书中的节点除了有两个分别指向左右的指针,还有一个指向父节点的指针思路:见程序(剑指offer)/** * 1.如果该节点的右孩子不为空,则下一个节点位右孩子的最左子孙 * 2.如果该节点的有孩子为空,并且为父亲的左孩子,则中序遍历的下一个节点为父亲 * 3.如果该节点的右孩子节点为空,原创 2017-08-23 22:30:23 · 283 阅读 · 0 评论 -
《剑指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 · 203 阅读 · 0 评论 -
《剑指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 · 314 阅读 · 0 评论 -
《剑指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 · 359 阅读 · 0 评论 -
华为机试(字符串最后一个单词长度,计算字符串的个数,明明的随机数) Java实现
题目来源:牛客网题目描述计算字符串最后一个单词的长度,单词以空格隔开。 输入描述:一行字符串,非空,长度小于5000。输出描述:整数N,最后一个单词的长度import java.util.*;/** * Created by a819 on 2017/8/30. */public class H_zuihouyigedanci {原创 2017-08-30 19:52:14 · 491 阅读 · 0 评论 -
华为机试(字符串间隔,进制转换,质数因子)Java
题目来源:牛客网1.字符串分隔题目描述•连续输入字符串,请按长度为8拆分每个字符串后输出到新的字符串数组; •长度不是8整数倍的字符串请在后面补数字0,空字符串不处理。 输入描述:连续输入字符串(输入2次,每个字符串长度小于100)输出描述:输出到长度为8的新字符串数组输入abc123456789输出abc0000012345678900原创 2017-09-19 09:58:52 · 649 阅读 · 0 评论 -
华为机试(取近似值,合并表,提取不重复整数,字符个数统计)Java实现
题目来源:牛客网1.取近似值题目描述写出一个程序,接受一个正浮点数值,输出该数值的近似整数值。如果小数点后数值大于等于5,向上取整;小于5,则向下取整。/** * Created by a819 on 2017/9/2. */import java.util.*;public class Main { public static void main(String[]原创 2017-09-19 10:46:40 · 522 阅读 · 0 评论 -
华为笔试题
题目描述将一段压缩后的字符串解压缩,并且排序输出。解压规则:每个字符串后边跟一个数字,表示这个字符串的重复数字 将每个字符串的字符重复次数升序排序,并输出结果。例如:a3b2,输出结果为bbaaa思路:将每个字符串和数字分别取出存到两个数组对这两个数组进行排序最后进行重复的拼接工作。程序:public class Dzip...原创 2018-09-05 22:14:00 · 609 阅读 · 0 评论 -
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 · 217 阅读 · 0 评论 -
面试编程题:单例模式singleton
今天笔试有一个的singleton的实现,由于光有个概念,没写对。。。看过之后实现较简单,自己动手做了下单例模式是一种常用的软件设计模式。在它的核心结构中只包含一个被称为单例的特殊类。通过单例模式可以保证系统中一个类只有一个实例。即一个类只有一个对象实例/*第一种生成singleton优点:简单,缺点:生成的资源浪费*/class singleton1{ private sing原创 2017-07-11 15:59:07 · 751 阅读 · 0 评论 -
ArrayList Java实现
public class arrayList implements Iterable{ private Object[]data=null; private int capacity; private int currentsize; arrayList(){ this(10); } arrayList(int initialsize){ if(initialsize>0)翻译 2017-07-03 18:47:18 · 231 阅读 · 0 评论 -
palindrome-number
Determine whether an integer is a palindrome. Do this without extra space.思路:将数字reverse,查看是否相同考虑空间复杂性,public class Solution { public boolean isPalindrome(int x) { int oldvalue=x;原创 2017-08-07 19:33:09 · 174 阅读 · 0 评论 -
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 · 271 阅读 · 0 评论 -
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 · 328 阅读 · 0 评论 -
best time to buy and sell stock
1.Say you have an array for which the i th element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the sto原创 2017-08-02 09:17:26 · 230 阅读 · 0 评论 -
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 · 241 阅读 · 0 评论 -
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 · 222 阅读 · 0 评论 -
LeetCode:maxi&mum depth of binary tree&balanced-binary-tree
class TreeNode{ public int val=1; TreeNode left; TreeNode right; TreeNode(int x){ this.val=x; }}public class Solution { //public int ldepth=1,rdepth=1; public int depth; public int maxDep原创 2017-07-31 21:43:06 · 272 阅读 · 0 评论 -
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 · 190 阅读 · 0 评论 -
reverse integer
LeetCode 题目:Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 click to show spoilers.Have you thought about this?Here are some good questions to as原创 2017-08-02 19:24:22 · 340 阅读 · 0 评论 -
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 · 297 阅读 · 0 评论 -
剑指Offer(第2版) 面试题3、面试题4,Java实现
面试题三:找出数组中重复的数字简单实现,没有考虑时间和空间复杂度,测试用例与书上的不一样import java.util.*;public class FindDuplicatedElements { private Set ls=new LinkedHashSet(); public void findDuplicated(int[] arr) throws Exception{原创 2017-06-19 20:56:01 · 354 阅读 · 0 评论 -
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 · 289 阅读 · 0 评论
分享