- 博客(164)
- 问答 (1)
- 收藏
- 关注
原创 关于 原码 反码 与 补码
今天做leetcode 405. Convert a Number to Hexadecimal要求把一个数转化成二进制十六进制,是补码形式的正数的时候很容易,但到了负数就有点懵逼了.然后恶补了一下原码 反码 补码 的知识,成功解题1. 原码所谓原码就是符号位加上数字的二进制表示,int为例,第一位表示符号 (0正数 1负数)简单期间一个字节表示+7的原码为: 000...
2018-03-17 14:31:14 671
原创 606. Construct String from Binary Tree
You need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way.The null node needs to be represented by empty parenthesis pair “()”. And you ...
2018-03-17 10:09:35 132
原创 492. Construct the Rectangle
For a web developer, it is very important to know how to design a web page’s size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L...
2018-03-16 01:34:28 111
原创 LeetCode 596. Classes More Than 5 Students
There is a table courses with columns: student and classPlease list out all classes which have more than or equal to 5 students.For example, the table:+---------+------------+| student | clas...
2018-03-16 00:54:11 185
原创 LeetCode 563. Binary Tree Tilt
Given a binary tree, return the tilt of the whole tree.The tilt of a tree node is defined as the absolute difference between the sum of all left subtree node values and the sum of all right subtree ...
2018-03-15 23:40:00 123
原创 LeetCode 693. Binary Number with Alternating Bits
Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.Example 1:Input: 5Output: TrueExplanation:The binary representati...
2018-03-15 15:21:22 164
原创 LeetCode 682. Baseball Game
You’re now a baseball game point recorder.Given a list of strings, each string can be one of the 4 following types:Integer (one round’s score): Directly represents the number of points you get in ...
2018-03-15 14:07:53 185
原创 LeetCode 190. Reverse Bits
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 00111001011...
2018-03-14 00:16:50 101
原创 LeetCode160. Intersection of Two Linked Lists
Write a SQL query to find all duplicate emails in a table named Person.+----+---------+| Id | Email |+----+---------+| 1 | a@b.com || 2 | c@d.com || 3 | a@b.com |+----+---------+For e...
2018-03-13 19:18:49 112
原创 LeetCode 181. Employees Earning More Than Their Managers
The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.+----+-------+--------+-----------+| Id | Name | Salary |...
2018-03-13 18:33:53 177
原创 175. Combine Two Tables
Table: Person+-------------+---------+| Column Name | Type |+-------------+---------+| PersonId | int || FirstName | varchar || LastName | varchar |+-------------+---------+...
2018-03-13 14:46:47 82
原创 LeetCode 160. Intersection of Two Linked Lists
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 ↘ ...
2018-03-13 14:26:21 88
原创 LeetCode 136. Single Number
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 using extra...
2018-03-13 01:08:33 109
原创 LeeCode 125. Valid Palindrome
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” is not a pa...
2018-03-13 00:25:18 133
原创 LeetCode 196. Delete Duplicate Emails
Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id.+----+------------------+| Id | Email |+----+-----...
2018-03-13 00:06:25 97
原创 LeetCode 665. Non-decreasing Array
Given an array with n integers, your task is to check if it could become non-decreasing by modifying at most 1 element.We define an array is non-decreasing if array[i] <= array[i + 1] holds for e...
2018-03-12 01:51:24 97
转载 Java中数组复制的几种方法
/** * @author zhengbinMac */public class Test { public static void main(String[] args) { int[] array1 = {1,2,3,4,5}; // 1.通过for循环 int[] array2 = new int[5]; for(...
2018-03-12 01:08:15 155
原创 LeetCode 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 diffe...
2018-03-12 00:27:49 87
原创 LeetCode 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.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the...
2018-03-11 23:13:52 87
原创 LeetCode 14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings. public String getPrefix(String str1, String str2) { String result = ""; String duan = ""; ...
2018-03-11 22:50:08 82
原创 LeetCode 83. Remove Duplicates from Sorted List
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->2->3....
2018-03-11 00:43:44 89
原创 LeetCode 69. Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x.x is guaranteed to be a non-negative integer.Example 1:Input: 4Output: 2Example 2:Input: 8Output: 2Explanation: The...
2018-03-11 00:32:55 111
原创 LeetCode 134. Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its ...
2018-03-10 01:07:36 167
原创 LeetCode 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 dep
2018-03-09 00:21:44 106
原创 LeetCode 140. Word Break II
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is a valid dictionary word. You may assume the dictio...
2018-03-08 18:20:04 114
原创 LeetCode 139. Word Break
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words. You may assu...
2018-03-08 00:09:25 126
原创 LeetCode 103. Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes’ values. (ie, from left to right, then right to left for the next level and alternate between).For example: Given binary tree
2018-03-07 22:05:48 108
原创 LeetCode 106. Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree.Note: You may assume that duplicates do not exist in the tree.For example, giveninorder = [9,3,15,20,7]postorder = [9,15,7,2
2018-03-07 16:45:06 246
原创 LeetCode 142. Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.Follow up: Can you solve it without using extra space?设置快慢指针,快指针速度2.慢
2018-03-06 01:14:57 94
原创 LeetCode 141. Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up: Can you solve it without using extra space?两种解法 1.遍历链表,用set存储.若发现已存在节点,则成环2.用快慢指针,若成环,最终快指针会从后追上慢指针. 该方法不消耗额外的空间解法1.public boolean h
2018-03-06 01:07:01 92
原创 堆排序
一直对这种排序没有仔细了解,今天学习了一下1.排序规则若是升序,则先构建大顶堆,反之构建小顶堆 2.该例使用升序排序 给定一个整形数组a[]={20,50,10,30,70,20,80}首先构造大顶堆 注意这里,元素20和元素80交换后,20所在的节点还有子节点,所以还要再和它的子节点5 6的元素进行比较,因此代码中adjustHeap函数递归调用,以防止交换后原节点不满足规则至此有序堆已经构
2018-03-05 01:49:03 103
原创 spark函数aggregate 简单实例理解
首先,Spark文档中aggregate函数定义如下def aggregate[U](zeroValue: U)(seqOp: (U, T) ⇒ U, combOp: (U, U) ⇒ U)(implicit arg0: ClassTag[U]): U这是一个柯里化函数,第一个参数列表中传一个初始化值,柯里化的目的是让后一个参数列表中的类型可以由前一个参数列表中参数类型进行推演得到...
2018-02-23 06:08:04 588
原创 更新集群文件scp简化脚本
经常会遇到集群中的某一个文件需要同步更新。 手动获取到文件绝对路径再使用scp命令有些繁琐 由于所有需要更新的文件在集群存储的路径都是相同的 于是写了一个简化脚本(自用)#!/bin/bashfilepath=`cd $(dirname $1); pwd`nodeNums=`expr $# - 1`if [ $nodeNums -lt 1 ]then echo '参数少
2018-02-18 02:23:43 546
原创 LeetCode 56. Merge Intervals
Given a collection of intervals, merge all overlapping intervals.For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18].public List<Interval> merge(List<Interval> intervals) {
2018-01-04 09:42:22 158
原创 LeetCode 91. Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total number of w
2018-01-03 19:30:43 221
原创 LeetCode 67. Add Binary
Given two binary strings, return their sum (also a binary string).For example, a = “11” b = “1” Return “100”.初始化tmp 每一位和tmp的值相加 tmp / 2为下一轮的tmp tmp % 2为该位应该填上的数 public String addBinary(String a,
2018-01-03 16:15:38 150
原创 LeetCode 54. Spiral Matrix
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example, Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]You should
2018-01-03 00:43:27 155
原创 LeetCode 48. Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note: You have to rotate the image in-place, which means you have to modify the input 2D matrix direct
2018-01-02 21:13:04 151
原创 LeetCode 104. Maximum Depth of Binary Tree
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 m
2018-01-02 16:46:48 136
原创 LeetCode 100. Same Tree
Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes have the same value.Example 1:Inp
2018-01-01 23:45:37 141
空空如也
接入有米广告sdk时遇到空指针报错,求帮忙
2016-09-15
TA创建的收藏夹 TA关注的收藏夹
TA关注的人