自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

Queen_Bey的博客

Queen Bey

  • 博客(136)
  • 收藏
  • 关注

原创 110. Balanced Binary Tree

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 never diff...

2018-08-07 23:57:00 123

原创 109. Convert Sorted List to Binary Search Tree

Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which the ...

2018-08-07 23:37:40 125

原创 378. Kth Smallest Element in a Sorted Matrix

Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.Note that it is the kth smallest element in the sorted order, not the...

2018-03-29 22:59:06 156

原创 371. Sum of Two Integers

Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example:Given a = 1 and b = 2, return 3.Credits:Special thanks to @fujiaozhu for adding this problem and ...

2018-03-29 22:43:02 136

原创 347. Top K Frequent Elements

Given a non-empty array of integers, return the k most frequent elements.For example,Given [1,1,1,2,2,3] and k = 2, return [1,2].Note: You may assume k is always valid, 1 ≤ k ≤ number of unique elemen...

2018-03-29 22:31:41 161

原创 344. Reverse String

Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".class Solution {    public String reverseString(String s) {        char[] c = s....

2018-03-29 22:16:31 117

原创 289. Game of Life

According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."Given a board with m by n c...

2018-03-29 22:07:58 117

原创 287. Find the Duplicate Number

Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, fi...

2018-03-29 21:47:07 135

原创 283. Move Zeroes

Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling your fun...

2018-03-29 21:23:00 140

原创 279. Perfect Squares

Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.For example, given n = 12, return 3 because 12 = 4 + 4 + 4; given n = 13, ret...

2018-03-29 20:42:44 130

原创 268. Missing Number

Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.Example 1Input: [3,0,1]Output: 2Example 2Input: [9,6,4,2,3,5,7,0,1]Output: 8Not...

2018-03-29 20:34:27 107

原创 242. Valid Anagram

Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.Note:You may assume the strin...

2018-03-29 20:10:27 134

转载 Spring事务传播特性的浅析——事务方法嵌套调用的迷茫

Spring事务传播特性的浅析——事务方法嵌套调用的迷茫 Spring事务传播机制回顾    Spring事务一个被讹传很广说法是:一个事务方法不应该调用另一个事务方法,否则将产生两个事务。结果造成开发人员在设计事务方法时束手束脚,生怕一不小心就踩到地雷。 其实这是不认识Spring事务传播机制而造成的误解,Spring对事务控制的支持统一在TransactionDefinition类中描述,该类...

2018-03-28 10:29:26 136

原创 240. Search a 2D Matrix II

Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to right.Integers in each col...

2018-03-25 23:17:21 113

原创 239. Sliding Window Maximum

Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window m...

2018-03-25 23:09:54 124

原创 238. Product of Array Except Self

Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O(n).F...

2018-03-25 22:40:29 123

原创 237. Delete Node in a Linked List

Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with ...

2018-03-25 22:31:35 131

原创 236. Lowest Common Ancestor of a Binary Tree

