![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 59
jizhi_de_wo
这个作者很懒,什么都没留下…
展开
-
Binary Tree Level Order Traversal
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { publi原创 2015-01-26 08:49:18 · 256 阅读 · 0 评论 -
Roman to Integer
public class Solution { public int romanToInt(String s) { int answer = 0; int i = 0; int len = s.length(); while(i < len) { int x=0;原创 2015-02-13 05:31:28 · 240 阅读 · 0 评论 -
Climbing Stairs
public class Solution { public int climbStairs(int n) { if(n == 0){ //n为零,零种走法 return 0; } if(n == 1){ //n为一,一种走法 return 1; }转载 2015-02-13 14:20:52 · 254 阅读 · 0 评论 -
Binary Tree Inorder Traversal
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { publi原创 2015-02-28 13:47:24 · 387 阅读 · 0 评论 -
Unique Binary Search Trees
public class Solution { public int numTrees(int n) { /* 解题关键:有n个结点的Tree的structure数量等于 左子树结点数等于0 ~ (n-1)时structure数量分别乘以右子树等于(n-1) ~ 0时structure数量之积的和 */ if(n转载 2015-02-15 08:30:41 · 232 阅读 · 0 评论 -
Binary Tree Preorder Traversal
//recursion vs iteration 递归与迭代//递归与迭代都是基于控制结构:迭代用重复结构,而递归用选择结构。//递归与迭代都涉及重复:迭代显式使用重复结构,而递归通过重复函数调用实现重复。//递归与迭代都涉及终止测试:迭代在循环条件失败时终止,递归在遇到基本情况时终止。//先序遍历是先访问根结点,再左子树,再右子树(即: 根>左>右)//解题思想,不断地把左结点放入l转载 2015-02-28 11:43:27 · 280 阅读 · 0 评论 -
Binary Tree Postorder Traversal
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { publi原创 2015-03-01 03:54:33 · 358 阅读 · 0 评论 -
Longest Substring Without Repeating Characters
import java.util.Hashtable;//漏写public class Solution { public int lengthOfLongestSubstring(String s) { Hashtable checkrepeatation = new Hashtable(); int i=1, j=0, currlength=1, lo原创 2015-03-03 00:57:14 · 255 阅读 · 0 评论 -
Anagrams
public class Solution { public List anagrams(String[] strs) { Map map = new HashMap(); Set set = new HashSet(); List result = new LinkedList(); if(strs.length == 0转载 2015-03-02 10:05:38 · 276 阅读 · 0 评论 -
Java String类知识总结并结合leetcode
字符串类型的转换/* You convert primitive types to a string with toString033 * String byteString = Byte.toString(bigByte);034 * String shortString = Short.toString(bigByte);035转载 2015-03-21 08:47:19 · 618 阅读 · 0 评论 -
Merge Two Sorted Lists
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public原创 2015-02-12 15:18:36 · 268 阅读 · 0 评论 -
leetocde banlanced binary tree
public class Solution { public boolean isBalanced(TreeNode root) { if(root == null) return true; if(isbalanced(root)==-1) return false; return true; } p原创 2015-01-24 06:15:13 · 305 阅读 · 0 评论 -
Binary Tree Level Order Traversal II
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ //import java.util.Arrays;import原创 2015-01-28 06:48:40 · 237 阅读 · 0 评论 -
ZigZag Conversion
public class Solution { public String convert(String s, int nRows) { int len = s.length();//len即为字符串长度 if(len<=nRows||nRows<=1) return s; //such condition can't form the zigzag rou转载 2015-02-04 23:46:43 · 302 阅读 · 0 评论 -
Valid Palindrome
//palindrome回文//我们只能考虑alphanumeric (字母与数字)。所以必须要找一个判别字母和数字的方法。int value=Integer.valueOf("1");//49//所以我的想法用数组,存下有效的ASCII,做做比较////还需注意ignoring cases.public class Solution { public boolean isPal原创 2015-02-06 01:06:24 · 266 阅读 · 0 评论 -
Valid Sudoku
import java.util.Hashtable;public class Solution { public boolean isValidSudoku(char[][] board) { int i, j, hit=0; for(i = 0; i <= 8 && hit == 0; i++) { Hashta原创 2015-02-23 13:53:34 · 392 阅读 · 0 评论 -
LeetCode Path Sum
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { publi原创 2015-02-11 09:44:28 · 258 阅读 · 0 评论 -
Single Number II
解题思路:用一个长度为32的数组a代表32个bit。用它记录下数组A中每一个元素在每一个bit上出现的次数(0次或1次)。然后对每个bit(即数组a的每个元素) 除3取余(出现三次的数,在每个bit上出现的次数叠加后,要么是3要么是0),每个bit余下来的值便是出现一次的数的每个bit上的值。最后根据每个bit的值,转成十进制的,便是出现一次的数。public class Solution {原创 2015-02-25 02:31:19 · 292 阅读 · 0 评论 -
Remove Nth Node From End of List
//一审题才发现,Try to do this in one pass. 是双指针的思想。但这样代码运行速度比平均速度要快/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { *原创 2015-02-11 10:23:14 · 273 阅读 · 0 评论 -
Single Number
用异或的方法,灰常简单public class Solution { public int singleNumber(int[] A) { int i = 0, j =0; for(; i < A.length; i++ ) j = j ^ A[i]; return j; }}下面这个是错误的代码,用hashtabl原创 2015-02-24 02:26:02 · 274 阅读 · 0 评论 -
Remove Duplicates from Sorted List
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public原创 2015-02-11 13:20:32 · 268 阅读 · 0 评论 -
Isomorphic Strings
public class Solution { public boolean isIsomorphic(String s, String t) { char[] map1 = new char[256], map2 = new char[256]; /*ASCII字符串共有256个,所以设为256*/ for (int i = 0; i <转载 2015-05-25 05:24:17 · 291 阅读 · 0 评论