CSDN博客地址---http://blog.csdn.net/bug_moving GitHub地址---https://github.com/androidwolf
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adj
Write a function that takes an unsigned integer and returns the number of ’1’ bits it has (also known as the Hamming weight). For example, the 32-bit integer ’11’ has binary representation
补充知识,Java的位运算(bitwise operators) Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 96
表格 Markdown使用管线图的方式实现表格,表格里面可以使用强调、链接等行内格式。 下面代码所示为一个基本的表格: 教程标题| 主要内容 -------|---------- 关于Markdown | 简介Markdown,Markdown的优缺点 Markdown基础 | Markdown的**基本语法**,格式化文本、代码、列表、链接和图片、分割线、转义符等
Java的位运算(bitwise operators)直接对整数类型的位进行操作,这些整数类型包括long、int、short、char和 byte,位运算符具体如下表: 运算符 说明 << 左移位,在低位处补0 >> 右移位,若为正数则高位补0,若为负数则高位补1 >>> 无符号右移位,无论正负都
Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4]. Note: Try to come up as many solutions
Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. Credits: Special thanks to @ts for adding this problem and c
Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, return its corresponding column number. For example: A -> 1 B -> 2 C -> 3 ... Z -&
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the majority e
Given a positive integer, return its corresponding column title as appear in an Excel sheet. For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB Credits:
[LeetCode]–165. Compare Version Numbers这个问题中,关于String的split(“.”)不能切分的问题。 今天开发中使用字符串分割函数split(),发现: String s = "upload/20120416135915265.sql"; System.out.println(s.split(".")); 输出
Compare two version numbers version1 and version2. If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0. You may assume that the version strings are
Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists: A: a1 → a2 ↘
单链表逆转置的递归与非递归方式 Node类 public class ListNode { int val; ListNode next; ListNode(int x) { val = x; } } 先看递归求解: public ListNode reverse1(ListNode head) {
[LeetCode]–155. Min Stack 在这个问题中,我遇到了==和equals的问题,虽然试一下就能得出结果,但是我想弄明白。 java中的数据类型,可分为两类: 1.基本数据类型,也称原始数据类型。byte,short,char,int,long,float,double,boolean 他们之间的比较,应用双等号(==),比较的是他们的值。
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) – Push element x onto stack. pop() – Removes the element on top of the stack. to
Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? 最常见的想法是遍历linked list,同时用个set进行记录遍历过的节点,如果遍历linked list时发现当前节点已经在set中出现过了。那就
Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without
[LeetCode]–125. Valid Palindrome 在这个题里面遇到一个没见过判断字符串是否为字母啊数字的方法。这里解释一下。 使用isDigit判断是否为数字 public static boolean isNumeric(String str){ for (int i = str.length();--i>=0;){ if
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, “A man, a plan, a canal: Panama” is a palindrome. “race a car”
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 complete at most one transaction (ie, buy one and sell one share of th
[LeetCode]–119. Pascal’s Triangle II 在做这个题的时候,我发现了一个list初始化的问题。就是set必须是new出来的具体list初始化之后才能使用,不然就会报错。下面就研究一下set和add。 package yanning; import java.util.LinkedList; import java.util.List
Given an index k, return the kth row of the Pascal’s triangle. For example, given k = 3, Return [1,3,3,1]. Note: Could you optimize your algorithm to use only O(k) extra space? public
今天研究了一下Java多线程,顺便写了一下多线程中的经典问题—–生产者消费者经典问题,推荐一个线程链接Java基础知识回顾–线程 这个里面其实写了生产者与消费者问题,估计在后面大家看起来比较费劲,所以我提取出来再讲解一遍。 package yanning; public class ProducerConsumer { public static void m
Given numRows, generate the first numRows of Pascal’s triangle. For example, given numRows = 5, Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] 我是用数组做的,在草稿纸上稍微画一画应该就能找
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given the below binary tr
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. 这个算法的难点就是,要判断左边或右边是否为空,因为如果
摘要: 以下是我收集的 Java 开发牛人必备的网站。这些网站可以提供信息,以及一些很棒的讲座, 还能解答一般问题、面试问题等。质量是衡量一个网站的关键因素,我个人认为这些网站质 量都很好。接下来,我会跟大家分享我是如何使用这些网站学习和娱乐的。或许你会认为有些网站适合任何水平的开发者,但是我认为:对于 Java 开发牛人来说,网站的好坏取决于如何使用它们。 英文原文: T
问题:如果main方法被声明为private会怎样? 答案:能正常编译,但运行的时候会提示”main方法不是public的”。 问题:Java里的传引用和传值的区别是什么? 答案:传引用是指传递的是地址而不是值本身,传值则是传递值的一份拷贝。 问题:如果要重写一个对象的equals方法,还要考虑什么? 答案:hashCode。 问题:Java的”一次编写,处处运行
这个也是一点点更新哈,不会一次写完。 String 和StringBuffer的区别 JAVA平台提供了两个类:String和StringBuffer,它们可以储存和操作字符串,即包含多个字符的字符数据这个String类提供了数值不可改变字符串而这个StringBuffer类提供的字符串进行修改当你知道字符数据要改变的时候你就可以使用StringBuffer典型地,你可以
1.前台后台都做吗? 10分 这一般是我的第一个问题,超过90%的人会回答:”都做,后台多一点,前台少一点” 这不是我想要的答案,鬼都知道程序员都要多少涉及一下前台,后台更不用说了. 碰到过一个聪明人,他是这么回答的: 前台js写的比较熟练,html的框架模板也能搭建的非常整齐美观,只是特效能力比较差 这个问题我不想过多讨论,加分但不减分 2.事务,什么是事务,为何
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node ne
Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root). For example: Given binary tree [3,9,20,nu
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. 二话不说,递归求解,一次通过。 public int
Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level). For example: Given binary tree [3,9,20,null,null,15,7], 3 / \ 9
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
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. pub
Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 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? 这是一个很经典的爬楼梯问题,面试也会经常遇
Given two binary strings, return their sum (also a binary string). For example, a = “11” b = “1” Return “100”. 二进制算法,加上对字符串的处理。 public String addBinary(String a, String b) {
Given a non-negative number represented as an array of digits, plus one to the number. The digits are stored such that the most significant digit is at the head of the list. 题目的意思就是把这个数组代
Given a string s consists of upper/lower-case alphabets and empty space characters ’ ‘, return the length of last word in the string. If the last word does not exist, return 0. Note: A wo
The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, … 1 is read off as “one 1” or 11. 11 is read off as “two 1s” or 21. 21 is read off
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character ‘.’. A partially fi
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 就是找到子串第一次出现的 位置。 public int strStr(String haystack, String n
Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you must do this in place with constant me
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this in p
Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should u
Merge 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. 这里sorted说的是从小到大。 /** * Definition for singly
Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid. The brackets must close in the correct order, “()” and “()[]{}” are a