Menu Sidebar
Menu

Archive: September 7, 2015

H-Index II

public class Solution { public int hIndex(int[] citations) { int l = 0; int r = citations.length – 1; while(l<=r) { int m = l + (r-l) / 2; if(citations[m] < citations.length – m) l=m+1; else r=m-1; } return citations.length – l; } }

H-Index

public class Solution { public int hIndex(int[] citations) { if(citations == null || citations.length == 0) return 0; Arrays.sort(citations); // 0 1 3 5 6 for(int i = 0; i < citations.length; i++){ int index = citations.length – i; if(citations[i] >= index) return index; } return 0; } }  

[SPOJ] ONP – Transform the Expression

原题: http://www.spoj.com/problems/ONP/ 题目大意: 一个代数表达式转换成Reverse Polish Notation. 分析: wiki上就有规则. 其实这个题只有三个规则: 看到(, 忽略 看到操作符(加减乘除)入栈 看到), 出栈,打印 其余直接打印 public class ONP { public void solve(int testNumber, InputReader in, OutputWriter out) { String s = in.readLine(); out.printLine(infixToPostfix(s)); } public String infixToPostfix(String infix) { Stack<Character> st = new Stack<>(); StringBuffer sb = new StringBuffer(); String opt = “+-*/^”; for (int i […]

书脊

这青苔碧瓦堆, 俺曾睡风流觉, 将五十年兴亡看饱.

September 2015
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
282930