牛客网 剑指offer
PENGGB023
电音与代码也许是一对儿...
展开
-
二维数组中的查找
public class Solution { public boolean Find(int target, int [][] array) { try { for (int i = 0; i < array.length; i++) { if (array[i][0] > target) { // 如果比array[原创 2017-06-09 17:57:32 · 212 阅读 · 0 评论 -
数值的整数次方
import java.math.BigDecimal;public class Solution { public double Power(double base, int exponent) { boolean isSub = false; BigDecimal result = new BigDecimal(base+"");原创 2017-06-09 18:04:34 · 189 阅读 · 0 评论 -
调整数组顺序使奇数位于偶数前面
public class Solution { public void reOrderArray(int [] array) { int k = 0; for (int i = 0; i < array.length; i++) { if (array[i] % 2 != 0) { int temp =原创 2017-06-09 18:05:19 · 222 阅读 · 0 评论 -
链表中倒数第k个结点
/*public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; }}*/public class Solution { public ListNode FindKthToTail(ListNode head,int k)原创 2017-06-09 18:06:03 · 201 阅读 · 0 评论 -
反转链表
/*struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { }};*/class Solution {public: ListNode* ReverseList(ListNode* pHead) {原创 2017-06-09 18:06:29 · 205 阅读 · 0 评论 -
合并两个排序的链表
/*struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { }};*/class Solution {public: ListNode* Merge(ListNode* pHead1, ListNode* p原创 2017-06-09 18:07:08 · 218 阅读 · 0 评论 -
树的子结构
/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { }};*/class Solution {public: bool原创 2017-06-09 18:07:36 · 222 阅读 · 0 评论 -
二叉树的镜像
/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { }};*/class Solution {public: void原创 2017-06-09 18:08:18 · 206 阅读 · 0 评论 -
顺时针打印矩阵
class Solution {public: vector<int> printMatrix(vector<vector<int> > matrix) { int direction[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; int m = matrix.size(); int n = matr原创 2017-06-09 18:08:50 · 243 阅读 · 0 评论 -
进制中1的个数
public class Solution { public int NumberOf1(int n) { int num = 0; // 负数在计算机中以补码形式存在,补码为原码最高位不变,其余位取反再加1 // ~取反操作符,是连最高位也取反。 // 整数左移在末尾添0,右移在前面添0 // 负数左移在末尾添原创 2017-06-09 18:04:07 · 278 阅读 · 0 评论 -
矩形覆盖
public class Solution { public int RectCover(int target) { if (target == 0) return 0; if (target == 1) return 1; if (target == 2) return原创 2017-06-09 18:03:37 · 193 阅读 · 0 评论 -
替换空格
public class Solution { public String replaceSpace(StringBuffer str) { return str.toString().replaceAll(" ", "%20"); }}原创 2017-06-09 17:58:25 · 284 阅读 · 0 评论 -
从尾到头打印链表
/*** public class ListNode {* int val;* ListNode next = null;** ListNode(int val) {* this.val = val;* }* }**/import java.util.ArrayList;public c原创 2017-06-09 17:59:14 · 188 阅读 · 0 评论 -
重建二叉树
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { public原创 2017-06-09 17:59:55 · 235 阅读 · 0 评论 -
用两个栈实现队列
import java.util.Stack;public class Solution { Stack<Integer> stack1 = new Stack<Integer>(); Stack<Integer> stack2 = new Stack<Integer>(); public void push(int node) { // 入栈数据时,将入栈的数原创 2017-06-09 18:00:26 · 172 阅读 · 0 评论 -
旋转数组的最小数字
import java.util.ArrayList;public class Solution { public int minNumberInRotateArray(int [] array) { if (array == null || array.length == 0) { return 0; } int m原创 2017-06-09 18:01:09 · 192 阅读 · 0 评论 -
斐波拉契数列
public class Solution { public int Fibonacci(int n) { int[] array = new int[40] ; array[1] = 1; array[2] = 1; for (int i = 3; i <= n; i++) array[i] = arr原创 2017-06-09 18:01:40 · 291 阅读 · 0 评论 -
跳台阶
public class Solution { public int JumpFloor(int target) { if (target == 1) return 1; if (target == 2) return 2; int[] array = new int [target + 1];原创 2017-06-09 18:02:28 · 199 阅读 · 0 评论 -
变态跳台阶
public class Solution { public int JumpFloorII(int target) { int[] array = new int[target+1]; array[0] = 1; array[1] = 1; for(int i = 2; i <= target; i++) {原创 2017-06-09 18:02:53 · 320 阅读 · 0 评论 -
包含min函数的栈
#include <stack>using namespace std;class Solution {public: void push(int value) { s.push(value); } void pop() { if (!s.empty()) {s.pop();} } int top()原创 2017-06-09 18:09:37 · 313 阅读 · 0 评论