/** * Definition for a binary tree node. * public class TreeNode { *     int val; *     TreeNode left; *     TreeNode right; *     TreeNode(int x) { val = x; } * } */class Solution {    public TreeNod...

2018-03-25 22:29:01 131

原创 234. Palindrome Linked List

/** * Definition for singly-linked list. * public class ListNode { *     int val; *     ListNode next; *     ListNode(int x) { val = x; } * } */class Solution {    public boolean isPalindrome(ListNode...

2018-03-25 22:14:28 122

原创 230. Kth Smallest Element in a BST

Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements.Follow up:What if the BST is modifi...

2018-03-25 22:06:21 113

原创 227. Basic Calculator II

计算器的实现考虑使用栈。class Solution {    public int calculate(String s) {        int length = s.length();        if(s==null || length==0){            return 0;        }        int num = 0;        char sign = '...

2018-03-25 21:51:15 133

原创 217. Contains Duplicate

Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is...

2018-03-25 21:41:05 90

原创 212. Word Search II

用DFclass Solution {    public List<String> findWords(char[][] board, String[] words) {        List<String> res = new ArrayList<String>();        TrieNode root = buildTrie(words);    ...

2018-03-25 21:15:35 158

原创 215. Kth Largest Element in an Array

注意快排在与下标相关的排序题目中。public class Solution {    public int findKthLargest(int[] nums, int k) {        int start = 0, end = nums.length - 1, index = nums.length - k;        while (start < end) {        ...

2018-03-24 22:38:50 89

原创 210. Course Schedule II

public int[] findOrder(int numCourses, int[][] prerequisites) {     if (numCourses == 0) return null;    // Convert graph presentation from edges to indegree of adjacent list.    int indegree[] = new ...

2018-03-24 22:23:19 124

原创 208. Implement Trie (Prefix Tree)

Implement a trie with insert, search, and startsWith methods.class TrieNode {boolean isEnd;TrieNode[] children;public TrieNode() {    isEnd = true;    children = new TrieNode[26];}}public class Trie {...

2018-03-24 22:10:27 126

原创 207. Course Schedule

类似这种节点之间存在单向关系的问题可以用DFS和BFS来实现,而且BFS的性能一般比较好一点。BFS:public class Solution { public boolean canFinish(int numCourses, int[][] prerequisites) { ArrayList[] graph = new ArrayList[numCourses];...

2018-03-24 21:41:41 138

原创 206. Reverse Linked List

Reverse a singly linked list.class Solution {    public ListNode reverseList(ListNode head) {        ListNode node = head;        ListNode prev = null;        while(node != null){            ListNode ...

2018-03-24 20:38:21 129

原创 204. Count Primes

用数组进行记录。public class Solution {    public int countPrimes(int n) {         boolean[] notPrime = new boolean[n];        int count = 0;        for (int i = 2; i < n; i++) {            if (notPrime...

2018-03-24 20:03:47 88

原创 202. Happy Number

用HashSet存储已经出现过的数字,若重复出现肯定就不行了。public boolean isHappy(int n) {    Set<Integer> inLoop = new HashSet<Integer>();    int squareSum,remain;while (inLoop.add(n)) { squareSum = 0;while (n >...

2018-03-24 19:41:31 106

原创 200. Number of Islands

注意深度搜索和广度搜索中,广度搜索的性能会高一些。DFS:public int numIslands(char[][] grid) { int count=0; for(int i=0;i<grid.length;i++) for(int j=0;j<grid[0].length;j++){ if(grid[i][j]=='1')...

2018-03-24 19:21:29 100

原创 198. House Robber

这道题的本质相当于在一列数组中取出一个或多个不相邻数,使其和最大。那么我们对于这类求极值的问题首先考虑动态规划Dynamic Programming来解,我们维护一个一位数组dp,其中dp[i]表示到i位置时不相邻数能形成的最大和,那么递推公式怎么写呢,我们先拿一个简单的例子来分析一下,比如说nums为{3, 2, 1, 5},那么我们来看我们的dp数组应该是什么样的,首先dp[0]=3没啥疑问,...

2018-03-24 17:38:52 130

原创 191. Number of 1 Bits

public static int hammingWeight(int n) {int ones = 0;    while(n!=0) {    ones = ones + (n & 1);    n = n>>>1;    }    return ones;}

2018-03-24 16:46:31 115

原创 190. Reverse Bits

注意有符号右移和无符号右移的区别。public int reverseBits(int n) {    int result = 0;    for (int i = 0; i < 32; i++) {        result += n & 1;        n >>>= 1;   // CATCH: must do unsigned shift       ...

2018-03-22 15:21:10 108

原创 189. Rotate Array

public void rotate(int[] nums, int k) {    k %= nums.length;    reverse(nums, 0, nums.length - 1);    reverse(nums, 0, k - 1);    reverse(nums, k, nums.length - 1);}public void reverse(int[] nums, int...

2018-03-20 23:21:23 104

原创 179. Largest Number

public class Solution {     public String largestNumber(int[] num) {if(num == null || num.length == 0)     return "";// Convert int array to String array, so we can sort later onString[] s_num = new ...

2018-03-20 23:14:48 110

原创 172. Factorial Trailing Zeroes

只需数字中有多少个因子“5”就可以了,因为因子“2”的数量肯定要比“5”的数量多。public class Solution {    public int trailingZeroes(int n) {        int r = 0;        while (n > 0) {            n /= 5;            r += n;        }       ...

2018-03-20 23:08:04 102

原创 171. Excel Sheet Column Number

注意到进制转换的问题,10进制与其它进制的转换。public int titleToNumber(String s) {    int result = 0;    for(int i = 0 ; i < s.length(); i++) {      result = result * 26 + (s.charAt(i) - 'A' + 1);    }    return result;...

2018-03-20 22:58:06 118

原创 169. Majority Element

public int majorityElement3(int[] nums) {    int count=0, ret = 0;    for (int num: nums) {        if (count==0)            ret = num;        if (num!=ret)            count--;        else            c...

2018-03-20 22:51:56 119

原创 166. Fraction to Recurring Decimal

注意除法被除数由取余产生,当余数之前出现过的时候最后结果就是循环小数,余数只能小于被除数,所以是有限个,当出现循环或者余数为零,除法就结束了。public class Solution {    public String fractionToDecimal(int numerator, int denominator) {        if (numerator == 0) {        ...

2018-03-20 22:33:05 94

空空如也

空空如也

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

TA关注的人

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