![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 54
普通网友
这个作者很懒,什么都没留下…
展开
-
leetcode第六题6. ZigZag Conversion
The 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)P A H NA P L S I I原创 2016-09-09 00:47:57 · 185 阅读 · 0 评论 -
108. Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.Subscribe to see which companies asked this question本题题意是要求左右子树高度相等,其实就是二分查找代码,如下原创 2016-10-14 21:09:11 · 141 阅读 · 0 评论 -
60. Permutation Sequence
60. Permutation SequenceTotal Accepted: 65886 Total Submissions: 249649 Difficulty: Medium The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and原创 2016-10-04 20:08:11 · 202 阅读 · 0 评论 -
无向图判断是否有环
第一步:删除所有度的顶点及相关的边,并将另外与这些边相关的其它顶点的度减一。 第二步:将度数变为1的顶点排入队列,并从该队列中取出一个顶点重复步骤一。 如果最后还有未删除顶点,则存在环,否则没有环。第一步:删除所有度 第二步:将度数变为1的顶点排入队列,并从该队列中取出一个顶点重复步骤一。 如果最原创 2016-10-29 00:23:30 · 454 阅读 · 0 评论 -
6. ZigZag Conversion
第一次数组方式,时间112ms,public class Solution { public String convert(String s, int numRows) { String result=""; if(numRows==1){ return s; } if(s!=null && !("".endsWith(s))){ c原创 2016-11-11 21:42:45 · 173 阅读 · 0 评论 -
7. Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321 第一次public class Solution { public int reverse(int x) { int plusX = x>0?x:-x; c原创 2016-11-11 22:09:45 · 163 阅读 · 0 评论 -
18. 4Sum
Given an array S of n integers, are there elements a,b, c, and d in S such that a + b +c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: The solution s原创 2016-11-12 00:20:06 · 152 阅读 · 0 评论 -
29. Divide Two Integers
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.Subscribe to see which companies asked this question让除数大于被除数右移一位,进行操作:public c原创 2016-11-14 23:39:46 · 159 阅读 · 0 评论 -
后数组是否是二叉搜索树的后序
public class VerifySquenceOfBST { public static boolean isSquenceOfBST(int [] a,int startId,int rootId){ if(a==null||a.length<=0){ return false; } if(原创 2017-03-10 22:17:55 · 148 阅读 · 0 评论 -
leetcode涉及的思想
1.DFS2.到目前为止。。。。原创 2017-03-27 14:16:16 · 358 阅读 · 0 评论 -
50. Pow(x, n)
x^n n = 7 = 111 = 2^2 + 2^1 + 2^0,则 x^n = x^(2^2 + 2^1 + 2^0) = x^(2^2) * x^(2^1 ) * x^(2^0) public class Solution { public double myPow(double x, int n) { double res = 1.原创 2017-08-16 09:52:59 · 142 阅读 · 0 评论 -
全排列 算法
全排列是将一组数按一定顺序进行排列,如果这组数有n个,那么全排列数为n!个。现以{1, 2, 3, 4, 5}为例说明如何编写全排列的递归算法。1、首先看最后两个数4, 5。 它们的全排列为4 5和5 4, 即以4开头的5的全排列和以5开头的4的全排列。由于一个数的全排列就是其本身,从而得到以上结果。2、再看后三个数3, 4, 5。它们的全排列为3 4 5、3 5 4、 4 3 5原创 2017-08-16 14:20:54 · 163 阅读 · 0 评论 -
96. Unique Binary Search Trees
96. Unique Binary Search Trees Total Accepted: 98825Total Submissions: 252602Difficulty: MediumContributors: Admin Given n, how many structurally unique BST's (binary search tree原创 2016-10-13 13:18:03 · 150 阅读 · 0 评论 -
187. Repeated DNA Sequences
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.Write原创 2016-10-23 23:57:32 · 146 阅读 · 0 评论 -
7Reverse Integer
public int reverse(int x) { int plusX = x>0?x:-x; char[] char_x = (""+plusX).toCharArray(); int start=0, end=char_x.length-1; char flag; while(end > start){原创 2016-09-10 23:53:09 · 147 阅读 · 0 评论 -
8String to Integer (atoi)
public int myAtoi(String str) { String strResult=""; if(str == null || str.trim().equals("")){ return 0; } char[] no_space_char = str.trim().原创 2016-09-11 00:32:09 · 181 阅读 · 0 评论 -
二进制 十进制互转
十进制转二进制 -------》 Integer.toBinaryString二进制转十进制 --------》 int result = 0;for(char c : string.toCharArray()){result = result*2 + (c-'0');}原创 2016-09-13 23:48:39 · 326 阅读 · 0 评论 -
A100 正确使用递归和灵活使用if
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.Subscribe to原创 2016-09-14 22:55:00 · 187 阅读 · 0 评论 -
A101
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4 3B原创 2016-09-15 07:55:00 · 148 阅读 · 0 评论 -
121. Best Time to Buy and Sell Stock
Say you have an array for which the ith element is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),原创 2016-09-15 23:06:18 · 159 阅读 · 0 评论 -
18. 4Sum 加 神奇的发现加疑问。。。
Given an array S of n integers, are there elements a,b, c, and d in S such that a + b +c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: The solution s原创 2016-09-19 23:43:53 · 196 阅读 · 0 评论 -
172. Factorial Trailing Zeroes
n!就是1*2*3*4*.......*n,没出现一个5,0就增加一个,比如,103!=1*2*3*4*5*6*7*........*10*.........*103,所所以至少出现5,10,15,20.。。。。100,除以5又得,1,2,3,4,5,。。。。20这又是四个,依次往下,即可Given an integer n, return the number of trailing z原创 2016-10-22 22:24:46 · 134 阅读 · 0 评论 -
1. Two Sum
第一次代码:37mspublic class Solution { public int[] twoSum(int[] nums, int target) { for(int i = 0; i < nums.length; i++){ for(int j = i + 1; j < nums.length; j++){原创 2016-11-03 10:54:34 · 167 阅读 · 0 评论 -
2. Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link原创 2016-11-03 11:47:21 · 135 阅读 · 0 评论 -
179. Largest Number
Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is9534330.本题不能用全排列,否则超时,研究此题,便知此题是考原创 2016-10-23 21:41:26 · 185 阅读 · 0 评论 -
43. Multiply Strings
public class Solution { public String multiply(String num1, String num2) { int[] product = new int[num1.length() + num2.length()]; for(int i = num1.length() - 1; i >= 0; i--){原创 2017-08-16 09:15:22 · 138 阅读 · 0 评论