|
亲!马上注册或者登录会查看更多内容!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
请大家尽快加入YY频道。加入方法:登录YY后,右下角搜索YY频道,我们的模拟面试yy频道号码是:77475576
今天的面试官:Max 清歌
今天的求职者:Apollo_synth
今天的题目两道,一道coding,一道design题目。
下面是白板:
https://docs.google.com/document ... 8x8L4fi9Vvj97A/edit
模拟面试白板,现在正在coding
- public List<String[]> solveQueen() {
- List<String[]> rst = new ArrayList<String[]>();
- ArrayList<Integer> cols = new ArrayList<Integer>();
- helper(8, cols, rst);
- return rst;
- }
- private boolean helper(int n, ArrayList<Integer> cols, List<String[]> rst) {
- if (cols.size() == n) {
- String[] sol = creatSol(n, cols);
- rst.add(sol);
- return true;
- }
- for (int i = 0; i < n; i++) {
- if (!valid(cols, i)) {
- continue;
- }
- cols.add(i);
- boolean rst = helper(n, cols, rst);
- cols.remove(cols.size() - 1);
- }
- return rst;
- }
- private String[] createSol(int n, ArrayList<Integer> cols) {
- String[] rst = new String[n];
- for (int i = 0; i < n; i++) {
- StringBuilder sb = new StringBuilder();
- for (int j = 0; j < n; j++) {
- sb.append(‘.’);
- }
- sb.setCharAt(cols.get(i), ‘Q’);
- rst【i】 = sb.toString();
- }
- return rst;
- }
- private boolean isValid(ArrayList<Integer> cols, int col) {
- int row = cols.size();
- for (int i = 0; i < row; i++) {
- if (cols.get(i) == col) {
- return false;
- }
- if (i - cols.get(i) == row - col) {
- return false;
- }
- if (i + cols.get(i) == row + col) {
- return false;
- }
- }
- return true;
- }
- ----
- function makeRequest(data, callback) {
- setTimeout(function() {
- console.log('a');
- callback(null, 'success');
- }, 1000);
- }
- makeRequestion();
- console.log('b');
- // b
- // a
- var fakeData = {};
- makeRequest(fakeData, function(err, result) {
- if (err) return err;
- console.log(result);
- };
- // Promise
- var promise = Promisify(makeRequest);
- promise(fakeData).next(function(result) {
- console.log('b');
- };
- // a
- // b
- // how would we implement Promises
- function Promisify(func) {
- arguments.push(then);
- func.apply(arguments)
- return {
- then: then function(result) {
- }
- };
- }
复制代码
|
|